@intra-mart/accel 0.4.0 → 0.5.0-dev.202608030656

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.
@@ -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 = (await p.multiselect({
251
- message: withHint("prompt.modules", locale),
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 detected = detectAgents();
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({
@@ -1 +1,2 @@
1
+ export declare const FS_CONCURRENCY = 64;
1
2
  export declare const mapWithConcurrency: <T, R>(items: readonly T[], limit: number, fn: (item: T, index: number) => Promise<R>) => Promise<R[]>;
@@ -1,3 +1,4 @@
1
+ export const FS_CONCURRENCY = 64;
1
2
  export const mapWithConcurrency = async (items, limit, fn) => {
2
3
  if (!(limit >= 1)) {
3
4
  throw new RangeError(`limit must be >= 1, got ${limit}`);
@@ -1 +1,2 @@
1
1
  export declare const computeSha1: (content: string | Buffer) => string;
2
+ export declare const computeSha256: (content: string | Buffer) => string;
@@ -4,3 +4,8 @@ export const computeSha1 = (content) => {
4
4
  hash.update(content);
5
5
  return hash.digest("hex");
6
6
  };
7
+ export const computeSha256 = (content) => {
8
+ const hash = createHash("sha256");
9
+ hash.update(content);
10
+ return hash.digest("hex");
11
+ };
@@ -0,0 +1 @@
1
+ export declare const isSafeRelPath: (p: string) => boolean;
@@ -0,0 +1,5 @@
1
+ export const isSafeRelPath = (p) => p.length > 0 &&
2
+ !p.startsWith("/") &&
3
+ !p.includes("\\") &&
4
+ !/^[A-Za-z]:/.test(p) &&
5
+ !p.split("/").includes("..");
@@ -1,5 +1,6 @@
1
1
  import { readFile, writeFile, mkdir } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
+ import { isSafeRelPath } from "./safe-rel-path.js";
3
4
  const ACCEL_DIR = ".accel";
4
5
  const SETTINGS_FILE = "settings.json";
5
6
  const HASHSUM_FILE = "hashsum.txt";
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intra-mart/accel",
3
- "version": "0.4.0",
3
+ "version": "0.5.0-dev.202608030656",
4
4
  "type": "module",
5
5
  "description": "CLI tool for intra-mart Accel Platform development",
6
6
  "author": "NTT DATA INTRAMART",