@intra-mart/accel 0.4.0 → 0.5.0-dev.202608040843
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 +140 -4
- package/dist/asset/deployer.js +3 -4
- package/dist/asset/git-provider.js +53 -25
- package/dist/asset/installer.d.ts +4 -1
- package/dist/asset/installer.js +13 -0
- package/dist/asset/updater.d.ts +6 -1
- package/dist/asset/updater.js +122 -23
- package/dist/commands/cache.d.ts +1 -0
- package/dist/commands/cache.js +74 -0
- package/dist/commands/preset.d.ts +31 -0
- package/dist/commands/preset.js +396 -0
- package/dist/commands/switch.d.ts +28 -0
- package/dist/commands/switch.js +262 -0
- package/dist/commands/update.d.ts +4 -0
- package/dist/commands/update.js +75 -23
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/types.d.ts +8 -0
- package/dist/core/validators.d.ts +2 -0
- package/dist/core/validators.js +7 -0
- package/dist/git/object-cache.d.ts +12 -0
- package/dist/git/object-cache.js +95 -0
- package/dist/git/object-store.d.ts +3 -1
- package/dist/git/object-store.js +49 -9
- package/dist/i18n/en.js +59 -0
- package/dist/i18n/ja.js +59 -0
- package/dist/i18n/zh_CN.js +59 -0
- package/dist/index.js +6 -0
- package/dist/interactive/prompts.d.ts +4 -1
- package/dist/interactive/prompts.js +51 -43
- package/dist/utils/concurrency.d.ts +1 -0
- package/dist/utils/concurrency.js +1 -0
- package/dist/utils/hash.d.ts +1 -0
- package/dist/utils/hash.js +5 -0
- package/dist/utils/preset-io.d.ts +23 -0
- package/dist/utils/preset-io.js +164 -0
- package/dist/utils/safe-rel-path.d.ts +1 -0
- package/dist/utils/safe-rel-path.js +5 -0
- package/dist/utils/settings-io.d.ts +1 -0
- package/dist/utils/settings-io.js +4 -2
- package/package.json +1 -1
package/dist/asset/updater.js
CHANGED
|
@@ -4,7 +4,8 @@ import { buildEvalContext } from "../core/eval-context.js";
|
|
|
4
4
|
import { walkAssetRepo } from "./walker.js";
|
|
5
5
|
import { renderAssetContent } from "./renderer.js";
|
|
6
6
|
import { computeSha1 } from "../utils/hash.js";
|
|
7
|
-
|
|
7
|
+
import { FS_CONCURRENCY, mapWithConcurrency } from "../utils/concurrency.js";
|
|
8
|
+
import { isSafeRelPath } from "../utils/safe-rel-path.js";
|
|
8
9
|
export const buildRenderedPlan = async (tree, settings, materialize, collect) => {
|
|
9
10
|
const context = buildEvalContext(settings);
|
|
10
11
|
const entries = await walkAssetRepo(tree, settings.accelplatformVersion.semver, context, collect);
|
|
@@ -20,18 +21,17 @@ export const buildRenderedPlan = async (tree, settings, materialize, collect) =>
|
|
|
20
21
|
...new Set(safeEntries.map((e) => e.sourceRelPath)),
|
|
21
22
|
]);
|
|
22
23
|
}
|
|
23
|
-
const
|
|
24
|
-
for (const entry of safeEntries) {
|
|
24
|
+
const rendered = await mapWithConcurrency(safeEntries, FS_CONCURRENCY, async (entry) => {
|
|
25
25
|
const raw = await tree.readFile(entry.sourceRelPath);
|
|
26
26
|
const content = renderAssetContent(raw, entry.relativePath, entry.meta?.replacements ?? [], context);
|
|
27
|
-
|
|
27
|
+
return {
|
|
28
28
|
relativePath: entry.relativePath,
|
|
29
29
|
content,
|
|
30
30
|
version: entry.meta?.version ?? "0.0.0",
|
|
31
31
|
sha1: computeSha1(content),
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
return new Map(rendered.map((asset) => [asset.relativePath, asset]));
|
|
35
35
|
};
|
|
36
36
|
export const collectFileStates = async (projectDir, basePlan, theirsPlan, recorded) => {
|
|
37
37
|
const recordedMap = new Map(recorded.map((e) => [e.filePath, e]));
|
|
@@ -40,12 +40,12 @@ export const collectFileStates = async (projectDir, basePlan, theirsPlan, record
|
|
|
40
40
|
...theirsPlan.keys(),
|
|
41
41
|
...recordedMap.keys(),
|
|
42
42
|
]);
|
|
43
|
-
const
|
|
44
|
-
for (const key of [...keys].sort()) {
|
|
43
|
+
const targets = [...keys].sort().flatMap((key) => {
|
|
45
44
|
const theirs = theirsPlan.get(key) ?? null;
|
|
46
45
|
const rec = recordedMap.get(key) ?? null;
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
return theirs || rec ? [{ key, theirs, rec }] : [];
|
|
47
|
+
});
|
|
48
|
+
return mapWithConcurrency(targets, FS_CONCURRENCY, async ({ key, theirs, rec }) => {
|
|
49
49
|
let oursContent = null;
|
|
50
50
|
try {
|
|
51
51
|
oursContent = await readFile(join(projectDir, key), "utf-8");
|
|
@@ -53,15 +53,14 @@ export const collectFileStates = async (projectDir, basePlan, theirsPlan, record
|
|
|
53
53
|
catch {
|
|
54
54
|
oursContent = null;
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
return {
|
|
57
57
|
relativePath: key,
|
|
58
58
|
base: basePlan.get(key) ?? null,
|
|
59
59
|
theirs,
|
|
60
60
|
oursContent,
|
|
61
61
|
recorded: rec,
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return states;
|
|
62
|
+
};
|
|
63
|
+
});
|
|
65
64
|
};
|
|
66
65
|
export const classifyFile = async (state, merge) => {
|
|
67
66
|
const { relativePath, base, theirs, oursContent, recorded } = state;
|
|
@@ -195,6 +194,99 @@ export const classifyFileFallback = async (state, merge, keepEdited) => {
|
|
|
195
194
|
record: theirsRecord,
|
|
196
195
|
};
|
|
197
196
|
};
|
|
197
|
+
export const classifyFileSwitch = (state) => {
|
|
198
|
+
const { relativePath, base, theirs, oursContent, recorded } = state;
|
|
199
|
+
if (recorded) {
|
|
200
|
+
if (!theirs) {
|
|
201
|
+
if (oursContent === null) {
|
|
202
|
+
return { relativePath, op: "none", outcome: "removed", record: "remove" };
|
|
203
|
+
}
|
|
204
|
+
const edited = computeSha1(oursContent) !== recorded.sha1;
|
|
205
|
+
if (edited) {
|
|
206
|
+
return {
|
|
207
|
+
relativePath,
|
|
208
|
+
op: "none",
|
|
209
|
+
outcome: "skipped-switch",
|
|
210
|
+
skipReason: "out-of-scope",
|
|
211
|
+
record: "keep",
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return { relativePath, op: "delete", outcome: "removed", record: "remove" };
|
|
215
|
+
}
|
|
216
|
+
const theirsRecord = {
|
|
217
|
+
filePath: relativePath,
|
|
218
|
+
version: theirs.version,
|
|
219
|
+
sha1: theirs.sha1,
|
|
220
|
+
};
|
|
221
|
+
const changed = base?.content !== theirs.content;
|
|
222
|
+
if (oursContent === null) {
|
|
223
|
+
if (!changed) {
|
|
224
|
+
return { relativePath, op: "none", outcome: "kept-deleted", record: "keep" };
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
relativePath,
|
|
228
|
+
op: "none",
|
|
229
|
+
outcome: "skipped-switch",
|
|
230
|
+
skipReason: "deleted",
|
|
231
|
+
record: "keep",
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
const edited = computeSha1(oursContent) !== recorded.sha1;
|
|
235
|
+
if (!edited) {
|
|
236
|
+
if (!changed) {
|
|
237
|
+
return { relativePath, op: "none", outcome: "up-to-date", record: "keep" };
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
relativePath,
|
|
241
|
+
op: "write",
|
|
242
|
+
outcome: "updated",
|
|
243
|
+
content: theirs.content,
|
|
244
|
+
record: theirsRecord,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
if (!changed) {
|
|
248
|
+
return { relativePath, op: "none", outcome: "kept-edited", record: "keep" };
|
|
249
|
+
}
|
|
250
|
+
if (oursContent === theirs.content) {
|
|
251
|
+
return { relativePath, op: "none", outcome: "adopted", record: theirsRecord };
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
relativePath,
|
|
255
|
+
op: "none",
|
|
256
|
+
outcome: "skipped-switch",
|
|
257
|
+
skipReason: "edited",
|
|
258
|
+
record: "keep",
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
if (!theirs) {
|
|
262
|
+
return { relativePath, op: "none", outcome: "up-to-date", record: "keep" };
|
|
263
|
+
}
|
|
264
|
+
const theirsRecord = {
|
|
265
|
+
filePath: relativePath,
|
|
266
|
+
version: theirs.version,
|
|
267
|
+
sha1: theirs.sha1,
|
|
268
|
+
};
|
|
269
|
+
if (oursContent === null) {
|
|
270
|
+
return {
|
|
271
|
+
relativePath,
|
|
272
|
+
op: "write",
|
|
273
|
+
outcome: "added",
|
|
274
|
+
content: theirs.content,
|
|
275
|
+
record: theirsRecord,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
if (oursContent === theirs.content) {
|
|
279
|
+
return { relativePath, op: "none", outcome: "adopted", record: theirsRecord };
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
relativePath,
|
|
283
|
+
op: "none",
|
|
284
|
+
outcome: "skipped-switch",
|
|
285
|
+
skipReason: "unmanaged",
|
|
286
|
+
record: "keep",
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
export const classifySwitch = (states) => states.map(classifyFileSwitch);
|
|
198
290
|
export const classifyAll = async (states, merge, fallback) => {
|
|
199
291
|
const actions = [];
|
|
200
292
|
for (const state of states) {
|
|
@@ -218,17 +310,19 @@ export const applyUpdateActions = async (projectDir, actions) => {
|
|
|
218
310
|
warnings: [],
|
|
219
311
|
redeployedWarn: [],
|
|
220
312
|
skippedEdited: [],
|
|
313
|
+
skippedSwitch: [],
|
|
221
314
|
changedFileCount: 0,
|
|
222
315
|
};
|
|
223
|
-
|
|
316
|
+
await mapWithConcurrency(actions.filter((a) => a.op === "delete"), FS_CONCURRENCY, async (action) => {
|
|
317
|
+
await unlink(join(projectDir, action.relativePath)).catch(() => { });
|
|
318
|
+
});
|
|
319
|
+
await mapWithConcurrency(actions.filter((a) => a.op === "write"), FS_CONCURRENCY, async (action) => {
|
|
224
320
|
const destPath = join(projectDir, action.relativePath);
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
else if (action.op === "delete") {
|
|
231
|
-
await unlink(destPath).catch(() => { });
|
|
321
|
+
await mkdir(dirname(destPath), { recursive: true });
|
|
322
|
+
await writeFile(destPath, action.content ?? "", "utf-8");
|
|
323
|
+
});
|
|
324
|
+
for (const action of actions) {
|
|
325
|
+
if (action.op !== "none") {
|
|
232
326
|
summary.changedFileCount++;
|
|
233
327
|
}
|
|
234
328
|
switch (action.outcome) {
|
|
@@ -264,6 +358,9 @@ export const applyUpdateActions = async (projectDir, actions) => {
|
|
|
264
358
|
case "skipped-edited":
|
|
265
359
|
summary.skippedEdited.push(action.relativePath);
|
|
266
360
|
break;
|
|
361
|
+
case "skipped-switch":
|
|
362
|
+
summary.skippedSwitch.push(action.relativePath);
|
|
363
|
+
break;
|
|
267
364
|
case "added":
|
|
268
365
|
summary.added.push(action.relativePath);
|
|
269
366
|
break;
|
|
@@ -272,6 +369,8 @@ export const applyUpdateActions = async (projectDir, actions) => {
|
|
|
272
369
|
break;
|
|
273
370
|
case "up-to-date":
|
|
274
371
|
break;
|
|
372
|
+
default:
|
|
373
|
+
action.outcome;
|
|
275
374
|
}
|
|
276
375
|
}
|
|
277
376
|
return summary;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const cacheCommand: import("citty").CommandDef<import("citty").ArgsDef>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { rm } from "node:fs/promises";
|
|
2
|
+
import { defineCommand } from "citty";
|
|
3
|
+
import * as p from "@clack/prompts";
|
|
4
|
+
import { cacheReposDir, directorySize, listCacheRepos, resolveCacheRoot, } from "../git/object-cache.js";
|
|
5
|
+
import { getMessage } from "../i18n/index.js";
|
|
6
|
+
import { detectLocale } from "../utils/locale-detect.js";
|
|
7
|
+
import { sanitizeDisplayText } from "../utils/sanitize-text.js";
|
|
8
|
+
const formatBytes = (bytes) => {
|
|
9
|
+
if (bytes >= 1024 ** 3)
|
|
10
|
+
return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
|
|
11
|
+
if (bytes >= 1024 ** 2)
|
|
12
|
+
return `${(bytes / 1024 ** 2).toFixed(1)} MB`;
|
|
13
|
+
if (bytes >= 1024)
|
|
14
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
15
|
+
return `${bytes} B`;
|
|
16
|
+
};
|
|
17
|
+
const infoCommand = defineCommand({
|
|
18
|
+
meta: {
|
|
19
|
+
name: "info",
|
|
20
|
+
description: "Show the asset cache location and disk usage",
|
|
21
|
+
},
|
|
22
|
+
run: async () => {
|
|
23
|
+
const locale = detectLocale();
|
|
24
|
+
const root = resolveCacheRoot();
|
|
25
|
+
let dirLine = getMessage("cache.info.dir", locale, { path: root });
|
|
26
|
+
if (process.env["ACCEL_CACHE_DIR"]) {
|
|
27
|
+
dirLine += ` ${getMessage("cache.info.overridden", locale)}`;
|
|
28
|
+
}
|
|
29
|
+
p.log.info(dirLine);
|
|
30
|
+
const repos = await listCacheRepos(root);
|
|
31
|
+
if (repos.length === 0) {
|
|
32
|
+
p.log.info(getMessage("cache.info.empty", locale));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const total = repos.reduce((sum, repo) => sum + repo.size, 0);
|
|
36
|
+
p.log.info(getMessage("cache.info.total", locale, { size: formatBytes(total) }));
|
|
37
|
+
for (const repo of repos) {
|
|
38
|
+
p.log.info(` ${sanitizeDisplayText(repo.url ?? repo.dir)} — ${formatBytes(repo.size)}`);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const clearCommand = defineCommand({
|
|
43
|
+
meta: {
|
|
44
|
+
name: "clear",
|
|
45
|
+
description: "Delete the asset cache (it will be re-downloaded on demand)",
|
|
46
|
+
},
|
|
47
|
+
run: async () => {
|
|
48
|
+
const locale = detectLocale();
|
|
49
|
+
const reposDir = cacheReposDir(resolveCacheRoot());
|
|
50
|
+
try {
|
|
51
|
+
const size = await directorySize(reposDir);
|
|
52
|
+
if (size === 0) {
|
|
53
|
+
p.log.info(getMessage("cache.clear.empty", locale));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
await rm(reposDir, { recursive: true, force: true });
|
|
57
|
+
p.log.success(getMessage("cache.clear.done", locale, { size: formatBytes(size) }));
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
p.log.error(err instanceof Error ? err.message : String(err));
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
export const cacheCommand = defineCommand({
|
|
66
|
+
meta: {
|
|
67
|
+
name: "cache",
|
|
68
|
+
description: "Manage the persistent asset object cache",
|
|
69
|
+
},
|
|
70
|
+
subCommands: {
|
|
71
|
+
info: infoCommand,
|
|
72
|
+
clear: clearCommand,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Release } from "../core/catalog.js";
|
|
2
|
+
import { promptModules, promptFeatures, promptAgents } from "../interactive/prompts.js";
|
|
3
|
+
import { type PresetSummary } from "../utils/preset-io.js";
|
|
4
|
+
export type PresetCreateCliValues = {
|
|
5
|
+
name?: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
modules?: string[];
|
|
9
|
+
features?: string[];
|
|
10
|
+
agents?: string[];
|
|
11
|
+
};
|
|
12
|
+
export type PresetCreatePrompts = {
|
|
13
|
+
text: (opts: {
|
|
14
|
+
message: string;
|
|
15
|
+
validate?: (value: string | undefined) => string | undefined;
|
|
16
|
+
}) => Promise<string | symbol>;
|
|
17
|
+
confirm: (opts: {
|
|
18
|
+
message: string;
|
|
19
|
+
initialValue?: boolean;
|
|
20
|
+
}) => Promise<boolean | symbol>;
|
|
21
|
+
modules: typeof promptModules;
|
|
22
|
+
features: typeof promptFeatures;
|
|
23
|
+
agents: typeof promptAgents;
|
|
24
|
+
};
|
|
25
|
+
export declare const runPresetCreateInteractive: (ctx: {
|
|
26
|
+
projectDir: string;
|
|
27
|
+
locale: string;
|
|
28
|
+
}, release: Release, cli: PresetCreateCliValues, force?: boolean, prompts?: PresetCreatePrompts) => Promise<void>;
|
|
29
|
+
export declare const buildPresetListBody: (summaries: PresetSummary[]) => string;
|
|
30
|
+
export declare const buildPresetShowBody: (raw: Record<string, unknown>, locale: string) => string;
|
|
31
|
+
export declare const presetCommand: import("citty").CommandDef<import("citty").ArgsDef>;
|