agentdock-cli 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -33
- package/dist/package.json +1 -1
- package/dist/src/cli.js +1 -7
- package/dist/src/constants/command-error-codes.js +0 -2
- package/package.json +1 -1
- package/dist/src/commands/init.js +0 -65
- package/dist/src/commands/upgrade.js +0 -243
- package/dist/src/constants/upgrade-warning-codes.js +0 -9
- package/dist/src/types/upgrade-report.js +0 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AgentDock
|
|
2
2
|
|
|
3
|
-
AgentDock 是 **AI 编码助手(Claude Code / Codex)环境的迁移、备份与版本化工具**——你的 AI 编程助手的 dotfiles
|
|
3
|
+
AgentDock 是 **AI 编码助手(Claude Code / Codex)环境的迁移、备份与版本化工具**——你的 AI 编程助手的 dotfiles 工具。
|
|
4
4
|
|
|
5
5
|
> 产品定位、目标用户、边界与路线图见 **[产品需求文档 (PRD)](./docs/PRD.md)**,本文档对外口径一律以 PRD 为准。
|
|
6
6
|
|
|
@@ -23,31 +23,17 @@ npx agentdock-cli --help
|
|
|
23
23
|
|
|
24
24
|
## 功能范围(按层)
|
|
25
25
|
|
|
26
|
-
- `
|
|
26
|
+
- `scan`:自动发现并提取 Claude Code / Codex 的 AI 助手环境(MCP / Skill / Agent / Plugin / Hook / 记忆),隔离敏感信息,产出领域化 manifest v3
|
|
27
|
+
- `export`:把扫描产物打包成可迁移包(敏感值替换为占位符,绝不写入真实 token)
|
|
28
|
+
- `install`:从迁移包还原到目标机(支持 `--env` 回注真实值)
|
|
27
29
|
- `validate`:校验清单
|
|
28
|
-
- `
|
|
29
|
-
- `install`:从导出包恢复到目标目录
|
|
30
|
-
- `upgrade`:将旧版 manifest 升级到新版结构
|
|
31
|
-
- `scan`:自动发现并提取 Claude Code / Codex 的 AI 助手环境(MCP / Skill / Agent / Plugin / Hook / 记忆),隔离敏感信息,产出领域化 manifest v3(预览中)
|
|
30
|
+
- `doctor`:体检当前环境或迁移包——无真实令牌泄露、无运行态文件混入
|
|
32
31
|
- `list`:列出已扫描捕获(或安装包包含)的助手环境定义清单,纯展示、不读取源机、不改动任何文件
|
|
33
32
|
|
|
34
33
|
## Quickstart
|
|
35
34
|
|
|
36
35
|
```bash
|
|
37
|
-
npm run cli --
|
|
38
|
-
npm run cli -- validate agentdock.yml --json
|
|
39
|
-
npm run cli -- init ./my-project --json
|
|
40
|
-
npm run cli -- export agentdock.yml
|
|
41
|
-
npm run cli -- export agentdock.yml --json
|
|
42
|
-
npm run cli -- install ./dist/exported ./dist/restored
|
|
43
|
-
npm run cli -- install ./dist/exported ./dist/restored --json
|
|
44
|
-
npm run cli -- upgrade agentdock.yml
|
|
45
|
-
npm run cli -- upgrade agentdock.yml --dry-run
|
|
46
|
-
npm run cli -- upgrade agentdock.yml --dry-run --verbose
|
|
47
|
-
npm run cli -- upgrade agentdock.yml --dry-run --json
|
|
48
|
-
npm run cli -- upgrade agentdock.yml --write ./agentdock.v2.yml
|
|
49
|
-
npm run cli -- upgrade agentdock.yml --backup
|
|
50
|
-
npm run cli -- upgrade agentdock.yml --force --dry-run
|
|
36
|
+
# 安装后所有命令以 agentdock 调用;仓库贡献者可用开发模式 npm run cli -- <command>
|
|
51
37
|
npm run cli -- scan
|
|
52
38
|
npm run cli -- scan --agent claude --json
|
|
53
39
|
npm run cli -- scan --agent claude --root ~ --out ./scan-out
|
|
@@ -91,14 +77,8 @@ agentdock list --package ./pkg
|
|
|
91
77
|
## Current behavior
|
|
92
78
|
|
|
93
79
|
- manifest v2 支持 `sources[*].destination`
|
|
94
|
-
- v1 manifest
|
|
95
|
-
- `
|
|
96
|
-
- `upgrade --dry-run` 可先查看 diff 预览,不写回文件
|
|
97
|
-
- `upgrade --dry-run --json` 输出机器可读 diff 结果(单行 JSON)
|
|
98
|
-
- `upgrade --dry-run --json` 还包含 `summary`(`addedDestinationCount`、`changedLineCount`、`sourceCount`、`templateCount`、`warningCount`、`warnings`)
|
|
99
|
-
- `init/validate/export/install/upgrade --json` 现已统一为版本化协议(`schemaVersion`、`generatedAt`、`toolVersion`、`command`、`success`、`data`、`errors`)
|
|
100
|
-
- `upgrade --json` 的升级专用字段(如 `diff`、`summary`)已统一放入 `data`
|
|
101
|
-
- `upgrade` 文本模式默认输出稳定摘要;仅在 `--verbose` 时附加 diff 详情
|
|
80
|
+
- v1 manifest 仍可读取并校验(仅用于兼容旧包)
|
|
81
|
+
- `validate/export/install/scan/doctor/list --json` 统一为版本化协议(`schemaVersion`、`generatedAt`、`toolVersion`、`command`、`success`、`data`、`errors`)
|
|
102
82
|
- 所有 `--json` 的 `errors` 为结构化数组:`[{ code, message }]`
|
|
103
83
|
- `scan` 自动发现 AI 助手环境并隔离敏感信息,生成 `agentdock.scan.yml` + `.env.example` + `scan-report.md`:
|
|
104
84
|
- **Claude Code**:MCP(来自 `.claude.json`)、skills、agents、plugins、hooks、记忆文件与 `settings.json`
|
|
@@ -119,9 +99,6 @@ agentdock list --package ./pkg
|
|
|
119
99
|
- `list --from-scan <yml>` 读取 v3 扫描 manifest(`agentdock.scan.yml`);`list --package <dir>` 读取安装包的 `manifest.resolved.json` 并额外展示 `meta/install-plan.json` 的文件→目标映射
|
|
120
100
|
- `list --out <dir>` 把清单写入 `list-report.md`;`--json` 输出机器可读清单(沿用统一协议)
|
|
121
101
|
- 错误码新增 `LIST_FAILED`(list 运行期异常兜底)
|
|
122
|
-
- `upgrade --write <path>` 将升级结果写到新文件,保留原文件不变
|
|
123
|
-
- `upgrade --backup` 原位升级前生成备份文件(`<manifest>.bak.<timestamp>`)
|
|
124
|
-
- `upgrade --force` 即使已是 v2 也会按当前规则重新处理并输出 diff
|
|
125
102
|
- templates 在 `export` 阶段完成 `{{VAR_NAME}}` 渲染
|
|
126
103
|
- `options.followSymlinks` 默认是 `true`,导出目录时会跟随并复制链接目标内容
|
|
127
104
|
- 设置 `options.followSymlinks: false` 可在导出时跳过链接目录/文件
|
|
@@ -136,8 +113,6 @@ agentdock list --package ./pkg
|
|
|
136
113
|
- `MISSING_ARGUMENT`
|
|
137
114
|
- `MANIFEST_NOT_FOUND`
|
|
138
115
|
- `MANIFEST_INVALID`
|
|
139
|
-
- `MANIFEST_ALREADY_EXISTS`
|
|
140
|
-
- `UNSUPPORTED_MANIFEST_VERSION`
|
|
141
116
|
- `TEMPLATE_VARIABLE_MISSING`
|
|
142
117
|
- `MISSING_PACKAGE_MANIFEST`
|
|
143
118
|
- `MISSING_INSTALL_PLAN`
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentdock-cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Migrate, back up, and version your AI coding assistant environment (Claude Code / Codex) — MCP servers, Skills, Agents, Plugins, Hooks, and memory — as a portable, secret-isolated package.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
package/dist/src/cli.js
CHANGED
|
@@ -3,12 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.runCli = runCli;
|
|
5
5
|
const export_1 = require("./commands/export");
|
|
6
|
-
const init_1 = require("./commands/init");
|
|
7
6
|
const install_1 = require("./commands/install");
|
|
8
7
|
const scan_1 = require("./commands/scan");
|
|
9
8
|
const doctor_1 = require("./commands/doctor");
|
|
10
9
|
const list_1 = require("./commands/list");
|
|
11
|
-
const upgrade_1 = require("./commands/upgrade");
|
|
12
10
|
const validate_1 = require("./commands/validate");
|
|
13
11
|
function parseCliOptions(args) {
|
|
14
12
|
const positionals = [];
|
|
@@ -94,12 +92,8 @@ async function runCli(args) {
|
|
|
94
92
|
return (0, validate_1.runValidateCommand)(positionals[0], options);
|
|
95
93
|
case 'export':
|
|
96
94
|
return (0, export_1.runExportCommand)(positionals[0], options);
|
|
97
|
-
case 'init':
|
|
98
|
-
return (0, init_1.runInitCommand)(positionals[0], options);
|
|
99
95
|
case 'install':
|
|
100
96
|
return (0, install_1.runInstallCommand)(positionals[0], positionals[1], options);
|
|
101
|
-
case 'upgrade':
|
|
102
|
-
return (0, upgrade_1.runUpgradeCommand)(positionals[0], options);
|
|
103
97
|
case 'scan':
|
|
104
98
|
return (0, scan_1.runScanCommand)(options);
|
|
105
99
|
case 'doctor':
|
|
@@ -110,7 +104,7 @@ async function runCli(args) {
|
|
|
110
104
|
return {
|
|
111
105
|
exitCode: 1,
|
|
112
106
|
stdout: [],
|
|
113
|
-
stderr: ['Usage: agentdock <
|
|
107
|
+
stderr: ['Usage: agentdock <scan|export|install|validate|doctor|list> [path]'],
|
|
114
108
|
};
|
|
115
109
|
}
|
|
116
110
|
}
|
|
@@ -6,8 +6,6 @@ exports.COMMAND_ERROR_CODES = {
|
|
|
6
6
|
MISSING_ARGUMENT: 'MISSING_ARGUMENT',
|
|
7
7
|
MANIFEST_NOT_FOUND: 'MANIFEST_NOT_FOUND',
|
|
8
8
|
MANIFEST_INVALID: 'MANIFEST_INVALID',
|
|
9
|
-
MANIFEST_ALREADY_EXISTS: 'MANIFEST_ALREADY_EXISTS',
|
|
10
|
-
UNSUPPORTED_MANIFEST_VERSION: 'UNSUPPORTED_MANIFEST_VERSION',
|
|
11
9
|
TEMPLATE_VARIABLE_MISSING: 'TEMPLATE_VARIABLE_MISSING',
|
|
12
10
|
MISSING_PACKAGE_MANIFEST: 'MISSING_PACKAGE_MANIFEST',
|
|
13
11
|
MISSING_INSTALL_PLAN: 'MISSING_INSTALL_PLAN',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentdock-cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Migrate, back up, and version your AI coding assistant environment (Claude Code / Codex) — MCP servers, Skills, Agents, Plugins, Hooks, and memory — as a portable, secret-isolated package.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
@@ -1,65 +0,0 @@
|
|
|
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.runInitCommand = runInitCommand;
|
|
7
|
-
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
10
|
-
const command_json_1 = require("../utils/command-json");
|
|
11
|
-
async function runInitCommand(targetDirectory, options = {}) {
|
|
12
|
-
const projectRoot = node_path_1.default.resolve(targetDirectory ?? process.cwd());
|
|
13
|
-
const manifestPath = node_path_1.default.join(projectRoot, 'agentdock.yml');
|
|
14
|
-
const examplePath = node_path_1.default.resolve(__dirname, '../../examples/agentdock.example.yml');
|
|
15
|
-
try {
|
|
16
|
-
await promises_1.default.access(manifestPath);
|
|
17
|
-
if (options.json === true) {
|
|
18
|
-
return {
|
|
19
|
-
exitCode: 1,
|
|
20
|
-
stdout: [(0, command_json_1.toJsonLine)('init', false, { targetDirectory: projectRoot, manifestPath }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.MANIFEST_ALREADY_EXISTS, `Manifest already exists: ${manifestPath}`)])],
|
|
21
|
-
stderr: [],
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
exitCode: 1,
|
|
26
|
-
stdout: [],
|
|
27
|
-
stderr: [`Manifest already exists: ${manifestPath}`],
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
// continue
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
const template = await promises_1.default.readFile(examplePath, 'utf8');
|
|
35
|
-
await promises_1.default.mkdir(projectRoot, { recursive: true });
|
|
36
|
-
await promises_1.default.writeFile(manifestPath, template, 'utf8');
|
|
37
|
-
if (options.json === true) {
|
|
38
|
-
return {
|
|
39
|
-
exitCode: 0,
|
|
40
|
-
stdout: [(0, command_json_1.toJsonLine)('init', true, { targetDirectory: projectRoot, manifestPath }, [])],
|
|
41
|
-
stderr: [],
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
exitCode: 0,
|
|
46
|
-
stdout: [`Created manifest: ${manifestPath}`],
|
|
47
|
-
stderr: [],
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
52
|
-
if (options.json === true) {
|
|
53
|
-
return {
|
|
54
|
-
exitCode: 1,
|
|
55
|
-
stdout: [(0, command_json_1.toJsonLine)('init', false, { targetDirectory: projectRoot, manifestPath }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR, message)])],
|
|
56
|
-
stderr: [],
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
exitCode: 1,
|
|
61
|
-
stdout: [],
|
|
62
|
-
stderr: [message],
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,243 +0,0 @@
|
|
|
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.runUpgradeCommand = runUpgradeCommand;
|
|
7
|
-
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const diff_1 = require("diff");
|
|
10
|
-
const yaml_1 = __importDefault(require("yaml"));
|
|
11
|
-
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
12
|
-
const upgrade_warning_codes_1 = require("../constants/upgrade-warning-codes");
|
|
13
|
-
const source_destination_1 = require("../core/source-destination");
|
|
14
|
-
const fs_1 = require("../utils/fs");
|
|
15
|
-
const command_json_1 = require("../utils/command-json");
|
|
16
|
-
function renderDiff(beforeText, afterText) {
|
|
17
|
-
const lines = [];
|
|
18
|
-
for (const part of (0, diff_1.diffLines)(beforeText, afterText)) {
|
|
19
|
-
const prefix = part.added ? '+' : part.removed ? '-' : ' ';
|
|
20
|
-
for (const line of part.value.split('\n')) {
|
|
21
|
-
if (line.length === 0) {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
lines.push(`${prefix}${line}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return lines;
|
|
28
|
-
}
|
|
29
|
-
function countAddedDestinations(diffOutput) {
|
|
30
|
-
return diffOutput.filter((line) => line.startsWith('+') && line.includes('destination: ')).length;
|
|
31
|
-
}
|
|
32
|
-
function buildWarnings(changed, addedDestinationCount) {
|
|
33
|
-
if (!changed) {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
if (addedDestinationCount === 0) {
|
|
37
|
-
return [
|
|
38
|
-
{
|
|
39
|
-
code: upgrade_warning_codes_1.UPGRADE_WARNING_CODES.FORMAT_ONLY_CHANGE,
|
|
40
|
-
message: upgrade_warning_codes_1.UPGRADE_WARNING_MESSAGES[upgrade_warning_codes_1.UPGRADE_WARNING_CODES.FORMAT_ONLY_CHANGE],
|
|
41
|
-
},
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
function toUpgradeData(manifestPath, fromVersion, toVersion, changed, dryRun, diffOutput, sourceCount, templateCount, outputPath) {
|
|
47
|
-
const changedLineCount = diffOutput.filter((line) => line.startsWith('+') || line.startsWith('-')).length;
|
|
48
|
-
const addedDestinationCount = countAddedDestinations(diffOutput);
|
|
49
|
-
const warnings = buildWarnings(changed, addedDestinationCount);
|
|
50
|
-
return {
|
|
51
|
-
manifestPath,
|
|
52
|
-
outputPath,
|
|
53
|
-
fromVersion,
|
|
54
|
-
toVersion,
|
|
55
|
-
changed,
|
|
56
|
-
dryRun,
|
|
57
|
-
diff: diffOutput,
|
|
58
|
-
summary: {
|
|
59
|
-
addedDestinationCount,
|
|
60
|
-
changedLineCount,
|
|
61
|
-
sourceCount,
|
|
62
|
-
templateCount,
|
|
63
|
-
warningCount: warnings.length,
|
|
64
|
-
warnings,
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
function toTextLines(data, verbose) {
|
|
69
|
-
const lines = [
|
|
70
|
-
'Upgrade summary:',
|
|
71
|
-
`manifest: ${data.manifestPath}`,
|
|
72
|
-
`output: ${data.outputPath ?? data.manifestPath}`,
|
|
73
|
-
`version: ${data.fromVersion} -> ${data.toVersion}`,
|
|
74
|
-
`mode: ${data.dryRun ? 'dry-run' : 'write'}`,
|
|
75
|
-
`changed: ${data.changed ? 'yes' : 'no'}`,
|
|
76
|
-
`sources: ${data.summary.sourceCount}`,
|
|
77
|
-
`templates: ${data.summary.templateCount}`,
|
|
78
|
-
`changedLines: ${data.summary.changedLineCount}`,
|
|
79
|
-
`addedDestinations: ${data.summary.addedDestinationCount}`,
|
|
80
|
-
`warnings: ${data.summary.warningCount}`,
|
|
81
|
-
];
|
|
82
|
-
for (const warning of data.summary.warnings) {
|
|
83
|
-
lines.push(`warning.${warning.code}: ${warning.message}`);
|
|
84
|
-
}
|
|
85
|
-
if (verbose) {
|
|
86
|
-
lines.push('diff:');
|
|
87
|
-
if (data.diff.length === 0) {
|
|
88
|
-
lines.push('(no diff)');
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
lines.push(...data.diff);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return lines;
|
|
95
|
-
}
|
|
96
|
-
async function runUpgradeCommand(manifestPath, options = {}) {
|
|
97
|
-
const usage = 'Usage: agentdock upgrade <manifestPath> [--dry-run] [--json] [--verbose] [--write <path>] [--backup] [--force]';
|
|
98
|
-
if (!manifestPath) {
|
|
99
|
-
if (options.json === true) {
|
|
100
|
-
return {
|
|
101
|
-
exitCode: 1,
|
|
102
|
-
stdout: [(0, command_json_1.toJsonLine)('upgrade', false, {
|
|
103
|
-
manifestPath: '',
|
|
104
|
-
fromVersion: 0,
|
|
105
|
-
toVersion: 0,
|
|
106
|
-
changed: false,
|
|
107
|
-
dryRun: options.dryRun === true,
|
|
108
|
-
diff: [],
|
|
109
|
-
summary: {
|
|
110
|
-
addedDestinationCount: 0,
|
|
111
|
-
changedLineCount: 0,
|
|
112
|
-
sourceCount: 0,
|
|
113
|
-
templateCount: 0,
|
|
114
|
-
warningCount: 0,
|
|
115
|
-
warnings: [],
|
|
116
|
-
},
|
|
117
|
-
}, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.MISSING_ARGUMENT, usage)])],
|
|
118
|
-
stderr: [],
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
exitCode: 1,
|
|
123
|
-
stdout: [],
|
|
124
|
-
stderr: [usage],
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
const absolutePath = node_path_1.default.resolve(manifestPath);
|
|
129
|
-
const requestedOutputPath = options.writePath ? node_path_1.default.resolve(options.writePath) : undefined;
|
|
130
|
-
const raw = await promises_1.default.readFile(absolutePath, 'utf8');
|
|
131
|
-
const manifest = yaml_1.default.parse(raw);
|
|
132
|
-
const fromVersion = manifest.version;
|
|
133
|
-
if (manifest.version === 2 && options.force !== true) {
|
|
134
|
-
const data = toUpgradeData(absolutePath, 2, 2, false, options.dryRun === true, [], manifest.sources.length, manifest.templates?.length ?? 0, requestedOutputPath);
|
|
135
|
-
if (options.json === true) {
|
|
136
|
-
return {
|
|
137
|
-
exitCode: 0,
|
|
138
|
-
stdout: [(0, command_json_1.toJsonLine)('upgrade', true, data, [])],
|
|
139
|
-
stderr: [],
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
exitCode: 0,
|
|
144
|
-
stdout: toTextLines(data, options.verbose === true),
|
|
145
|
-
stderr: [],
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
if (manifest.version !== 1 && manifest.version !== 2) {
|
|
149
|
-
if (options.json === true) {
|
|
150
|
-
const data = toUpgradeData(absolutePath, fromVersion, 2, false, options.dryRun === true, [], manifest.sources?.length ?? 0, manifest.templates?.length ?? 0, requestedOutputPath);
|
|
151
|
-
return {
|
|
152
|
-
exitCode: 1,
|
|
153
|
-
stdout: [(0, command_json_1.toJsonLine)('upgrade', false, data, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.UNSUPPORTED_MANIFEST_VERSION, `Unsupported manifest version: ${manifest.version}`)])],
|
|
154
|
-
stderr: [],
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
exitCode: 1,
|
|
159
|
-
stdout: [],
|
|
160
|
-
stderr: [`Unsupported manifest version: ${manifest.version}`],
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
const upgraded = {
|
|
164
|
-
...manifest,
|
|
165
|
-
version: 2,
|
|
166
|
-
sources: manifest.sources.map((source) => ({
|
|
167
|
-
...source,
|
|
168
|
-
destination: (0, source_destination_1.resolveSourceDestination)(source),
|
|
169
|
-
})),
|
|
170
|
-
};
|
|
171
|
-
const output = yaml_1.default.stringify(upgraded);
|
|
172
|
-
const diffOutput = renderDiff(raw, output);
|
|
173
|
-
if (options.dryRun === true) {
|
|
174
|
-
const data = toUpgradeData(absolutePath, fromVersion, 2, diffOutput.length > 0, true, diffOutput, upgraded.sources.length, upgraded.templates?.length ?? 0, requestedOutputPath);
|
|
175
|
-
if (options.json === true) {
|
|
176
|
-
return {
|
|
177
|
-
exitCode: 0,
|
|
178
|
-
stdout: [(0, command_json_1.toJsonLine)('upgrade', true, data, [])],
|
|
179
|
-
stderr: [],
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
return {
|
|
183
|
-
exitCode: 0,
|
|
184
|
-
stdout: toTextLines(data, options.verbose === true),
|
|
185
|
-
stderr: [],
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
const outputPath = requestedOutputPath ?? absolutePath;
|
|
189
|
-
if (options.backup === true && outputPath === absolutePath) {
|
|
190
|
-
const timestamp = new Date().toISOString().replace(/[-:.TZ]/g, '');
|
|
191
|
-
const backupPath = `${absolutePath}.bak.${timestamp}`;
|
|
192
|
-
await promises_1.default.copyFile(absolutePath, backupPath);
|
|
193
|
-
}
|
|
194
|
-
await promises_1.default.mkdir(node_path_1.default.dirname(outputPath), { recursive: true });
|
|
195
|
-
await (0, fs_1.writeTextFile)(outputPath, output);
|
|
196
|
-
const data = toUpgradeData(absolutePath, fromVersion, 2, diffOutput.length > 0, false, diffOutput, upgraded.sources.length, upgraded.templates?.length ?? 0, outputPath);
|
|
197
|
-
if (options.json === true) {
|
|
198
|
-
return {
|
|
199
|
-
exitCode: 0,
|
|
200
|
-
stdout: [(0, command_json_1.toJsonLine)('upgrade', true, data, [])],
|
|
201
|
-
stderr: [],
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
return {
|
|
205
|
-
exitCode: 0,
|
|
206
|
-
stdout: toTextLines(data, options.verbose === true),
|
|
207
|
-
stderr: [],
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
212
|
-
if (options.json === true) {
|
|
213
|
-
const code = message.includes('ENOENT')
|
|
214
|
-
? command_error_codes_1.COMMAND_ERROR_CODES.MANIFEST_NOT_FOUND
|
|
215
|
-
: command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR;
|
|
216
|
-
return {
|
|
217
|
-
exitCode: 1,
|
|
218
|
-
stdout: [(0, command_json_1.toJsonLine)('upgrade', false, {
|
|
219
|
-
manifestPath: node_path_1.default.resolve(manifestPath),
|
|
220
|
-
fromVersion: 0,
|
|
221
|
-
toVersion: 2,
|
|
222
|
-
changed: false,
|
|
223
|
-
dryRun: options.dryRun === true,
|
|
224
|
-
diff: [],
|
|
225
|
-
summary: {
|
|
226
|
-
addedDestinationCount: 0,
|
|
227
|
-
changedLineCount: 0,
|
|
228
|
-
sourceCount: 0,
|
|
229
|
-
templateCount: 0,
|
|
230
|
-
warningCount: 0,
|
|
231
|
-
warnings: [],
|
|
232
|
-
},
|
|
233
|
-
}, [(0, command_json_1.toJsonError)(code, message)])],
|
|
234
|
-
stderr: [],
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
return {
|
|
238
|
-
exitCode: 1,
|
|
239
|
-
stdout: [],
|
|
240
|
-
stderr: [message],
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UPGRADE_WARNING_MESSAGES = exports.UPGRADE_WARNING_CODES = void 0;
|
|
4
|
-
exports.UPGRADE_WARNING_CODES = {
|
|
5
|
-
FORMAT_ONLY_CHANGE: 'FORMAT_ONLY_CHANGE',
|
|
6
|
-
};
|
|
7
|
-
exports.UPGRADE_WARNING_MESSAGES = {
|
|
8
|
-
[exports.UPGRADE_WARNING_CODES.FORMAT_ONLY_CHANGE]: 'Upgrade only changed formatting or normalization, no new destinations were introduced.',
|
|
9
|
-
};
|