@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
|
@@ -31,5 +31,8 @@ export declare const validateNonInteractive: (opts: PromptOptions) => string[];
|
|
|
31
31
|
export declare const validateCliValues: (opts: PromptOptions, validators: Validators) => void;
|
|
32
32
|
export declare const validateCatalogValues: (opts: PromptOptions, release: Release, locale: string) => void;
|
|
33
33
|
export declare const collectSettingsErrors: (opts: PromptOptions, locale: string, releaseIdFallback?: string) => string[];
|
|
34
|
-
export declare const printIntro: (mode: "init" | "attach" | "update", locale: string) => void;
|
|
34
|
+
export declare const printIntro: (mode: "init" | "attach" | "update" | "switch" | "preset", locale: string) => void;
|
|
35
|
+
export declare const promptModules: (release: Release, initialValues: string[], locale: string) => Promise<string[]>;
|
|
36
|
+
export declare const promptFeatures: (release: Release, initialValues: string[] | undefined, locale: string) => Promise<string[]>;
|
|
37
|
+
export declare const promptAgents: (initialValues: string[] | undefined, locale: string) => Promise<string[]>;
|
|
35
38
|
export declare const runPrompts: (opts: PromptOptions) => Promise<ResolvedOptions>;
|
|
@@ -101,6 +101,54 @@ export const printIntro = (mode, locale) => {
|
|
|
101
101
|
p.intro("Accel CLI");
|
|
102
102
|
p.note(getMessage(`intro.${mode}`, locale));
|
|
103
103
|
};
|
|
104
|
+
export const promptModules = async (release, initialValues, locale) => {
|
|
105
|
+
const releaseArtifactIds = release.modules.map((m) => m.artifactId);
|
|
106
|
+
const modules = (await p.multiselect({
|
|
107
|
+
message: withHint("prompt.modules", locale),
|
|
108
|
+
options: release.modules.map((m) => ({
|
|
109
|
+
value: m.artifactId,
|
|
110
|
+
label: resolveLabel(m.labels, locale),
|
|
111
|
+
})),
|
|
112
|
+
initialValues: initialValues.filter((m) => releaseArtifactIds.includes(m)),
|
|
113
|
+
required: true,
|
|
114
|
+
}));
|
|
115
|
+
if (p.isCancel(modules))
|
|
116
|
+
process.exit(0);
|
|
117
|
+
return modules;
|
|
118
|
+
};
|
|
119
|
+
export const promptFeatures = async (release, initialValues, locale) => {
|
|
120
|
+
if (release.functions.length === 0) {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
const featureIds = release.functions.map((f) => f.id);
|
|
124
|
+
const selected = (await p.multiselect({
|
|
125
|
+
message: withHint("prompt.features", locale),
|
|
126
|
+
options: release.functions.map((f) => ({
|
|
127
|
+
value: f.id,
|
|
128
|
+
label: resolveLabel(f.labels, locale),
|
|
129
|
+
})),
|
|
130
|
+
initialValues: initialValues?.filter((f) => featureIds.includes(f)) ?? featureIds,
|
|
131
|
+
required: true,
|
|
132
|
+
}));
|
|
133
|
+
if (p.isCancel(selected))
|
|
134
|
+
process.exit(0);
|
|
135
|
+
return selected;
|
|
136
|
+
};
|
|
137
|
+
export const promptAgents = async (initialValues, locale) => {
|
|
138
|
+
const detected = detectAgents();
|
|
139
|
+
const defaults = initialValues?.filter((a) => AGENT_OPTIONS.includes(a)) ??
|
|
140
|
+
(detected.length > 0
|
|
141
|
+
? detected.map((a) => a.name)
|
|
142
|
+
: [...AGENT_OPTIONS]);
|
|
143
|
+
const agents = (await p.multiselect({
|
|
144
|
+
message: withHint("prompt.agent", locale),
|
|
145
|
+
options: AGENT_OPTIONS.map((a) => ({ value: a, label: a })),
|
|
146
|
+
initialValues: defaults,
|
|
147
|
+
}));
|
|
148
|
+
if (p.isCancel(agents))
|
|
149
|
+
process.exit(0);
|
|
150
|
+
return agents;
|
|
151
|
+
};
|
|
104
152
|
export const runPrompts = async (opts) => {
|
|
105
153
|
const locale = opts.locale;
|
|
106
154
|
const validators = createValidators(locale);
|
|
@@ -247,36 +295,8 @@ export const runPrompts = async (opts) => {
|
|
|
247
295
|
p.log.warning(getMessage("warning.moduleMismatch", locale));
|
|
248
296
|
}
|
|
249
297
|
}
|
|
250
|
-
const modules =
|
|
251
|
-
|
|
252
|
-
options: release.modules.map((m) => ({
|
|
253
|
-
value: m.artifactId,
|
|
254
|
-
label: resolveLabel(m.labels, locale),
|
|
255
|
-
})),
|
|
256
|
-
initialValues: moduleDefault,
|
|
257
|
-
required: true,
|
|
258
|
-
}));
|
|
259
|
-
if (p.isCancel(modules))
|
|
260
|
-
process.exit(0);
|
|
261
|
-
let features;
|
|
262
|
-
if (release.functions.length === 0) {
|
|
263
|
-
features = [];
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
const featureIds = release.functions.map((f) => f.id);
|
|
267
|
-
const selected = (await p.multiselect({
|
|
268
|
-
message: withHint("prompt.features", locale),
|
|
269
|
-
options: release.functions.map((f) => ({
|
|
270
|
-
value: f.id,
|
|
271
|
-
label: resolveLabel(f.labels, locale),
|
|
272
|
-
})),
|
|
273
|
-
initialValues: opts.feature?.filter((f) => featureIds.includes(f)) ?? featureIds,
|
|
274
|
-
required: true,
|
|
275
|
-
}));
|
|
276
|
-
if (p.isCancel(selected))
|
|
277
|
-
process.exit(0);
|
|
278
|
-
features = selected;
|
|
279
|
-
}
|
|
298
|
+
const modules = await promptModules(release, moduleDefault, locale);
|
|
299
|
+
const features = await promptFeatures(release, opts.feature, locale);
|
|
280
300
|
const group = (await p.text({
|
|
281
301
|
message: withHint("prompt.group", locale),
|
|
282
302
|
defaultValue: opts.group ?? DEFAULT_SETTINGS.group,
|
|
@@ -313,19 +333,7 @@ export const runPrompts = async (opts) => {
|
|
|
313
333
|
}));
|
|
314
334
|
if (p.isCancel(javascript))
|
|
315
335
|
process.exit(0);
|
|
316
|
-
const
|
|
317
|
-
const agentOptions = AGENT_OPTIONS.map((a) => ({ value: a, label: a }));
|
|
318
|
-
const defaultAgents = opts.agent?.filter((a) => AGENT_OPTIONS.includes(a)) ??
|
|
319
|
-
(detected.length > 0
|
|
320
|
-
? detected.map((a) => a.name)
|
|
321
|
-
: [...AGENT_OPTIONS]);
|
|
322
|
-
const agents = (await p.multiselect({
|
|
323
|
-
message: withHint("prompt.agent", locale),
|
|
324
|
-
options: agentOptions,
|
|
325
|
-
initialValues: defaultAgents,
|
|
326
|
-
}));
|
|
327
|
-
if (p.isCancel(agents))
|
|
328
|
-
process.exit(0);
|
|
336
|
+
const agents = await promptAgents(opts.agent, locale);
|
|
329
337
|
let withGit = opts.withGit ?? true;
|
|
330
338
|
if (opts.isInit) {
|
|
331
339
|
withGit = (await p.confirm({
|
package/dist/utils/hash.d.ts
CHANGED
package/dist/utils/hash.js
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AccelPreset } from "../core/types.js";
|
|
2
|
+
import { type Release } from "../core/catalog.js";
|
|
3
|
+
export declare const presetsDir: (projectDir: string) => string;
|
|
4
|
+
export declare const presetPath: (projectDir: string, name: string) => string;
|
|
5
|
+
export declare const writePreset: (projectDir: string, preset: AccelPreset) => Promise<void>;
|
|
6
|
+
export declare const presetExists: (projectDir: string, name: string) => Promise<boolean>;
|
|
7
|
+
export declare const deletePreset: (projectDir: string, name: string) => Promise<void>;
|
|
8
|
+
export type PresetSummary = {
|
|
9
|
+
name: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const listPresetSummaries: (projectDir: string) => Promise<PresetSummary[]>;
|
|
14
|
+
export declare const formatPresetDisplayName: (summary: PresetSummary) => string;
|
|
15
|
+
export declare const buildPresetSelectOptions: (presets: PresetSummary[], locale: string) => Array<{
|
|
16
|
+
value: string;
|
|
17
|
+
label: string;
|
|
18
|
+
hint?: string;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const parsePresetChoice: (choice: string) => string | undefined;
|
|
21
|
+
export declare const validatePresetSchema: (raw: unknown, expectedName: string, locale: string) => string[];
|
|
22
|
+
export declare const collectPresetCatalogErrors: (preset: AccelPreset, release: Release, locale: string) => string[];
|
|
23
|
+
export declare const loadAndValidatePreset: (projectDir: string, name: string, releaseId: string, locale: string) => Promise<AccelPreset>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { readFile, writeFile, mkdir, readdir, rm, stat } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { PRESET_NAME_PATTERN, createPresetNameValidator, createReleaseValidators, createValidators, } from "../core/validators.js";
|
|
4
|
+
import { findReleaseById } from "../core/catalog.js";
|
|
5
|
+
import { getMessage } from "../i18n/index.js";
|
|
6
|
+
import { ACCEL_DIR } from "./settings-io.js";
|
|
7
|
+
import { sanitizeDisplayText } from "./sanitize-text.js";
|
|
8
|
+
import { mapWithConcurrency, FS_CONCURRENCY } from "./concurrency.js";
|
|
9
|
+
const PRESETS_DIR = "presets";
|
|
10
|
+
const PRESET_EXT = ".json";
|
|
11
|
+
export const presetsDir = (projectDir) => join(projectDir, ACCEL_DIR, PRESETS_DIR);
|
|
12
|
+
export const presetPath = (projectDir, name) => {
|
|
13
|
+
if (!PRESET_NAME_PATTERN.test(name)) {
|
|
14
|
+
throw new Error(`Invalid preset name: ${name}`);
|
|
15
|
+
}
|
|
16
|
+
return join(presetsDir(projectDir), `${name}${PRESET_EXT}`);
|
|
17
|
+
};
|
|
18
|
+
export const writePreset = async (projectDir, preset) => {
|
|
19
|
+
const filePath = presetPath(projectDir, preset.name);
|
|
20
|
+
await mkdir(presetsDir(projectDir), { recursive: true });
|
|
21
|
+
await writeFile(filePath, JSON.stringify(preset, null, 2) + "\n", "utf-8");
|
|
22
|
+
};
|
|
23
|
+
export const presetExists = async (projectDir, name) => {
|
|
24
|
+
try {
|
|
25
|
+
await stat(presetPath(projectDir, name));
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const deletePreset = async (projectDir, name) => {
|
|
33
|
+
await rm(presetPath(projectDir, name));
|
|
34
|
+
};
|
|
35
|
+
export const listPresetSummaries = async (projectDir) => {
|
|
36
|
+
let entries;
|
|
37
|
+
try {
|
|
38
|
+
entries = await readdir(presetsDir(projectDir));
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const names = entries
|
|
44
|
+
.filter((f) => f.endsWith(PRESET_EXT))
|
|
45
|
+
.map((f) => f.slice(0, -PRESET_EXT.length))
|
|
46
|
+
.filter((n) => PRESET_NAME_PATTERN.test(n))
|
|
47
|
+
.sort((a, b) => a.localeCompare(b));
|
|
48
|
+
return mapWithConcurrency(names, FS_CONCURRENCY, async (name) => {
|
|
49
|
+
const summary = { name };
|
|
50
|
+
try {
|
|
51
|
+
const raw = JSON.parse(await readFile(presetPath(projectDir, name), "utf-8"));
|
|
52
|
+
if (typeof raw.label === "string" && raw.label.length > 0) {
|
|
53
|
+
summary.label = raw.label;
|
|
54
|
+
}
|
|
55
|
+
if (typeof raw.description === "string" && raw.description.length > 0) {
|
|
56
|
+
summary.description = raw.description;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
}
|
|
61
|
+
return summary;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
export const formatPresetDisplayName = (summary) => summary.label
|
|
65
|
+
? `${sanitizeDisplayText(summary.label)} (${summary.name})`
|
|
66
|
+
: summary.name;
|
|
67
|
+
const PRESET_CHOICE_PREFIX = "preset:";
|
|
68
|
+
export const buildPresetSelectOptions = (presets, locale) => presets.map((summary) => ({
|
|
69
|
+
value: `${PRESET_CHOICE_PREFIX}${summary.name}`,
|
|
70
|
+
label: getMessage("preset.prompt.select.usePreset", locale, {
|
|
71
|
+
name: formatPresetDisplayName(summary),
|
|
72
|
+
}),
|
|
73
|
+
...(summary.description
|
|
74
|
+
? { hint: sanitizeDisplayText(summary.description) }
|
|
75
|
+
: {}),
|
|
76
|
+
}));
|
|
77
|
+
export const parsePresetChoice = (choice) => choice.startsWith(PRESET_CHOICE_PREFIX)
|
|
78
|
+
? choice.slice(PRESET_CHOICE_PREFIX.length)
|
|
79
|
+
: undefined;
|
|
80
|
+
const isStringArray = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
81
|
+
export const validatePresetSchema = (raw, expectedName, locale) => {
|
|
82
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
83
|
+
return [
|
|
84
|
+
getMessage("preset.error.parse", locale, { message: "not an object" }),
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
const obj = raw;
|
|
88
|
+
const errors = [];
|
|
89
|
+
for (const field of ["modules", "features", "agents"]) {
|
|
90
|
+
if (!isStringArray(obj[field])) {
|
|
91
|
+
errors.push(getMessage("preset.error.field", locale, { field }));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (obj.name !== expectedName) {
|
|
95
|
+
errors.push(getMessage("preset.error.nameMismatch", locale, {
|
|
96
|
+
value: sanitizeDisplayText(typeof obj.name === "string" ? obj.name : String(obj.name)),
|
|
97
|
+
name: expectedName,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
return errors;
|
|
101
|
+
};
|
|
102
|
+
export const collectPresetCatalogErrors = (preset, release, locale) => {
|
|
103
|
+
const releaseValidators = createReleaseValidators(locale, release);
|
|
104
|
+
const agentValidator = createValidators(locale).agent;
|
|
105
|
+
const errors = [];
|
|
106
|
+
for (const module of preset.modules) {
|
|
107
|
+
const error = releaseValidators.module(module);
|
|
108
|
+
if (error)
|
|
109
|
+
errors.push(error);
|
|
110
|
+
}
|
|
111
|
+
for (const feature of preset.features) {
|
|
112
|
+
const error = releaseValidators.feature(feature);
|
|
113
|
+
if (error)
|
|
114
|
+
errors.push(error);
|
|
115
|
+
}
|
|
116
|
+
for (const agent of preset.agents) {
|
|
117
|
+
const error = agentValidator(agent);
|
|
118
|
+
if (error)
|
|
119
|
+
errors.push(error);
|
|
120
|
+
}
|
|
121
|
+
return errors.map((error) => sanitizeDisplayText(error));
|
|
122
|
+
};
|
|
123
|
+
const invalidPresetError = (name, errors, locale) => new Error(getMessage("preset.error.invalid", locale, {
|
|
124
|
+
name,
|
|
125
|
+
errors: errors.map((e) => ` - ${e}`).join("\n"),
|
|
126
|
+
}));
|
|
127
|
+
export const loadAndValidatePreset = async (projectDir, name, releaseId, locale) => {
|
|
128
|
+
const nameError = createPresetNameValidator(locale)(name);
|
|
129
|
+
if (nameError) {
|
|
130
|
+
throw new Error(nameError);
|
|
131
|
+
}
|
|
132
|
+
let content;
|
|
133
|
+
try {
|
|
134
|
+
content = await readFile(presetPath(projectDir, name), "utf-8");
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
throw new Error(getMessage("preset.error.notFound", locale, { name }));
|
|
138
|
+
}
|
|
139
|
+
let raw;
|
|
140
|
+
try {
|
|
141
|
+
raw = JSON.parse(content);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
throw invalidPresetError(name, [
|
|
145
|
+
getMessage("preset.error.parse", locale, {
|
|
146
|
+
message: sanitizeDisplayText(err instanceof Error ? err.message : String(err)),
|
|
147
|
+
}),
|
|
148
|
+
], locale);
|
|
149
|
+
}
|
|
150
|
+
const schemaErrors = validatePresetSchema(raw, name, locale);
|
|
151
|
+
if (schemaErrors.length > 0) {
|
|
152
|
+
throw invalidPresetError(name, schemaErrors, locale);
|
|
153
|
+
}
|
|
154
|
+
const preset = raw;
|
|
155
|
+
const release = findReleaseById(releaseId);
|
|
156
|
+
if (!release) {
|
|
157
|
+
throw new Error(getMessage("error.invalidVersion", locale, { version: releaseId }));
|
|
158
|
+
}
|
|
159
|
+
const catalogErrors = collectPresetCatalogErrors(preset, release, locale);
|
|
160
|
+
if (catalogErrors.length > 0) {
|
|
161
|
+
throw invalidPresetError(name, catalogErrors, locale);
|
|
162
|
+
}
|
|
163
|
+
return preset;
|
|
164
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isSafeRelPath: (p: string) => boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AccelSettings, HashsumEntry } from "../core/types.js";
|
|
2
|
+
export declare const ACCEL_DIR = ".accel";
|
|
2
3
|
export declare const writeSettings: (projectDir: string, settings: AccelSettings) => Promise<void>;
|
|
3
4
|
export declare const readSettings: (projectDir: string) => Promise<AccelSettings>;
|
|
4
5
|
export declare const readSettingsSafe: (projectDir: string) => Promise<AccelSettings | null>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
|
|
3
|
+
import { isSafeRelPath } from "./safe-rel-path.js";
|
|
4
|
+
export const ACCEL_DIR = ".accel";
|
|
4
5
|
const SETTINGS_FILE = "settings.json";
|
|
5
6
|
const HASHSUM_FILE = "hashsum.txt";
|
|
6
7
|
const ensureAccelDir = async (projectDir) => {
|
|
@@ -46,7 +47,8 @@ export const parseHashsum = (content) => {
|
|
|
46
47
|
version: match[2],
|
|
47
48
|
sha1: match[3],
|
|
48
49
|
};
|
|
49
|
-
})
|
|
50
|
+
})
|
|
51
|
+
.filter((e) => isSafeRelPath(e.filePath));
|
|
50
52
|
};
|
|
51
53
|
export const writeHashsum = async (projectDir, entries) => {
|
|
52
54
|
const accelDir = await ensureAccelDir(projectDir);
|