@asterai/cli 0.1.0
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 +157 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +6 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +5 -0
- package/dist/commands/auth.d.ts +10 -0
- package/dist/commands/auth.js +17 -0
- package/dist/commands/build.d.ts +12 -0
- package/dist/commands/build.js +43 -0
- package/dist/commands/codegen.d.ts +11 -0
- package/dist/commands/codegen.js +89 -0
- package/dist/commands/deploy.d.ts +14 -0
- package/dist/commands/deploy.js +70 -0
- package/dist/commands/init.d.ts +10 -0
- package/dist/commands/init.js +21 -0
- package/dist/compile.d.ts +7 -0
- package/dist/compile.js +28 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +21 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/oclif.manifest.json +196 -0
- package/package.json +81 -0
package/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# @asterai/cli
|
|
2
|
+
|
|
3
|
+
CLI for building and deploying AsterAI plugins
|
|
4
|
+
|
|
5
|
+
[](https://oclif.io)
|
|
6
|
+
[](https://npmjs.org/package/@asterai/cli)
|
|
7
|
+
[](https://npmjs.org/package/@asterai/cli)
|
|
8
|
+
|
|
9
|
+
<!-- toc -->
|
|
10
|
+
* [@asterai/cli](#asteraicli)
|
|
11
|
+
* [Usage](#usage)
|
|
12
|
+
* [Commands](#commands)
|
|
13
|
+
<!-- tocstop -->
|
|
14
|
+
|
|
15
|
+
# Usage
|
|
16
|
+
|
|
17
|
+
<!-- usage -->
|
|
18
|
+
```sh-session
|
|
19
|
+
$ npm install -g @asterai/cli
|
|
20
|
+
$ asterai COMMAND
|
|
21
|
+
running command...
|
|
22
|
+
$ asterai (--version)
|
|
23
|
+
@asterai/cli/0.1.0 linux-x64 node-v20.12.2
|
|
24
|
+
$ asterai --help [COMMAND]
|
|
25
|
+
USAGE
|
|
26
|
+
$ asterai COMMAND
|
|
27
|
+
...
|
|
28
|
+
```
|
|
29
|
+
<!-- usagestop -->
|
|
30
|
+
|
|
31
|
+
# Commands
|
|
32
|
+
|
|
33
|
+
<!-- commands -->
|
|
34
|
+
* [`asterai auth KEY`](#asterai-auth-key)
|
|
35
|
+
* [`asterai build [INPUT]`](#asterai-build-input)
|
|
36
|
+
* [`asterai codegen`](#asterai-codegen)
|
|
37
|
+
* [`asterai deploy [INPUT]`](#asterai-deploy-input)
|
|
38
|
+
* [`asterai help [COMMAND]`](#asterai-help-command)
|
|
39
|
+
* [`asterai init [OUTDIR]`](#asterai-init-outdir)
|
|
40
|
+
|
|
41
|
+
## `asterai auth KEY`
|
|
42
|
+
|
|
43
|
+
authenticate to asterai
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
USAGE
|
|
47
|
+
$ asterai auth KEY
|
|
48
|
+
|
|
49
|
+
DESCRIPTION
|
|
50
|
+
authenticate to asterai
|
|
51
|
+
|
|
52
|
+
EXAMPLES
|
|
53
|
+
$ asterai auth
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
_See code: [src/commands/auth.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.1.0/src/commands/auth.ts)_
|
|
57
|
+
|
|
58
|
+
## `asterai build [INPUT]`
|
|
59
|
+
|
|
60
|
+
compiles the plugin
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
USAGE
|
|
64
|
+
$ asterai build [INPUT] [-m <value>]
|
|
65
|
+
|
|
66
|
+
FLAGS
|
|
67
|
+
-m, --manifest=<value> [default: plugin.asterai.yaml] manifest path
|
|
68
|
+
|
|
69
|
+
DESCRIPTION
|
|
70
|
+
compiles the plugin
|
|
71
|
+
|
|
72
|
+
EXAMPLES
|
|
73
|
+
$ asterai build
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
_See code: [src/commands/build.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.1.0/src/commands/build.ts)_
|
|
77
|
+
|
|
78
|
+
## `asterai codegen`
|
|
79
|
+
|
|
80
|
+
Generate code from the plugin manifest
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
USAGE
|
|
84
|
+
$ asterai codegen [-m <value>] [-o <value>]
|
|
85
|
+
|
|
86
|
+
FLAGS
|
|
87
|
+
-m, --manifest=<value> [default: plugin.asterai.yaml] manifest path
|
|
88
|
+
-o, --outputDir=<value> [default: generated] output directory
|
|
89
|
+
|
|
90
|
+
DESCRIPTION
|
|
91
|
+
Generate code from the plugin manifest
|
|
92
|
+
|
|
93
|
+
EXAMPLES
|
|
94
|
+
$ asterai codegen
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
_See code: [src/commands/codegen.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.1.0/src/commands/codegen.ts)_
|
|
98
|
+
|
|
99
|
+
## `asterai deploy [INPUT]`
|
|
100
|
+
|
|
101
|
+
compiles and uploads the plugin to asterai
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
USAGE
|
|
105
|
+
$ asterai deploy [INPUT] -a <value> [-m <value>] [-e <value>]
|
|
106
|
+
|
|
107
|
+
FLAGS
|
|
108
|
+
-a, --app=<value> (required) app ID to immediately configure this plugin with
|
|
109
|
+
-e, --endpoint=<value> [default: https://api.asterai.io/app/plugin]
|
|
110
|
+
-m, --manifest=<value> [default: plugin.asterai.yaml] manifest path
|
|
111
|
+
|
|
112
|
+
DESCRIPTION
|
|
113
|
+
compiles and uploads the plugin to asterai
|
|
114
|
+
|
|
115
|
+
EXAMPLES
|
|
116
|
+
$ asterai deploy --app 66a46b12-b1a7-4b72-a64a-0e4fe21902b6
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
_See code: [src/commands/deploy.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.1.0/src/commands/deploy.ts)_
|
|
120
|
+
|
|
121
|
+
## `asterai help [COMMAND]`
|
|
122
|
+
|
|
123
|
+
Display help for asterai.
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
USAGE
|
|
127
|
+
$ asterai help [COMMAND...] [-n]
|
|
128
|
+
|
|
129
|
+
ARGUMENTS
|
|
130
|
+
COMMAND... Command to show help for.
|
|
131
|
+
|
|
132
|
+
FLAGS
|
|
133
|
+
-n, --nested-commands Include all nested commands in the output.
|
|
134
|
+
|
|
135
|
+
DESCRIPTION
|
|
136
|
+
Display help for asterai.
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.0.22/src/commands/help.ts)_
|
|
140
|
+
|
|
141
|
+
## `asterai init [OUTDIR]`
|
|
142
|
+
|
|
143
|
+
Initialise a new plugin project
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
USAGE
|
|
147
|
+
$ asterai init [OUTDIR]
|
|
148
|
+
|
|
149
|
+
DESCRIPTION
|
|
150
|
+
Initialise a new plugin project
|
|
151
|
+
|
|
152
|
+
EXAMPLES
|
|
153
|
+
$ asterai init project-name
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
_See code: [src/commands/init.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.1.0/src/commands/init.ts)_
|
|
157
|
+
<!-- commandsstop -->
|
package/bin/dev.cmd
ADDED
package/bin/dev.js
ADDED
package/bin/run.cmd
ADDED
package/bin/run.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class Auth extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
key: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {};
|
|
9
|
+
run(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Args, Command } from "@oclif/core";
|
|
2
|
+
import { getConfigValue, setConfigValue } from "../config.js";
|
|
3
|
+
export default class Auth extends Command {
|
|
4
|
+
static args = {
|
|
5
|
+
key: Args.string({
|
|
6
|
+
required: true,
|
|
7
|
+
}),
|
|
8
|
+
};
|
|
9
|
+
static description = "authenticate to asterai";
|
|
10
|
+
static examples = [`<%= config.bin %> <%= command.id %>`];
|
|
11
|
+
static flags = {};
|
|
12
|
+
async run() {
|
|
13
|
+
const { args } = await this.parse(Auth);
|
|
14
|
+
setConfigValue("key", args.key);
|
|
15
|
+
const value = getConfigValue("key");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class Build extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
input: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {
|
|
9
|
+
manifest: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Args, Command, Flags } from "@oclif/core";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import { compile } from "../compile.js";
|
|
5
|
+
export default class Build extends Command {
|
|
6
|
+
static args = {
|
|
7
|
+
input: Args.string({
|
|
8
|
+
default: "plugin.ts",
|
|
9
|
+
}),
|
|
10
|
+
};
|
|
11
|
+
static description = "compiles the plugin";
|
|
12
|
+
static examples = [`<%= config.bin %> <%= command.id %>`];
|
|
13
|
+
static flags = {
|
|
14
|
+
manifest: Flags.string({
|
|
15
|
+
char: "m",
|
|
16
|
+
description: "manifest path",
|
|
17
|
+
default: "plugin.asterai.yaml",
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
async run() {
|
|
21
|
+
const { args, flags } = await this.parse(Build);
|
|
22
|
+
const manifestPath = path.resolve(flags.manifest);
|
|
23
|
+
const inputFile = path.resolve(args.input);
|
|
24
|
+
if (!fs.existsSync(inputFile)) {
|
|
25
|
+
throw new Error(`input file not found (${args.input})`);
|
|
26
|
+
}
|
|
27
|
+
const inputFileName = path.parse(inputFile).name;
|
|
28
|
+
const baseDir = path.dirname(manifestPath);
|
|
29
|
+
const outDir = path.join(baseDir, "build");
|
|
30
|
+
const outputFile = path.join(outDir, `${inputFileName}.wasm`);
|
|
31
|
+
const libsDir = path.join(baseDir, "node_modules");
|
|
32
|
+
if (!fs.existsSync(libsDir)) {
|
|
33
|
+
throw new Error("no node_modules found in the plugin directory");
|
|
34
|
+
}
|
|
35
|
+
const options = {
|
|
36
|
+
inputFile,
|
|
37
|
+
baseDir,
|
|
38
|
+
outputFile,
|
|
39
|
+
libs: libsDir,
|
|
40
|
+
};
|
|
41
|
+
await compile(options);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class Codegen extends Command {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
manifest: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
outputDir: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Command, Flags } from "@oclif/core";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import z from "zod";
|
|
4
|
+
import YAML from "yaml";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
const ASC_TYPES = [
|
|
7
|
+
"i8",
|
|
8
|
+
"u8",
|
|
9
|
+
"i16",
|
|
10
|
+
"u16",
|
|
11
|
+
"i32",
|
|
12
|
+
"u32",
|
|
13
|
+
"i64",
|
|
14
|
+
"u64",
|
|
15
|
+
"isize",
|
|
16
|
+
"usize",
|
|
17
|
+
"f32",
|
|
18
|
+
"f64",
|
|
19
|
+
"bool",
|
|
20
|
+
"string",
|
|
21
|
+
];
|
|
22
|
+
const ManifestFunctionArgumentSchema = z.object({
|
|
23
|
+
name: z.string(),
|
|
24
|
+
description: z.string(),
|
|
25
|
+
type: z.enum(ASC_TYPES),
|
|
26
|
+
});
|
|
27
|
+
const ManifestFunctionSchema = z.object({
|
|
28
|
+
name: z.string(),
|
|
29
|
+
description: z.string(),
|
|
30
|
+
arguments: z.array(ManifestFunctionArgumentSchema),
|
|
31
|
+
});
|
|
32
|
+
const ManifestSchema = z.object({
|
|
33
|
+
name: z.string(),
|
|
34
|
+
functions: z.array(ManifestFunctionSchema),
|
|
35
|
+
});
|
|
36
|
+
export default class Codegen extends Command {
|
|
37
|
+
static args = {};
|
|
38
|
+
static description = "Generate code from the plugin manifest";
|
|
39
|
+
static examples = [`<%= config.bin %> <%= command.id %>`];
|
|
40
|
+
static flags = {
|
|
41
|
+
manifest: Flags.string({
|
|
42
|
+
char: "m",
|
|
43
|
+
description: "manifest path",
|
|
44
|
+
default: "plugin.asterai.yaml",
|
|
45
|
+
}),
|
|
46
|
+
outputDir: Flags.string({
|
|
47
|
+
char: "o",
|
|
48
|
+
description: "output directory",
|
|
49
|
+
default: "generated",
|
|
50
|
+
}),
|
|
51
|
+
};
|
|
52
|
+
async run() {
|
|
53
|
+
const { flags } = await this.parse(Codegen);
|
|
54
|
+
const manifestPath = path.resolve(flags.manifest);
|
|
55
|
+
const baseDir = path.dirname(manifestPath);
|
|
56
|
+
const outDir = path.join(baseDir, flags.outputDir);
|
|
57
|
+
const manifest = ManifestSchema.parse(YAML.parse(fs.readFileSync(manifestPath, "utf8")));
|
|
58
|
+
if (!fs.existsSync(outDir)) {
|
|
59
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
60
|
+
}
|
|
61
|
+
for (const func of manifest.functions) {
|
|
62
|
+
const className = `${capitaliseFirstLetter(func.name)}Args`;
|
|
63
|
+
const fileName = `${className}.ts`;
|
|
64
|
+
const filePath = path.join(outDir, fileName);
|
|
65
|
+
const stream = fs.createWriteStream(filePath);
|
|
66
|
+
writeFunctionFile(className, func.arguments, stream);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const writeFunctionFile = (className, args, stream) => {
|
|
71
|
+
stream.write(`\
|
|
72
|
+
import {parseTypeFromString, TypedMap} from "@asterai/sdk/collections";
|
|
73
|
+
|
|
74
|
+
export class ${className} extends TypedMap<string, string> {
|
|
75
|
+
${args.map(renderArgGetterString).join("")}
|
|
76
|
+
}
|
|
77
|
+
`);
|
|
78
|
+
};
|
|
79
|
+
const renderArgGetterString = (arg) => `
|
|
80
|
+
public get ${arg.name}(): ${arg.type} {
|
|
81
|
+
${arg.type === "string"
|
|
82
|
+
? `return this.mustGet("${arg.name}")`
|
|
83
|
+
: `
|
|
84
|
+
const value = this.mustGet("${arg.name}");
|
|
85
|
+
return parseTypeFromString<${arg.type}>(value, "${arg.type}");
|
|
86
|
+
`.trim()}
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
const capitaliseFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class Deploy extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
input: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {
|
|
9
|
+
app: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
|
+
manifest: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
|
+
endpoint: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Args, Command, Flags } from "@oclif/core";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import { compile } from "../compile.js";
|
|
5
|
+
import FormData from "form-data";
|
|
6
|
+
import axios from "axios";
|
|
7
|
+
import { getConfigValue } from "../config.js";
|
|
8
|
+
export default class Deploy extends Command {
|
|
9
|
+
static args = {
|
|
10
|
+
input: Args.string({
|
|
11
|
+
default: "plugin.ts",
|
|
12
|
+
}),
|
|
13
|
+
};
|
|
14
|
+
static description = "compiles and uploads the plugin to asterai";
|
|
15
|
+
static examples = [
|
|
16
|
+
`<%= config.bin %> <%= command.id %> --app 66a46b12-b1a7-4b72-a64a-0e4fe21902b6`,
|
|
17
|
+
];
|
|
18
|
+
static flags = {
|
|
19
|
+
app: Flags.string({
|
|
20
|
+
char: "a",
|
|
21
|
+
description: "app ID to immediately configure this plugin with",
|
|
22
|
+
required: true,
|
|
23
|
+
}),
|
|
24
|
+
manifest: Flags.string({
|
|
25
|
+
char: "m",
|
|
26
|
+
description: "manifest path",
|
|
27
|
+
default: "plugin.asterai.yaml",
|
|
28
|
+
}),
|
|
29
|
+
endpoint: Flags.string({
|
|
30
|
+
char: "e",
|
|
31
|
+
default: "https://api.asterai.io/app/plugin",
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
async run() {
|
|
35
|
+
const { args, flags } = await this.parse(Deploy);
|
|
36
|
+
const manifestPath = path.resolve(flags.manifest);
|
|
37
|
+
const inputFile = path.resolve(args.input);
|
|
38
|
+
if (!fs.existsSync(inputFile)) {
|
|
39
|
+
throw new Error(`input file not found (${args.input})`);
|
|
40
|
+
}
|
|
41
|
+
const inputFileName = path.parse(inputFile).name;
|
|
42
|
+
const baseDir = path.dirname(manifestPath);
|
|
43
|
+
const outDir = path.join(baseDir, "build");
|
|
44
|
+
const outputFile = path.join(outDir, `${inputFileName}.wasm`);
|
|
45
|
+
const libsDir = path.join(baseDir, "node_modules");
|
|
46
|
+
if (!fs.existsSync(libsDir)) {
|
|
47
|
+
throw new Error("no node_modules found in the plugin directory");
|
|
48
|
+
}
|
|
49
|
+
const options = {
|
|
50
|
+
inputFile,
|
|
51
|
+
baseDir,
|
|
52
|
+
outputFile,
|
|
53
|
+
libs: libsDir,
|
|
54
|
+
};
|
|
55
|
+
await compile(options);
|
|
56
|
+
const form = new FormData();
|
|
57
|
+
form.append("app_id", flags.app);
|
|
58
|
+
form.append("module", fs.createReadStream(outputFile));
|
|
59
|
+
form.append("manifest", fs.createReadStream(manifestPath));
|
|
60
|
+
await axios({
|
|
61
|
+
url: flags.endpoint,
|
|
62
|
+
method: "put",
|
|
63
|
+
data: form,
|
|
64
|
+
headers: {
|
|
65
|
+
Authorization: getConfigValue("key"),
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
console.log("done");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class Codegen extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
outDir: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {};
|
|
9
|
+
run(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Args, Command } from "@oclif/core";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import url from "url";
|
|
5
|
+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
6
|
+
const SOURCE_DIR = path.join(__dirname, "../../asterai-init-plugin");
|
|
7
|
+
export default class Codegen extends Command {
|
|
8
|
+
static args = {
|
|
9
|
+
outDir: Args.string({
|
|
10
|
+
default: "plugin",
|
|
11
|
+
}),
|
|
12
|
+
};
|
|
13
|
+
static description = "Initialise a new plugin project";
|
|
14
|
+
static examples = [`<%= config.bin %> <%= command.id %> project-name`];
|
|
15
|
+
static flags = {};
|
|
16
|
+
async run() {
|
|
17
|
+
const { args } = await this.parse(Codegen);
|
|
18
|
+
const outDir = path.resolve(args.outDir);
|
|
19
|
+
fs.cpSync(SOURCE_DIR, outDir, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
}
|
package/dist/compile.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as asc from "assemblyscript/asc";
|
|
2
|
+
const COMPILER_OPTIONS = {
|
|
3
|
+
stdout: process.stdout,
|
|
4
|
+
stderr: process.stderr,
|
|
5
|
+
};
|
|
6
|
+
export const compile = async (options) => {
|
|
7
|
+
// TODO also include a file here to remove the necessity of including
|
|
8
|
+
// export * from "@asterai/sdk";
|
|
9
|
+
// in each plugin.
|
|
10
|
+
const args = [
|
|
11
|
+
"--exportRuntime",
|
|
12
|
+
"--runtime",
|
|
13
|
+
"stub",
|
|
14
|
+
options.inputFile,
|
|
15
|
+
"--baseDir",
|
|
16
|
+
options.baseDir,
|
|
17
|
+
"--lib",
|
|
18
|
+
options.libs,
|
|
19
|
+
"--outFile",
|
|
20
|
+
options.outputFile,
|
|
21
|
+
"--optimize",
|
|
22
|
+
"--debug",
|
|
23
|
+
];
|
|
24
|
+
const result = await asc.main(args, COMPILER_OPTIONS);
|
|
25
|
+
if (result.error) {
|
|
26
|
+
throw result.error;
|
|
27
|
+
}
|
|
28
|
+
};
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
const CONFIG_PATH = path.join(os.homedir(), "/.asterai-cli.json");
|
|
5
|
+
const getConfig = () => {
|
|
6
|
+
let config;
|
|
7
|
+
try {
|
|
8
|
+
config = JSON.parse(fs.readFileSync(CONFIG_PATH).toString());
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
config = {};
|
|
12
|
+
}
|
|
13
|
+
return config;
|
|
14
|
+
};
|
|
15
|
+
export const getConfigValue = (key) => getConfig()[key];
|
|
16
|
+
export const setConfigValue = (key, value) => {
|
|
17
|
+
const config = getConfig();
|
|
18
|
+
config[key] = value;
|
|
19
|
+
const serialized = JSON.stringify(config);
|
|
20
|
+
fs.writeFileSync(CONFIG_PATH, serialized);
|
|
21
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { run } from "@oclif/core";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { run } from "@oclif/core";
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
{
|
|
2
|
+
"commands": {
|
|
3
|
+
"auth": {
|
|
4
|
+
"aliases": [],
|
|
5
|
+
"args": {
|
|
6
|
+
"key": {
|
|
7
|
+
"name": "key",
|
|
8
|
+
"required": true
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"description": "authenticate to asterai",
|
|
12
|
+
"examples": [
|
|
13
|
+
"<%= config.bin %> <%= command.id %>"
|
|
14
|
+
],
|
|
15
|
+
"flags": {},
|
|
16
|
+
"hasDynamicHelp": false,
|
|
17
|
+
"hiddenAliases": [],
|
|
18
|
+
"id": "auth",
|
|
19
|
+
"pluginAlias": "@asterai/cli",
|
|
20
|
+
"pluginName": "@asterai/cli",
|
|
21
|
+
"pluginType": "core",
|
|
22
|
+
"strict": true,
|
|
23
|
+
"enableJsonFlag": false,
|
|
24
|
+
"isESM": true,
|
|
25
|
+
"relativePath": [
|
|
26
|
+
"dist",
|
|
27
|
+
"commands",
|
|
28
|
+
"auth.js"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"build": {
|
|
32
|
+
"aliases": [],
|
|
33
|
+
"args": {
|
|
34
|
+
"input": {
|
|
35
|
+
"default": "plugin.ts",
|
|
36
|
+
"name": "input"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"description": "compiles the plugin",
|
|
40
|
+
"examples": [
|
|
41
|
+
"<%= config.bin %> <%= command.id %>"
|
|
42
|
+
],
|
|
43
|
+
"flags": {
|
|
44
|
+
"manifest": {
|
|
45
|
+
"char": "m",
|
|
46
|
+
"description": "manifest path",
|
|
47
|
+
"name": "manifest",
|
|
48
|
+
"default": "plugin.asterai.yaml",
|
|
49
|
+
"hasDynamicHelp": false,
|
|
50
|
+
"multiple": false,
|
|
51
|
+
"type": "option"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"hasDynamicHelp": false,
|
|
55
|
+
"hiddenAliases": [],
|
|
56
|
+
"id": "build",
|
|
57
|
+
"pluginAlias": "@asterai/cli",
|
|
58
|
+
"pluginName": "@asterai/cli",
|
|
59
|
+
"pluginType": "core",
|
|
60
|
+
"strict": true,
|
|
61
|
+
"enableJsonFlag": false,
|
|
62
|
+
"isESM": true,
|
|
63
|
+
"relativePath": [
|
|
64
|
+
"dist",
|
|
65
|
+
"commands",
|
|
66
|
+
"build.js"
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
"codegen": {
|
|
70
|
+
"aliases": [],
|
|
71
|
+
"args": {},
|
|
72
|
+
"description": "Generate code from the plugin manifest",
|
|
73
|
+
"examples": [
|
|
74
|
+
"<%= config.bin %> <%= command.id %>"
|
|
75
|
+
],
|
|
76
|
+
"flags": {
|
|
77
|
+
"manifest": {
|
|
78
|
+
"char": "m",
|
|
79
|
+
"description": "manifest path",
|
|
80
|
+
"name": "manifest",
|
|
81
|
+
"default": "plugin.asterai.yaml",
|
|
82
|
+
"hasDynamicHelp": false,
|
|
83
|
+
"multiple": false,
|
|
84
|
+
"type": "option"
|
|
85
|
+
},
|
|
86
|
+
"outputDir": {
|
|
87
|
+
"char": "o",
|
|
88
|
+
"description": "output directory",
|
|
89
|
+
"name": "outputDir",
|
|
90
|
+
"default": "generated",
|
|
91
|
+
"hasDynamicHelp": false,
|
|
92
|
+
"multiple": false,
|
|
93
|
+
"type": "option"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"hasDynamicHelp": false,
|
|
97
|
+
"hiddenAliases": [],
|
|
98
|
+
"id": "codegen",
|
|
99
|
+
"pluginAlias": "@asterai/cli",
|
|
100
|
+
"pluginName": "@asterai/cli",
|
|
101
|
+
"pluginType": "core",
|
|
102
|
+
"strict": true,
|
|
103
|
+
"enableJsonFlag": false,
|
|
104
|
+
"isESM": true,
|
|
105
|
+
"relativePath": [
|
|
106
|
+
"dist",
|
|
107
|
+
"commands",
|
|
108
|
+
"codegen.js"
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
"deploy": {
|
|
112
|
+
"aliases": [],
|
|
113
|
+
"args": {
|
|
114
|
+
"input": {
|
|
115
|
+
"default": "plugin.ts",
|
|
116
|
+
"name": "input"
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"description": "compiles and uploads the plugin to asterai",
|
|
120
|
+
"examples": [
|
|
121
|
+
"<%= config.bin %> <%= command.id %> --app 66a46b12-b1a7-4b72-a64a-0e4fe21902b6"
|
|
122
|
+
],
|
|
123
|
+
"flags": {
|
|
124
|
+
"app": {
|
|
125
|
+
"char": "a",
|
|
126
|
+
"description": "app ID to immediately configure this plugin with",
|
|
127
|
+
"name": "app",
|
|
128
|
+
"required": true,
|
|
129
|
+
"hasDynamicHelp": false,
|
|
130
|
+
"multiple": false,
|
|
131
|
+
"type": "option"
|
|
132
|
+
},
|
|
133
|
+
"manifest": {
|
|
134
|
+
"char": "m",
|
|
135
|
+
"description": "manifest path",
|
|
136
|
+
"name": "manifest",
|
|
137
|
+
"default": "plugin.asterai.yaml",
|
|
138
|
+
"hasDynamicHelp": false,
|
|
139
|
+
"multiple": false,
|
|
140
|
+
"type": "option"
|
|
141
|
+
},
|
|
142
|
+
"endpoint": {
|
|
143
|
+
"char": "e",
|
|
144
|
+
"name": "endpoint",
|
|
145
|
+
"default": "https://api.asterai.io/app/plugin",
|
|
146
|
+
"hasDynamicHelp": false,
|
|
147
|
+
"multiple": false,
|
|
148
|
+
"type": "option"
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
"hasDynamicHelp": false,
|
|
152
|
+
"hiddenAliases": [],
|
|
153
|
+
"id": "deploy",
|
|
154
|
+
"pluginAlias": "@asterai/cli",
|
|
155
|
+
"pluginName": "@asterai/cli",
|
|
156
|
+
"pluginType": "core",
|
|
157
|
+
"strict": true,
|
|
158
|
+
"enableJsonFlag": false,
|
|
159
|
+
"isESM": true,
|
|
160
|
+
"relativePath": [
|
|
161
|
+
"dist",
|
|
162
|
+
"commands",
|
|
163
|
+
"deploy.js"
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
"init": {
|
|
167
|
+
"aliases": [],
|
|
168
|
+
"args": {
|
|
169
|
+
"outDir": {
|
|
170
|
+
"default": "plugin",
|
|
171
|
+
"name": "outDir"
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
"description": "Initialise a new plugin project",
|
|
175
|
+
"examples": [
|
|
176
|
+
"<%= config.bin %> <%= command.id %> project-name"
|
|
177
|
+
],
|
|
178
|
+
"flags": {},
|
|
179
|
+
"hasDynamicHelp": false,
|
|
180
|
+
"hiddenAliases": [],
|
|
181
|
+
"id": "init",
|
|
182
|
+
"pluginAlias": "@asterai/cli",
|
|
183
|
+
"pluginName": "@asterai/cli",
|
|
184
|
+
"pluginType": "core",
|
|
185
|
+
"strict": true,
|
|
186
|
+
"enableJsonFlag": false,
|
|
187
|
+
"isESM": true,
|
|
188
|
+
"relativePath": [
|
|
189
|
+
"dist",
|
|
190
|
+
"commands",
|
|
191
|
+
"init.js"
|
|
192
|
+
]
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
"version": "0.1.0"
|
|
196
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@asterai/cli",
|
|
3
|
+
"description": "CLI for building and deploying AsterAI plugins",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"author": "asterai <support@asterai.io>",
|
|
6
|
+
"repository": "asterai-io/asterai-sdk",
|
|
7
|
+
"homepage": "https://github.com/asterai-io/asterai-sdk",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"asterai",
|
|
10
|
+
"cli",
|
|
11
|
+
"oclif"
|
|
12
|
+
],
|
|
13
|
+
"license": "UNLICENSED",
|
|
14
|
+
"main": "dist/index.js",
|
|
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
|
+
},
|
|
28
|
+
"bin": {
|
|
29
|
+
"asterai": "./bin/run.js"
|
|
30
|
+
},
|
|
31
|
+
"bugs": "https://github.com/asterai-io/asterai-sdk/issues",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18.0.0"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"/bin",
|
|
37
|
+
"/dist",
|
|
38
|
+
"/oclif.manifest.json"
|
|
39
|
+
],
|
|
40
|
+
"oclif": {
|
|
41
|
+
"bin": "asterai",
|
|
42
|
+
"dirname": "asterai",
|
|
43
|
+
"commands": "./dist/commands",
|
|
44
|
+
"plugins": [
|
|
45
|
+
"@oclif/plugin-help"
|
|
46
|
+
],
|
|
47
|
+
"topicSeparator": " ",
|
|
48
|
+
"topics": {}
|
|
49
|
+
},
|
|
50
|
+
"types": "dist/index.d.ts",
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@oclif/core": "^3",
|
|
53
|
+
"@oclif/plugin-help": "^6",
|
|
54
|
+
"@oclif/plugin-plugins": "^5",
|
|
55
|
+
"assemblyscript": "^0.27.27",
|
|
56
|
+
"axios": "^1.7.2",
|
|
57
|
+
"form-data": "^4.0.0",
|
|
58
|
+
"yaml": "^2.4.5",
|
|
59
|
+
"zod": "^3.23.8"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@oclif/prettier-config": "^0.2.1",
|
|
63
|
+
"@oclif/test": "^4",
|
|
64
|
+
"@types/chai": "^4",
|
|
65
|
+
"@types/mocha": "^10",
|
|
66
|
+
"@types/node": "^18",
|
|
67
|
+
"chai": "^4",
|
|
68
|
+
"eslint": "^8",
|
|
69
|
+
"eslint-config-oclif": "^5",
|
|
70
|
+
"eslint-config-oclif-typescript": "^3",
|
|
71
|
+
"eslint-config-prettier": "^9",
|
|
72
|
+
"husky": "^9.0.11",
|
|
73
|
+
"mocha": "^10",
|
|
74
|
+
"oclif": "^4",
|
|
75
|
+
"prettier": "^3.2.5",
|
|
76
|
+
"pretty-quick": "^4.0.0",
|
|
77
|
+
"shx": "^0.3.3",
|
|
78
|
+
"ts-node": "^10",
|
|
79
|
+
"typescript": "^5"
|
|
80
|
+
}
|
|
81
|
+
}
|