@asterai/cli 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @asterai/cli
20
20
  $ asterai COMMAND
21
21
  running command...
22
22
  $ asterai (--version)
23
- @asterai/cli/0.6.1 linux-x64 node-v20.12.2
23
+ @asterai/cli/0.6.2 linux-x64 node-v20.12.2
24
24
  $ asterai --help [COMMAND]
25
25
  USAGE
26
26
  $ asterai COMMAND
@@ -53,7 +53,7 @@ EXAMPLES
53
53
  $ asterai auth
54
54
  ```
55
55
 
56
- _See code: [src/commands/auth.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.1/src/commands/auth.ts)_
56
+ _See code: [src/commands/auth.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.2/src/commands/auth.ts)_
57
57
 
58
58
  ## `asterai deploy`
59
59
 
@@ -77,7 +77,7 @@ EXAMPLES
77
77
  $ asterai deploy --app 66a46b12-b1a7-4b72-a64a-0e4fe21902b6
78
78
  ```
79
79
 
80
- _See code: [src/commands/deploy.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.1/src/commands/deploy.ts)_
80
+ _See code: [src/commands/deploy.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.2/src/commands/deploy.ts)_
81
81
 
82
82
  ## `asterai help [COMMAND]`
83
83
 
@@ -105,7 +105,11 @@ Initialise a new plugin project
105
105
 
106
106
  ```
107
107
  USAGE
108
- $ asterai init [OUTDIR]
108
+ $ asterai init [OUTDIR] [--typescript] [--rust]
109
+
110
+ FLAGS
111
+ --rust init a the plugin project in rust
112
+ --typescript init a the plugin project in typescript
109
113
 
110
114
  DESCRIPTION
111
115
  Initialise a new plugin project
@@ -114,7 +118,7 @@ EXAMPLES
114
118
  $ asterai init project-name
115
119
  ```
116
120
 
117
- _See code: [src/commands/init.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.1/src/commands/init.ts)_
121
+ _See code: [src/commands/init.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.2/src/commands/init.ts)_
118
122
 
119
123
  ## `asterai pkg [INPUT]`
120
124
 
@@ -139,7 +143,7 @@ EXAMPLES
139
143
  $ asterai pkg
140
144
  ```
141
145
 
142
- _See code: [src/commands/pkg.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.1/src/commands/pkg.ts)_
146
+ _See code: [src/commands/pkg.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.2/src/commands/pkg.ts)_
143
147
 
144
148
  ## `asterai query`
145
149
 
@@ -162,5 +166,5 @@ EXAMPLES
162
166
  $ asterai query
163
167
  ```
164
168
 
165
- _See code: [src/commands/query.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.1/src/commands/query.ts)_
169
+ _See code: [src/commands/query.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.2/src/commands/query.ts)_
166
170
  <!-- commandsstop -->
package/bin/dev.js CHANGED
File without changes
@@ -1,10 +1,17 @@
1
1
  import { Command } from "@oclif/core";
2
+ export type InitFlags = {
3
+ rust?: boolean;
4
+ typescript?: boolean;
5
+ };
2
6
  export default class Codegen extends Command {
3
7
  static args: {
4
8
  outDir: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
9
  };
6
10
  static description: string;
7
11
  static examples: string[];
8
- static flags: {};
12
+ static flags: {
13
+ typescript: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
14
+ rust: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
15
+ };
9
16
  run(): Promise<void>;
10
17
  }
@@ -1,9 +1,10 @@
1
- import { Args, Command } from "@oclif/core";
1
+ import { Args, Command, Flags } from "@oclif/core";
2
2
  import path from "path";
3
3
  import fs from "fs";
4
4
  import url from "url";
5
5
  const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
