@lark-apaas/miaoda-cli 0.1.16-beta.70f1b39 → 0.1.17-alpha.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/dist/cli/commands/app/index.js +43 -0
- package/dist/cli/commands/deploy/modern.js +9 -0
- package/dist/cli/handlers/app/index.js +3 -1
- package/dist/cli/handlers/app/migrate.js +223 -0
- package/dist/cli/handlers/deploy/modern.js +39 -0
- package/dist/config/migrate-configs/index.js +35 -0
- package/dist/config/migrate-configs/vite-react-to-nestjs-react-fullstack.js +293 -0
- package/dist/config/migrate.js +15 -0
- package/dist/services/app/init/index.js +2 -1
- package/dist/services/deploy/modern/atoms/local-release.js +7 -2
- package/dist/services/deploy/modern/pipelines/local.js +4 -1
- package/dist/utils/codemod-client-toolkit-lite.js +106 -0
- package/dist/utils/migrate-rule.js +319 -0
- package/package.json +17 -14
- package/upgrade/templates/design-stack/templates/.githooks/pre-commit +0 -0
- package/upgrade/templates/design-stack/templates/scripts/dev-local.js +0 -0
- package/upgrade/templates/design-stack/templates/scripts/dev.sh +0 -0
- package/upgrade/templates/nestjs-react-fullstack/templates/.githooks/pre-commit +0 -0
- package/upgrade/templates/nestjs-react-fullstack/templates/scripts/build.sh +0 -0
- package/upgrade/templates/nestjs-react-fullstack/templates/scripts/dev-local.js +0 -0
- package/upgrade/templates/nestjs-react-fullstack/templates/scripts/dev.sh +0 -0
- package/upgrade/templates/nestjs-react-fullstack/templates/scripts/run.sh +0 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerAppCommands = registerAppCommands;
|
|
4
|
+
const commander_1 = require("commander");
|
|
4
5
|
const shared_1 = require("../../../cli/commands/shared");
|
|
5
6
|
const index_1 = require("../../../cli/handlers/app/index");
|
|
7
|
+
const index_2 = require("../../../config/migrate-configs/index");
|
|
6
8
|
const error_1 = require("../../../utils/error");
|
|
7
9
|
function registerAppCommands(program, opts = {}) {
|
|
8
10
|
const description = opts.includeInit
|
|
@@ -22,8 +24,49 @@ function registerAppCommands(program, opts = {}) {
|
|
|
22
24
|
if (opts.includeInit) {
|
|
23
25
|
registerAppInit(appCmd);
|
|
24
26
|
registerAppSync(appCmd);
|
|
27
|
+
registerAppMigrate(appCmd);
|
|
25
28
|
}
|
|
26
29
|
}
|
|
30
|
+
function registerAppMigrate(parent) {
|
|
31
|
+
const supportedDesc = (0, index_2.listSupportedMigrations)()
|
|
32
|
+
.map((m) => `${m.from} → ${m.to}`)
|
|
33
|
+
.join(', ');
|
|
34
|
+
// 渐进式披露:migrate 是给妙搭平台 / 用户主动触发的命令,**不暴露给 Agent**。
|
|
35
|
+
// - `miaoda app -h` / `miaoda app help` 都不列出此命令
|
|
36
|
+
// - 但 `miaoda app migrate --to xxx` 仍能直接调用(仅命令注册时打 hidden 标记,行为不变)
|
|
37
|
+
// - `--help` 也不显示 ——commander hidden 命令仅显式 invoke 时才暴露
|
|
38
|
+
// 用 addCommand(cmd, { hidden: true }) 而非 parent.command(...),因为 commander 13
|
|
39
|
+
// 的 fluent `.command()` 不支持设置 hidden。
|
|
40
|
+
const cmd = new commander_1.Command('migrate')
|
|
41
|
+
.description('跨 stack 原地迁移:按 MigrateConfig 全套 apply(move + delete + 模板覆盖 + 字段 merge + set-stack)')
|
|
42
|
+
.requiredOption('--to <stack>', '目标 stack 短名')
|
|
43
|
+
.option('--from <stack>', '源 stack;默认读 .spark/meta.json 当前 stack')
|
|
44
|
+
.option('--dir <path>', '项目目录,默认 cwd(需含 .spark/meta.json)')
|
|
45
|
+
.addHelpText('after', `
|
|
46
|
+
已支持的迁移路径
|
|
47
|
+
${supportedDesc || '(none)'}
|
|
48
|
+
|
|
49
|
+
JSON 输出
|
|
50
|
+
{"data": {"from": "...", "to": "...",
|
|
51
|
+
"appliedRules": [{"type": "...", "action": "...", "path": "...", "detail": "..."}],
|
|
52
|
+
"moved": [...], "deleted": [...], "synced": [...], "merged": [...], "patched": [...],
|
|
53
|
+
"skipped": N,
|
|
54
|
+
"nextActions": [...]}}
|
|
55
|
+
|
|
56
|
+
示例
|
|
57
|
+
$ miaoda app migrate --to nestjs-react-fullstack
|
|
58
|
+
$ miaoda app migrate --from vite-react --to nestjs-react-fullstack
|
|
59
|
+
$ miaoda app migrate --to nestjs-react-fullstack --dir /path/to/app
|
|
60
|
+
`);
|
|
61
|
+
cmd.action((0, shared_1.withHelp)(cmd, async (rawOpts) => {
|
|
62
|
+
await (0, index_1.handleAppMigrate)({
|
|
63
|
+
dir: rawOpts.dir,
|
|
64
|
+
from: rawOpts.from,
|
|
65
|
+
to: rawOpts.to,
|
|
66
|
+
});
|
|
67
|
+
}));
|
|
68
|
+
parent.addCommand(cmd, { hidden: true });
|
|
69
|
+
}
|
|
27
70
|
function registerAppSync(parent) {
|
|
28
71
|
const cmd = parent
|
|
29
72
|
.command('sync')
|
|
@@ -16,6 +16,7 @@ function registerDeployCommandsModern(program) {
|
|
|
16
16
|
.description('触发 modern 应用发布:本地构建 + 本地部署(preRelease + localPublish)')
|
|
17
17
|
.option('--dir <path>', '项目目录', '.')
|
|
18
18
|
.option('--skip-build', '跳过 build 步骤(已构建好时使用)', false)
|
|
19
|
+
.option('--conf <json>', '关联元信息 JSON,仅识别 checkPointVersion / commitID 两字段')
|
|
19
20
|
.addHelpText('after', `
|
|
20
21
|
不要用异步模式或后台模式调用 deploy,否则调用可能提前结束,Agent 会误判发布已完成。
|
|
21
22
|
|
|
@@ -32,6 +33,12 @@ function registerDeployCommandsModern(program) {
|
|
|
32
33
|
6. savePluginInstances(扫描 dist/output_capabilities/*.json 批量注册)
|
|
33
34
|
7. finalizeLocalRelease(Finished|Failed)
|
|
34
35
|
|
|
36
|
+
--conf(关联元信息透传)
|
|
37
|
+
值为 JSON string,只识别两个字段,其余 key 忽略:
|
|
38
|
+
checkPointVersion 关联的 checkpoint 版本
|
|
39
|
+
commitID 关联的代码 commit ID
|
|
40
|
+
两字段均可选;非法 JSON / 非对象 / 字段值非字符串会报错。
|
|
41
|
+
|
|
35
42
|
JSON 输出(stdout)
|
|
36
43
|
{"data": {"appId": "...", "version": <n>, "url": "...", "releaseID": "...", "preReleaseID": "..."}}
|
|
37
44
|
|
|
@@ -39,12 +46,14 @@ JSON 输出(stdout)
|
|
|
39
46
|
$ miaoda deploy
|
|
40
47
|
$ miaoda deploy --dir ./my-app
|
|
41
48
|
$ miaoda deploy --skip-build
|
|
49
|
+
$ miaoda deploy --conf '{"checkPointVersion":"v3","commitID":"a1b2c3d"}'
|
|
42
50
|
`);
|
|
43
51
|
deployCmd.action((0, shared_1.withHelp)(deployCmd, async (rawOpts) => {
|
|
44
52
|
await (0, modern_1.handleDeployModern)({
|
|
45
53
|
dir: rawOpts.dir ?? '.',
|
|
46
54
|
appId: (0, shared_1.resolveAppId)({}),
|
|
47
55
|
skipBuild: rawOpts.skipBuild,
|
|
56
|
+
conf: rawOpts.conf,
|
|
48
57
|
});
|
|
49
58
|
}));
|
|
50
59
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SUPPORTED_STACKS = exports.handleAppUpgrade = exports.handleAppSync = exports.handleAppInit = exports.handleAppUpdate = exports.handleAppGet = void 0;
|
|
3
|
+
exports.SUPPORTED_STACKS = exports.handleAppMigrate = exports.handleAppUpgrade = exports.handleAppSync = exports.handleAppInit = exports.handleAppUpdate = exports.handleAppGet = void 0;
|
|
4
4
|
var get_1 = require("./get");
|
|
5
5
|
Object.defineProperty(exports, "handleAppGet", { enumerable: true, get: function () { return get_1.handleAppGet; } });
|
|
6
6
|
var update_1 = require("./update");
|
|
@@ -10,6 +10,8 @@ Object.defineProperty(exports, "handleAppInit", { enumerable: true, get: functio
|
|
|
10
10
|
var sync_1 = require("./sync");
|
|
11
11
|
Object.defineProperty(exports, "handleAppSync", { enumerable: true, get: function () { return sync_1.handleAppSync; } });
|
|
12
12
|
Object.defineProperty(exports, "handleAppUpgrade", { enumerable: true, get: function () { return sync_1.handleAppUpgrade; } });
|
|
13
|
+
var migrate_1 = require("./migrate");
|
|
14
|
+
Object.defineProperty(exports, "handleAppMigrate", { enumerable: true, get: function () { return migrate_1.handleAppMigrate; } });
|
|
13
15
|
// commands 层渲染 help 时需要这份枚举;从 handler barrel 转发,避免 commands → services 越界
|
|
14
16
|
var index_1 = require("../../../services/app/init/index");
|
|
15
17
|
Object.defineProperty(exports, "SUPPORTED_STACKS", { enumerable: true, get: function () { return index_1.SUPPORTED_STACKS; } });
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.handleAppMigrate = handleAppMigrate;
|
|
7
|
+
const node_child_process_1 = require("node:child_process");
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const index_1 = require("../../../config/migrate-configs/index");
|
|
12
|
+
const index_2 = require("../../../services/app/init/index");
|
|
13
|
+
const migrate_rule_1 = require("../../../utils/migrate-rule");
|
|
14
|
+
const spark_meta_1 = require("../../../utils/spark-meta");
|
|
15
|
+
const error_1 = require("../../../utils/error");
|
|
16
|
+
const output_1 = require("../../../utils/output");
|
|
17
|
+
const logger_1 = require("../../../utils/logger");
|
|
18
|
+
/**
|
|
19
|
+
* miaoda app migrate --to <stack> [--from <stack>] [--dir <path>]
|
|
20
|
+
*
|
|
21
|
+
* 跨 stack 原地迁移:把 user app 从源 stack(默认 .spark/meta.json 当前 stack)转到目标 stack。
|
|
22
|
+
* 同一个 git 仓库内进行,不动 git history,所有改动作为 working tree 变更体现,用户跑完后
|
|
23
|
+
* 自行 `git status` / `git diff` 评估并 commit。
|
|
24
|
+
*
|
|
25
|
+
* 跟 sync 的区别:sync 是同 stack 内的版本对齐,migrate 是跨 stack 切换(布局重排、依赖
|
|
26
|
+
* 集合切换、配置文件全套替换)。两条命令的 rule 引擎共享(applyMigrateRules 内部对
|
|
27
|
+
* SyncRule 委派给 applySyncRules)。
|
|
28
|
+
*
|
|
29
|
+
* 执行流:
|
|
30
|
+
* 1. 校验 user app 已 init(.spark/meta.json 存在)+ 当前 stack 匹配 from
|
|
31
|
+
* 2. 拿到 (from, to) 对应的 MigrateConfig 与模板源根目录
|
|
32
|
+
* 3. 顺序执行 rules:move-* → delete-* → delete-json-keys → file/directory →
|
|
33
|
+
* merge-json → set-stack
|
|
34
|
+
* 4. 清掉 node_modules(package-lock.json 已经在 rules 里 delete),跑 npm install
|
|
35
|
+
* 物化新依赖集合 —— migrate 改了 dependencies / devDependencies 集合(删 lite +
|
|
36
|
+
* 加 NestJS 全套),不重装就跑不起来。
|
|
37
|
+
* 同一条 npm install 顺手把 config.followLatestPackages 钉 `@latest`,覆盖
|
|
38
|
+
* template caret range 拉不到 pre-release 的盲区(详见 MigrateConfig 注释)。
|
|
39
|
+
*
|
|
40
|
+
* 不做事:
|
|
41
|
+
* - 不自动 commit / stash —— 让用户自己用 git review 改动
|
|
42
|
+
* - 不动 .agent/skills/(那是 miaoda skills sync 的事,迁移后用户应该单独跑一次切到新 stack 的 skills)
|
|
43
|
+
*/
|
|
44
|
+
async function handleAppMigrate(opts) {
|
|
45
|
+
await Promise.resolve();
|
|
46
|
+
const targetDir = node_path_1.default.resolve(opts.dir ?? process.cwd());
|
|
47
|
+
const meta = (0, spark_meta_1.readSparkMeta)(targetDir);
|
|
48
|
+
if (meta.stack === undefined || meta.stack === '') {
|
|
49
|
+
throw new error_1.AppError('MIGRATE_META_INCOMPLETE', '.spark/meta.json missing stack — run `miaoda app init` first');
|
|
50
|
+
}
|
|
51
|
+
const from = opts.from ?? meta.stack;
|
|
52
|
+
if (opts.from !== undefined && opts.from !== meta.stack) {
|
|
53
|
+
throw new error_1.AppError('MIGRATE_FROM_MISMATCH', `--from '${opts.from}' but current stack is '${meta.stack}'`, {
|
|
54
|
+
next_actions: ['省略 --from 让 cli 自动读 meta.json,或确认 user app 状态'],
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (from === opts.to) {
|
|
58
|
+
throw new error_1.AppError('MIGRATE_NOOP', `from and to are both '${from}', nothing to do`);
|
|
59
|
+
}
|
|
60
|
+
const config = (0, index_1.getMigrateConfig)(from, opts.to);
|
|
61
|
+
if (config === null) {
|
|
62
|
+
const supported = (0, index_1.listSupportedMigrations)()
|
|
63
|
+
.map((m) => `${m.from} → ${m.to}`)
|
|
64
|
+
.join(', ');
|
|
65
|
+
throw new error_1.AppError('MIGRATE_PATH_NOT_SUPPORTED', `no migrate config for '${from}' → '${opts.to}'`, {
|
|
66
|
+
next_actions: [`已支持:${supported || '(none)'}`],
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// migrate 用 init 同款的 renderTemplate 拉目标 stack 的 npm template tarball 到 tmp,
|
|
70
|
+
// 再把 tmp 当作 sourceRoot 喂给 applyMigrateRules。这样 migrate config 里 file/directory
|
|
71
|
+
// rule 的 `from` 引用的是完整的 npm template 渲染产物,不需要在 upgrade/templates/ 重复
|
|
72
|
+
// 维护一份 server/ + client/ + 全套配置 —— 复杂度由 init 那条链路 amortize。
|
|
73
|
+
const tmpRoot = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'miaoda-migrate-'));
|
|
74
|
+
const projectName = node_path_1.default.basename(targetDir);
|
|
75
|
+
let templateVersion;
|
|
76
|
+
let templateArchType;
|
|
77
|
+
let results;
|
|
78
|
+
try {
|
|
79
|
+
const tpl = (0, index_2.renderTemplate)({ stack: opts.to, targetDir: tmpRoot, projectName });
|
|
80
|
+
templateVersion = tpl.version;
|
|
81
|
+
templateArchType = tpl.archType;
|
|
82
|
+
// template package.json 的 user 私有字段(name / version / private 等)不参与 merge —— 否
|
|
83
|
+
// 则会被 deepMergeJson 当成 template 端"权威值"覆盖 user 项目原本的字段。这里在 tmp 端
|
|
84
|
+
// 直接 strip 这些字段,让 merge-json rule 只对 dependencies / devDependencies / scripts
|
|
85
|
+
// 等 schema-level 字段生效。
|
|
86
|
+
stripUserOwnedFields(node_path_1.default.join(tmpRoot, 'package.json'));
|
|
87
|
+
(0, logger_1.log)('migrate', `Rendered ${opts.to}@${tpl.version} to tmp, applying ${config.rules.length.toString()} rule(s)`);
|
|
88
|
+
results = (0, migrate_rule_1.applyMigrateRules)(config.rules, {
|
|
89
|
+
sourceRoot: tmpRoot,
|
|
90
|
+
targetDir,
|
|
91
|
+
logPrefix: 'migrate',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
node_fs_1.default.rmSync(tmpRoot, { recursive: true, force: true });
|
|
96
|
+
}
|
|
97
|
+
// archType / version 字段同步:set-stack rule 只切 stack,archType 是从 npm template 包
|
|
98
|
+
// 的 miaodaTemplate.archType 拿到的动态值,rule 配置时不知道,由 handler 在拿到
|
|
99
|
+
// renderTemplate 结果后单独写。version 也一并写回方便 sync 后续诊断。
|
|
100
|
+
(0, spark_meta_1.writeSparkMeta)(targetDir, { archType: templateArchType, version: templateVersion });
|
|
101
|
+
// 清掉 user app 的 node_modules —— migrate 改了 dependencies 集合(删 lite + 加 NestJS
|
|
102
|
+
// 全套)+ rule 已经把 package-lock.json 删了。如果 node_modules 留着,npm install 时旧
|
|
103
|
+
// 包还在 node_modules 顶层 hoist 树里,可能跟新 package.json spec 撞 peer 冲突
|
|
104
|
+
// (比如旧 coding-preset-vite-react@1.0.8 peer vite@^8 跟新 vite@^7 撞)。
|
|
105
|
+
// 软失败:node_modules 不存在不报错。
|
|
106
|
+
const nodeModulesPath = node_path_1.default.join(targetDir, 'node_modules');
|
|
107
|
+
if (node_fs_1.default.existsSync(nodeModulesPath)) {
|
|
108
|
+
(0, logger_1.log)('migrate', '清理 node_modules(dependencies 集合已变)...');
|
|
109
|
+
node_fs_1.default.rmSync(nodeModulesPath, { recursive: true, force: true });
|
|
110
|
+
}
|
|
111
|
+
// 跑 npm install 物化新依赖集合 + 把 followLatestPackages 钉 latest
|
|
112
|
+
// --ignore-scripts 绕开 action-plugin postinstall 在缺平台 env 时的 ENOENT
|
|
113
|
+
// --registry 钉同一份 npmmirror(跟 init / sync 行为一致)
|
|
114
|
+
// 软失败:install 挂了不阻断 emit;用户拿到详细 error,自行 npm install 兜底
|
|
115
|
+
const followLatest = config.followLatestPackages ?? [];
|
|
116
|
+
const installArgs = [
|
|
117
|
+
'install',
|
|
118
|
+
'--no-audit',
|
|
119
|
+
'--no-fund',
|
|
120
|
+
'--ignore-scripts',
|
|
121
|
+
'--registry',
|
|
122
|
+
(0, index_2.resolveNpmInstallRegistry)(),
|
|
123
|
+
...followLatest.map((pkg) => `${pkg}@latest`),
|
|
124
|
+
];
|
|
125
|
+
(0, logger_1.log)('migrate', `Running npm ${installArgs.join(' ')}...`);
|
|
126
|
+
let installError;
|
|
127
|
+
try {
|
|
128
|
+
(0, node_child_process_1.execFileSync)('npm', installArgs, {
|
|
129
|
+
cwd: targetDir,
|
|
130
|
+
stdio: (0, output_1.isJsonMode)() ? ['ignore', 'ignore', 'inherit'] : 'inherit',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
installError = err instanceof Error ? err.message : String(err);
|
|
135
|
+
(0, logger_1.log)('migrate', `⚠ npm install failed (continuing): ${installError}`);
|
|
136
|
+
}
|
|
137
|
+
(0, output_1.emit)({
|
|
138
|
+
data: {
|
|
139
|
+
from,
|
|
140
|
+
to: opts.to,
|
|
141
|
+
templateVersion,
|
|
142
|
+
appliedRules: results.map((r) => ({
|
|
143
|
+
type: r.rule.type,
|
|
144
|
+
action: r.action,
|
|
145
|
+
path: r.path,
|
|
146
|
+
detail: r.detail,
|
|
147
|
+
})),
|
|
148
|
+
...summarizeResults(results),
|
|
149
|
+
followLatestPackages: followLatest,
|
|
150
|
+
installError,
|
|
151
|
+
nextActions: [
|
|
152
|
+
'git status / git diff 评估改动并 commit',
|
|
153
|
+
'miaoda skills sync 同步到新 stack 的 agent skills',
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 从 tmp 端 template package.json 中删除 user 项目通常拥有的字段,避免 merge-json 时这些
|
|
160
|
+
* 字段被 template 值覆盖。需要 strip 的字段以 npm 模板里"通常专属于具体应用"的为准。
|
|
161
|
+
*/
|
|
162
|
+
function stripUserOwnedFields(pkgPath) {
|
|
163
|
+
if (!node_fs_1.default.existsSync(pkgPath))
|
|
164
|
+
return;
|
|
165
|
+
const json = JSON.parse(node_fs_1.default.readFileSync(pkgPath, 'utf-8'));
|
|
166
|
+
const userOwned = [
|
|
167
|
+
'name',
|
|
168
|
+
'version',
|
|
169
|
+
'private',
|
|
170
|
+
'description',
|
|
171
|
+
'author',
|
|
172
|
+
'keywords',
|
|
173
|
+
'license',
|
|
174
|
+
'repository',
|
|
175
|
+
'homepage',
|
|
176
|
+
'bugs',
|
|
177
|
+
];
|
|
178
|
+
let changed = false;
|
|
179
|
+
for (const key of userOwned) {
|
|
180
|
+
if (Reflect.deleteProperty(json, key))
|
|
181
|
+
changed = true;
|
|
182
|
+
}
|
|
183
|
+
if (changed) {
|
|
184
|
+
node_fs_1.default.writeFileSync(pkgPath, JSON.stringify(json, null, 2) + '\n');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function summarizeResults(results) {
|
|
188
|
+
const moved = [];
|
|
189
|
+
const deleted = [];
|
|
190
|
+
const synced = [];
|
|
191
|
+
const merged = [];
|
|
192
|
+
const patched = [];
|
|
193
|
+
let skipped = 0;
|
|
194
|
+
for (const r of results) {
|
|
195
|
+
if (r.path === undefined)
|
|
196
|
+
continue;
|
|
197
|
+
switch (r.action) {
|
|
198
|
+
case 'moved':
|
|
199
|
+
moved.push(r.path);
|
|
200
|
+
break;
|
|
201
|
+
case 'deleted':
|
|
202
|
+
deleted.push(r.path);
|
|
203
|
+
break;
|
|
204
|
+
case 'synced':
|
|
205
|
+
case 'created':
|
|
206
|
+
synced.push(r.path);
|
|
207
|
+
break;
|
|
208
|
+
case 'merged':
|
|
209
|
+
merged.push(r.path);
|
|
210
|
+
break;
|
|
211
|
+
case 'patched':
|
|
212
|
+
patched.push(r.path);
|
|
213
|
+
break;
|
|
214
|
+
case 'skipped':
|
|
215
|
+
skipped++;
|
|
216
|
+
break;
|
|
217
|
+
case 'appended':
|
|
218
|
+
case 'noop':
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return { moved, deleted, synced, merged, patched, skipped };
|
|
223
|
+
}
|
|
@@ -3,10 +3,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseDeployConf = parseDeployConf;
|
|
6
7
|
exports.handleDeployModern = handleDeployModern;
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
9
|
const output_1 = require("../../../utils/output");
|
|
10
|
+
const error_1 = require("../../../utils/error");
|
|
9
11
|
const index_1 = require("../../../services/deploy/modern/index");
|
|
12
|
+
const CONF_EXPECTED = '期望形如 {"checkPointVersion":"...","commitID":"..."} 的 JSON 对象';
|
|
13
|
+
/**
|
|
14
|
+
* 解析 `--conf` JSON string,只取 checkPointVersion / commitID 两个白名单字段。
|
|
15
|
+
* - 未传 → 返回 {}(行为不变)。
|
|
16
|
+
* - 非法 JSON / 非 object / 字段值非 string → 抛 DEPLOY_CONF_INVALID。
|
|
17
|
+
* - 空串字段视为未提供(不进 body,保持可选语义);未知 key 忽略。
|
|
18
|
+
*/
|
|
19
|
+
function parseDeployConf(raw) {
|
|
20
|
+
if (raw === undefined || raw === '')
|
|
21
|
+
return {};
|
|
22
|
+
let parsed;
|
|
23
|
+
try {
|
|
24
|
+
parsed = JSON.parse(raw);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
throw new error_1.AppError('DEPLOY_CONF_INVALID', `--conf 不是合法 JSON,${CONF_EXPECTED}`);
|
|
28
|
+
}
|
|
29
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
30
|
+
throw new error_1.AppError('DEPLOY_CONF_INVALID', `--conf 必须是 JSON 对象,${CONF_EXPECTED}`);
|
|
31
|
+
}
|
|
32
|
+
const source = parsed;
|
|
33
|
+
const conf = {};
|
|
34
|
+
for (const key of ['checkPointVersion', 'commitID']) {
|
|
35
|
+
const value = source[key];
|
|
36
|
+
if (value === undefined)
|
|
37
|
+
continue;
|
|
38
|
+
if (typeof value !== 'string') {
|
|
39
|
+
throw new error_1.AppError('DEPLOY_CONF_INVALID', `--conf.${key} 必须是字符串,${CONF_EXPECTED}`);
|
|
40
|
+
}
|
|
41
|
+
if (value !== '')
|
|
42
|
+
conf[key] = value;
|
|
43
|
+
}
|
|
44
|
+
return conf;
|
|
45
|
+
}
|
|
10
46
|
/**
|
|
11
47
|
* miaoda deploy(modern scene 专用,CLI 表面对齐 openclaw-cli)
|
|
12
48
|
*
|
|
@@ -14,10 +50,13 @@ const index_1 = require("../../../services/deploy/modern/index");
|
|
|
14
50
|
*/
|
|
15
51
|
async function handleDeployModern(opts) {
|
|
16
52
|
const projectDir = node_path_1.default.resolve(opts.dir);
|
|
53
|
+
const conf = parseDeployConf(opts.conf);
|
|
17
54
|
const result = await (0, index_1.runModernDeploy)({
|
|
18
55
|
projectDir,
|
|
19
56
|
appId: opts.appId,
|
|
20
57
|
skipBuild: opts.skipBuild ?? false,
|
|
58
|
+
checkPointVersion: conf.checkPointVersion,
|
|
59
|
+
commitID: conf.commitID,
|
|
21
60
|
});
|
|
22
61
|
(0, output_1.emit)({
|
|
23
62
|
data: {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 跨 stack 迁移注册表 —— 按 (from, to) 二元组查找对应的 MigrateConfig。
|
|
4
|
+
*
|
|
5
|
+
* 跟 sync 注册表 (src/config/sync-configs/index.ts) 的关系:sync 一份配置对应一个 stack,
|
|
6
|
+
* migrate 一份配置对应 (源 stack, 目标 stack) 二元组;模板资产 migrate 在 runtime 从 npm
|
|
7
|
+
* 拉目标 stack 的 template tarball(init 用同一套 renderTemplate),不再用 upgrade/templates/
|
|
8
|
+
* 的子集。
|
|
9
|
+
*
|
|
10
|
+
* 新增迁移路径:
|
|
11
|
+
* 1. src/config/migrate-configs/<from>-to-<to>.ts 里 export default MIGRATE_CONFIG
|
|
12
|
+
* 2. 在 MIGRATE_REGISTRY 加一条
|
|
13
|
+
*/
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.getMigrateConfig = getMigrateConfig;
|
|
19
|
+
exports.listSupportedMigrations = listSupportedMigrations;
|
|
20
|
+
const vite_react_to_nestjs_react_fullstack_1 = __importDefault(require("./vite-react-to-nestjs-react-fullstack"));
|
|
21
|
+
/** key 格式:`<from>:<to>` */
|
|
22
|
+
const MIGRATE_REGISTRY = {
|
|
23
|
+
'vite-react:nestjs-react-fullstack': vite_react_to_nestjs_react_fullstack_1.default,
|
|
24
|
+
};
|
|
25
|
+
/** 返回 (from, to) 对应的 MigrateConfig;未注册时返回 null。 */
|
|
26
|
+
function getMigrateConfig(from, to) {
|
|
27
|
+
return MIGRATE_REGISTRY[`${from}:${to}`] ?? null;
|
|
28
|
+
}
|
|
29
|
+
/** 列出已支持的迁移路径,给 handler / 命令 help 用 */
|
|
30
|
+
function listSupportedMigrations() {
|
|
31
|
+
return Object.keys(MIGRATE_REGISTRY).map((key) => {
|
|
32
|
+
const [from, to] = key.split(':');
|
|
33
|
+
return { from, to };
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* vite-react → nestjs-react-fullstack 的跨 stack 迁移规则。
|
|
4
|
+
*
|
|
5
|
+
* 设计原则:**最小改动**。只动 fullstack 形态必须的文件 / package.json key,user 已有
|
|
6
|
+
* 的 vite.config / tsconfig / eslint / prettier / tailwind / postcss / components.json
|
|
7
|
+
* 等业务配置一律**保留**,不被 template 整体覆盖。
|
|
8
|
+
*
|
|
9
|
+
* 步骤:
|
|
10
|
+
* 1. src/ public/ 搬到 client/ 下(fullstack 布局)
|
|
11
|
+
* 2. 清掉 vite-react 时代的根 index.html / eslint.config.mjs / package-lock.json
|
|
12
|
+
* 3. 删 user package.json 里 lite SDK 相关 key(保留 coding-preset-vite-react)
|
|
13
|
+
* 4. 把 NestJS server runtime 拷进来(server/ + nest-cli.json + tsconfig.node.json
|
|
14
|
+
* + client/index.html 等 fullstack 形态新增的资产)
|
|
15
|
+
* 5. 把 fullstack 必需的 scripts 加到 package.json(dev / build / type:check 等)
|
|
16
|
+
* 6. 从 fullstack template/package.json 取版本号,精确加 NestJS 强依赖白名单
|
|
17
|
+
* (client-toolkit + 几个 @nestjs/* + fullstack-nestjs-core + hbs 等;不全量 merge)
|
|
18
|
+
* 7. codemod 业务代码:@lark-apaas/client-toolkit-lite → @lark-apaas/client-toolkit
|
|
19
|
+
* 8. codemod vite.config:defineConfig(...) → defineConfig(..., { fullstack: true }),
|
|
20
|
+
* 让 coding-preset-vite-react 启用 fullstack dev-proxy / html-output / basename /
|
|
21
|
+
* server-log 4 件套,vite 8080 反代 HTML / API 到 nest 3000
|
|
22
|
+
* 9. set-stack 切 .spark/meta.json
|
|
23
|
+
*
|
|
24
|
+
* 跟 SDK 的协作:client-toolkit@1.2.52+ 顶层 single-entry 完整 re-export 了
|
|
25
|
+
* client-toolkit-lite 全部 48 项 API(fullstack-plugin#1124),所以 codemod 只换
|
|
26
|
+
* 包名、specifier 列表不动就够。
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.MIGRATE_CONFIG = void 0;
|
|
30
|
+
exports.MIGRATE_CONFIG = {
|
|
31
|
+
from: 'vite-react',
|
|
32
|
+
to: 'nestjs-react-fullstack',
|
|
33
|
+
rules: [
|
|
34
|
+
// ===== 1. 用户领地搬迁 =====
|
|
35
|
+
{ type: 'move-directory', from: 'src', to: 'client/src' },
|
|
36
|
+
{ type: 'move-directory', from: 'public', to: 'client/public' },
|
|
37
|
+
// shared/ 不动(两边布局相同);.env / .spark_project 同理。
|
|
38
|
+
// ===== 2. 清理 vite-react 残留 =====
|
|
39
|
+
// 根 index.html 被 client/index.html 取代(fullstack 用 HBS 渲染)
|
|
40
|
+
{ type: 'delete-file', to: 'index.html' },
|
|
41
|
+
// ESLint 9 flat config 文件名变了(user eslint.config.mjs → eslint.config.js)
|
|
42
|
+
{ type: 'delete-file', to: 'eslint.config.mjs' },
|
|
43
|
+
// 依赖集合变了,lockfile 重新生成
|
|
44
|
+
{ type: 'delete-file', to: 'package-lock.json' },
|
|
45
|
+
// ===== 3. 从 user package.json 删 vite-react 专属字段 =====
|
|
46
|
+
// 注意保留 devDependencies.@lark-apaas/coding-preset-vite-react —— user 迁移后
|
|
47
|
+
// vite.config 仍用它(开 fullstack 模式即可),不切到 fullstack-vite-preset。
|
|
48
|
+
{
|
|
49
|
+
type: 'delete-json-keys',
|
|
50
|
+
to: 'package.json',
|
|
51
|
+
keys: [
|
|
52
|
+
// 顶层 "type": "module" —— vite-react ESM 入口约定,nestjs CommonJS 不需要
|
|
53
|
+
'type',
|
|
54
|
+
// lite SDK:codemod 后 import 走 client-toolkit 顶层
|
|
55
|
+
'dependencies.@lark-apaas/client-toolkit-lite',
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
// ===== 4. fullstack 形态必需资产(覆盖 user 已有同名文件) =====
|
|
59
|
+
// server/ 整目录:main.ts / app.module.ts / common/ / modules/view/ 等(fullstack 必需)
|
|
60
|
+
{ type: 'directory', from: 'server', to: 'server', overwrite: true },
|
|
61
|
+
// nest-cli.json:nest build 入口
|
|
62
|
+
{ type: 'file', from: 'nest-cli.json', to: 'nest-cli.json', overwrite: true },
|
|
63
|
+
// tsconfig.* —— vite-react 时代 tsconfig 配 include: ["src"],迁完代码搬到 client/src,
|
|
64
|
+
// include 路径不对 + 老 tsconfig.app 还 extends @lark-apaas/coding-presets-react;
|
|
65
|
+
// 整体覆盖到 fullstack 版本(include 改 client/** + shared/**、extends fullstack-presets)。
|
|
66
|
+
// user 自己加的 paths / strict 等设置如有需要,按 git diff 手动加回。
|
|
67
|
+
{ type: 'file', from: 'tsconfig.json', to: 'tsconfig.json', overwrite: true },
|
|
68
|
+
{ type: 'file', from: 'tsconfig.app.json', to: 'tsconfig.app.json', overwrite: true },
|
|
69
|
+
{ type: 'file', from: 'tsconfig.node.json', to: 'tsconfig.node.json', overwrite: true },
|
|
70
|
+
// ESLint 9 flat config —— vite-react 用 eslint.config.mjs 已删,fullstack 用
|
|
71
|
+
// eslint.config.js (commonjs) + extends @lark-apaas/fullstack-presets;user 通常不改
|
|
72
|
+
{ type: 'file', from: 'eslint.config.js', to: 'eslint.config.js', overwrite: true },
|
|
73
|
+
// client/index.html:HBS 模板(fullstack 用,vite-react 用根 index.html 已删)
|
|
74
|
+
{ type: 'file', from: 'client/index.html', to: 'client/index.html', overwrite: true },
|
|
75
|
+
// scripts/ 整目录:fullstack 形态启动 / 构建 / lint 所需的 8 个平台脚本(dev.sh /
|
|
76
|
+
// dev.js / dev-local.js / build.sh / lint.js / prune-smart.js / run.sh / hooks/)。
|
|
77
|
+
// dev.sh exec node dev.js,dev.js 才是并发起 nest + vite 的核心 —— 漏一个 dev 跑不起来。
|
|
78
|
+
// overwrite: true:这些脚本由平台 cli 维护,user 一般不改;按 fullstack 版本覆盖。
|
|
79
|
+
{ type: 'directory', from: 'scripts', to: 'scripts', overwrite: true },
|
|
80
|
+
// .githooks(fallback,user 已有则保留)
|
|
81
|
+
{ type: 'directory', from: '.githooks', to: '.githooks', overwrite: false },
|
|
82
|
+
// shared/ fallback(user 已有同名文件保留,template 新增文件加入)
|
|
83
|
+
{ type: 'directory', from: 'shared', to: 'shared', overwrite: false },
|
|
84
|
+
// .env fallback(user 没有时用 template 默认)
|
|
85
|
+
{ type: 'file', from: '.env', to: '.env', overwrite: false },
|
|
86
|
+
// ===== 5. 加 fullstack 形态必需的 scripts =====
|
|
87
|
+
// 这些 scripts 用 user 现有的可能性低(vite-react 没有 nest 相关 script),直接覆盖
|
|
88
|
+
{
|
|
89
|
+
type: 'add-script',
|
|
90
|
+
name: 'dev',
|
|
91
|
+
command: './scripts/dev.sh',
|
|
92
|
+
overwrite: true,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
type: 'add-script',
|
|
96
|
+
name: 'dev:server',
|
|
97
|
+
command: 'NODE_ENV=development nest start --watch',
|
|
98
|
+
overwrite: true,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
type: 'add-script',
|
|
102
|
+
name: 'dev:client',
|
|
103
|
+
command: 'NODE_ENV=development vite --config vite.config.ts',
|
|
104
|
+
overwrite: true,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
type: 'add-script',
|
|
108
|
+
name: 'build',
|
|
109
|
+
command: './scripts/build.sh',
|
|
110
|
+
overwrite: true,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
type: 'add-script',
|
|
114
|
+
name: 'build:server',
|
|
115
|
+
command: 'NODE_ENV=production nest build',
|
|
116
|
+
overwrite: true,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
type: 'add-script',
|
|
120
|
+
name: 'build:client',
|
|
121
|
+
command: 'NODE_ENV=production vite build --config vite.config.ts',
|
|
122
|
+
overwrite: true,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
type: 'add-script',
|
|
126
|
+
name: 'build:prod',
|
|
127
|
+
command: 'npm run build:server && npm run build:client',
|
|
128
|
+
overwrite: true,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
type: 'add-script',
|
|
132
|
+
name: 'start',
|
|
133
|
+
command: 'NODE_ENV=production node main.js',
|
|
134
|
+
overwrite: true,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
type: 'add-script',
|
|
138
|
+
name: 'type:check:server',
|
|
139
|
+
command: 'tsc --noEmit --project tsconfig.node.json',
|
|
140
|
+
overwrite: true,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
type: 'add-script',
|
|
144
|
+
name: 'type:check:client',
|
|
145
|
+
command: 'tsc --noEmit --project tsconfig.app.json',
|
|
146
|
+
overwrite: true,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
type: 'add-script',
|
|
150
|
+
name: 'type:check',
|
|
151
|
+
command: 'concurrently -n "server,client" -c "blue,green" "npm run type:check:server" "npm run type:check:client"',
|
|
152
|
+
overwrite: true,
|
|
153
|
+
},
|
|
154
|
+
// ----- 平台脚本调用链 -----
|
|
155
|
+
// build.sh 步骤 1 跑 `npm run gen:openapi`,缺这条 npm ERR missing script,build 直接挂。
|
|
156
|
+
// scripts/lint.js 内部 spawn `npm run eslint` 和 `npm run stylelint`,缺这两条 lint 挂。
|
|
157
|
+
// 这些都是 fullstack 平台脚本自洽必需的桥接 script,user 不会自定义,直接覆盖。
|
|
158
|
+
{
|
|
159
|
+
type: 'add-script',
|
|
160
|
+
name: 'gen:openapi',
|
|
161
|
+
command: "echo 'UNSUPPORTED, SKIP'",
|
|
162
|
+
overwrite: true,
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
type: 'add-script',
|
|
166
|
+
name: 'gen:db-schema',
|
|
167
|
+
command: 'npx -y @lark-apaas/db-schema-sync@latest --output server/database/schema.ts --export-custom-types',
|
|
168
|
+
overwrite: true,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
type: 'add-script',
|
|
172
|
+
name: 'eslint',
|
|
173
|
+
command: 'eslint . --quiet',
|
|
174
|
+
overwrite: true,
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
type: 'add-script',
|
|
178
|
+
name: 'stylelint',
|
|
179
|
+
command: 'stylelint client/src/**/*.css --quiet',
|
|
180
|
+
overwrite: true,
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
type: 'add-script',
|
|
184
|
+
name: 'lint',
|
|
185
|
+
command: 'node ./scripts/lint.js',
|
|
186
|
+
overwrite: true,
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
type: 'add-script',
|
|
190
|
+
name: 'precommit',
|
|
191
|
+
command: 'node scripts/hooks/run-precommit.js',
|
|
192
|
+
overwrite: true,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
type: 'add-script',
|
|
196
|
+
name: 'upgrade',
|
|
197
|
+
command: 'npx -y @lark-apaas/fullstack-cli sync --disable-gen-openapi',
|
|
198
|
+
overwrite: true,
|
|
199
|
+
},
|
|
200
|
+
// ----- user 可能自定义的 scripts -----
|
|
201
|
+
// format/test 多半 user 自己改过(prettier 配 / jest 配),保留 user 自有值。
|
|
202
|
+
{
|
|
203
|
+
type: 'add-script',
|
|
204
|
+
name: 'format',
|
|
205
|
+
command: 'prettier --write "{server,client,test}/**/*.{js,ts,tsx,json,md}"',
|
|
206
|
+
overwrite: false,
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
type: 'add-script',
|
|
210
|
+
name: 'test',
|
|
211
|
+
command: 'jest',
|
|
212
|
+
overwrite: false,
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
type: 'add-script',
|
|
216
|
+
name: 'test:watch',
|
|
217
|
+
command: 'jest --watch',
|
|
218
|
+
overwrite: false,
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
type: 'add-script',
|
|
222
|
+
name: 'test:e2e',
|
|
223
|
+
command: 'jest --config test/e2e/jest.config.js',
|
|
224
|
+
overwrite: false,
|
|
225
|
+
},
|
|
226
|
+
// ===== 6. 从 fullstack template 取版本号加 NestJS 强依赖(精确白名单) =====
|
|
227
|
+
// 不走 merge-json(template 130+ devDeps 全 merge 会污染 user 业务依赖集合);
|
|
228
|
+
// 白名单只列 fullstack 启动能跑起来必需的最小集。
|
|
229
|
+
{
|
|
230
|
+
type: 'add-deps-from-template',
|
|
231
|
+
from: 'package.json',
|
|
232
|
+
to: 'package.json',
|
|
233
|
+
dependencies: [
|
|
234
|
+
// NestJS server 核心
|
|
235
|
+
'@nestjs/core',
|
|
236
|
+
'@nestjs/common',
|
|
237
|
+
'@nestjs/platform-express',
|
|
238
|
+
'@nestjs/config',
|
|
239
|
+
'@nestjs/axios',
|
|
240
|
+
'@nestjs/swagger',
|
|
241
|
+
// 妙搭 fullstack server SDK(main.ts / view module 等都依赖)
|
|
242
|
+
'@lark-apaas/fullstack-nestjs-core',
|
|
243
|
+
// HBS 模板引擎(client/index.html 渲染)
|
|
244
|
+
'hbs',
|
|
245
|
+
// NestJS runtime 必需
|
|
246
|
+
'reflect-metadata',
|
|
247
|
+
'rxjs',
|
|
248
|
+
'tslib',
|
|
249
|
+
// DTO 校验 / 转换
|
|
250
|
+
'class-transformer',
|
|
251
|
+
'class-validator',
|
|
252
|
+
// .env 加载(scripts/dev.sh 用到 dotenv-cli 风格)
|
|
253
|
+
'dotenv',
|
|
254
|
+
// client-toolkit:替代 lite,业务代码 codemod 后走它
|
|
255
|
+
'@lark-apaas/client-toolkit',
|
|
256
|
+
],
|
|
257
|
+
devDependencies: [
|
|
258
|
+
// nest start / nest build 必需
|
|
259
|
+
'@nestjs/cli',
|
|
260
|
+
'@nestjs/testing',
|
|
261
|
+
// server ts 编译
|
|
262
|
+
'ts-node',
|
|
263
|
+
'@types/express',
|
|
264
|
+
'@types/hbs',
|
|
265
|
+
'@types/node',
|
|
266
|
+
// 并发跑 nest + vite(scripts/dev.sh 用 concurrently)
|
|
267
|
+
'concurrently',
|
|
268
|
+
// fullstack server 端 tsconfig.node.json 通过 extends 引这个包
|
|
269
|
+
// (@lark-apaas/fullstack-presets/lib/simple/tsconfig/tsconfig.node.json);
|
|
270
|
+
// 不装会导致 nest build / type:check:server / vite dev 解析 tsconfig 时 ENOENT
|
|
271
|
+
'@lark-apaas/fullstack-presets',
|
|
272
|
+
],
|
|
273
|
+
},
|
|
274
|
+
// ===== 7. 业务代码 codemod:lite → client-toolkit 包名替换 =====
|
|
275
|
+
// client-toolkit@1.2.52+ 顶层完整 re-export lite 全部 48 项,specifier 列表不动。
|
|
276
|
+
// 同时扫 shared/(client/server 共享代码也可能引 lite 类型 / utils)。
|
|
277
|
+
{ type: 'codemod-client-toolkit-lite', root: 'client/src' },
|
|
278
|
+
{ type: 'codemod-client-toolkit-lite', root: 'shared' },
|
|
279
|
+
// ===== 8. vite.config codemod:加 { fullstack: true } 第二参 =====
|
|
280
|
+
// user vite.config 现在是 defineConfig({...}) 单参;fullstack 形态需要 vite 8080
|
|
281
|
+
// 反代 HTML / API 到 nest 3000,coding-preset-vite-react 用 fullstack option 启用
|
|
282
|
+
// 这一行为(详见 fullstack-plugin coding-preset-vite-react#fullstack)。
|
|
283
|
+
{ type: 'codemod-vite-config-fullstack', to: 'vite.config.ts' },
|
|
284
|
+
// ===== 9. 切 stack =====
|
|
285
|
+
{ type: 'set-stack', stack: 'nestjs-react-fullstack' },
|
|
286
|
+
],
|
|
287
|
+
// install 收尾要钉 latest 的关键平台包 —— 见 MigrateConfig.followLatestPackages 注释。
|
|
288
|
+
// - client-toolkit:codemod 后业务代码依赖 lite 兼容 API(getCurrentUserProfile 等),
|
|
289
|
+
// 这些 API 当前只在 alpha 版本里。template caret range 不匹配 pre-release,必须显式 latest。
|
|
290
|
+
// - coding-preset-vite-react:本次切到 MIAODA_APP_TYPE='3' env 检测,老版本 preset 不认 env。
|
|
291
|
+
followLatestPackages: ['@lark-apaas/client-toolkit', '@lark-apaas/coding-preset-vite-react'],
|
|
292
|
+
};
|
|
293
|
+
exports.default = exports.MIGRATE_CONFIG;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MigrateRule 类型定义 —— miaoda app migrate(跨 stack 迁移)的核心抽象。
|
|
4
|
+
*
|
|
5
|
+
* 跟 sync 的关系:sync 是**同 stack 内**的版本同步(脚手架更新、平台依赖钉版本);
|
|
6
|
+
* migrate 是**跨 stack 切换**(如 vite-react → nestjs-react-fullstack)。
|
|
7
|
+
*
|
|
8
|
+
* 复用:MigrateRule 把 SyncRule 全部纳入联合类型(10 种)—— migrate 也要做覆盖 / 删除 /
|
|
9
|
+
* merge-json / patch-script 等动作,没必要重新定义。
|
|
10
|
+
*
|
|
11
|
+
* 新增:MoveRule 和 SetStackRule 是 migrate 专有的语义,sync 用不上:
|
|
12
|
+
* - MoveRule:把用户领地从老布局搬到新布局(如 src/ → client/src/),完成后源消失。
|
|
13
|
+
* - SetStackRule:把 .spark/meta.json 的 stack 字段切到新 stack,migrate 必跑的收尾。
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.installDependencies = exports.writeSparkMeta = exports.readSparkMeta = exports.TEMPLATE_PACKAGE_BY_STACK = exports.SUPPORTED_STACKS = exports.renderTemplate = void 0;
|
|
3
|
+
exports.resolveNpmInstallRegistry = exports.installDependencies = exports.writeSparkMeta = exports.readSparkMeta = exports.TEMPLATE_PACKAGE_BY_STACK = exports.SUPPORTED_STACKS = exports.renderTemplate = void 0;
|
|
4
4
|
var template_1 = require("./template");
|
|
5
5
|
Object.defineProperty(exports, "renderTemplate", { enumerable: true, get: function () { return template_1.renderTemplate; } });
|
|
6
6
|
Object.defineProperty(exports, "SUPPORTED_STACKS", { enumerable: true, get: function () { return template_1.SUPPORTED_STACKS; } });
|
|
@@ -10,3 +10,4 @@ Object.defineProperty(exports, "readSparkMeta", { enumerable: true, get: functio
|
|
|
10
10
|
Object.defineProperty(exports, "writeSparkMeta", { enumerable: true, get: function () { return spark_meta_1.writeSparkMeta; } });
|
|
11
11
|
var install_1 = require("./install");
|
|
12
12
|
Object.defineProperty(exports, "installDependencies", { enumerable: true, get: function () { return install_1.installDependencies; } });
|
|
13
|
+
Object.defineProperty(exports, "resolveNpmInstallRegistry", { enumerable: true, get: function () { return install_1.resolveNpmInstallRegistry; } });
|
|
@@ -10,8 +10,13 @@ const logger_1 = require("../../../../utils/logger");
|
|
|
10
10
|
* 创建本地发布单(加锁;不挂 pipeline)。
|
|
11
11
|
* 返回的 releaseId 必须由 finalizeLocalRelease 翻为终态,否则发布单一直挂着。
|
|
12
12
|
*/
|
|
13
|
-
async function createLocalRelease(appId, version) {
|
|
14
|
-
return (0, index_1.createLocalRelease)({
|
|
13
|
+
async function createLocalRelease(appId, version, extra) {
|
|
14
|
+
return (0, index_1.createLocalRelease)({
|
|
15
|
+
appID: appId,
|
|
16
|
+
version,
|
|
17
|
+
checkPointVersion: extra?.checkPointVersion,
|
|
18
|
+
commitID: extra?.commitID,
|
|
19
|
+
});
|
|
15
20
|
}
|
|
16
21
|
/**
|
|
17
22
|
* 把本地发布单翻为终态。Finished / Failed 由 pipeline 视上下游结果决定。
|
|
@@ -43,7 +43,10 @@ async function localBuildLocalPublishPipeline(opts) {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
(0, logger_1.log)('deploy', 'Creating local release...');
|
|
46
|
-
const release = await (0, index_1.createLocalRelease)(ctx.appId, pre.version
|
|
46
|
+
const release = await (0, index_1.createLocalRelease)(ctx.appId, pre.version, {
|
|
47
|
+
checkPointVersion: opts.checkPointVersion,
|
|
48
|
+
commitID: opts.commitID,
|
|
49
|
+
});
|
|
47
50
|
try {
|
|
48
51
|
(0, logger_1.log)('deploy', 'Uploading artifacts...');
|
|
49
52
|
await (0, index_1.uploadArtifacts)({ projectDir: ctx.projectDir, appId: ctx.appId, data });
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Codemod:把 `@lark-apaas/client-toolkit-lite` 的 import 改写到 `@lark-apaas/client-toolkit`。
|
|
4
|
+
*
|
|
5
|
+
* 用于 `miaoda app migrate vite-react → nestjs-react-fullstack`:迁移后让两个包共存属于
|
|
6
|
+
* lib 冗余(两份 react / 两套主题 / 两套 axios),所以扫 user 代码把 lite import 改写到
|
|
7
|
+
* full,然后用 delete-json-keys 移除 lite dep。
|
|
8
|
+
*
|
|
9
|
+
* 实现策略:单行包名替换。
|
|
10
|
+
*
|
|
11
|
+
* client-toolkit 自 v1.2.48 起在顶层 single-entry 完整 re-export 了 client-toolkit-lite
|
|
12
|
+
* 的全部 48 项(components / hooks / utils / integrations / logger / trace / types /
|
|
13
|
+
* constants),跟 lite 同名同签 —— 所以 codemod 只需把 import 来源包名从 `-lite` 换掉,
|
|
14
|
+
* specifier 列表完全不动。CSS `@import` 同理(client-toolkit 顶层加了 ./styles.css 别名)。
|
|
15
|
+
*
|
|
16
|
+
* 边界:
|
|
17
|
+
* - 仅处理形如 `import [type] { A, B as C } from '@lark-apaas/client-toolkit-lite'` 的
|
|
18
|
+
* named import;default import / namespace import / 跨多行 specifier 当前不识别,
|
|
19
|
+
* 但只要 `from '...lite'` 在同一行,包名替换仍有效(regex 抓 from 段)。
|
|
20
|
+
*/
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.rewriteLiteImports = rewriteLiteImports;
|
|
26
|
+
exports.rewriteCssText = rewriteCssText;
|
|
27
|
+
exports.rewriteText = rewriteText;
|
|
28
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
29
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
30
|
+
const LITE_PKG = '@lark-apaas/client-toolkit-lite';
|
|
31
|
+
const FULL_PKG = '@lark-apaas/client-toolkit';
|
|
32
|
+
/**
|
|
33
|
+
* 递归扫描 rootDir 下的 .ts/.tsx/.js/.jsx/.css 文件,把 lite import 改写到 full。
|
|
34
|
+
*/
|
|
35
|
+
function rewriteLiteImports(rootDir) {
|
|
36
|
+
const result = {
|
|
37
|
+
filesScanned: 0,
|
|
38
|
+
filesChanged: [],
|
|
39
|
+
rewrittenSymbols: 0,
|
|
40
|
+
unmapped: [],
|
|
41
|
+
};
|
|
42
|
+
if (!node_fs_1.default.existsSync(rootDir))
|
|
43
|
+
return result;
|
|
44
|
+
for (const file of walk(rootDir)) {
|
|
45
|
+
const isJs = /\.(ts|tsx|js|jsx)$/.test(file);
|
|
46
|
+
const isCss = file.endsWith('.css');
|
|
47
|
+
if (!isJs && !isCss)
|
|
48
|
+
continue;
|
|
49
|
+
result.filesScanned++;
|
|
50
|
+
const before = node_fs_1.default.readFileSync(file, 'utf-8');
|
|
51
|
+
if (!before.includes(LITE_PKG))
|
|
52
|
+
continue;
|
|
53
|
+
const rel = node_path_1.default.relative(rootDir, file);
|
|
54
|
+
const { text, count } = isJs ? rewriteText(before, rel) : rewriteCssText(before, rel);
|
|
55
|
+
if (count > 0) {
|
|
56
|
+
node_fs_1.default.writeFileSync(file, text);
|
|
57
|
+
result.filesChanged.push(rel);
|
|
58
|
+
result.rewrittenSymbols += count;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* css 改写器:单行包名替换。`@import "@lark-apaas/client-toolkit-lite/<path>"` →
|
|
65
|
+
* `@import "@lark-apaas/client-toolkit/<path>"`。其中 styles.css 在 full 端已加同名别名
|
|
66
|
+
* 指向 ./lib/index.css。
|
|
67
|
+
*/
|
|
68
|
+
function rewriteCssText(source, _fileLabel) {
|
|
69
|
+
let count = 0;
|
|
70
|
+
const re = /(@import\s+['"])@lark-apaas\/client-toolkit-lite(\/[^'"]*)?(['"])/g;
|
|
71
|
+
const text = source.replace(re, (_match, p1, sub, p3) => {
|
|
72
|
+
count++;
|
|
73
|
+
return `${p1}${FULL_PKG}${sub ?? ''}${p3}`;
|
|
74
|
+
});
|
|
75
|
+
return { text, count, unmapped: [] };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* JS/TS 文件改写器:把任何 `from '@lark-apaas/client-toolkit-lite'` 改成 full 包名。
|
|
79
|
+
* specifier 列表完全保留 —— full 顶层 single-entry 已经兼容 lite 全部 48 项 export。
|
|
80
|
+
*
|
|
81
|
+
* 同样兼容 dynamic import / require / `export ... from` 等其他形式(只要包名字符串在)。
|
|
82
|
+
*/
|
|
83
|
+
function rewriteText(source, _fileLabel) {
|
|
84
|
+
let count = 0;
|
|
85
|
+
// 既匹配 `from 'pkg'` 也匹配 `from "pkg"`,单双引号都管。
|
|
86
|
+
// 同时覆盖 `import('pkg')` / `require('pkg')` 等其他常见形态。
|
|
87
|
+
const re = /(['"])@lark-apaas\/client-toolkit-lite(['"])/g;
|
|
88
|
+
const text = source.replace(re, (_match, p1, p2) => {
|
|
89
|
+
count++;
|
|
90
|
+
return `${p1}${FULL_PKG}${p2}`;
|
|
91
|
+
});
|
|
92
|
+
return { text, count, unmapped: [] };
|
|
93
|
+
}
|
|
94
|
+
function* walk(dir) {
|
|
95
|
+
for (const entry of node_fs_1.default.readdirSync(dir, { withFileTypes: true })) {
|
|
96
|
+
if (entry.name === 'node_modules' || entry.name.startsWith('.'))
|
|
97
|
+
continue;
|
|
98
|
+
const full = node_path_1.default.join(dir, entry.name);
|
|
99
|
+
if (entry.isDirectory()) {
|
|
100
|
+
yield* walk(full);
|
|
101
|
+
}
|
|
102
|
+
else if (entry.isFile()) {
|
|
103
|
+
yield full;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.applyMigrateRules = applyMigrateRules;
|
|
7
|
+
exports.rewriteViteConfigForFullstack = rewriteViteConfigForFullstack;
|
|
8
|
+
exports.rewriteAliasSrcPaths = rewriteAliasSrcPaths;
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const sync_rule_1 = require("./sync-rule");
|
|
12
|
+
const spark_meta_1 = require("./spark-meta");
|
|
13
|
+
const codemod_client_toolkit_lite_1 = require("./codemod-client-toolkit-lite");
|
|
14
|
+
const logger_1 = require("./logger");
|
|
15
|
+
/**
|
|
16
|
+
* 顺序执行 MigrateRule[]:
|
|
17
|
+
* - move-* / set-stack 是 migrate 专有 rule,本模块直接处理。
|
|
18
|
+
* - 其余(directory / file / merge-json / delete-* / add-script / ...)全部委派给
|
|
19
|
+
* applySyncRules —— 单条调用,逻辑跟 sync 完全对齐,避免行为漂移。
|
|
20
|
+
*
|
|
21
|
+
* 一条 rule 报错不影响后续(applySyncRules 内部已有 try/catch;本模块的 applyMove / applySetStack
|
|
22
|
+
* 当前不 catch —— 如果 move 失败说明状态已经被破坏,应当直接抛错让 handler 决定回滚或上报)。
|
|
23
|
+
*/
|
|
24
|
+
function applyMigrateRules(rules, opts) {
|
|
25
|
+
const results = [];
|
|
26
|
+
for (const rule of rules) {
|
|
27
|
+
if (rule.type === 'move-directory' || rule.type === 'move-file') {
|
|
28
|
+
results.push(applyMove(rule, opts));
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (rule.type === 'set-stack') {
|
|
32
|
+
results.push(applySetStack(rule, opts));
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (rule.type === 'delete-json-keys') {
|
|
36
|
+
results.push(applyDeleteJsonKeys(rule, opts));
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (rule.type === 'codemod-client-toolkit-lite') {
|
|
40
|
+
results.push(applyCodemodLite(rule, opts));
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (rule.type === 'codemod-vite-config-fullstack') {
|
|
44
|
+
results.push(applyCodemodViteConfigFullstack(rule, opts));
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (rule.type === 'add-deps-from-template') {
|
|
48
|
+
results.push(applyAddDepsFromTemplate(rule, opts));
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
// 前面 if 已经把 migrate 专用 rule 都 narrow 掉,剩下的必然是 SyncRule
|
|
52
|
+
const [syncResult] = (0, sync_rule_1.applySyncRules)([rule], opts);
|
|
53
|
+
results.push(syncResult);
|
|
54
|
+
}
|
|
55
|
+
return results;
|
|
56
|
+
}
|
|
57
|
+
function applyMove(rule, opts) {
|
|
58
|
+
const logPrefix = opts.logPrefix ?? 'migrate';
|
|
59
|
+
const src = node_path_1.default.join(opts.targetDir, rule.from);
|
|
60
|
+
const dest = node_path_1.default.join(opts.targetDir, rule.to);
|
|
61
|
+
const onConflict = rule.onConflict ?? 'merge';
|
|
62
|
+
if (!node_fs_1.default.existsSync(src)) {
|
|
63
|
+
(0, logger_1.log)(logPrefix, ` ○ ${rule.from} (source not found, skip)`);
|
|
64
|
+
return { rule, action: 'skipped', path: rule.to };
|
|
65
|
+
}
|
|
66
|
+
if (node_fs_1.default.existsSync(dest)) {
|
|
67
|
+
if (onConflict === 'skip') {
|
|
68
|
+
(0, logger_1.log)(logPrefix, ` ○ ${rule.to} (already exists, skip per onConflict=skip)`);
|
|
69
|
+
return { rule, action: 'skipped', path: rule.to };
|
|
70
|
+
}
|
|
71
|
+
if (onConflict === 'overwrite') {
|
|
72
|
+
node_fs_1.default.rmSync(dest, { recursive: true, force: true });
|
|
73
|
+
moveAtomic(src, dest);
|
|
74
|
+
(0, logger_1.log)(logPrefix, ` ✓ ${rule.from} → ${rule.to} (overwritten)`);
|
|
75
|
+
return { rule, action: 'moved', path: rule.to, detail: rule.from };
|
|
76
|
+
}
|
|
77
|
+
// 'merge':把 src 的内容递归 overlay 到 dest,源 entry 完成后整体清掉
|
|
78
|
+
mergeOverlay(src, dest);
|
|
79
|
+
node_fs_1.default.rmSync(src, { recursive: true, force: true });
|
|
80
|
+
(0, logger_1.log)(logPrefix, ` ✓ ${rule.from} → ${rule.to} (merged)`);
|
|
81
|
+
return { rule, action: 'moved', path: rule.to, detail: rule.from };
|
|
82
|
+
}
|
|
83
|
+
// 目标不存在 —— 直接 rename
|
|
84
|
+
const destDir = node_path_1.default.dirname(dest);
|
|
85
|
+
if (destDir !== '.' && !node_fs_1.default.existsSync(destDir)) {
|
|
86
|
+
node_fs_1.default.mkdirSync(destDir, { recursive: true });
|
|
87
|
+
}
|
|
88
|
+
moveAtomic(src, dest);
|
|
89
|
+
(0, logger_1.log)(logPrefix, ` ✓ ${rule.from} → ${rule.to}`);
|
|
90
|
+
return { rule, action: 'moved', path: rule.to, detail: rule.from };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* fs.renameSync 在跨设备 / 跨文件系统时报 EXDEV(Linux/macOS),fallback 到 cp -r + rm。
|
|
94
|
+
* worktree 内通常同一卷不会触发,但 tmp 目录跟 user app 可能不同卷,留这层兜底。
|
|
95
|
+
*/
|
|
96
|
+
function moveAtomic(src, dest) {
|
|
97
|
+
try {
|
|
98
|
+
node_fs_1.default.renameSync(src, dest);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
if (err.code !== 'EXDEV') {
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
104
|
+
node_fs_1.default.cpSync(src, dest, { recursive: true });
|
|
105
|
+
node_fs_1.default.rmSync(src, { recursive: true, force: true });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 把 src 的每个 entry 复制到 dest 同路径下(src 是文件则覆盖 dest 同名文件;src 是目录则
|
|
110
|
+
* 递归创建 + 复制)。同名冲突一律 src 覆盖 dest。本函数不删 src;调用方负责清理。
|
|
111
|
+
*/
|
|
112
|
+
function mergeOverlay(src, dest) {
|
|
113
|
+
const stat = node_fs_1.default.statSync(src);
|
|
114
|
+
if (stat.isFile()) {
|
|
115
|
+
node_fs_1.default.mkdirSync(node_path_1.default.dirname(dest), { recursive: true });
|
|
116
|
+
node_fs_1.default.copyFileSync(src, dest);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (!node_fs_1.default.existsSync(dest)) {
|
|
120
|
+
node_fs_1.default.mkdirSync(dest, { recursive: true });
|
|
121
|
+
}
|
|
122
|
+
for (const entry of node_fs_1.default.readdirSync(src)) {
|
|
123
|
+
mergeOverlay(node_path_1.default.join(src, entry), node_path_1.default.join(dest, entry));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function applySetStack(rule, opts) {
|
|
127
|
+
const logPrefix = opts.logPrefix ?? 'migrate';
|
|
128
|
+
(0, spark_meta_1.writeSparkMeta)(opts.targetDir, { stack: rule.stack });
|
|
129
|
+
(0, logger_1.log)(logPrefix, ` ✓ .spark/meta.json stack → ${rule.stack}`);
|
|
130
|
+
return { rule, action: 'patched', path: '.spark/meta.json', detail: rule.stack };
|
|
131
|
+
}
|
|
132
|
+
function applyDeleteJsonKeys(rule, opts) {
|
|
133
|
+
const logPrefix = opts.logPrefix ?? 'migrate';
|
|
134
|
+
const dest = node_path_1.default.join(opts.targetDir, rule.to);
|
|
135
|
+
if (!node_fs_1.default.existsSync(dest)) {
|
|
136
|
+
(0, logger_1.log)(logPrefix, ` ○ ${rule.to} (not found, skip delete-json-keys)`);
|
|
137
|
+
return { rule, action: 'skipped', path: rule.to };
|
|
138
|
+
}
|
|
139
|
+
const text = node_fs_1.default.readFileSync(dest, 'utf-8');
|
|
140
|
+
const json = JSON.parse(text);
|
|
141
|
+
const deleted = [];
|
|
142
|
+
for (const dotKey of rule.keys) {
|
|
143
|
+
if (deleteAtDotPath(json, dotKey))
|
|
144
|
+
deleted.push(dotKey);
|
|
145
|
+
}
|
|
146
|
+
if (deleted.length === 0) {
|
|
147
|
+
(0, logger_1.log)(logPrefix, ` ○ ${rule.to} (no listed keys present)`);
|
|
148
|
+
return { rule, action: 'noop', path: rule.to };
|
|
149
|
+
}
|
|
150
|
+
// 保持原文件末尾换行约定(package.json 一般以 \n 结尾)
|
|
151
|
+
const trailing = text.endsWith('\n') ? '\n' : '';
|
|
152
|
+
node_fs_1.default.writeFileSync(dest, JSON.stringify(json, null, 2) + trailing);
|
|
153
|
+
(0, logger_1.log)(logPrefix, ` ✓ ${rule.to} (deleted ${deleted.length.toString()} key(s): ${deleted.join(', ')})`);
|
|
154
|
+
return { rule, action: 'patched', path: rule.to, detail: deleted.join(',') };
|
|
155
|
+
}
|
|
156
|
+
function applyCodemodLite(rule, opts) {
|
|
157
|
+
const logPrefix = opts.logPrefix ?? 'migrate';
|
|
158
|
+
const root = node_path_1.default.join(opts.targetDir, rule.root ?? 'client/src');
|
|
159
|
+
const r = (0, codemod_client_toolkit_lite_1.rewriteLiteImports)(root);
|
|
160
|
+
if (r.filesChanged.length === 0 && r.unmapped.length === 0) {
|
|
161
|
+
(0, logger_1.log)(logPrefix, ` ○ ${rule.root ?? 'client/src'} (no @lark-apaas/client-toolkit-lite imports found)`);
|
|
162
|
+
return { rule, action: 'noop', path: rule.root ?? 'client/src' };
|
|
163
|
+
}
|
|
164
|
+
const detail = `${r.rewrittenSymbols.toString()} symbol(s) in ${r.filesChanged.length.toString()} file(s)` +
|
|
165
|
+
(r.unmapped.length > 0 ? `; ${r.unmapped.length.toString()} unmapped` : '');
|
|
166
|
+
(0, logger_1.log)(logPrefix, ` ✓ ${rule.root ?? 'client/src'} (codemod: ${detail})`);
|
|
167
|
+
for (const u of r.unmapped) {
|
|
168
|
+
(0, logger_1.log)(logPrefix, ` ⚠ unmapped: ${u.file}:${u.line.toString()} '${u.symbol}'`);
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
rule,
|
|
172
|
+
action: r.rewrittenSymbols > 0 ? 'patched' : 'noop',
|
|
173
|
+
path: rule.root ?? 'client/src',
|
|
174
|
+
detail,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function applyCodemodViteConfigFullstack(rule, opts) {
|
|
178
|
+
const logPrefix = opts.logPrefix ?? 'migrate';
|
|
179
|
+
const rel = rule.to ?? 'vite.config.ts';
|
|
180
|
+
const dest = node_path_1.default.join(opts.targetDir, rel);
|
|
181
|
+
if (!node_fs_1.default.existsSync(dest)) {
|
|
182
|
+
(0, logger_1.log)(logPrefix, ` ○ ${rel} (not found, skip)`);
|
|
183
|
+
return { rule, action: 'skipped', path: rel };
|
|
184
|
+
}
|
|
185
|
+
const before = node_fs_1.default.readFileSync(dest, 'utf-8');
|
|
186
|
+
const { text, aliasRewriteCount } = rewriteViteConfigForFullstack(before);
|
|
187
|
+
if (aliasRewriteCount === 0) {
|
|
188
|
+
(0, logger_1.log)(logPrefix, ` ○ ${rel} (no src alias path to rewrite)`);
|
|
189
|
+
return { rule, action: 'noop', path: rel };
|
|
190
|
+
}
|
|
191
|
+
node_fs_1.default.writeFileSync(dest, text);
|
|
192
|
+
(0, logger_1.log)(logPrefix, ` ✓ ${rel} (rewrote ${aliasRewriteCount.toString()} alias path(s) src → client/src)`);
|
|
193
|
+
return {
|
|
194
|
+
rule,
|
|
195
|
+
action: 'patched',
|
|
196
|
+
path: rel,
|
|
197
|
+
detail: `${aliasRewriteCount.toString()} alias path(s)`,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* 把 vite.config.ts 里 alias 字符串里 `src` 起头的路径重写到 `client/src`。
|
|
202
|
+
*
|
|
203
|
+
* vite-react 时代 user 业务代码在 `src/`,迁移后搬到 `client/src/`,vite.config
|
|
204
|
+
* 里的 alias(典型如 `'@': path.resolve(__dirname, 'src')`)必须同步改:
|
|
205
|
+
* path.resolve(<args>, 'src') → 'src' 替换为 'client/src'
|
|
206
|
+
* path.resolve(<args>, 'src/<rest>') → 同上
|
|
207
|
+
* path.join(<args>, 'src') → 同上
|
|
208
|
+
* './src' / './src/<rest>' 字符串 → './client/src' / './client/src/<rest>'
|
|
209
|
+
* 边界:仅匹配整段 'src' 起头(避免 'sub/src' 误改),保留单/双引号原样。
|
|
210
|
+
*
|
|
211
|
+
* 注:fullstack 形态识别 **不再** 通过 `defineConfig` 的 option 第二参,而是
|
|
212
|
+
* 由 `coding-preset-vite-react` 内部读 `process.env.MIAODA_APP_TYPE === '3'`
|
|
213
|
+
* 自动判断(fullstack stack 的 archType 是 3)—— 所以 vite.config 完全不需要
|
|
214
|
+
* 加 option,只需 alias 路径同步即可。
|
|
215
|
+
*/
|
|
216
|
+
function rewriteViteConfigForFullstack(source) {
|
|
217
|
+
const { text, count } = rewriteAliasSrcPaths(source);
|
|
218
|
+
return { text, aliasRewriteCount: count };
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* vite.config 里 alias 路径重写:`src` 起头的路径加 `client/` 前缀。
|
|
222
|
+
*
|
|
223
|
+
* 匹配的形态(不限制在 resolve.alias 块内 —— vite.config 顶层很少出现非 alias 用的
|
|
224
|
+
* `src` 字符串,业务 import 走 `@/...`,所以全文匹配是安全的):
|
|
225
|
+
*
|
|
226
|
+
* path.resolve(<args>, 'src') → path.resolve(<args>, 'client/src')
|
|
227
|
+
* path.resolve(<args>, 'src/<rest>') → path.resolve(<args>, 'client/src/<rest>')
|
|
228
|
+
* path.join(<args>, 'src') → 同上
|
|
229
|
+
* './src' / './src/<rest>'(独立字符串) → './client/src' / './client/src/<rest>'
|
|
230
|
+
*
|
|
231
|
+
* 已含 `client/src` 的不动(视为已迁移),`sub/src` 之类(src 不在词首)不动。
|
|
232
|
+
*/
|
|
233
|
+
function rewriteAliasSrcPaths(source) {
|
|
234
|
+
let count = 0;
|
|
235
|
+
// path.resolve(...) / path.join(...) 的最后一个参数是 'src' 或 'src/...' 起头
|
|
236
|
+
// 匹配 ['"]src[/'"],保留引号
|
|
237
|
+
const pathCallRe = /(\bpath\s*\.\s*(?:resolve|join)\s*\([^)]*?,\s*)(['"`])(src)(\/[^'"`]*)?(['"`])/g;
|
|
238
|
+
let next = source.replace(pathCallRe, (_match, prefix, q1, _src, rest, q2) => {
|
|
239
|
+
count++;
|
|
240
|
+
return `${prefix}${q1}client/src${rest ?? ''}${q2}`;
|
|
241
|
+
});
|
|
242
|
+
// 独立的相对路径字符串字面量 './src' 或 './src/...'(不在 path.resolve 参数里)
|
|
243
|
+
// 注意:path.resolve / join 已被上一步处理,这里只匹配剩下的 './src...' 字面量。
|
|
244
|
+
// 这种用法在 vite.config 较少(典型是直接给 alias 字符串值),但兜底处理。
|
|
245
|
+
const relativeRe = /(['"`])\.\/(src)(\/[^'"`]*)?(['"`])/g;
|
|
246
|
+
next = next.replace(relativeRe, (_match, q1, _src, rest, q2) => {
|
|
247
|
+
count++;
|
|
248
|
+
return `${q1}./client/src${rest ?? ''}${q2}`;
|
|
249
|
+
});
|
|
250
|
+
return { text: next, count };
|
|
251
|
+
}
|
|
252
|
+
function applyAddDepsFromTemplate(rule, opts) {
|
|
253
|
+
const logPrefix = opts.logPrefix ?? 'migrate';
|
|
254
|
+
const userPath = node_path_1.default.join(opts.targetDir, rule.to ?? 'package.json');
|
|
255
|
+
const tplPath = node_path_1.default.join(opts.sourceRoot, rule.from ?? 'package.json');
|
|
256
|
+
if (!node_fs_1.default.existsSync(userPath)) {
|
|
257
|
+
(0, logger_1.log)(logPrefix, ` ○ ${rule.to ?? 'package.json'} (not found, skip add-deps-from-template)`);
|
|
258
|
+
return { rule, action: 'skipped', path: rule.to ?? 'package.json' };
|
|
259
|
+
}
|
|
260
|
+
if (!node_fs_1.default.existsSync(tplPath)) {
|
|
261
|
+
(0, logger_1.log)(logPrefix, ` ⚠ template ${rule.from ?? 'package.json'} not found, skip add-deps-from-template`);
|
|
262
|
+
return { rule, action: 'skipped', path: rule.to ?? 'package.json' };
|
|
263
|
+
}
|
|
264
|
+
const userText = node_fs_1.default.readFileSync(userPath, 'utf-8');
|
|
265
|
+
const userJson = JSON.parse(userText);
|
|
266
|
+
const tplJson = JSON.parse(node_fs_1.default.readFileSync(tplPath, 'utf-8'));
|
|
267
|
+
const added = [];
|
|
268
|
+
const missingInTpl = [];
|
|
269
|
+
for (const grp of ['dependencies', 'devDependencies']) {
|
|
270
|
+
const whitelist = rule[grp] ?? [];
|
|
271
|
+
if (whitelist.length === 0)
|
|
272
|
+
continue;
|
|
273
|
+
userJson[grp] ??= {};
|
|
274
|
+
for (const dep of whitelist) {
|
|
275
|
+
// 在 template 里找版本号:优先 tpl 同 grp,其次另一 grp(template 可能把 dep 写在
|
|
276
|
+
// dependencies/devDependencies 任一处,跟 user 当前 grp 不一定一致)
|
|
277
|
+
const tplVersion = tplJson[grp]?.[dep] ??
|
|
278
|
+
(grp === 'dependencies' ? tplJson.devDependencies?.[dep] : tplJson.dependencies?.[dep]);
|
|
279
|
+
if (tplVersion === undefined) {
|
|
280
|
+
missingInTpl.push(dep);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
userJson[grp][dep] = tplVersion;
|
|
284
|
+
added.push(`${grp}.${dep}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (added.length === 0 && missingInTpl.length === 0) {
|
|
288
|
+
(0, logger_1.log)(logPrefix, ` ○ ${rule.to ?? 'package.json'} (no deps to add)`);
|
|
289
|
+
return { rule, action: 'noop', path: rule.to ?? 'package.json' };
|
|
290
|
+
}
|
|
291
|
+
const trailing = userText.endsWith('\n') ? '\n' : '';
|
|
292
|
+
node_fs_1.default.writeFileSync(userPath, JSON.stringify(userJson, null, 2) + trailing);
|
|
293
|
+
(0, logger_1.log)(logPrefix, ` ✓ ${rule.to ?? 'package.json'} (added ${added.length.toString()} dep(s)${missingInTpl.length > 0 ? `; ${missingInTpl.length.toString()} missing in template: ${missingInTpl.join(', ')}` : ''})`);
|
|
294
|
+
return {
|
|
295
|
+
rule,
|
|
296
|
+
action: 'patched',
|
|
297
|
+
path: rule.to ?? 'package.json',
|
|
298
|
+
detail: added.join(','),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* 按 dot path 删除嵌套对象里的一个 leaf key。返回是否真的删了一项。
|
|
303
|
+
* 不支持包含 `.` 的字段名(实际 dep 名 / scripts 名不会含 `.`,够用)。
|
|
304
|
+
*/
|
|
305
|
+
function deleteAtDotPath(obj, dotPath) {
|
|
306
|
+
const parts = dotPath.split('.');
|
|
307
|
+
let cursor = obj;
|
|
308
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
309
|
+
const next = cursor[parts[i]];
|
|
310
|
+
if (next === undefined || next === null || typeof next !== 'object')
|
|
311
|
+
return false;
|
|
312
|
+
cursor = next;
|
|
313
|
+
}
|
|
314
|
+
const leaf = parts[parts.length - 1];
|
|
315
|
+
if (!Object.prototype.hasOwnProperty.call(cursor, leaf))
|
|
316
|
+
return false;
|
|
317
|
+
// 用 Reflect.deleteProperty 避开 eslint 对 `delete obj[computedKey]` 的禁用规则
|
|
318
|
+
return Reflect.deleteProperty(cursor, leaf);
|
|
319
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/miaoda-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17-alpha.0",
|
|
4
4
|
"description": "Miaoda 平台命令行工具,面向 Agent 调用",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": {
|
|
@@ -17,6 +17,20 @@
|
|
|
17
17
|
"dist",
|
|
18
18
|
"upgrade"
|
|
19
19
|
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "bash scripts/build.sh",
|
|
22
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
23
|
+
"lint": "eslint src/ --max-warnings 0",
|
|
24
|
+
"format": "prettier --write src/",
|
|
25
|
+
"format:check": "prettier --check src/",
|
|
26
|
+
"test": "vitest run --project=unit",
|
|
27
|
+
"test:watch": "vitest --project=unit",
|
|
28
|
+
"test:integration": "vitest run --project=integration",
|
|
29
|
+
"dev": "node --import tsx src/main.ts",
|
|
30
|
+
"cli": "node --env-file-if-exists=integration/.env --import tsx src/main.ts",
|
|
31
|
+
"prepare": "husky",
|
|
32
|
+
"prepublishOnly": "pnpm format:check && pnpm lint && pnpm build && pnpm test"
|
|
33
|
+
},
|
|
20
34
|
"keywords": [
|
|
21
35
|
"miaoda",
|
|
22
36
|
"cli",
|
|
@@ -51,16 +65,5 @@
|
|
|
51
65
|
"vitest": "^4.1.4",
|
|
52
66
|
"xml2js": "^0.6.2"
|
|
53
67
|
},
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
57
|
-
"lint": "eslint src/ --max-warnings 0",
|
|
58
|
-
"format": "prettier --write src/",
|
|
59
|
-
"format:check": "prettier --check src/",
|
|
60
|
-
"test": "vitest run --project=unit",
|
|
61
|
-
"test:watch": "vitest --project=unit",
|
|
62
|
-
"test:integration": "vitest run --project=integration",
|
|
63
|
-
"dev": "node --import tsx src/main.ts",
|
|
64
|
-
"cli": "node --env-file-if-exists=integration/.env --import tsx src/main.ts"
|
|
65
|
-
}
|
|
66
|
-
}
|
|
68
|
+
"packageManager": "pnpm@10.16.1+sha512.0e155aa2629db8672b49e8475da6226aa4bdea85fdcdfdc15350874946d4f3c91faaf64cbdc4a5d1ab8002f473d5c3fcedcd197989cf0390f9badd3c04678706"
|
|
69
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|