@intra-mart/accel 0.3.1 → 0.4.0-dev.202607140628

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +55 -12
  2. package/dist/asset/asset-tree.d.ts +5 -0
  3. package/dist/asset/asset-tree.js +7 -0
  4. package/dist/asset/deployer.d.ts +2 -1
  5. package/dist/asset/deployer.js +32 -59
  6. package/dist/asset/file-provider.js +19 -18
  7. package/dist/asset/git-provider.d.ts +14 -0
  8. package/dist/asset/git-provider.js +198 -0
  9. package/dist/asset/installer.d.ts +6 -0
  10. package/dist/asset/installer.js +31 -0
  11. package/dist/asset/renderer.d.ts +2 -0
  12. package/dist/asset/renderer.js +22 -0
  13. package/dist/asset/types.d.ts +1 -1
  14. package/dist/asset/updater.d.ts +52 -0
  15. package/dist/asset/updater.js +301 -0
  16. package/dist/asset/walker.d.ts +3 -2
  17. package/dist/asset/walker.js +67 -45
  18. package/dist/commands/asset-provider.d.ts +7 -0
  19. package/dist/commands/asset-provider.js +9 -0
  20. package/dist/commands/attach.d.ts +0 -4
  21. package/dist/commands/attach.js +11 -20
  22. package/dist/commands/deploy.d.ts +11 -6
  23. package/dist/commands/deploy.js +77 -23
  24. package/dist/commands/init.d.ts +0 -4
  25. package/dist/commands/init.js +11 -20
  26. package/dist/commands/update.d.ts +86 -0
  27. package/dist/commands/update.js +438 -0
  28. package/dist/core/constants.d.ts +3 -3
  29. package/dist/core/constants.js +4 -2
  30. package/dist/core/types.d.ts +11 -0
  31. package/dist/deploy/api-client.d.ts +6 -2
  32. package/dist/deploy/api-client.js +8 -4
  33. package/dist/deploy/deploy-files.d.ts +20 -0
  34. package/dist/deploy/deploy-files.js +37 -0
  35. package/dist/git/errors.d.ts +6 -0
  36. package/dist/git/errors.js +9 -0
  37. package/dist/git/http.d.ts +3 -0
  38. package/dist/git/http.js +58 -0
  39. package/dist/git/object-store.d.ts +13 -0
  40. package/dist/git/object-store.js +79 -0
  41. package/dist/git/pkt-line.d.ts +13 -0
  42. package/dist/git/pkt-line.js +41 -0
  43. package/dist/git/smart-http.d.ts +18 -0
  44. package/dist/git/smart-http.js +109 -0
  45. package/dist/i18n/en.js +49 -6
  46. package/dist/i18n/ja.js +49 -6
  47. package/dist/i18n/zh_CN.js +49 -6
  48. package/dist/index.js +4 -1
  49. package/dist/interactive/progress.js +1 -0
  50. package/dist/interactive/prompts.d.ts +7 -1
  51. package/dist/interactive/prompts.js +63 -64
  52. package/dist/markdown/section-replacement.js +34 -8
  53. package/dist/utils/args.d.ts +1 -0
  54. package/dist/utils/args.js +4 -0
  55. package/dist/utils/fs-list.d.ts +1 -0
  56. package/dist/utils/fs-list.js +11 -0
  57. package/dist/utils/merge-file.d.ts +6 -0
  58. package/dist/utils/merge-file.js +20 -0
  59. package/package.json +6 -8
  60. package/dist/asset/github-provider.d.ts +0 -2
  61. package/dist/asset/github-provider.js +0 -37
  62. package/dist/asset/local-provider.d.ts +0 -2
  63. package/dist/asset/local-provider.js +0 -24
  64. package/dist/utils/archive.d.ts +0 -3
  65. package/dist/utils/archive.js +0 -20
  66. package/dist/utils/https.d.ts +0 -2
  67. package/dist/utils/https.js +0 -44