6
- const SOURCE_DIR = path.join(__dirname, "../../asterai-init-plugin");
6
+ const SOURCE_DIR_TYPESCRIPT = path.join(__dirname, "../../init/typescript");
7
+ const SOURCE_DIR_RUST = path.join(__dirname, "../../init/rust");
7
8
  export default class Codegen extends Command {
8
9
  static args = {
9
10
  outDir: Args.string({
@@ -12,10 +13,41 @@ export default class Codegen extends Command {
12
13
  };
13
14
  static description = "Initialise a new plugin project";
14
15
  static examples = [`<%= config.bin %> <%= command.id %> project-name`];
15
- static flags = {};
16
+ static flags = {
17
+ typescript: Flags.boolean({
18
+ default: undefined,
19
+ description: "init a the plugin project in typescript",
20
+ }),
21
+ rust: Flags.boolean({
22
+ default: false,
23
+ description: "init a the plugin project in rust",
24
+ }),
25
+ };
16
26
  async run() {
17
- const { args } = await this.parse(Codegen);
27
+ const { args, flags } = await this.parse(Codegen);
28
+ assertOneLanguageFlag([flags.typescript, flags.rust]);
18
29
  const outDir = path.resolve(args.outDir);
19
- fs.cpSync(SOURCE_DIR, outDir, { recursive: true });
30
+ const sourceDir = getSourceDirByFlag(flags);
31
+ fs.cpSync(sourceDir, outDir, { recursive: true });
20
32
  }
21
33
  }
34
+ const assertOneLanguageFlag = (flags) => {
35
+ const undefinedCount = flags.reduce((acc, curr) => (curr === undefined ? acc + 1 : acc), 0);
36
+ const trueCount = flags.reduce((acc, curr) => (curr ? acc + 1 : acc), 0);
37
+ if (trueCount === 0 && undefinedCount !== 1) {
38
+ throw new Error("one language flag must be set");
39
+ }
40
+ if (trueCount > 1) {
41
+ throw new Error("only one language flag can be set");
42
+ }
43
+ };
44
+ const getSourceDirByFlag = (flags) => {
45
+ if (flags.rust) {
46
+ return SOURCE_DIR_RUST;
47
+ }
48
+ // Typescript is the default option.
49
+ if (flags.typescript === true || flags.typescript === undefined) {
50
+ return SOURCE_DIR_TYPESCRIPT;
51
+ }
52
+ throw new Error("Invalid flags configuration.");
53
+ };
File without changes
File without changes
@@ -103,7 +103,20 @@
103
103
  "examples": [
104
104
  "<%= config.bin %> <%= command.id %> project-name"
105
105
  ],
106
- "flags": {},
106
+ "flags": {
107
+ "typescript": {
108
+ "description": "init a the plugin project in typescript",
109
+ "name": "typescript",
110
+ "allowNo": false,
111
+ "type": "boolean"
112
+ },
113
+ "rust": {
114
+ "description": "init a the plugin project in rust",
115
+ "name": "rust",
116
+ "allowNo": false,
117
+ "type": "boolean"
118
+ }
119
+ },
107
120
  "hasDynamicHelp": false,
108
121
  "hiddenAliases": [],
109
122
  "id": "init",
@@ -231,5 +244,5 @@
231
244
  ]
232
245
  }
233
246
  },
234
- "version": "0.6.1"
247
+ "version": "0.6.2"
235
248
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@asterai/cli",
3
3
  "description": "CLI for building and deploying asterai plugins",
4
- "version": "0.6.1",
4
+ "version": "0.6.2",
5
5
  "author": "asterai <support@asterai.io>",
6
6
  "repository": "asterai-io/asterai-sdk",
7
7
  "homepage": "https://github.com/asterai-io/asterai-sdk",
@@ -13,6 +13,18 @@
13
13
  "license": "UNLICENSED",
14
14
  "main": "dist/index.js",
15
15
  "type": "module",
16
+ "scripts": {
17
+ "prepare": "cd .. && husky cli/.husky",
18
+ "build": "shx rm -rf dist && tsc -b",
19
+ "lint": "eslint . --ext .ts",
20
+ "postpack": "shx rm -f oclif.manifest.json",
21
+ "posttest": "pnpm run lint",
22
+ "prepack": "oclif manifest && oclif readme",
23
+ "test": "mocha --forbid-only \"test/**/*.test.ts\"",
24
+ "version": "oclif readme && git add README.md",
25
+ "format": "prettier --write .",
26
+ "format-staged": "pretty-quick --staged"
27
+ },
16
28
  "bin": {
17
29
  "asterai": "./bin/run.js"
18
30
  },
@@ -79,14 +91,5 @@
79
91
  "shx": "^0.3.3",
80
92
  "ts-node": "^10",
81
93
  "typescript": "^5"
82
- },
83
- "scripts": {
84
- "build": "shx rm -rf dist && tsc -b",
85
- "lint": "eslint . --ext .ts",
86
- "posttest": "pnpm run lint",
87
- "test": "mocha --forbid-only \"test/**/*.test.ts\"",
88
- "version": "oclif readme && git add README.md",
89
- "format": "prettier --write .",
90
- "format-staged": "pretty-quick --staged"
91
94
  }
92
- }
95
+ }
@@ -1,2 +0,0 @@
1
- target/
2
- wit/
@@ -1,10 +0,0 @@
1
- .idea/
2
- node_modules/
3
- package-lock.json
4
- pnpm-lock.yaml
5
- build/
6
- generated/
7
- .vscode/
8
- tsconfig.tsbuildinfo
9
- *.wasm
10
- typegen/