@asterai/cli 0.3.0 → 0.3.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 +10 -7
- package/dist/commands/codegen.d.ts +7 -1
- package/dist/commands/codegen.js +81 -0
- package/oclif.manifest.json +28 -1
- package/package.json +1 -1
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.3.
|
|
23
|
+
@asterai/cli/0.3.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.3.
|
|
56
|
+
_See code: [src/commands/auth.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/auth.ts)_
|
|
57
57
|
|
|
58
58
|
## `asterai build [INPUT]`
|
|
59
59
|
|
|
@@ -73,7 +73,7 @@ EXAMPLES
|
|
|
73
73
|
$ asterai build
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
_See code: [src/commands/build.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.
|
|
76
|
+
_See code: [src/commands/build.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/build.ts)_
|
|
77
77
|
|
|
78
78
|
## `asterai codegen`
|
|
79
79
|
|
|
@@ -81,11 +81,14 @@ Generate code from the plugin manifest
|
|
|
81
81
|
|
|
82
82
|
```
|
|
83
83
|
USAGE
|
|
84
|
-
$ asterai codegen [-m <value>] [-o <value>]
|
|
84
|
+
$ asterai codegen [-m <value>] [-o <value>] [-a <value>] [-l <value>] [-s]
|
|
85
85
|
|
|
86
86
|
FLAGS
|
|
87
|
+
-a, --appId=<value> app id
|
|
88
|
+
-l, --language=<value> [default: js] language of generated typings
|
|
87
89
|
-m, --manifest=<value> [default: plugin.asterai.proto] manifest path
|
|
88
90
|
-o, --outputDir=<value> [default: generated] output directory
|
|
91
|
+
-s, --staging use staging endpoint
|
|
89
92
|
|
|
90
93
|
DESCRIPTION
|
|
91
94
|
Generate code from the plugin manifest
|
|
@@ -94,7 +97,7 @@ EXAMPLES
|
|
|
94
97
|
$ asterai codegen
|
|
95
98
|
```
|
|
96
99
|
|
|
97
|
-
_See code: [src/commands/codegen.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.
|
|
100
|
+
_See code: [src/commands/codegen.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/codegen.ts)_
|
|
98
101
|
|
|
99
102
|
## `asterai deploy [INPUT]`
|
|
100
103
|
|
|
@@ -117,7 +120,7 @@ EXAMPLES
|
|
|
117
120
|
$ asterai deploy --app 66a46b12-b1a7-4b72-a64a-0e4fe21902b6
|
|
118
121
|
```
|
|
119
122
|
|
|
120
|
-
_See code: [src/commands/deploy.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.
|
|
123
|
+
_See code: [src/commands/deploy.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/deploy.ts)_
|
|
121
124
|
|
|
122
125
|
## `asterai help [COMMAND]`
|
|
123
126
|
|
|
@@ -154,5 +157,5 @@ EXAMPLES
|
|
|
154
157
|
$ asterai init project-name
|
|
155
158
|
```
|
|
156
159
|
|
|
157
|
-
_See code: [src/commands/init.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.
|
|
160
|
+
_See code: [src/commands/init.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/init.ts)_
|
|
158
161
|
<!-- commandsstop -->
|
|
@@ -2,6 +2,9 @@ import { Command } from "@oclif/core";
|
|
|
2
2
|
export type CodegenFlags = {
|
|
3
3
|
manifest: string;
|
|
4
4
|
outputDir: string;
|
|
5
|
+
appId?: string;
|
|
6
|
+
language?: string;
|
|
7
|
+
staging?: boolean;
|
|
5
8
|
};
|
|
6
9
|
export default class Codegen extends Command {
|
|
7
10
|
static args: {};
|
|
@@ -10,7 +13,10 @@ export default class Codegen extends Command {
|
|
|
10
13
|
static flags: {
|
|
11
14
|
manifest: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
12
15
|
outputDir: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
16
|
+
appId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
17
|
+
language: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
18
|
+
staging: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
13
19
|
};
|
|
14
20
|
run(): Promise<void>;
|
|
15
21
|
}
|
|
16
|
-
export declare const codegen: (flags: CodegenFlags) => void
|
|
22
|
+
export declare const codegen: (flags: CodegenFlags) => Promise<void>;
|
package/dist/commands/codegen.js
CHANGED
|
@@ -2,8 +2,13 @@ import { Command, Flags } from "@oclif/core";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import { execSync } from "node:child_process";
|
|
5
|
+
import axios from "axios";
|
|
6
|
+
import { getConfigValue } from "../config.js";
|
|
7
|
+
import os from "os";
|
|
5
8
|
// Relative path from the plugin root directory.
|
|
6
9
|
const AS_PROTO_GEN_PATH = "./node_modules/.bin/as-proto-gen";
|
|
10
|
+
const PRODUCTION_ENDPOINT_BASE_URL = "https://api.asterai.io";
|
|
11
|
+
const STAGING_ENDPOINT_BASE_URL = "https://staging.api.asterai.io";
|
|
7
12
|
export default class Codegen extends Command {
|
|
8
13
|
static args = {};
|
|
9
14
|
static description = "Generate code from the plugin manifest";
|
|
@@ -19,6 +24,23 @@ export default class Codegen extends Command {
|
|
|
19
24
|
description: "output directory",
|
|
20
25
|
default: "generated",
|
|
21
26
|
}),
|
|
27
|
+
appId: Flags.string({
|
|
28
|
+
char: "a",
|
|
29
|
+
description: "app id",
|
|
30
|
+
required: false,
|
|
31
|
+
}),
|
|
32
|
+
language: Flags.string({
|
|
33
|
+
char: "l",
|
|
34
|
+
description: "language of generated typings",
|
|
35
|
+
required: false,
|
|
36
|
+
default: "js",
|
|
37
|
+
}),
|
|
38
|
+
staging: Flags.boolean({
|
|
39
|
+
char: "s",
|
|
40
|
+
description: "use staging endpoint",
|
|
41
|
+
required: false,
|
|
42
|
+
default: false,
|
|
43
|
+
}),
|
|
22
44
|
};
|
|
23
45
|
async run() {
|
|
24
46
|
const { flags } = await this.parse(Codegen);
|
|
@@ -35,6 +57,12 @@ export const codegen = (flags) => {
|
|
|
35
57
|
else {
|
|
36
58
|
deleteOldGeneratedFiles(outDir);
|
|
37
59
|
}
|
|
60
|
+
if (flags.appId && flags.language) {
|
|
61
|
+
return generateClientTypings(outDir, flags.language, flags.appId, flags.staging ?? false);
|
|
62
|
+
}
|
|
63
|
+
return generateAssemblyScriptPluginTypings(flags, baseDir);
|
|
64
|
+
};
|
|
65
|
+
const generateAssemblyScriptPluginTypings = async (flags, baseDir) => {
|
|
38
66
|
const absoluteAsProtoGenPath = path.join(baseDir, AS_PROTO_GEN_PATH);
|
|
39
67
|
try {
|
|
40
68
|
execSync("protoc --version");
|
|
@@ -66,3 +94,56 @@ const deleteOldGeneratedFiles = (outDir) => {
|
|
|
66
94
|
fs.unlinkSync(deletePath);
|
|
67
95
|
}
|
|
68
96
|
};
|
|
97
|
+
const generateClientTypings = async (outDir, language, appId, shouldUseStaging) => {
|
|
98
|
+
const manifestsResponse = await downloadEnabledPluginsManifests(appId, shouldUseStaging);
|
|
99
|
+
const asteraiProto = await fetchAsteraiProto();
|
|
100
|
+
const aggregatedManifest = aggregateManifests(manifestsResponse.manifests, asteraiProto);
|
|
101
|
+
const appPrefix = `app.${appId}`;
|
|
102
|
+
fs.writeFileSync(path.join(outDir, `${appPrefix}.proto`), aggregatedManifest.content);
|
|
103
|
+
if (language === "ts") {
|
|
104
|
+
console.log("generating TypeScript typings for plugin manifest...");
|
|
105
|
+
const jsOutput = `${appPrefix}.js`;
|
|
106
|
+
const dTsOutput = `${appPrefix}.d.ts`;
|
|
107
|
+
execSync(`
|
|
108
|
+
npx -p protobufjs-cli pbjs -t static --no-service ${aggregatedManifest.filePath} -o ${path.join(outDir, jsOutput)}
|
|
109
|
+
`);
|
|
110
|
+
execSync(`
|
|
111
|
+
npx -p protobufjs-cli pbts -o ${path.join(outDir, dTsOutput)} ${path.join(outDir, jsOutput)}
|
|
112
|
+
`);
|
|
113
|
+
fs.unlinkSync(aggregatedManifest.filePath);
|
|
114
|
+
console.log("Typings generated successfully.");
|
|
115
|
+
}
|
|
116
|
+
console.log("done.");
|
|
117
|
+
};
|
|
118
|
+
const fetchAsteraiProto = () => {
|
|
119
|
+
// TODO: fetch this from the local file system instead.
|
|
120
|
+
return axios
|
|
121
|
+
.get("https://unpkg.com/@asterai/sdk@latest/protobuf/asterai.proto")
|
|
122
|
+
.then(r => r.data);
|
|
123
|
+
};
|
|
124
|
+
const aggregateManifests = (manifests, asteraiProto) => {
|
|
125
|
+
let aggregatedManifest = `${asteraiProto}\n`;
|
|
126
|
+
const osTmpDir = os.tmpdir();
|
|
127
|
+
const aggregatedManifestPath = path.join(osTmpDir, "plugins.asterai.proto");
|
|
128
|
+
for (const manifest of manifests) {
|
|
129
|
+
aggregatedManifest += `${manifest.proto}\n`;
|
|
130
|
+
}
|
|
131
|
+
fs.writeFileSync(aggregatedManifestPath, aggregatedManifest);
|
|
132
|
+
return {
|
|
133
|
+
content: aggregatedManifest,
|
|
134
|
+
filePath: aggregatedManifestPath,
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
const downloadEnabledPluginsManifests = async (appId, shouldUseStaging) => {
|
|
138
|
+
const baseUrl = shouldUseStaging
|
|
139
|
+
? STAGING_ENDPOINT_BASE_URL
|
|
140
|
+
: PRODUCTION_ENDPOINT_BASE_URL;
|
|
141
|
+
const response = await axios({
|
|
142
|
+
url: `${baseUrl}/app/${appId}/plugin/manifests`,
|
|
143
|
+
method: "GET",
|
|
144
|
+
headers: {
|
|
145
|
+
Authorization: getConfigValue("key"),
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
return response.data;
|
|
149
|
+
};
|
package/oclif.manifest.json
CHANGED
|
@@ -91,6 +91,33 @@
|
|
|
91
91
|
"hasDynamicHelp": false,
|
|
92
92
|
"multiple": false,
|
|
93
93
|
"type": "option"
|
|
94
|
+
},
|
|
95
|
+
"appId": {
|
|
96
|
+
"char": "a",
|
|
97
|
+
"description": "app id",
|
|
98
|
+
"name": "appId",
|
|
99
|
+
"required": false,
|
|
100
|
+
"hasDynamicHelp": false,
|
|
101
|
+
"multiple": false,
|
|
102
|
+
"type": "option"
|
|
103
|
+
},
|
|
104
|
+
"language": {
|
|
105
|
+
"char": "l",
|
|
106
|
+
"description": "language of generated typings",
|
|
107
|
+
"name": "language",
|
|
108
|
+
"required": false,
|
|
109
|
+
"default": "js",
|
|
110
|
+
"hasDynamicHelp": false,
|
|
111
|
+
"multiple": false,
|
|
112
|
+
"type": "option"
|
|
113
|
+
},
|
|
114
|
+
"staging": {
|
|
115
|
+
"char": "s",
|
|
116
|
+
"description": "use staging endpoint",
|
|
117
|
+
"name": "staging",
|
|
118
|
+
"required": false,
|
|
119
|
+
"allowNo": false,
|
|
120
|
+
"type": "boolean"
|
|
94
121
|
}
|
|
95
122
|
},
|
|
96
123
|
"hasDynamicHelp": false,
|
|
@@ -198,5 +225,5 @@
|
|
|
198
225
|
]
|
|
199
226
|
}
|
|
200
227
|
},
|
|
201
|
-
"version": "0.3.
|
|
228
|
+
"version": "0.3.2"
|
|
202
229
|
}
|
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.3.
|
|
4
|
+
"version": "0.3.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",
|