@lark-apaas/fullstack-cli 1.1.16-alpha.2 → 1.1.16-alpha.3
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 +20 -0
- package/dist/index.js +75 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -227,6 +227,26 @@ fullstack-cli capability migration --dry-run
|
|
|
227
227
|
fullstack-cli --version
|
|
228
228
|
```
|
|
229
229
|
|
|
230
|
+
### 8. 全局选项
|
|
231
|
+
|
|
232
|
+
#### Canary 环境
|
|
233
|
+
|
|
234
|
+
支持通过 `--canary` 选项指定 canary 环境,会在 HTTP 请求中添加 `x-tt-env` header:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
# 通过命令行参数指定
|
|
238
|
+
fullstack-cli --canary boe_canary action-plugin install @office/feishu-create-group
|
|
239
|
+
|
|
240
|
+
# 也可以放在命令后面
|
|
241
|
+
fullstack-cli action-plugin install @office/feishu-create-group --canary boe_canary
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
也支持通过环境变量设置:
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
FORCE_FRAMEWORK_CLI_CANARY_ENV=boe_canary fullstack-cli action-plugin install @office/feishu-create-group
|
|
248
|
+
```
|
|
249
|
+
|
|
230
250
|
## package.json 配置
|
|
231
251
|
|
|
232
252
|
在用户项目的 `package.json` 中添加:
|
package/dist/index.js
CHANGED
|
@@ -63,9 +63,18 @@ var FullstackCLI = class {
|
|
|
63
63
|
constructor(version) {
|
|
64
64
|
this.program = new Command();
|
|
65
65
|
this.hooks = new HooksManager();
|
|
66
|
-
this.program.name("fullstack-cli").description("CLI tool for fullstack template management").version(version);
|
|
66
|
+
this.program.name("fullstack-cli").description("CLI tool for fullstack template management").version(version).option("--canary <env>", "Set canary environment (e.g., boe_canary)");
|
|
67
|
+
this.setupGlobalOptions();
|
|
67
68
|
this.setupDefaultHooks();
|
|
68
69
|
}
|
|
70
|
+
setupGlobalOptions() {
|
|
71
|
+
this.program.hook("preAction", (thisCommand) => {
|
|
72
|
+
const opts = thisCommand.opts();
|
|
73
|
+
if (opts.canary) {
|
|
74
|
+
process.env.FORCE_FRAMEWORK_CLI_CANARY_ENV = opts.canary;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
69
78
|
setupDefaultHooks() {
|
|
70
79
|
this.hooks.afterRun((ctx, error) => {
|
|
71
80
|
if (error) {
|
|
@@ -232,6 +241,20 @@ function sanitizeIdentifier(name) {
|
|
|
232
241
|
}
|
|
233
242
|
return sanitized;
|
|
234
243
|
}
|
|
244
|
+
function getUniqueIdentifier(name, usedIdentifiers) {
|
|
245
|
+
const base = sanitizeIdentifier(name);
|
|
246
|
+
if (!usedIdentifiers.has(base)) {
|
|
247
|
+
usedIdentifiers.add(base);
|
|
248
|
+
return base;
|
|
249
|
+
}
|
|
250
|
+
let suffix = 2;
|
|
251
|
+
while (usedIdentifiers.has(`${base}${suffix}`)) {
|
|
252
|
+
suffix++;
|
|
253
|
+
}
|
|
254
|
+
const unique = `${base}${suffix}`;
|
|
255
|
+
usedIdentifiers.add(unique);
|
|
256
|
+
return unique;
|
|
257
|
+
}
|
|
235
258
|
|
|
236
259
|
// src/commands/db/gen-dbschema/transforms/ast/rename-identifiers.ts
|
|
237
260
|
var PG_FACTORIES = [
|
|
@@ -282,10 +305,27 @@ function getCurrentName(decl) {
|
|
|
282
305
|
const name = decl.getName();
|
|
283
306
|
return name.replace(/^"|"$/g, "");
|
|
284
307
|
}
|
|
308
|
+
function collectExistingIdentifiers(ctx) {
|
|
309
|
+
const { sourceFile } = ctx;
|
|
310
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
311
|
+
for (const statement of sourceFile.getStatements()) {
|
|
312
|
+
if (!Node.isVariableStatement(statement)) {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
for (const decl of statement.getDeclarations()) {
|
|
316
|
+
const name = getCurrentName(decl);
|
|
317
|
+
if (name) {
|
|
318
|
+
identifiers.add(name);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return identifiers;
|
|
323
|
+
}
|
|
285
324
|
var renameIdentifiersTransform = {
|
|
286
325
|
name: "rename-identifiers",
|
|
287
326
|
transform(ctx) {
|
|
288
327
|
const { sourceFile, stats } = ctx;
|
|
328
|
+
const usedIdentifiers = collectExistingIdentifiers(ctx);
|
|
289
329
|
const renames = [];
|
|
290
330
|
for (const statement of sourceFile.getStatements()) {
|
|
291
331
|
if (!Node.isVariableStatement(statement)) {
|
|
@@ -307,10 +347,13 @@ var renameIdentifiersTransform = {
|
|
|
307
347
|
continue;
|
|
308
348
|
}
|
|
309
349
|
const currentName = getCurrentName(decl);
|
|
310
|
-
const
|
|
311
|
-
if (
|
|
312
|
-
|
|
350
|
+
const baseSanitized = sanitizeIdentifier(tableName);
|
|
351
|
+
if (baseSanitized === currentName) {
|
|
352
|
+
continue;
|
|
313
353
|
}
|
|
354
|
+
usedIdentifiers.delete(currentName);
|
|
355
|
+
const sanitized = getUniqueIdentifier(tableName, usedIdentifiers);
|
|
356
|
+
renames.push({ decl, from: currentName, to: sanitized });
|
|
314
357
|
}
|
|
315
358
|
}
|
|
316
359
|
for (const { decl, from, to } of renames.reverse()) {
|
|
@@ -760,17 +803,27 @@ var defaultTransforms = [
|
|
|
760
803
|
];
|
|
761
804
|
|
|
762
805
|
// src/commands/db/gen-dbschema/transforms/text/patch-defects.ts
|
|
806
|
+
function collectExistingIdentifiers2(source) {
|
|
807
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
808
|
+
const exportPattern = /export\s+const\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=/g;
|
|
809
|
+
let match;
|
|
810
|
+
while ((match = exportPattern.exec(source)) !== null) {
|
|
811
|
+
identifiers.add(match[1]);
|
|
812
|
+
}
|
|
813
|
+
return identifiers;
|
|
814
|
+
}
|
|
763
815
|
function patchDefects(source) {
|
|
764
816
|
let fixed = 0;
|
|
765
817
|
const renamedQuotedExports = [];
|
|
766
818
|
let text = source;
|
|
819
|
+
const usedIdentifiers = collectExistingIdentifiers2(source);
|
|
767
820
|
text = text.replace(/\.default\('\)/g, () => {
|
|
768
821
|
fixed += 1;
|
|
769
822
|
return `.default('')`;
|
|
770
823
|
});
|
|
771
824
|
const quotedExportPattern = /export const\s+"([^"]+)"\s*=/g;
|
|
772
|
-
text = text.replace(quotedExportPattern, (
|
|
773
|
-
const sanitized =
|
|
825
|
+
text = text.replace(quotedExportPattern, (_match, quotedName) => {
|
|
826
|
+
const sanitized = getUniqueIdentifier(quotedName, usedIdentifiers);
|
|
774
827
|
renamedQuotedExports.push({ from: quotedName, to: sanitized });
|
|
775
828
|
fixed += 1;
|
|
776
829
|
return `export const ${sanitized} =`;
|
|
@@ -899,8 +952,11 @@ function ensureImportIdentifier(source, packageName, identifier) {
|
|
|
899
952
|
}
|
|
900
953
|
function resolveTemplateTypesPath() {
|
|
901
954
|
const candidates = [
|
|
955
|
+
// Source code paths (relative to transforms/text/)
|
|
902
956
|
new URL("../../template/types.ts", import.meta.url),
|
|
903
|
-
new URL("../template/types.ts", import.meta.url)
|
|
957
|
+
new URL("../template/types.ts", import.meta.url),
|
|
958
|
+
// Bundled path (relative to dist/index.js)
|
|
959
|
+
new URL("./gen-dbschema-template/types.ts", import.meta.url)
|
|
904
960
|
];
|
|
905
961
|
for (const url of candidates) {
|
|
906
962
|
const p = fileURLToPath(url);
|
|
@@ -3550,17 +3606,17 @@ function analyzeImports(sourceFile) {
|
|
|
3550
3606
|
}
|
|
3551
3607
|
|
|
3552
3608
|
// src/commands/migration/versions/v001_capability/code-migrator/analyzers/call-site-analyzer.ts
|
|
3553
|
-
import { SyntaxKind as
|
|
3609
|
+
import { SyntaxKind as SyntaxKind5 } from "ts-morph";
|
|
3554
3610
|
function analyzeCallSites(sourceFile, imports) {
|
|
3555
3611
|
const callSites = [];
|
|
3556
3612
|
const importMap = /* @__PURE__ */ new Map();
|
|
3557
3613
|
for (const imp of imports) {
|
|
3558
3614
|
importMap.set(imp.importName, imp.capabilityId);
|
|
3559
3615
|
}
|
|
3560
|
-
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3616
|
+
const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind5.CallExpression);
|
|
3561
3617
|
for (const callExpr of callExpressions) {
|
|
3562
3618
|
const expression = callExpr.getExpression();
|
|
3563
|
-
if (expression.getKind() ===
|
|
3619
|
+
if (expression.getKind() === SyntaxKind5.Identifier) {
|
|
3564
3620
|
const functionName = expression.getText();
|
|
3565
3621
|
const capabilityId = importMap.get(functionName);
|
|
3566
3622
|
if (capabilityId) {
|
|
@@ -3573,11 +3629,11 @@ function analyzeCallSites(sourceFile, imports) {
|
|
|
3573
3629
|
text: callExpr.getText()
|
|
3574
3630
|
});
|
|
3575
3631
|
}
|
|
3576
|
-
} else if (expression.getKind() ===
|
|
3577
|
-
const propAccess = expression.asKind(
|
|
3632
|
+
} else if (expression.getKind() === SyntaxKind5.PropertyAccessExpression) {
|
|
3633
|
+
const propAccess = expression.asKind(SyntaxKind5.PropertyAccessExpression);
|
|
3578
3634
|
if (propAccess) {
|
|
3579
3635
|
const objectExpr = propAccess.getExpression();
|
|
3580
|
-
if (objectExpr.getKind() ===
|
|
3636
|
+
if (objectExpr.getKind() === SyntaxKind5.Identifier) {
|
|
3581
3637
|
const objectName = objectExpr.getText();
|
|
3582
3638
|
const capabilityId = importMap.get(objectName);
|
|
3583
3639
|
if (capabilityId) {
|
|
@@ -3806,7 +3862,7 @@ function addInjection(sourceFile) {
|
|
|
3806
3862
|
}
|
|
3807
3863
|
|
|
3808
3864
|
// src/commands/migration/versions/v001_capability/code-migrator/transformers/call-site-transformer.ts
|
|
3809
|
-
import { SyntaxKind as
|
|
3865
|
+
import { SyntaxKind as SyntaxKind6 } from "ts-morph";
|
|
3810
3866
|
var DEFAULT_ACTION_NAME = "run";
|
|
3811
3867
|
function generateNewCallText(capabilityId, actionName, args) {
|
|
3812
3868
|
const argsText = args.trim() || "{}";
|
|
@@ -3821,19 +3877,19 @@ function transformCallSites(sourceFile, imports) {
|
|
|
3821
3877
|
});
|
|
3822
3878
|
}
|
|
3823
3879
|
let replacedCount = 0;
|
|
3824
|
-
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3880
|
+
const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind6.CallExpression);
|
|
3825
3881
|
const sortedCalls = [...callExpressions].sort((a, b) => b.getStart() - a.getStart());
|
|
3826
3882
|
for (const callExpr of sortedCalls) {
|
|
3827
3883
|
const expression = callExpr.getExpression();
|
|
3828
3884
|
let importInfo;
|
|
3829
|
-
if (expression.getKind() ===
|
|
3885
|
+
if (expression.getKind() === SyntaxKind6.Identifier) {
|
|
3830
3886
|
const functionName = expression.getText();
|
|
3831
3887
|
importInfo = importMap.get(functionName);
|
|
3832
|
-
} else if (expression.getKind() ===
|
|
3833
|
-
const propAccess = expression.asKind(
|
|
3888
|
+
} else if (expression.getKind() === SyntaxKind6.PropertyAccessExpression) {
|
|
3889
|
+
const propAccess = expression.asKind(SyntaxKind6.PropertyAccessExpression);
|
|
3834
3890
|
if (propAccess) {
|
|
3835
3891
|
const objectExpr = propAccess.getExpression();
|
|
3836
|
-
if (objectExpr.getKind() ===
|
|
3892
|
+
if (objectExpr.getKind() === SyntaxKind6.Identifier) {
|
|
3837
3893
|
const objectName = objectExpr.getText();
|
|
3838
3894
|
importInfo = importMap.get(objectName);
|
|
3839
3895
|
}
|