@lark-apaas/miaoda-cli 0.1.39-beta.73a593e → 0.1.39-beta.7cd293b
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 +48 -1
- package/dist/api/deploy/api.js +3 -1
- package/dist/api/deploy/approval.js +77 -0
- package/dist/api/deploy/index.js +7 -1
- package/dist/api/deploy/schemas.js +3 -0
- package/dist/api/deploy/types.js +19 -1
- package/dist/cli/commands/app/index.js +171 -15
- package/dist/cli/commands/deploy/index.js +30 -6
- package/dist/cli/commands/deploy/modern.js +34 -11
- package/dist/cli/commands/skills/index.js +10 -1
- package/dist/cli/handlers/app/import.js +191 -0
- package/dist/cli/handlers/app/index.js +7 -1
- package/dist/cli/handlers/app/init.js +76 -2
- package/dist/cli/handlers/app/migrate.js +131 -212
- package/dist/cli/handlers/app/sync.js +41 -4
- package/dist/cli/handlers/deploy/deploy.js +57 -4
- package/dist/cli/handlers/deploy/format.js +13 -0
- package/dist/cli/handlers/deploy/get.js +41 -1
- package/dist/cli/handlers/deploy/helpers.js +29 -2
- package/dist/cli/handlers/deploy/modern.js +39 -3
- package/dist/cli/handlers/deploy/polling.js +13 -9
- package/dist/cli/handlers/skills/sync.js +3 -16
- package/dist/config/fullstack-managed-files.js +67 -0
- package/dist/config/migrate-configs/html-to-design-html.js +1 -1
- package/dist/config/migrate-configs/index.js +9 -0
- package/dist/config/migrate-configs/vite-react-to-nestjs-react-fullstack.js +227 -197
- package/dist/config/sync-configs/design-stack.js +3 -4
- package/dist/config/sync-configs/nestjs-react-fullstack.js +17 -23
- package/dist/services/app/import/download.js +141 -0
- package/dist/services/app/import/index.js +39 -0
- package/dist/services/app/import/manifest.js +97 -0
- package/dist/services/app/import/place.js +327 -0
- package/dist/services/app/import/rules.js +293 -0
- package/dist/services/app/init/async-install.js +21 -0
- package/dist/services/app/init/index.js +3 -1
- package/dist/services/app/init/workspace-check.js +105 -0
- package/dist/services/app/migrate/detect.js +34 -0
- package/dist/services/app/migrate/index.js +8 -0
- package/dist/services/app/migrate/restart.js +59 -0
- package/dist/services/app/migrate/run.js +565 -0
- package/dist/services/app/migrate/symlinks.js +146 -0
- package/dist/services/deploy/modern/atoms/local-release.js +3 -0
- package/dist/services/deploy/modern/patch/actions.js +7 -1
- package/dist/services/deploy/modern/patch/index.js +2 -1
- package/dist/services/deploy/modern/pipelines/design-local.js +7 -1
- package/dist/services/deploy/modern/pipelines/local.js +7 -1
- package/dist/utils/coding-steering-files.js +55 -0
- package/dist/utils/coding-steering-flat.js +206 -0
- package/dist/utils/coding-steering.js +182 -326
- package/dist/utils/engineering-state.js +52 -0
- package/dist/utils/http.js +6 -6
- package/dist/utils/migrate-adapters.js +634 -0
- package/dist/utils/migrate-rule.js +801 -36
- package/dist/utils/npm-pack.js +13 -1
- package/dist/utils/project-snapshot.js +99 -0
- package/dist/utils/skills-extension.js +95 -0
- package/dist/utils/spark-meta.js +31 -10
- package/dist/utils/sync-rule.js +86 -11
- package/dist/utils/typescript-exclude.js +36 -0
- package/package.json +1 -1
- package/upgrade/templates/nestjs-react-fullstack/templates/scripts/build.sh +39 -22
- package/upgrade/templates/nestjs-react-fullstack/templates/scripts/prune-smart.js +61 -2
|
@@ -18,7 +18,14 @@ function registerDeployCommandsModern(program) {
|
|
|
18
18
|
.option('--dir <path>', '项目目录', '.')
|
|
19
19
|
.option('--skip-build', '跳过 build 步骤(已构建好时使用)', false)
|
|
20
20
|
.option('--skip-release', '不创建/更新本地发布单,发布单状态由外部托管', false)
|
|
21
|
-
.option('--conf <json>', '关联元信息 JSON,仅识别 checkPointVersion / commitID
|
|
21
|
+
.option('--conf <json>', '关联元信息 JSON,仅识别 checkPointVersion / commitID / sessionID / marker / versionLevel 五字段')
|
|
22
|
+
// 这三个 flag 只在父命令声明一份,deploy 与 deploy patch 共用。
|
|
23
|
+
// 不能在 patch 上再声明一遍:commander 遇到父子同名 option 会把值判给父命令,
|
|
24
|
+
// 子命令拿到空数组,`deploy patch --create x` 会静默失效(deploy-patch-wiring 测试可复现)。
|
|
25
|
+
// patch 从 deployCmd.opts() 读,与它今天读 --dir 的方式一致。
|
|
26
|
+
.option('--create <relpath>', '新增文件(可重复)', shared_1.collectRepeatedOption, [])
|
|
27
|
+
.option('--update <relpath>', '修改文件(可重复)', shared_1.collectRepeatedOption, [])
|
|
28
|
+
.option('--delete <relpath>', '删除文件(可重复)', shared_1.collectRepeatedOption, [])
|
|
22
29
|
.addHelpText('after', `
|
|
23
30
|
不要用异步模式或后台模式调用 deploy,否则调用可能提前结束,Agent 会误判发布已完成。
|
|
24
31
|
|
|
@@ -41,14 +48,27 @@ function registerDeployCommandsModern(program) {
|
|
|
41
48
|
外部据 stdout 返回的 version / preReleaseID 自行建单,并据本命令的
|
|
42
49
|
退出码决定把发布单翻成 Finished 还是 Failed —— 失败态由外部负责,CLI 不再兜底。
|
|
43
50
|
该模式下 releaseID / url 输出为 null(CLI 未建单,无从得知)。
|
|
44
|
-
注意:--conf
|
|
51
|
+
注意:--conf 的四个字段唯一消费者是 createLocalRelease,
|
|
45
52
|
本模式下不生效(静默忽略,不报错),需要关联请在外部建单时自行传递。
|
|
46
53
|
|
|
54
|
+
--create / --update / --delete(变更文件清单)
|
|
55
|
+
可重复,值为工程根相对路径(禁绝对路径与 "..")。deploy patch 消费它做增量发布;
|
|
56
|
+
在 deploy 下当前是预留口子——只校验路径并记一行日志,不改变上传行为:
|
|
57
|
+
deploy 仍然全量上传产物,latest 每次被重建为工作区的精确镜像(prune 清理远端多余对象),
|
|
58
|
+
以此保证 git 仓库与 TOS 资源不会不一致。
|
|
59
|
+
后续若实现增量上传,从这里取「要 PUT 哪些文件」即可,调用方无需改动;
|
|
60
|
+
删除仍交给 prune,因为 prune 比对的是完整本地清单,与上传了哪些文件无关。
|
|
61
|
+
|
|
47
62
|
--conf(关联元信息透传)
|
|
48
|
-
值为 JSON string
|
|
63
|
+
值为 JSON string,只识别四个字段,其余 key 忽略:
|
|
49
64
|
checkPointVersion 关联的 checkpoint 版本
|
|
50
65
|
commitID 关联的代码 commit ID
|
|
51
|
-
|
|
66
|
+
sessionID 发起本次发布的页面会话 ID,原样透传不做净化
|
|
67
|
+
marker 本次发布的变更说明,落发布单 description
|
|
68
|
+
四字段均可选;非法 JSON / 非对象 / 字段值非字符串会报错。
|
|
69
|
+
versionLevel:本次发布的版本档位。"major" 声明这是一个大版本,历史记录里强制开新组;
|
|
70
|
+
"minor" 声明是小版本,即使距上次发布超过聚合阈值也不提升。不传则由服务端按
|
|
71
|
+
时间间隔自动判定,与改造前行为一致——只有会主动声明档位的链路需要传。
|
|
52
72
|
|
|
53
73
|
JSON 输出(stdout)
|
|
54
74
|
{"data": {"appId": "...", "version": <n>, "url": "...", "releaseID": "...", "preReleaseID": "..."}}
|
|
@@ -60,6 +80,8 @@ JSON 输出(stdout)
|
|
|
60
80
|
$ miaoda deploy --skip-build
|
|
61
81
|
$ miaoda deploy --skip-release
|
|
62
82
|
$ miaoda deploy --conf '{"checkPointVersion":"v3","commitID":"a1b2c3d"}'
|
|
83
|
+
$ miaoda deploy --conf '{"commitID":"a1b2c3d","sessionID":"<uuid>","marker":"编辑保存:修改 index.html"}'
|
|
84
|
+
$ miaoda deploy --update index.html --create assets/new.js --delete old.html
|
|
63
85
|
`);
|
|
64
86
|
deployCmd.action((0, shared_1.withHelp)(deployCmd, async (rawOpts) => {
|
|
65
87
|
await (0, modern_1.handleDeployModern)({
|
|
@@ -68,17 +90,18 @@ JSON 输出(stdout)
|
|
|
68
90
|
skipBuild: rawOpts.skipBuild,
|
|
69
91
|
skipRelease: rawOpts.skipRelease,
|
|
70
92
|
conf: rawOpts.conf,
|
|
93
|
+
creates: rawOpts.create,
|
|
94
|
+
updates: rawOpts.update,
|
|
95
|
+
deletes: rawOpts.delete,
|
|
71
96
|
});
|
|
72
97
|
}));
|
|
73
98
|
const patchCmd = deployCmd
|
|
74
99
|
.command('patch')
|
|
75
100
|
.description('design-html 增量发布:按文件 create/update/delete,.html 变动时同步 routes.json')
|
|
76
|
-
.option('--create <relpath>', '新增文件(可重复)', shared_1.collectRepeatedOption, [])
|
|
77
|
-
.option('--update <relpath>', '覆盖已有文件(可重复)', shared_1.collectRepeatedOption, [])
|
|
78
|
-
.option('--delete <relpath>', '删除文件(可重复)', shared_1.collectRepeatedOption, [])
|
|
79
101
|
.option('--session-id <id>', '会话 ID,发布时透传给下游(可选)')
|
|
80
102
|
.addHelpText('after', `
|
|
81
|
-
--dir
|
|
103
|
+
--dir / --create / --update / --delete 声明在父命令 deploy 上,本命令共用,用法不变。
|
|
104
|
+
--dir 为项目目录,默认当前目录。
|
|
82
105
|
仅支持 design-html(design_local_deploy)。路径为工程根相对路径(= 服务端 latest 下 key),
|
|
83
106
|
禁绝对路径与 ".."。--create/--update 的本地文件必须存在。改动里含任意 .html(增 / 改 / 删)
|
|
84
107
|
时自动重算并随包更新 routes.json;纯非 .html 改动不动 routes.json。
|
|
@@ -98,9 +121,9 @@ JSON 输出
|
|
|
98
121
|
await (0, index_1.handleDeployPatch)({
|
|
99
122
|
appId: (0, shared_1.resolveAppId)({}),
|
|
100
123
|
dir: deployCmd.opts().dir ?? '.',
|
|
101
|
-
creates:
|
|
102
|
-
updates:
|
|
103
|
-
deletes:
|
|
124
|
+
creates: deployCmd.opts().create,
|
|
125
|
+
updates: deployCmd.opts().update,
|
|
126
|
+
deletes: deployCmd.opts().delete,
|
|
104
127
|
sessionID: rawOpts.sessionId,
|
|
105
128
|
});
|
|
106
129
|
}));
|
|
@@ -23,7 +23,7 @@ function registerSkillsSync(parent) {
|
|
|
23
23
|
.command('sync')
|
|
24
24
|
.description('同步 skills 到 user app(默认 coding-steering;带 --type 时走 sandbox-skills)')
|
|
25
25
|
.option('--dir <path>', '项目目录,默认当前目录', '.')
|
|
26
|
-
.option('--version <ver>', 'coding-steering
|
|
26
|
+
.option('--version <ver>', '指定公共 coding-steering 包的版本或 dist-tag')
|
|
27
27
|
.option('--local', '走本地 dev / agent 输出形态:拷到 .agents/skills 平铺 + 创建 .claude/skills 软链。' +
|
|
28
28
|
'不传时退回老形态:拷到 .agent/skills/steering/<stack>/skills/(跟沙箱端 update-skills.sh 对齐)', false)
|
|
29
29
|
.option('--type <type>', '走 sandbox 分支:miaoda | miaoda-modern | miaoda-design | openclaw。有值时忽略 --local,' +
|
|
@@ -35,6 +35,13 @@ function registerSkillsSync(parent) {
|
|
|
35
35
|
前置要求
|
|
36
36
|
当前目录(或 --dir)已走过 'miaoda app init'(.spark/meta.json 含 stack)
|
|
37
37
|
|
|
38
|
+
技术栈 skill 来源
|
|
39
|
+
MIAODA_SANDBOX_PROVIDER=tae 时,从 bnpm 额外同步 @byted-miaoda/coding-steering-extension-internal。
|
|
40
|
+
有 miaodaSkillsExtension 协议时按 add/remove 动作同步;旧包沿用目录叠加。
|
|
41
|
+
remove 排除基础 skill,撤销动作或切回公共版后恢复当前公共版本。
|
|
42
|
+
内网包优先取 --tgz-key 对应的 lane 版本,没有时 BOE 取 dev、其余环境取 latest。--version 仅影响公共来源。
|
|
43
|
+
未设置或其他 provider 值时仅同步公共包。
|
|
44
|
+
|
|
38
45
|
输出形态(--local 切换)
|
|
39
46
|
默认(不传 --local):
|
|
40
47
|
.agent/skills/steering/<stack>/skills/<skill>/...
|
|
@@ -54,6 +61,8 @@ function registerSkillsSync(parent) {
|
|
|
54
61
|
JSON 输出
|
|
55
62
|
{"data": {"stack": "...", "version": "...", "syncedSkills": [...], "techSynced": true|false,
|
|
56
63
|
"claudeSkillsLink": "created|updated|noop|conflict|unsupported" // 仅 --local 时}}
|
|
64
|
+
内网包同步成功时包含 internalVersion;协议排除项列在 removedSkills。
|
|
65
|
+
本地移除遇到自建或手改条目时返回 SKILLS_REMOVE_CONFLICT;恢复或覆盖冲突列在 preservedLocalSkills。
|
|
57
66
|
|
|
58
67
|
传 --type 时:
|
|
59
68
|
{"data": {"mode": "sandbox", "type": "...", "packageName": "...", "version": "...",
|
|
@@ -0,0 +1,191 @@
|
|
|
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.handleAppImport = handleAppImport;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const index_1 = require("../../../services/app/import/index");
|
|
11
|
+
const error_1 = require("../../../utils/error");
|
|
12
|
+
const logger_1 = require("../../../utils/logger");
|
|
13
|
+
const output_1 = require("../../../utils/output");
|
|
14
|
+
function readPackageJson(file, label, warnings) {
|
|
15
|
+
try {
|
|
16
|
+
return (0, index_1.readJsonFile)(file);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
warnings.push(`${label} 不是合法 JSON,依赖清单按空处理:${err instanceof Error ? err.message : String(err)}`);
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function readPrevFileCounts(manifestFile) {
|
|
24
|
+
try {
|
|
25
|
+
const prev = JSON.parse(node_fs_1.default.readFileSync(manifestFile, 'utf-8'));
|
|
26
|
+
return prev.fileCounts;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* miaoda app import --zip <path> | --zip-url <url> [--platform <p>] [--rules-json <json>] [--dry-run]
|
|
34
|
+
*
|
|
35
|
+
* 外部平台(lovable / replit / gemini / 普通 zip)项目导入:在已 `app init` 的工程里,
|
|
36
|
+
* 把用户代码按平台规则叠加到 client/ shared/,其余原样落到 source_package/。
|
|
37
|
+
* 不碰模板托管文件、不合并 package.json、不装依赖 —— 用户 package.json 保留在
|
|
38
|
+
* source_package/package.json,依赖分析写进 manifest 交给 Coding Agent 后续按需安装。
|
|
39
|
+
*
|
|
40
|
+
* 落盘两阶段(先暂存、再 rename),manifest 最后写,作为幂等标记。
|
|
41
|
+
*/
|
|
42
|
+
async function handleAppImport(opts) {
|
|
43
|
+
const hasZip = Boolean(opts.zip);
|
|
44
|
+
const hasUrl = Boolean(opts.zipUrl);
|
|
45
|
+
if (hasZip === hasUrl) {
|
|
46
|
+
throw new error_1.AppError('ARGS_INVALID', '--zip 与 --zip-url 必须且只能传一个');
|
|
47
|
+
}
|
|
48
|
+
const platform = (0, index_1.parsePlatform)(opts.platform);
|
|
49
|
+
const rules = (0, index_1.resolveImportRules)(platform, opts.rulesJson);
|
|
50
|
+
const projectDir = node_path_1.default.resolve(opts.dir ?? process.cwd());
|
|
51
|
+
if (!node_fs_1.default.existsSync(node_path_1.default.join(projectDir, '.spark', 'meta.json'))) {
|
|
52
|
+
throw new error_1.AppError('NOT_INITIALIZED', `工程未初始化(缺少 .spark/meta.json):${projectDir}`, {
|
|
53
|
+
next_actions: ['先执行 miaoda app init --template <stack> 再导入'],
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const manifestFile = (0, index_1.importManifestPath)(projectDir);
|
|
57
|
+
if (node_fs_1.default.existsSync(manifestFile)) {
|
|
58
|
+
(0, logger_1.log)('import', `Already imported (${index_1.IMPORT_MANIFEST_REL} exists), skip`);
|
|
59
|
+
if (!(0, output_1.isJsonMode)())
|
|
60
|
+
process.stdout.write(`Already imported: ${manifestFile}\n`);
|
|
61
|
+
(0, output_1.emit)({
|
|
62
|
+
data: {
|
|
63
|
+
imported: false,
|
|
64
|
+
alreadyImported: true,
|
|
65
|
+
platform,
|
|
66
|
+
fileCounts: readPrevFileCounts(manifestFile),
|
|
67
|
+
manifestPath: index_1.IMPORT_MANIFEST_REL,
|
|
68
|
+
warnings: [],
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const tmpDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'miaoda-import-'));
|
|
74
|
+
try {
|
|
75
|
+
const warnings = [];
|
|
76
|
+
let zipPath;
|
|
77
|
+
if (opts.zipUrl) {
|
|
78
|
+
zipPath = node_path_1.default.join(tmpDir, 'import.zip');
|
|
79
|
+
await (0, index_1.downloadZip)(opts.zipUrl, zipPath);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
zipPath = node_path_1.default.resolve(opts.zip ?? '');
|
|
83
|
+
(0, index_1.assertLocalZip)(zipPath);
|
|
84
|
+
}
|
|
85
|
+
const extractDir = node_path_1.default.join(tmpDir, 'extracted');
|
|
86
|
+
warnings.push(...(0, index_1.extractImportZip)(zipPath, extractDir).warnings);
|
|
87
|
+
const { entries, renamed } = (0, index_1.normalizeEntries)((0, index_1.collectFiles)(extractDir), platform);
|
|
88
|
+
if (entries.length === 0) {
|
|
89
|
+
throw new error_1.AppError('INVALID_ZIP', '导入包内没有可导入的文件');
|
|
90
|
+
}
|
|
91
|
+
for (const r of renamed)
|
|
92
|
+
warnings.push(`路径段过长已重命名:${r.from} → ${r.to}`);
|
|
93
|
+
const plan = (0, index_1.buildImportPlan)({ entries, platform, rules, projectDir });
|
|
94
|
+
warnings.push(...plan.warnings);
|
|
95
|
+
for (const c of plan.protectedConflicts) {
|
|
96
|
+
warnings.push(`目标为模板受保护路径,已改放 ${c.placedAt}:${c.target}`);
|
|
97
|
+
}
|
|
98
|
+
if (plan.overwrites.length > 0) {
|
|
99
|
+
warnings.push(`覆盖了工程中已有的 ${String(plan.overwrites.length)} 个文件`);
|
|
100
|
+
}
|
|
101
|
+
const dependencies = analyzeDependencies({
|
|
102
|
+
entries,
|
|
103
|
+
extractDir,
|
|
104
|
+
projectDir,
|
|
105
|
+
warnings,
|
|
106
|
+
});
|
|
107
|
+
if (opts.dryRun) {
|
|
108
|
+
if (!(0, output_1.isJsonMode)()) {
|
|
109
|
+
process.stdout.write(`Dry run: ${String(plan.placements.length)} file(s) planned\n`);
|
|
110
|
+
}
|
|
111
|
+
(0, output_1.emit)({
|
|
112
|
+
data: {
|
|
113
|
+
imported: false,
|
|
114
|
+
alreadyImported: false,
|
|
115
|
+
dryRun: true,
|
|
116
|
+
platform,
|
|
117
|
+
fileCounts: plan.fileCounts,
|
|
118
|
+
manifestPath: index_1.IMPORT_MANIFEST_REL,
|
|
119
|
+
warnings,
|
|
120
|
+
plan: {
|
|
121
|
+
placements: plan.placements.map((p) => ({ source: p.source, target: p.target })),
|
|
122
|
+
deletions: plan.deletions,
|
|
123
|
+
overwrites: plan.overwrites,
|
|
124
|
+
excludedPaths: plan.excludedPaths,
|
|
125
|
+
protectedConflicts: plan.protectedConflicts,
|
|
126
|
+
replacedTemplateFiles: plan.replacedTemplateFiles,
|
|
127
|
+
dependencies,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
applyWithStaging({ plan, extractDir, projectDir });
|
|
134
|
+
const manifest = (0, index_1.buildImportManifest)({ platform, plan, dependencies });
|
|
135
|
+
try {
|
|
136
|
+
(0, index_1.writeImportPendingMarker)(projectDir);
|
|
137
|
+
(0, index_1.writeImportManifest)(projectDir, manifest);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
throw new error_1.AppError('WRITE_FAILED', `写 ${index_1.IMPORT_MANIFEST_REL} 失败:${err instanceof Error ? err.message : String(err)}`);
|
|
141
|
+
}
|
|
142
|
+
(0, logger_1.log)('import', `Imported ${String(plan.placements.length)} file(s) (${platform})`);
|
|
143
|
+
if (!(0, output_1.isJsonMode)()) {
|
|
144
|
+
process.stdout.write(`✓ Imported ${String(plan.placements.length)} file(s) from ${platform} package into ${projectDir}\n`);
|
|
145
|
+
}
|
|
146
|
+
(0, output_1.emit)({
|
|
147
|
+
data: {
|
|
148
|
+
imported: true,
|
|
149
|
+
alreadyImported: false,
|
|
150
|
+
platform,
|
|
151
|
+
fileCounts: plan.fileCounts,
|
|
152
|
+
manifestPath: index_1.IMPORT_MANIFEST_REL,
|
|
153
|
+
warnings,
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
node_fs_1.default.rmSync(tmpDir, { recursive: true, force: true });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function analyzeDependencies(opts) {
|
|
162
|
+
const pkgEntry = opts.entries.find((e) => e.normalized === 'package.json');
|
|
163
|
+
if (!pkgEntry)
|
|
164
|
+
return [];
|
|
165
|
+
const sourcePkg = readPackageJson(node_path_1.default.join(opts.extractDir, ...pkgEntry.raw.split('/')), '导入包 package.json', opts.warnings);
|
|
166
|
+
const projectPkg = readPackageJson(node_path_1.default.join(opts.projectDir, 'package.json'), '工程 package.json', opts.warnings);
|
|
167
|
+
return (0, index_1.classifyDependencies)({ sourcePkg, projectPkg });
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 暂存目录放在工程 .spark/import/ 下:与工程同一文件系统,rename 不会 EXDEV。
|
|
171
|
+
* 若 .spark/import/ 是本次新建的且导入失败,连目录一起清掉,保证失败时工程原样。
|
|
172
|
+
*/
|
|
173
|
+
function applyWithStaging(opts) {
|
|
174
|
+
const importDir = node_path_1.default.join(opts.projectDir, '.spark', 'import');
|
|
175
|
+
const createdImportDir = !node_fs_1.default.existsSync(importDir);
|
|
176
|
+
const stagingDir = node_path_1.default.join(importDir, `.staging-${String(process.pid)}-${String(Date.now())}`);
|
|
177
|
+
try {
|
|
178
|
+
node_fs_1.default.mkdirSync(stagingDir, { recursive: true });
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
throw new error_1.AppError('WRITE_FAILED', `创建暂存目录失败:${err instanceof Error ? err.message : String(err)}`);
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
(0, index_1.applyImportPlan)({ ...opts, stagingDir });
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
if (createdImportDir)
|
|
188
|
+
node_fs_1.default.rmSync(importDir, { recursive: true, force: true });
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PACK_MODES = exports.DEFAULT_PACK_MODE = exports.DEFAULT_PACK_OUT = exports.handleAppPack = exports.SUPPORTED_STACKS = exports.handleAppMigrate = exports.UPGRADE_MANIFEST_FILENAME = exports.DEFAULT_EXPORT_OUT = exports.handleAppExport = exports.handleAppUpgrade = exports.handleAppSync = exports.handleAppInit = exports.handleAppUpdate = exports.handleAppGet = void 0;
|
|
3
|
+
exports.DEFAULT_IMPORT_PLATFORM = exports.IMPORT_PLATFORMS = exports.handleAppImport = exports.PACK_MODES = exports.DEFAULT_PACK_MODE = exports.DEFAULT_PACK_OUT = exports.handleAppPack = exports.SUPPORTED_STACKS = exports.handleAppMigrate = exports.UPGRADE_MANIFEST_FILENAME = exports.DEFAULT_EXPORT_OUT = exports.handleAppExport = 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");
|
|
@@ -24,3 +24,9 @@ Object.defineProperty(exports, "handleAppPack", { enumerable: true, get: functio
|
|
|
24
24
|
Object.defineProperty(exports, "DEFAULT_PACK_OUT", { enumerable: true, get: function () { return pack_1.DEFAULT_PACK_OUT; } });
|
|
25
25
|
Object.defineProperty(exports, "DEFAULT_PACK_MODE", { enumerable: true, get: function () { return pack_1.DEFAULT_PACK_MODE; } });
|
|
26
26
|
Object.defineProperty(exports, "PACK_MODES", { enumerable: true, get: function () { return pack_1.PACK_MODES; } });
|
|
27
|
+
var import_1 = require("./import");
|
|
28
|
+
Object.defineProperty(exports, "handleAppImport", { enumerable: true, get: function () { return import_1.handleAppImport; } });
|
|
29
|
+
// commands 层渲染 help 用的枚举,同 SUPPORTED_STACKS 走 handler barrel 转发
|
|
30
|
+
var index_2 = require("../../../services/app/import/index");
|
|
31
|
+
Object.defineProperty(exports, "IMPORT_PLATFORMS", { enumerable: true, get: function () { return index_2.IMPORT_PLATFORMS; } });
|
|
32
|
+
Object.defineProperty(exports, "DEFAULT_IMPORT_PLATFORM", { enumerable: true, get: function () { return index_2.DEFAULT_IMPORT_PLATFORM; } });
|
|
@@ -15,6 +15,7 @@ const logs_dir_1 = require("../../../utils/logs-dir");
|
|
|
15
15
|
const env_1 = require("../../../utils/env");
|
|
16
16
|
const error_1 = require("../../../utils/error");
|
|
17
17
|
const output_1 = require("../../../utils/output");
|
|
18
|
+
const engineering_state_1 = require("../../../utils/engineering-state");
|
|
18
19
|
/**
|
|
19
20
|
* miaoda app init
|
|
20
21
|
*
|
|
@@ -32,24 +33,56 @@ const output_1 = require("../../../utils/output");
|
|
|
32
33
|
* 的版本(没经 sync 覆盖);首次 install 装的也是 template 钉的版本(没升 latest),
|
|
33
34
|
* package.json 跟 template 完全一致。dev.sh 入口的 sync 会修正这些 drift。
|
|
34
35
|
*
|
|
35
|
-
* 幂等:.spark/meta.json
|
|
36
|
+
* 幂等:.spark/meta.json 存在时不重跑渲染 / 安装(不覆盖业务代码),但会做只读就绪核验并输出
|
|
37
|
+
* ready / problems —— meta 存在不等于就绪;--strict 时未就绪退出码 1。
|
|
36
38
|
* 半渲染状态(package.json 在但 meta.json 不在)会重新跑完整流程。
|
|
39
|
+
*
|
|
40
|
+
* 同步安装失败:meta 仍写出(脚手架已渲染,避免重跑覆盖已开始编辑的文件),本地执行记录标为
|
|
41
|
+
* 失败,输出 status=failed / failedStage=install。只有 --strict(平台严格调用)以退出码 1 结束;
|
|
42
|
+
* 不带 --strict 时退出码 0 —— lark-cli `+init` 等调用方按退出码判成败,且依赖由后续
|
|
43
|
+
* `miaoda app sync`(dev.sh 入口)补装,安装抖动不能让整条初始化失败。
|
|
37
44
|
*/
|
|
38
45
|
async function handleAppInit(opts) {
|
|
39
46
|
await Promise.resolve();
|
|
40
47
|
const targetDir = opts.targetDir ?? process.cwd();
|
|
41
48
|
const metaPath = node_path_1.default.join(targetDir, '.spark', 'meta.json');
|
|
42
49
|
if (node_fs_1.default.existsSync(metaPath)) {
|
|
50
|
+
let expectedStack;
|
|
51
|
+
if (opts.template || opts.appType) {
|
|
52
|
+
try {
|
|
53
|
+
expectedStack = (0, index_1.resolveStack)({ template: opts.template, appType: opts.appType });
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
// 非严格调用保持历史行为:已初始化时不因参数校验失败而报错
|
|
57
|
+
if (opts.strict)
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const check = (0, index_1.checkWorkspaceReady)({ targetDir, expectedStack });
|
|
43
62
|
if (!(0, output_1.isJsonMode)()) {
|
|
44
63
|
process.stdout.write(`Already initialized: ${metaPath}\n`);
|
|
64
|
+
for (const p of check.problems) {
|
|
65
|
+
process.stdout.write(` ✗ ${p.code}: ${p.message}\n`);
|
|
66
|
+
}
|
|
45
67
|
}
|
|
46
68
|
(0, output_1.emit)({
|
|
47
69
|
data: {
|
|
48
70
|
initialized: false,
|
|
49
71
|
reason: 'already_initialized',
|
|
50
72
|
targetDir,
|
|
73
|
+
stack: check.stack,
|
|
74
|
+
ready: check.ready,
|
|
75
|
+
problems: check.problems,
|
|
51
76
|
},
|
|
52
77
|
});
|
|
78
|
+
if (opts.strict && !check.ready) {
|
|
79
|
+
(0, output_1.emitError)(new error_1.AppError('WORKSPACE_NOT_READY', check.problems.map((p) => `${p.code}: ${p.message}`).join('; '), {
|
|
80
|
+
next_actions: [
|
|
81
|
+
'按 problems 修复:依赖 / 文件问题执行 miaoda app sync,布局不符执行 miaoda app migrate',
|
|
82
|
+
],
|
|
83
|
+
}));
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
}
|
|
53
86
|
return;
|
|
54
87
|
}
|
|
55
88
|
const stack = (0, index_1.resolveStack)({ template: opts.template, appType: opts.appType });
|
|
@@ -130,25 +163,34 @@ async function handleAppInit(opts) {
|
|
|
130
163
|
app_id: opts.appId,
|
|
131
164
|
});
|
|
132
165
|
// async 模式:meta 已落盘(= 脚手架就绪),再派发后台安装并立即返回(不等装完)。
|
|
166
|
+
// 执行记录先标 running,后台 worker 结束时改写为 succeeded / failed;中断则停留在 running。
|
|
133
167
|
let asyncDispatch;
|
|
134
168
|
if (opts.asyncInstall) {
|
|
169
|
+
recordInitState(targetDir, 'running', 'install');
|
|
135
170
|
asyncDispatch = (0, index_1.dispatchAsyncInstall)({ targetDir });
|
|
136
171
|
}
|
|
172
|
+
const installFailed = installResult?.source === 'failed';
|
|
173
|
+
if (installResult !== undefined) {
|
|
174
|
+
recordInitState(targetDir, installFailed ? 'failed' : 'succeeded', installResult.source === 'skipped' ? 'install-skipped' : 'install', installResult.error);
|
|
175
|
+
}
|
|
137
176
|
if (!(0, output_1.isJsonMode)()) {
|
|
138
177
|
if (opts.asyncInstall && asyncDispatch) {
|
|
139
178
|
process.stdout.write(`✓ Initialized ${stack} (template ${tplResult.version}, steering ${steeringResult.version}, install dispatched in background pid ${String(asyncDispatch.pid)}) in ${targetDir}\n`);
|
|
140
179
|
}
|
|
141
180
|
else if (installResult) {
|
|
142
|
-
process.stdout.write(
|
|
181
|
+
process.stdout.write(`${installFailed ? '✗' : '✓'} Initialized ${stack} (template ${tplResult.version}, steering ${steeringResult.version}, install ${installResult.source}) in ${targetDir}\n`);
|
|
143
182
|
}
|
|
144
183
|
}
|
|
145
184
|
(0, output_1.emit)({
|
|
146
185
|
data: {
|
|
147
186
|
initialized: true,
|
|
187
|
+
status: installFailed ? 'failed' : 'succeeded',
|
|
188
|
+
failedStage: installFailed ? 'install' : undefined,
|
|
148
189
|
template: stack,
|
|
149
190
|
templatePackage: tplResult.packageName,
|
|
150
191
|
templateVersion: tplResult.version,
|
|
151
192
|
steeringVersion: steeringResult.version,
|
|
193
|
+
internalSteeringVersion: steeringResult.internalVersion,
|
|
152
194
|
archType: tplResult.archType,
|
|
153
195
|
appId: opts.appId,
|
|
154
196
|
appType: opts.appType,
|
|
@@ -157,6 +199,7 @@ async function handleAppInit(opts) {
|
|
|
157
199
|
importedFileCount: sourceImport.importedFileCount,
|
|
158
200
|
sourceIgnoredReason: sourceImport.sourceIgnoredReason,
|
|
159
201
|
syncedSkills: steeringResult.syncedSkills,
|
|
202
|
+
preservedLocalSkills: steeringResult.preservedLocalSkills,
|
|
160
203
|
techSynced: steeringResult.techSynced,
|
|
161
204
|
steeringError,
|
|
162
205
|
gitHooks: hookActivation.action,
|
|
@@ -177,8 +220,39 @@ async function handleAppInit(opts) {
|
|
|
177
220
|
cacheZip: installResult?.cacheZip,
|
|
178
221
|
installError: installResult?.error,
|
|
179
222
|
}),
|
|
223
|
+
nextActions: installFailed
|
|
224
|
+
? [
|
|
225
|
+
'检查 npm 输出定位安装错误(网络 / registry / 依赖冲突),修复后执行 miaoda app sync 补装依赖',
|
|
226
|
+
]
|
|
227
|
+
: undefined,
|
|
180
228
|
},
|
|
181
229
|
});
|
|
230
|
+
if (installFailed) {
|
|
231
|
+
if (opts.strict) {
|
|
232
|
+
(0, output_1.emitError)(new error_1.AppError('INIT_INSTALL_FAILED', `npm install failed: ${installResult?.error ?? ''}`, {
|
|
233
|
+
retryable: true,
|
|
234
|
+
next_actions: ['修复安装错误后执行 miaoda app sync 补装依赖'],
|
|
235
|
+
}));
|
|
236
|
+
process.exitCode = 1;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
(0, logger_1.log)('init', '⚠ npm install failed (continuing; run `miaoda app sync` to install later)');
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function recordInitState(targetDir, status, stage, error) {
|
|
244
|
+
try {
|
|
245
|
+
(0, engineering_state_1.writeEngineeringState)(targetDir, {
|
|
246
|
+
operation: 'init',
|
|
247
|
+
status,
|
|
248
|
+
stage,
|
|
249
|
+
code: status === 'failed' ? 'INIT_INSTALL_FAILED' : undefined,
|
|
250
|
+
message: error?.slice(0, 500),
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
catch (err) {
|
|
254
|
+
(0, logger_1.log)('init', `⚠ failed to record engineering state: ${err instanceof Error ? err.message : String(err)}`);
|
|
255
|
+
}
|
|
182
256
|
}
|
|
183
257
|
/**
|
|
184
258
|
* 处理 --source-path 导入:当前仅 app_type=modern_html 生效。
|