Initial commit: Crypto trader application

This commit is contained in:
2025-12-25 20:20:40 -05:00
commit 07a04c1bb8
47895 changed files with 2042266 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) Pooya Parsa <pooya@pi0.io> and Anthony Fu <https://github.com/antfu>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+202
View File
@@ -0,0 +1,202 @@
# 🧀 Magicast
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![bundle][bundle-src]][bundle-href]
[![Codecov][codecov-src]][codecov-href]
[![License][license-src]][license-href]
[![JSDocs][jsdocs-src]][jsdocs-href]
Programmatically modify JavaScript and TypeScript source codes with a simplified, elegant and familiar syntax. Built on top of the [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) parsed by [recast](https://github.com/benjamn/recast) and [babel](https://babeljs.io/).
🧙🏼 **Magical** modify a JS/TS file and write back magically just like JSON!<br>
🔀 **Exports/Import** manipulate module's imports and exports at ease<br>
💼 **Function Arguments** easily manipulate arguments passed to a function call, like `defineConfig()`<br>
🎨 **Smart Formatting** preseves the formatting style (quotes, tabs, etc.) from the original code<br>
🧑‍💻 **Readable** get rid of the complexity of AST manipulation and make your code super readable<br>
## Install
Install npm package:
```sh
yarn add --dev magicast
npm install -D magicast
pnpm add -D magicast
```
Import utilities:
```js
import { parseModule, generateCode, builders, createNode } from "magicast";
```
## Examples
**Example:** Modify a file:
`config.js`:
```js
export default {
foo: ["a"],
};
```
Code to modify and append `b` to `foo` prop of defaultExport:
```js
import { loadFile, writeFile } from "magicast";
const mod = await loadFile("config.js");
mod.exports.default.foo.push("b");
await writeFile(mod, "config.js");
```
Updated `config.js`:
```js
export default {
foo: ["a", "b"],
};
```
**Example:** Directly use AST utils:
```js
import { parseModule, generateCode } from "magicast";
// Parse to AST
const mod = parseModule(`export default { }`);
// Ensure foo is an array
mod.exports.default.foo ||= [];
// Add a new array member
mod.exports.default.foo.push("b");
mod.exports.default.foo.unshift("a");
// Generate code
const { code, map } = generateCode(mod);
```
Generated code:
```js
export default {
foo: ["a", "b"],
};
```
**Example:** Get the AST directly:
```js
import { parseModule, generateCode } from "magicast";
const mod = parseModule(`export default { }`);
const ast = mod.exports.default.$ast;
// do something with ast
```
**Example:** Function arguments:
```js
import { parseModule, generateCode } from "magicast";
const mod = parseModule(`export default defineConfig({ foo: 'bar' })`);
// Support for both bare object export and `defineConfig` wrapper
const options =
mod.exports.default.$type === "function-call"
? mod.exports.default.$args[0]
: mod.exports.default;
console.log(options.foo); // bar
```
**Example:** Create a function call:
```js
import { parseModule, generateCode, builders } from "magicast";
const mod = parseModule(`export default {}`);
const options = (mod.exports.default.list = builders.functionCall(
"create",
[1, 2, 3],
));
console.log(mod.generateCode()); // export default { list: create([1, 2, 3]) }
```
## Notes
As JavaScript is a very dynamic language, you should be aware that Magicast's convention **CAN NOT cover all possible cases**. Magicast serves as a simple and maintainable interface to update static-ish JavaScript code. When interacting with Magicast node, be aware that every option might have chance to throw an error depending on the input code. We recommend to always wrap the code in a `try/catch` block (even better to do some defensive coding), for example:
```ts
import { loadFile, writeFile } from "magicast";
function updateConfig() {
try {
const mod = await loadFile("config.js");
mod.exports.default.foo.push("b");
await writeFile(mod);
} catch {
console.error("Unable to update config.js");
console.error(
"Please update it manually with the following instructions: ...",
);
// handle error
}
}
```
## High Level Helpers
We also experiment to provide a few high level helpers to make common tasks easier. You could import them from `magicast/helpers`. They might be moved to a separate package in the future.
```js
import {
deepMergeObject,
addNuxtModule,
addVitePlugin,
// ...
} from "magicast/helpers";
```
We recommend to check out the [source code](./src/helpers) and [test cases](./test/helpers) for more details.
## Development
- Clone this repository
- Install latest LTS version of [Node.js](https://nodejs.org/en/)
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`
## License
Made with 💛
Published under [MIT License](./LICENSE).
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/magicast?style=flat&colorA=18181B&colorB=F0DB4F
[npm-version-href]: https://npmjs.com/package/magicast
[npm-downloads-src]: https://img.shields.io/npm/dm/magicast?style=flat&colorA=18181B&colorB=F0DB4F
[npm-downloads-href]: https://npmjs.com/package/magicast
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/magicast/main?style=flat&colorA=18181B&colorB=F0DB4F
[codecov-href]: https://codecov.io/gh/unjs/magicast
[bundle-src]: https://img.shields.io/bundlephobia/minzip/magicast?style=flat&colorA=18181B&colorB=F0DB4F
[bundle-href]: https://bundlephobia.com/result?p=magicast
[license-src]: https://img.shields.io/github/license/unjs/magicast.svg?style=flat&colorA=18181B&colorB=F0DB4F
[license-href]: https://github.com/unjs/magicast/blob/main/LICENSE
[jsdocs-src]: https://img.shields.io/badge/jsDocs.io-reference-18181B?style=flat&colorA=18181B&colorB=F0DB4F
[jsdocs-href]: https://www.jsdocs.io/package/magicast
+71
View File
@@ -0,0 +1,71 @@
{
"name": "magicast",
"version": "0.5.1",
"description": "Modify a JS/TS file and write back magically just like JSON!",
"repository": "unjs/magicast",
"license": "MIT",
"sideEffects": false,
"type": "module",
"exports": {
".": "./dist/index.js",
"./helpers": "./dist/helpers/index.js",
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"dependencies": {
"@babel/parser": "^7.28.5",
"@babel/types": "^7.28.5",
"source-map-js": "^1.2.1"
},
"devDependencies": {
"@types/node": "^24.9.1",
"@vitest/coverage-v8": "^4.0.4",
"@vitest/ui": "^4.0.4",
"ast-types": "^0.16.1",
"bumpp": "^10.3.1",
"eslint": "^9.38.0",
"eslint-config-unjs": "^0.5.0",
"giget": "^2.0.0",
"jiti": "^2.6.1",
"lint-staged": "^16.2.6",
"prettier": "^3.6.2",
"recast": "^0.23.11",
"simple-git-hooks": "^2.13.1",
"source-map": "npm:source-map-js@latest",
"taze": "^19.8.1",
"tsdown": "^0.15.11",
"tsx": "^4.20.6",
"typescript": "^5.9.3",
"vitest": "^4.0.4",
"magicast": "0.5.1"
},
"resolutions": {
"source-map": "npm:source-map-js@latest"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*.{ts,js,mjs,cjs}": [
"eslint --fix",
"prettier -w"
]
},
"scripts": {
"build": "tsdown",
"dev": "vitest dev",
"dev:ui": "vitest dev --ui",
"lint": "eslint --cache . && prettier -c .",
"lint:fix": "eslint --cache . --fix && prettier -c . -w",
"typecheck": "tsc --noEmit",
"release": "pnpm run test run && bumpp",
"test": "vitest",
"test:build": "TEST_BUILD=true vitest",
"test:full": "pnpm run test --run && pnpm run build && pnpm run test:build --run"
}
}