mowascript
Version:
MowaScript language implementation
110 lines (78 loc) โข 2.27 kB
Markdown
[[๐ Interslavic](../../05_cli.md) ยท [๐ฒ East Slavic](../east/05_cli.md)]
# ๐ป MowaJS Command-Line Interface (CLI)
MowaJS comes with a built-in CLI that lets you quickly run, compile, watch, and initialize projects using `.mowa` files.
## ๐ฆ Installation (globally or via `npx`)
```bash
# global installation
npm install -g mowascript
mowa init
npm install
npm run watch
# or run directly via npx
npx mowascript <command>
```
## ๐ง CLI Commands
### `mowa init <project_name>`
Initializes a new project with starter structure and templates:
```
my-project/
โโโ docs/
โ โโโ doc.md
โโโ src/
โ โโโ index.mowa
โโโ dist/
โโโ package.json
โโโ README.md
```
๐งฉ Creates `package.json`, copies template files, adds dependencies.
### `mowa build`
Compiles all `.mowa` files from `src/` into `.js` files in `dist/`.
- Reads all `.mowa` files in `src/`
- Transpiles them to JavaScript
- Saves output in `dist/` with the same structure
### `mowa run <file.mowa>`
Runs a `.mowa` file directly:
- Transpiles to JavaScript
- Prints the output code to console
- Executes it via `eval`
### `mowa watch`
Watch mode:
- Watches all `.mowa` files inside `src/`
- Automatically recompiles on change
- Deletes corresponding `.js` when `.mowa` is removed
Super useful during development โ no need to re-run `build` manually.
## ๐ Under the Hood
The CLI is implemented in `mowa.js`. Core functions include:
- `initProject()` โ creates structure and package.json
- `buildProject()` โ compiles `.mowa` โ `.js`
- `runFile()` โ runs a file via `eval`
- `watchProject()` โ live watch and transpile
## ๐ง Tips
- Use `mowa watch` during development
- Write code in `src/`, results appear in `dist/`
- Add `npm run build` to your scripts for convenience
## โ Sample `package.json` after `init`
```json
{
"name": "my-project",
"version": "1.0.0",
"type": "module",
"scripts": {
"build": "mowa build",
"start": "node dist/index.js"
},
"dependencies": {
"mowascript": "^1.0.0"
}
}
```
This CLI is the heart of MowaJS. It makes running, compiling, and bootstrapping projects smooth โ and your experience delightfully Slavic โค๏ธ