Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli with deno #59

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class
config.json
21 changes: 21 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Class cli

## Usage

```shell
deno --allow-read main.ts config.json
```

## Compiled executable

```shell
deno compile --allow-read -o class main.ts
ls -lnh class
-rwxr-xr-x 1 1000 1000 84M Oct 11 18:38 class
```

Run with

```shell
./class config.json
```
10 changes: 10 additions & 0 deletions packages/cli/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@classmodel/cli",
"version": "0.0.3",
"tasks": {
"dev": "deno run --watch main.ts"
},
"imports": {
"@classmodel/class": "jsr:@classmodel/class@^0.0.3"
}
}
45 changes: 45 additions & 0 deletions packages/cli/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions packages/cli/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { classConfig } from "@classmodel/class/config";
import { runClass } from "@classmodel/class/runner";

function main(args: string[], logger = console) {
if (args.length !== 1) {
console.error("Usage: class <config-file.json>");
Deno.exit(1);
}
try {
const configFile = args[0];
const configAsString = Deno.readTextFileSync(configFile);
const rawConfig = JSON.parse(configAsString);
const config = classConfig.parse(rawConfig);
const output = runClass(config);
logger.log(JSON.stringify(output, null, 2));
} catch (error) {
logger.error("Error running class:", error);
Deno.exit(1);
}
}

// Learn more at https://docs.deno.com/runtime/manual/examples/module_metadata#concepts
if (import.meta.main) {
main(Deno.args);
}