@@ -6,7 +6,7 @@ export const messages = {
6
6
  "prompt.artifactId": "请输入构件ID(Maven artifactId)",
7
7
  "prompt.artifactId.hint": "作为 Maven artifactId 写入 pom.xml(构件的标识符)\n构成成品 (jar/war 等) 文件名和 Maven 坐标的标识符。默认与项目名称相同;如需使用其他标识符请修改",
8
8
  "prompt.jugglingProject": "请输入IM-Juggling项目路径(可选)",
9
- "prompt.jugglingProject.hint": "若指定,则从 juggling.im 自动检测 iAP 版本和模块\n指定要联动的已有 IM-Juggling 项目目录路径;不需要时留空(例如: ../customer-portal-juggling)",
9
+ "prompt.jugglingProject.hint": "若指定,则从 juggling.im 自动检测 iAP 版本和模块\n指定要联动的已有 IM-Juggling 项目目录路径(例如: ../customer-portal-juggling)\n留空确认则不联动(在 update 中会解除已记录的联动)",
10
10
  "prompt.accelplatformVersion": "请选择iAP版本",
11
11
  "prompt.accelplatformVersion.hint": "iAP 本体的发行版。部署的资源(CLAUDE.md 等)会根据该版本变化",
12
12
  "prompt.modules": "请选择要使用的模块",
@@ -27,8 +27,9 @@ export const messages = {
27
27
  "prompt.agent.hint": "claude-code 部署到 .claude/ 下,codex 部署到 .codex/ 下,github-copilot 部署到 .github/ 下(指令书、skills 等)",
28
28
  "prompt.withGit": "是否初始化Git仓库?",
29
29
  "prompt.withGit.hint": "在创建的项目目录中执行 git init",
30
+ "prompt.useExistingSettings": "是否使用现有设置?",
31
+ "prompt.useExistingSettings.hint": "Yes: 跳过各项设置的重新输入,按当前设置更新资材 / No: 重新输入各项设置",
30
32
  "juggling.detected.version": "从juggling.im检测到版本: {version}",
31
- "juggling.detected.modules": "从juggling.im检测到模块: {modules}",
32
33
  "juggling.notFound": "在指定路径未找到juggling.im: {path}",
33
34
  "juggling.versionUnknown": "juggling.im 的版本 {version} 不存在于目录中。请手动选择版本和模块。",
34
35
  "warning.versionMismatch": "指定的iAP版本 ({option}) 与juggling.im ({juggling}) 不同。将使用指定值。",
@@ -49,6 +50,41 @@ export const messages = {
49
50
  "detach.complete": "解除完成。{skipped}个文件因用户修改而被跳过。",
50
51
  "detach.completeAll": "解除完成。所有资源已删除。",
51
52
  "detach.cancelled": "解除已取消。",
53
+ "intro.update": "将已部署的资源更新到资源仓库的最新版本。\n您编辑过的文件内容将被保留。\n确认设置后应用差异。",
54
+ "update.error.legacyProject": "此项目由不支持 update 的CLI版本创建。",
55
+ "update.error.notGitSource": "仅可更新从git源部署的项目(此项目从本地目录部署)。",
56
+ "update.error.baseFetch": "无法获取更新基准提交 {commit}(历史可能已被改写): {message}",
57
+ "update.warning.dirty": "项目存在未提交的更改。建议在 update 前先提交。",
58
+ "update.confirmDirty": "存在未提交的更改,是否继续?",
59
+ "update.invalidSettings": "现有设置中存在无效的值,请重新输入各项设置:\n{errors}",
60
+ "update.confirmApply": "以此设置更新项目,确定吗?",
61
+ "update.cancelled": "已取消update。",
62
+ "update.progress.range": "正在更新资源... ({from} → {to})",
63
+ "update.result.updated": "更新: {path}",
64
+ "update.result.merged": "更新: {path}(已与您的编辑合并)",
65
+ "update.result.kept": "保留: {path}(您已编辑,上游无变更)",
66
+ "update.result.keptDeleted": "保留: {path}(您已删除)",
67
+ "update.result.deleted": "删除: {path}(不再部署)",
68
+ "update.result.redeployed": "重新部署: {path}",
69
+ "update.result.added": "新增: {path}",
70
+ "update.result.adopted": "纳入管理: {path}(与现有文件内容一致)",
71
+ "update.result.conflict": "冲突: {path}",
72
+ "update.result.keptWarn": "保留: {path}(上游已不再部署,但因您已编辑而保留)",
73
+ "update.upToDate": "已是最新状态,无需更新。",
74
+ "update.complete": "update完成。更新{updated}个、保留{kept}个、删除{deleted}个文件。",
75
+ "update.conflictSummary": "发现{count}个冲突。请检查标记(<<<<<<<)并手动解决:",
76
+ "update.error.keepEditedWithoutAllow": "--keep-edited 仅可与 --allow-missing-base 一起使用。",
77
+ "update.error.baseFetchHint": "要以回退模式继续,请指定 --allow-missing-base(同时指定 --keep-edited 可保留并跳过已编辑的文件)。如果资源仓库已迁移,可通过 --asset-server-url / --asset-ref 更改获取源。作为最后手段,可执行 accel detach 后重新 init。",
78
+ "update.fallback.editedCount": "在没有基准提交(base)的情况下继续时,无法判定已编辑文件的上游变更。与上游存在差异的已编辑文件: {count}个",
79
+ "update.fallback.choice": "要如何继续?",
80
+ "update.fallback.choice.abort": "中止",
81
+ "update.fallback.choice.conflict": "以回退模式继续(在已编辑的文件中插入冲突标记)",
82
+ "update.fallback.choice.keep": "以回退模式继续(保留并跳过已编辑的文件)",
83
+ "update.fallback.continuing": "将在没有基准提交的回退模式下继续(仅通过 hashsum 的编辑检测进行分类)。",
84
+ "update.fallback.aborted": "update已中止。",
85
+ "update.result.redeployedWarn": "重新部署: {path}(您已删除该文件,但由于缺少基准提交无法判定上游变更)",
86
+ "update.result.skippedEdited": "保留: {path}(已编辑,跳过且未应用上游变更)",
87
+ "update.fallback.skippedSummary": "已跳过{count}个已编辑的文件,未应用上游变更:",
52
88
  "error.directoryExists": "目录已存在: {path}",
53
89
  "error.accelExists": ".accel目录已存在",
54
90
  "error.accelNotFound": "未找到.accel目录",
@@ -64,6 +100,9 @@ export const messages = {
64
100
  "error.invalidArtifactId": "构件ID违反Maven命名规则(^[A-Za-z0-9][A-Za-z0-9._-]*$): {value}",
65
101
  "error.invalidGroup": "组名违反Maven groupId命名规则(点分隔的Java标识符): {value}",
66
102
  "error.invalidProjectVersion": "项目版本违反Maven version命名规则(^[A-Za-z0-9][A-Za-z0-9._-]*$): {value}",
103
+ "error.gitAuthHint": "仓库要求身份验证(HTTP 401/403)。不支持需要身份验证的私有仓库,请指定公开仓库的 URL。",
104
+ "error.gitServerUnsupported": "该服务器不支持获取资源所需的 git 功能(smart HTTP protocol v2 / filter)。请使用 GitHub / GitLab / Gitea 等主流 git 托管服务。",
105
+ "error.gitUrlUnsupported": "资源仓库 URL 仅支持 HTTP(S)(不支持 SSH / file://): {url}",
67
106
  "summary.heading": "部署设置",
68
107
  "summary.label.name": "项目名称",
69
108
  "summary.label.artifactId": "构件ID",
@@ -82,6 +121,7 @@ export const messages = {
82
121
  "summary.outputDir": "输出目录",
83
122
  "summary.empty": "(无)",
84
123
  "progress.fetching": "正在获取资源仓库...",
124
+ "progress.downloading": "正在下载资源...",
85
125
  "progress.deploying.section": "正在部署 {section} 下 ({files})",
86
126
  "progress.deploying.root": "正在部署根目录文件 ({files})",
87
127
  "progress.installing": "正在执行 {command}...",
@@ -116,8 +156,10 @@ export const messages = {
116
156
  "deploy.confirm": "将按以下内容部署。是否继续?",
117
157
  "deploy.confirm.endpoint": "端点",
118
158
  "deploy.confirm.stagingId": "暂存环境",
119
- "deploy.confirm.sourceFile": "目标文件",
120
- "deploy.confirm.sentAs": "发送文件名",
159
+ "deploy.confirm.files": "要部署的文件(按发送顺序)",
160
+ "deploy.order.heading": "部署顺序",
161
+ "deploy.order.confirm": "是否按此顺序部署?",
162
+ "deploy.order.selectNext": "请选择第 {position} 个(共 {total} 个)要部署的文件",
121
163
  "deploy.result.deployId": "部署ID",
122
164
  "deploy.result.stagingId": "暂存环境",
123
165
  "deploy.result.status": "状态",
@@ -129,6 +171,9 @@ export const messages = {
129
171
  "deploy.error.missingStagingId": "非交互模式下必须指定 --staging-id。请指定目标暂存环境 ID。",
130
172
  "deploy.error.zipNotResolved": "无法唯一确定要部署的 zip。请使用 --file 明确指定要部署的文件。",
131
173
  "deploy.error.fileNotFound": "未找到指定的文件:{path}",
174
+ "deploy.error.additionalFileNotFound": "未找到指定的附加文件:{path}",
175
+ "deploy.error.additionalFileInvalidExtension": "附加文件仅支持 .imm / .zip:{path}",
176
+ "deploy.error.additionalFileDuplicate": "同一文件被重复指定:{path}",
132
177
  "deploy.error.network": "无法连接到 iAP: {message}",
133
178
  "deploy.error.server": "iAP 返回了错误: {message}",
134
179
  "deploy.error.unauthorized": "认证失败(401)。请确认 API 密钥是否正确。",
@@ -137,8 +182,6 @@ export const messages = {
137
182
  "deploy.error.badRequest": "请求无效(400)。",
138
183
  "deploy.error.serverError": "发生服务器错误(500)。",
139
184
  "deploy.error.unexpectedResponse": "收到意外的响应(HTTP {status})。",
140
- "deploy.reauth.notFound": "无法访问指定的端点(404)。请确认端点 URL 是否正确。",
141
- "deploy.reauth.notice": "请重新输入连接信息。",
142
185
  "deploy.result.shortcutUrl": "快捷链接",
143
186
  "deploy.setup.heading": "租户环境配置设置",
144
187
  "deploy.setup.confirm": "是否执行租户环境配置?",
package/dist/index.js CHANGED
@@ -3,18 +3,21 @@ import { defineCommand, runMain } from "citty";
3
3
  import { initCommand } from "./commands/init.js";
4
4
  import { attachCommand } from "./commands/attach.js";
5
5
  import { detachCommand } from "./commands/detach.js";
6
+ import { updateCommand } from "./commands/update.js";
6
7
  import { loginCommand } from "./commands/login.js";
7
8
  import { deployCommand } from "./commands/deploy.js";
9
+ import { CLI_VERSION } from "./core/constants.js";
8
10
  const main = defineCommand({
9
11
  meta: {
10
12
  name: "accel",
11
- version: "0.1.0",
13
+ version: CLI_VERSION,
12
14
  description: "CLI tool for intra-mart Accel Platform development",
13
15
  },
14
16
  subCommands: {
15
17
  init: initCommand,
16
18
  attach: attachCommand,
17
19
  detach: detachCommand,
20
+ update: updateCommand,
18
21
  login: loginCommand,
19
22
  deploy: deployCommand,
20
23
  },
@@ -9,6 +9,7 @@ const formatFileList = (files) => {
9
9
  };
10
10
  export const buildProgressCallbacks = (locale) => ({
11
11
  onFetchStart: () => p.log.info(getMessage("progress.fetching", locale)),
12
+ onDownloadStart: () => p.log.info(getMessage("progress.downloading", locale)),
12
13
  onSectionDeploy: (section, files) => {
13
14
  const filesStr = formatFileList(files);
14
15
  const key = section === ROOT_SECTION
@@ -19,11 +19,17 @@ export type PromptOptions = {
19
19
  withGit?: boolean;
20
20
  noInteraction?: boolean;
21
21
  isInit: boolean;
22
+ mode?: "init" | "attach" | "update";
23
+ skipIntro?: boolean;
24
+ skipValidation?: boolean;
22
25
  };
23
- export type ResolvedOptions = Omit<AccelSettings, "cliVersion" | "createdAt" | "deployedAssets"> & {
26
+ export type ResolvedOptions = Omit<AccelSettings, "cliVersion" | "createdAt" | "deployedAssets" | "assetSource" | "jugglingProject"> & {
24
27
  withGit: boolean;
28
+ jugglingProject: string | null | undefined;
25
29
  };
26
30
  export declare const validateNonInteractive: (opts: PromptOptions) => string[];
27
31
  export declare const validateCliValues: (opts: PromptOptions, validators: Validators) => void;
28
32
  export declare const validateCatalogValues: (opts: PromptOptions, release: Release, locale: string) => void;
33
+ export declare const collectSettingsErrors: (opts: PromptOptions, locale: string, releaseIdFallback?: string) => string[];
34
+ export declare const printIntro: (mode: "init" | "attach" | "update", locale: string) => void;
29
35
  export declare const runPrompts: (opts: PromptOptions) => Promise<ResolvedOptions>;
@@ -31,71 +31,68 @@ export const validateNonInteractive = (opts) => {
31
31
  }
32
32
  return missing;
33
33
  };
34
- export const validateCliValues = (opts, validators) => {
35
- if (opts.name !== undefined) {
36
- const err = validators.name(opts.name);
37
- if (err)
38
- throw new Error(err);
39
- }
40
- if (opts.artifactId !== undefined) {
41
- const err = validators.artifactId(opts.artifactId);
42
- if (err)
43
- throw new Error(err);
44
- }
45
- if (opts.group !== undefined) {
46
- const err = validators.group(opts.group);
47
- if (err)
48
- throw new Error(err);
49
- }
50
- if (opts.projectVersion !== undefined) {
51
- const err = validators.projectVersion(opts.projectVersion);
34
+ const collectFormatErrors = (opts, validators) => {
35
+ const errors = [];
36
+ const check = (validator, value) => {
37
+ if (value === undefined)
38
+ return;
39
+ const err = validator(value);
52
40
  if (err)
53
- throw new Error(err);
54
- }
55
- if (opts.accelplatformVersion !== undefined) {
56
- const err = validators.accelplatformVersion(opts.accelplatformVersion);
57
- if (err)
58
- throw new Error(err);
59
- }
60
- if (opts.database !== undefined) {
61
- const err = validators.database(opts.database);
62
- if (err)
63
- throw new Error(err);
64
- }
65
- if (opts.agent !== undefined) {
66
- for (const a of opts.agent) {
67
- const err = validators.agent(a);
68
- if (err)
69
- throw new Error(err);
70
- }
71
- }
72
- if (opts.packageManager !== undefined) {
73
- const err = validators.packageManager(opts.packageManager);
41
+ errors.push(err);
42
+ };
43
+ check(validators.name, opts.name);
44
+ check(validators.artifactId, opts.artifactId);
45
+ check(validators.group, opts.group);
46
+ check(validators.projectVersion, opts.projectVersion);
47
+ check(validators.accelplatformVersion, opts.accelplatformVersion);
48
+ check(validators.database, opts.database);
49
+ for (const a of opts.agent ?? [])
50
+ check(validators.agent, a);
51
+ check(validators.packageManager, opts.packageManager);
52
+ return errors;
53
+ };
54
+ const collectCatalogErrors = (opts, release, locale) => {
55
+ const releaseValidators = createReleaseValidators(locale, release);
56
+ const errors = [];
57
+ const check = (validator, value) => {
58
+ const err = validator(value);
74
59
  if (err)
75
- throw new Error(err);
76
- }
60
+ errors.push(err);
61
+ };
62
+ for (const m of opts.module ?? [])
63
+ check(releaseValidators.module, m);
64
+ for (const f of opts.feature ?? [])
65
+ check(releaseValidators.feature, f);
66
+ return errors;
67
+ };
68
+ export const validateCliValues = (opts, validators) => {
69
+ const [first] = collectFormatErrors(opts, validators);
70
+ if (first)
71
+ throw new Error(first);
77
72
  };
78
73
  export const validateCatalogValues = (opts, release, locale) => {
79
- const releaseValidators = createReleaseValidators(locale, release);
80
- if (opts.module !== undefined) {
81
- for (const m of opts.module) {
82
- const err = releaseValidators.module(m);
83
- if (err)
84
- throw new Error(err);
85
- }
86
- }
87
- if (opts.feature !== undefined) {
88
- for (const f of opts.feature) {
89
- const err = releaseValidators.feature(f);
90
- if (err)
91
- throw new Error(err);
92
- }
74
+ const [first] = collectCatalogErrors(opts, release, locale);
75
+ if (first)
76
+ throw new Error(first);
77
+ };
78
+ export const collectSettingsErrors = (opts, locale, releaseIdFallback) => {
79
+ const errors = collectFormatErrors(opts, createValidators(locale));
80
+ const releaseId = opts.accelplatformVersion ?? releaseIdFallback;
81
+ const release = releaseId ? findReleaseById(releaseId) : undefined;
82
+ if (release) {
83
+ errors.push(...collectCatalogErrors(opts, release, locale));
93
84
  }
85
+ return errors;
86
+ };
87
+ export const printIntro = (mode, locale) => {
88
+ p.intro("Accel CLI");
89
+ p.note(getMessage(`intro.${mode}`, locale));
94
90
  };
95
91
  export const runPrompts = async (opts) => {
96
92
  const locale = opts.locale;
97
93
  const validators = createValidators(locale);
98
- validateCliValues(opts, validators);
94
+ if (!opts.skipValidation)
95
+ validateCliValues(opts, validators);
99
96
  if (opts.noInteraction) {
100
97
  const missing = validateNonInteractive(opts);
101
98
  if (missing.length > 0) {
@@ -125,7 +122,7 @@ export const runPrompts = async (opts) => {
125
122
  }
126
123
  validateCatalogValues(opts, release, locale);
127
124
  const releaseArtifactIds = release.modules.map((m) => m.artifactId);
128
- const modules = opts.module && opts.module.length > 0
125
+ const modules = opts.module && (opts.module.length > 0 || opts.mode === "update")
129
126
  ? opts.module
130
127
  : opts.jugglingProject
131
128
  ? jugglingModules.filter((m) => releaseArtifactIds.includes(m))
@@ -144,12 +141,13 @@ export const runPrompts = async (opts) => {
144
141
  javascript: opts.javascript ?? DEFAULT_SETTINGS.javascript,
145
142
  locale,
146
143
  packageManager: opts.packageManager ?? DEFAULT_SETTINGS.packageManager,
147
- jugglingProject: opts.jugglingProject ?? null,
144
+ jugglingProject: opts.jugglingProject === "" ? null : opts.jugglingProject,
148
145
  withGit: opts.withGit ?? true,
149
146
  };
150
147
  }
151
- p.intro("Accel CLI");
152
- p.note(getMessage(opts.isInit ? "intro.init" : "intro.attach", locale));
148
+ const mode = opts.mode ?? (opts.isInit ? "init" : "attach");
149
+ if (!opts.skipIntro)
150
+ printIntro(mode, locale);
153
151
  const name = (await p.text({
154
152
  message: withHint("prompt.name", locale),
155
153
  defaultValue: opts.name ?? DEFAULT_SETTINGS.name,
@@ -169,7 +167,6 @@ export const runPrompts = async (opts) => {
169
167
  process.exit(0);
170
168
  const jugglingInput = (await p.text({
171
169
  message: withHint("prompt.jugglingProject", locale),
172
- defaultValue: opts.jugglingProject ?? "",
173
170
  initialValue: opts.jugglingProject ?? "",
174
171
  }));
175
172
  if (p.isCancel(jugglingInput))
@@ -224,7 +221,8 @@ export const runPrompts = async (opts) => {
224
221
  version: accelplatformVersionId,
225
222
  }));
226
223
  }
227
- validateCatalogValues(opts, release, locale);
224
+ if (!opts.skipValidation)
225
+ validateCatalogValues(opts, release, locale);
228
226
  const releaseArtifactIds = release.modules.map((m) => m.artifactId);
229
227
  const moduleDefault = opts.module && opts.module.length > 0
230
228
  ? opts.module.filter((m) => releaseArtifactIds.includes(m))
@@ -254,13 +252,14 @@ export const runPrompts = async (opts) => {
254
252
  features = [];
255
253
  }
256
254
  else {
255
+ const featureIds = release.functions.map((f) => f.id);
257
256
  const selected = (await p.multiselect({
258
257
  message: withHint("prompt.features", locale),
259
258
  options: release.functions.map((f) => ({
260
259
  value: f.id,
261
260
  label: resolveLabel(f.labels, locale),
262
261
  })),
263
- initialValues: opts.feature ?? release.functions.map((f) => f.id),
262
+ initialValues: opts.feature?.filter((f) => featureIds.includes(f)) ?? featureIds,
264
263
  required: true,
265
264
  }));
266
265
  if (p.isCancel(selected))
@@ -305,7 +304,7 @@ export const runPrompts = async (opts) => {
305
304
  process.exit(0);
306
305
  const detected = detectAgents();
307
306
  const agentOptions = AGENT_OPTIONS.map((a) => ({ value: a, label: a }));
308
- const defaultAgents = opts.agent ??
307
+ const defaultAgents = opts.agent?.filter((a) => AGENT_OPTIONS.includes(a)) ??
309
308
  (detected.length > 0
310
309
  ? detected.map((a) => a.name)
311
310
  : [...AGENT_OPTIONS]);
@@ -1,6 +1,5 @@
1
1
  import { unified } from "unified";
2
2
  import remarkParse from "remark-parse";
3
- import remarkStringify from "remark-stringify";
4
3
  import { evaluateCondition } from "../core/condition-evaluator.js";
5
4
  const findSectionRange = (tree, heading) => {
6
5
  let startIdx = -1;
@@ -43,21 +42,48 @@ const extractHeadingText = (node) => {
43
42
  })
44
43
  .join("");
45
44
  };
45
+ const toOffsetRange = (tree, content, range) => {
46
+ const from = tree.children[range.start]?.position?.start.offset;
47
+ const to = range.end < tree.children.length
48
+ ? tree.children[range.end]?.position?.start.offset
49
+ : content.length;
50
+ if (from === undefined || to === undefined)
51
+ return null;
52
+ return { from, to };
53
+ };
54
+ const mergeRanges = (ranges) => {
55
+ const sorted = [...ranges].sort((a, b) => a.from - b.from);
56
+ const merged = [];
57
+ for (const range of sorted) {
58
+ const last = merged[merged.length - 1];
59
+ if (last && range.from <= last.to) {
60
+ last.to = Math.max(last.to, range.to);
61
+ }
62
+ else {
63
+ merged.push({ ...range });
64
+ }
65
+ }
66
+ return merged;
67
+ };
46
68
  export const applySectionReplacements = (content, replacements, context) => {
47
- const processor = unified().use(remarkParse).use(remarkStringify);
48
- const tree = processor.parse(content);
69
+ const tree = unified().use(remarkParse).parse(content);
49
70
  const removals = [];
50
71
  for (const replacement of replacements) {
51
72
  if (!evaluateCondition(replacement.condition, context)) {
52
73
  const range = findSectionRange(tree, replacement.heading);
53
74
  if (range) {
54
- removals.push(range);
75
+ const offsets = toOffsetRange(tree, content, range);
76
+ if (offsets) {
77
+ removals.push(offsets);
78
+ }
55
79
  }
56
80
  }
57
81
  }
58
- removals.sort((a, b) => b.start - a.start);
59
- for (const { start, end } of removals) {
60
- tree.children.splice(start, end - start);
82
+ if (removals.length === 0)
83
+ return content;
84
+ let result = content;
85
+ for (const { from, to } of mergeRanges(removals).reverse()) {
86
+ result = result.slice(0, from) + result.slice(to);
61
87
  }
62
- return processor.stringify(tree);
88
+ return result;
63
89
  };
@@ -1 +1,2 @@
1
1
  export declare const lastFlagValue: (v: unknown) => string | undefined;
2
+ export declare const allFlagValues: (v: unknown) => string[];
@@ -2,3 +2,7 @@ export const lastFlagValue = (v) => {
2
2
  const x = Array.isArray(v) ? v[v.length - 1] : v;
3
3
  return typeof x === "string" ? x : undefined;
4
4
  };
5
+ export const allFlagValues = (v) => {
6
+ const arr = Array.isArray(v) ? v : [v];
7
+ return arr.filter((x) => typeof x === "string");
8
+ };
@@ -0,0 +1 @@
1
+ export declare const listFilesUnder: (dir: string) => Promise<string[]>;
@@ -0,0 +1,11 @@
1
+ import { readdir } from "node:fs/promises";
2
+ import { join, relative, sep } from "node:path";
3
+ export const listFilesUnder = async (dir) => {
4
+ const entries = await readdir(dir, {
5
+ recursive: true,
6
+ withFileTypes: true,
7
+ });
8
+ return entries
9
+ .filter((entry) => entry.isFile())
10
+ .map((entry) => relative(dir, join(entry.parentPath, entry.name)).split(sep).join("/"));
11
+ };
@@ -0,0 +1,6 @@
1
+ export type MergeResult = {
2
+ content: string;
3
+ conflicted: boolean;
4
+ };
5
+ export type MergeFn = (base: string, ours: string, theirs: string) => Promise<MergeResult>;
6
+ export declare const mergeFile: MergeFn;
@@ -0,0 +1,20 @@
1
+ import { diff3Merge } from "node-diff3";
2
+ export const mergeFile = async (base, ours, theirs) => {
3
+ const regions = diff3Merge(ours.split("\n"), base.split("\n"), theirs.split("\n"), {
4
+ excludeFalseConflicts: true,
5
+ stringSeparator: "\n",
6
+ });
7
+ let conflicted = false;
8
+ const lines = [];
9
+ for (const region of regions) {
10
+ if (region.ok) {
11
+ lines.push(...region.ok);
12
+ continue;
13
+ }
14
+ if (region.conflict) {
15
+ conflicted = true;
16
+ lines.push("<<<<<<< ours", ...region.conflict.a, "=======", ...region.conflict.b, ">>>>>>> theirs");
17
+ }
18
+ }
19
+ return { content: lines.join("\n"), conflicted };
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intra-mart/accel",
3
- "version": "0.3.1",
3
+ "version": "0.4.0-dev.202607140628",
4
4
  "type": "module",
5
5
  "description": "CLI tool for intra-mart Accel Platform development",
6
6
  "author": "NTT DATA INTRAMART",
@@ -34,22 +34,20 @@
34
34
  "test:unit": "vitest run tests/unit",
35
35
  "test:e2e": "vitest run tests/e2e",
36
36
  "test:watch": "vitest",
37
- "typecheck": "tsc --noEmit",
38
- "prepublishOnly": "tsc"
37
+ "typecheck": "tsc --noEmit"
39
38
  },
40
39
  "dependencies": {
41
40
  "@clack/prompts": "^1.4.0",
42
41
  "@intra-mart/catalog": "0.1.0-dev.202606250213",
43
42
  "citty": "^0.1.6",
44
43
  "fast-xml-parser": "^5.2.0",
45
- "remark": "^15.0.1",
44
+ "isomorphic-git": "^1.38.6",
45
+ "node-diff3": "^3.2.1",
46
46
  "remark-parse": "^11.0.0",
47
- "remark-stringify": "^11.0.0",
48
47
  "semver": "^7.7.1",
49
48
  "smol-toml": "^1.6.1",
50
- "tar": "^7.4.3",
51
- "unified": "^11.0.5",
52
- "unist-util-visit": "^5.0.0"
49
+ "undici": "^8.5.0",
50
+ "unified": "^11.0.5"
53
51
  },
54
52
  "devDependencies": {
55
53
  "@types/node": "^24",
@@ -1,2 +0,0 @@
1
- import type { AssetProvider } from "../core/types.js";
2
- export declare const createGitHubAssetProvider: (repoUrl: string, ref: string) => AssetProvider;
@@ -1,37 +0,0 @@
1
- import { join } from "node:path";
2
- import { mkdir, rm, readdir } from "node:fs/promises";
3
- import { extractTarGz, createTempDir } from "../utils/archive.js";
4
- import { downloadFile } from "../utils/https.js";
5
- export const createGitHubAssetProvider = (repoUrl, ref) => {
6
- let tmpDir = null;
7
- return {
8
- fetch: async () => {
9
- tmpDir = await createTempDir("accel-assets-");
10
- const archivePath = join(tmpDir, "assets.tar.gz");
11
- const extractDir = join(tmpDir, "repo");
12
- await mkdir(extractDir, { recursive: true });
13
- const base = repoUrl.replace(/\/+$/, "");
14
- const archiveUrl = `${base}/archive/${ref}.tar.gz`;
15
- try {
16
- await downloadFile(archiveUrl, archivePath);
17
- }
18
- catch (err) {
19
- const reason = err instanceof Error ? err.message : String(err);
20
- throw new Error(`Failed to fetch the asset repository from ${archiveUrl}. Check the URL and ref: ${reason}`);
21
- }
22
- await extractTarGz(archivePath, extractDir);
23
- const entries = await readdir(extractDir, { withFileTypes: true });
24
- const dirs = entries.filter((e) => e.isDirectory());
25
- if (dirs.length !== 1) {
26
- throw new Error(`Unexpected tarball structure (top-level directory count: ${dirs.length}).`);
27
- }
28
- return join(extractDir, dirs[0].name);
29
- },
30
- cleanup: async () => {
31
- if (tmpDir) {
32
- await rm(tmpDir, { recursive: true, force: true }).catch(() => { });
33
- tmpDir = null;
34
- }
35
- },
36
- };
37
- };
@@ -1,2 +0,0 @@
1
- import type { AssetProvider } from "../core/types.js";
2
- export declare const createLocalAssetProvider: (serverUrl: string) => AssetProvider;
@@ -1,24 +0,0 @@
1
- import { join } from "node:path";
2
- import { mkdir, rm } from "node:fs/promises";
3
- import { extractTarGz, createTempDir } from "../utils/archive.js";
4
- import { downloadFile } from "../utils/https.js";
5
- export const createLocalAssetProvider = (serverUrl) => {
6
- let tmpDir = null;
7
- return {
8
- fetch: async () => {
9
- tmpDir = await createTempDir("accel-assets-");
10
- const archivePath = join(tmpDir, "assets.tar.gz");
11
- const extractDir = join(tmpDir, "repo");
12
- await mkdir(extractDir, { recursive: true });
13
- await downloadFile(`${serverUrl}/archive`, archivePath);
14
- await extractTarGz(archivePath, extractDir);
15
- return extractDir;
16
- },
17
- cleanup: async () => {
18
- if (tmpDir) {
19
- await rm(tmpDir, { recursive: true, force: true }).catch(() => { });
20
- tmpDir = null;
21
- }
22
- },
23
- };
24
- };
@@ -1,3 +0,0 @@
1
- export declare const extractTarGz: (archivePath: string, destDir: string) => Promise<void>;
2
- export declare const createTarGz: (sourceDir: string, destPath: string, entries?: string[]) => Promise<void>;
3
- export declare const createTempDir: (prefix?: string) => Promise<string>;
@@ -1,20 +0,0 @@
1
- import { extract, create } from "tar";
2
- import { mkdtemp } from "node:fs/promises";
3
- import { join } from "node:path";
4
- import { tmpdir } from "node:os";
5
- export const extractTarGz = async (archivePath, destDir) => {
6
- await extract({
7
- file: archivePath,
8
- cwd: destDir,
9
- });
10
- };
11
- export const createTarGz = async (sourceDir, destPath, entries) => {
12
- await create({
13
- gzip: true,
14
- file: destPath,
15
- cwd: sourceDir,
16
- }, entries ?? ["."]);
17
- };
18
- export const createTempDir = async (prefix = "accel-") => {
19
- return mkdtemp(join(tmpdir(), prefix));
20
- };
@@ -1,2 +0,0 @@
1
- export declare const isInsecureRedirect: (from: string, location: string) => boolean;
2
- export declare const downloadFile: (url: string, destPath: string, redirectsLeft?: number) => Promise<void>;