@lark-apaas/fullstack-cli 1.1.21 → 1.1.22-alpha.1

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.
Files changed (3) hide show
  1. package/README.md +41 -3
  2. package/dist/index.js +128 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @lark-apaas/fullstack-cli
2
2
 
3
- > Fullstack 开发工具集 - 文件派生、数据库 Schema 生成、OpenAPI 生成、能力管理
3
+ > Fullstack 开发工具集 - 文件派生、数据库 Schema 生成、OpenAPI 生成、能力管理、构建工具
4
4
 
5
5
  ## 功能
6
6
 
@@ -9,6 +9,7 @@
9
9
  3. **OpenAPI 生成** - 自动生成 API 文档和客户端 SDK
10
10
  4. **Action 插件管理** - 安装、更新、删除 action 插件
11
11
  5. **能力配置管理** - 查看、充血、迁移能力配置
12
+ 6. **构建工具** - 获取 STI 制品上传凭证等构建相关操作
12
13
 
13
14
  ## 安装
14
15
 
@@ -201,7 +202,40 @@ fullstack-cli capability migration --skip-code
201
202
  }
202
203
  ```
203
204
 
204
- ### 7. CLI 命令
205
+ ### 7. 构建工具
206
+
207
+ 获取构建流程所需的 STI 制品上传凭证:
208
+
209
+ ```bash
210
+ # Pipeline 发布场景 - 需要 commit-id
211
+ fullstack-cli build get-token --app-id app_xxx --scene pipeline --commit-id abc123
212
+
213
+ # 静态资源部署场景
214
+ fullstack-cli build get-token --app-id app_xxx --scene static
215
+ ```
216
+
217
+ **参数说明:**
218
+
219
+ | 参数 | 必填 | 说明 |
220
+ |------|------|------|
221
+ | `--app-id <id>` | 是 | 应用 ID |
222
+ | `--scene <scene>` | 是 | 构建场景(`pipeline`、`static`) |
223
+ | `--commit-id <id>` | scene=pipeline 时必填 | Git Commit ID |
224
+
225
+ **输出:** stdout 输出 API 返回的完整 JSON,日志/错误输出到 stderr,便于脚本解析:
226
+
227
+ ```bash
228
+ token_response=$(fullstack-cli build get-token --app-id "$APP_ID" --scene pipeline --commit-id "$COMMIT_ID")
229
+ credential=$(echo "$token_response" | jq -r '.data.accessKeyID')
230
+ ```
231
+
232
+ **环境变量:**
233
+ - `FORCE_AUTHN_INNERAPI_DOMAIN` — API 域名
234
+ - `FORCE_AUTHN_ACCESS_KEY` — Access Key
235
+ - `FORCE_AUTHN_ACCESS_SECRET` — Secret Key
236
+ - `FORCE_FRAMEWORK_CLI_CANARY_ENV` — Canary 环境(可选)
237
+
238
+ ### 8. CLI 命令
205
239
 
206
240
  ```bash
207
241
  # 查看帮助
@@ -223,11 +257,15 @@ fullstack-cli capability --help
223
257
  fullstack-cli capability list
224
258
  fullstack-cli capability migration --dry-run
225
259
 
260
+ # 构建工具
261
+ fullstack-cli build --help
262
+ fullstack-cli build get-token --app-id <id> --scene <scene> [--commit-id <id>]
263
+
226
264
  # 查看版本
227
265
  fullstack-cli --version
