@asterai/cli 0.3.1 → 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 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.1 linux-x64 node-v20.12.2
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.1/src/commands/auth.ts)_
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.1/src/commands/build.ts)_
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
 
@@ -97,7 +97,7 @@ EXAMPLES
97
97
  $ asterai codegen
98
98
  ```
99
99
 
100
- _See code: [src/commands/codegen.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.1/src/commands/codegen.ts)_
100
+ _See code: [src/commands/codegen.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/codegen.ts)_
101
101
 
102
102
  ## `asterai deploy [INPUT]`
103
103
 
@@ -120,7 +120,7 @@ EXAMPLES
120
120
  $ asterai deploy --app 66a46b12-b1a7-4b72-a64a-0e4fe21902b6
121
121
  ```
122
122
 
123
- _See code: [src/commands/deploy.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.1/src/commands/deploy.ts)_
123
+ _See code: [src/commands/deploy.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/deploy.ts)_
124
124
 
125
125
  ## `asterai help [COMMAND]`
126
126
 
@@ -157,5 +157,5 @@ EXAMPLES
157
157
  $ asterai init project-name
158
158
  ```
159
159
 
160
- _See code: [src/commands/init.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.1/src/commands/init.ts)_
160
+ _See code: [src/commands/init.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/init.ts)_
161
161
  <!-- commandsstop -->
@@ -60,9 +60,9 @@ export const codegen = (flags) => {
60
60
  if (flags.appId && flags.language) {
61
61
  return generateClientTypings(outDir, flags.language, flags.appId, flags.staging ?? false);
62
62
  }
63
- return generateAssemblyScriptPluginTypings(outDir, baseDir, manifestPath);
63
+ return generateAssemblyScriptPluginTypings(flags, baseDir);
64
64
  };
65
- const generateAssemblyScriptPluginTypings = async (outDir, baseDir, manifestPath) => {
65
+ const generateAssemblyScriptPluginTypings = async (flags, baseDir) => {
66
66
  const absoluteAsProtoGenPath = path.join(baseDir, AS_PROTO_GEN_PATH);
67
67
  try {
68
68
  execSync("protoc --version");
@@ -77,7 +77,7 @@ const generateAssemblyScriptPluginTypings = async (outDir, baseDir, manifestPath
77
77
  execSync("protoc " +
78
78
  `--plugin='protoc-gen-as=${absoluteAsProtoGenPath}' ` +
79
79
  `--experimental_allow_proto3_optional ` +
80
- `--as_out='./${outDir}' ./${manifestPath}`);
80
+ `--as_out='./${flags.outputDir}' ./${flags.manifest}`);
81
81
  }
82
82
  catch (e) {
83
83
  console.error("Failed to generate protobuf types:", e);
@@ -96,32 +96,43 @@ const deleteOldGeneratedFiles = (outDir) => {
96
96
  };
97
97
  const generateClientTypings = async (outDir, language, appId, shouldUseStaging) => {
98
98
  const manifestsResponse = await downloadEnabledPluginsManifests(appId, shouldUseStaging);
99
- fs.writeFileSync(path.join(outDir, "manifests.json"), JSON.stringify(manifestsResponse, null, 2));
100
- console.log("manifests.json generated successfully.");
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);
101
103
  if (language === "ts") {
102
- const aggregatedManifestPath = aggregateManifests(manifestsResponse.manifests);
104
+ console.log("generating TypeScript typings for plugin manifest...");
105
+ const jsOutput = `${appPrefix}.js`;
106
+ const dTsOutput = `${appPrefix}.d.ts`;
103
107
  execSync(`
104
- npx -p protobufjs-cli pbjs -t static --no-service ${aggregatedManifestPath} -o ${path.join(outDir, "plugins.asterai.js")}
108
+ npx -p protobufjs-cli pbjs -t static --no-service ${aggregatedManifest.filePath} -o ${path.join(outDir, jsOutput)}
105
109
  `);
106
110
  execSync(`
107
- npx -p protobufjs-cli pbts -o ${path.join(outDir, "plugins.asterai.d.ts")} ${path.join(outDir, "plugins.asterai.js")}
111
+ npx -p protobufjs-cli pbts -o ${path.join(outDir, dTsOutput)} ${path.join(outDir, jsOutput)}
108
112
  `);
109
- fs.unlinkSync(aggregatedManifestPath);
113
+ fs.unlinkSync(aggregatedManifest.filePath);
110
114
  console.log("Typings generated successfully.");
111
115
  }
116
+ console.log("done.");
112
117
  };
113
- const aggregateManifests = (manifests) => {
114
- let aggregatedManifest = `
115
- syntax = 'proto3';
116
- \n
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`;
118
126
  const osTmpDir = os.tmpdir();
119
127
  const aggregatedManifestPath = path.join(osTmpDir, "plugins.asterai.proto");
120
128
  for (const manifest of manifests) {
121
129
  aggregatedManifest += `${manifest.proto}\n`;
122
130
  }
123
131
  fs.writeFileSync(aggregatedManifestPath, aggregatedManifest);
124
- return aggregatedManifestPath;
132
+ return {
133
+ content: aggregatedManifest,
134
+ filePath: aggregatedManifestPath,
135
+ };
125
136
  };
126
137
  const downloadEnabledPluginsManifests = async (appId, shouldUseStaging) => {
127
138
  const baseUrl = shouldUseStaging
@@ -225,5 +225,5 @@
225
225
  ]
226
226
  }
227
227
  },
228
- "version": "0.3.1"
228
+ "version": "0.3.2"
229
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.1",
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",