228
266
  ```
229
267
 
230
- ### 8. 全局选项
268
+ ### 9. 全局选项
231
269
 
232
270
  #### Canary 环境
233
271
 
package/dist/index.js CHANGED
@@ -481,6 +481,7 @@ var replaceUnknownTransform = {
481
481
  transform(ctx) {
482
482
  const { sourceFile, stats } = ctx;
483
483
  const fullText = sourceFile.getFullText();
484
+ const replacements = [];
484
485
  sourceFile.forEachDescendant((node) => {
485
486
  if (!Node5.isCallExpression(node)) {
486
487
  return;
@@ -511,13 +512,23 @@ var replaceUnknownTransform = {
511
512
  break;
512
513
  }
513
514
  }
515
+ replacements.push({
516
+ expression,
517
+ factoryName,
518
+ foundKnownType,
519
+ isArrayType,
520
+ node
521
+ });
522
+ });
523
+ for (const { expression, factoryName, foundKnownType, isArrayType, node } of replacements) {
514
524
  expression.replaceWithText(factoryName);
515
525
  if (isArrayType && foundKnownType) {
516
526
  const parent = node.getParent();
517
527
  if (Node5.isPropertyAccessExpression(parent) && parent.getName() === "array") {
518
528
  const grandParent = parent.getParent();
519
529
  if (Node5.isCallExpression(grandParent)) {
520
- grandParent.replaceWithText(node.getText());
530
+ const nodeText = node.getText();
531
+ grandParent.replaceWithText(nodeText);
521
532
  }
522
533
  }
523
534
  }
@@ -526,7 +537,7 @@ var replaceUnknownTransform = {
526
537
  } else {
527
538
  stats.fallbackToText++;
528
539
  }
529
- });
540
+ }
530
541
  const todoCommentRegex = /\/\/ TODO: failed to parse database type '[^']+'\s*\n/g;
531
542
  const currentText = sourceFile.getFullText();
532
543
  const cleanedText = currentText.replace(todoCommentRegex, "");
@@ -2604,6 +2615,42 @@ function getHttpClient() {
2604
2615
  return clientInstance;
2605
2616
  }
2606
2617
 
2618
+ // src/utils/telemetry.ts
2619
+ async function reportEvents(events) {
2620
+ if (events.length === 0) {
2621
+ return true;
2622
+ }
2623
+ try {
2624
+ const client = getHttpClient();
2625
+ const response = await client.post("/resource_events", {
2626
+ body: JSON.stringify({ events })
2627
+ });
2628
+ if (!response.ok) {
2629
+ console.warn(`[telemetry] Failed to report events: ${response.status} ${response.statusText}`);
2630
+ return false;
2631
+ }
2632
+ const result = await response.json();
2633
+ if (result.status_code !== "0") {
2634
+ console.warn(`[telemetry] API error: ${result.message}`);
2635
+ return false;
2636
+ }
2637
+ return true;
2638
+ } catch (error) {
2639
+ console.warn(`[telemetry] Failed to report events: ${error instanceof Error ? error.message : error}`);
2640
+ return false;
2641
+ }
2642
+ }
2643
+ async function reportInstallEvent(pluginKey, version) {
2644
+ await reportEvents([
2645
+ {
2646
+ resourceType: "plugin",
2647
+ resourceKey: pluginKey,
2648
+ eventType: "install",
2649
+ details: { version }
2650
+ }
2651
+ ]);
2652
+ }
2653
+
2607
2654
  // src/commands/action-plugin/api-client.ts
2608
2655
  var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
2609
2656
  async function getPluginVersions(keys, latestOnly = true) {
@@ -2927,6 +2974,8 @@ async function installOne(nameWithVersion) {
2927
2974
  writeActionPlugins(plugins);
2928
2975
  const source = fromCache ? "from cache" : "downloaded";
2929
2976
  console.log(`[action-plugin] Successfully installed ${name}@${installedVersion} (${source})`);
2977
+ reportInstallEvent(name, installedVersion).catch(() => {
2978
+ });
2930
2979
  return { name, version: installedVersion, success: true };
2931
2980
  } catch (error) {
2932
2981
  const message = error instanceof Error ? error.message : String(error);
@@ -6491,6 +6540,81 @@ var readLogsCommand = {
6491
6540
  }
6492
6541
  };
6493
6542
 
6543
+ // src/commands/build/types.ts
6544
+ var SCENE_CONFIGS = {
6545
+ pipeline: {
6546
+ name: "pipeline",
6547
+ requiredOptions: ["commitId"],
6548
+ buildRequestBody: (opts) => ({ commitID: opts.commitId })
6549
+ },
6550
+ static: {
6551
+ name: "static",
6552
+ requiredOptions: [],
6553
+ buildRequestBody: () => ({ commitID: "" })
6554
+ }
6555
+ };
6556
+
6557
+ // src/commands/build/api-client.ts
6558
+ async function genArtifactUploadCredential(appId, body) {
6559
+ const client = getHttpClient();
6560
+ const url = `/v1/app/${appId}/pipeline/gen_artifact_upload_credential`;
6561
+ const response = await client.post(url, body);
6562
+ if (!response.ok || response.status !== 200) {
6563
+ throw new Error(
6564
+ `API request failed: ${response.status} ${response.statusText}`
6565
+ );
6566
+ }
6567
+ return response.json();
6568
+ }
6569
+
6570
+ // src/commands/build/get-token.handler.ts
6571
+ async function getToken(options) {
6572
+ try {
6573
+ const sceneConfig = SCENE_CONFIGS[options.scene];
6574
+ if (!sceneConfig) {
6575
+ const available = Object.keys(SCENE_CONFIGS).join(", ");
6576
+ console.error(
6577
+ `[build] Error: invalid scene "${options.scene}". Available scenes: ${available}`
6578
+ );
6579
+ process.exit(1);
6580
+ }
6581
+ for (const key of sceneConfig.requiredOptions) {
6582
+ if (!options[key]) {
6583
+ console.error(
6584
+ `[build] Error: --${camelToKebab(key)} is required for scene "${options.scene}"`
6585
+ );
6586
+ process.exit(1);
6587
+ }
6588
+ }
6589
+ const body = sceneConfig.buildRequestBody(options);
6590
+ const response = await genArtifactUploadCredential(options.appId, body);
6591
+ console.log(JSON.stringify(response));
6592
+ } catch (error) {
6593
+ const message = error instanceof Error ? error.message : String(error);
6594
+ console.error(`[build] Error: ${message}`);
6595
+ process.exit(1);
6596
+ }
6597
+ }
6598
+ function camelToKebab(str) {
6599
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
6600
+ }
6601
+
6602
+ // src/commands/build/index.ts
6603
+ var getTokenCommand = {
6604
+ name: "get-token",
6605
+ description: "Get artifact upload credential (STI token)",
6606
+ register(program) {
6607
+ program.command(this.name).description(this.description).requiredOption("--app-id <id>", "Application ID").requiredOption("--scene <scene>", "Build scene (pipeline, static)").option("--commit-id <id>", "Git commit ID (required for pipeline scene)").action(async (options) => {
6608
+ await getToken(options);
6609
+ });
6610
+ }
6611
+ };
6612
+ var buildCommandGroup = {
6613
+ name: "build",
6614
+ description: "Build related commands",
6615
+ commands: [getTokenCommand]
6616
+ };
6617
+
6494
6618
  // src/commands/index.ts
6495
6619
  var commands = [
6496
6620
  genDbSchemaCommand,
@@ -6499,7 +6623,8 @@ var commands = [
6499
6623
  capabilityCommandGroup,
6500
6624
  componentCommandGroup,
6501
6625
  migrationCommand,
6502
- readLogsCommand
6626
+ readLogsCommand,
6627
+ buildCommandGroup
6503
6628
  ];
6504
6629
 
6505
6630
  // src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-cli",
3
- "version": "1.1.21",
3
+ "version": "1.1.22-alpha.1",
4
4
  "description": "CLI tool for fullstack template management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",