@oss-ma/tpl 1.0.30 → 1.0.31

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.
@@ -1,67 +1,38 @@
1
1
  // cli/src/engine/prompt.ts
2
- import prompts from "prompts";
2
+ import { input, select } from "@inquirer/prompts";
3
3
  export async function askQuestions(questions, opts = {}) {
4
4
  if (!questions?.length)
5
5
  return {};
6
- // --yes : aucune interaction, on prend les defaults
6
+ // --yes : no interaction, use defaults
7
7
  if (opts.yes) {
8
8
  const answers = {};
9
9
  for (const q of questions)
10
10
  answers[q.name] = String(q.default ?? "");
11
11
  return answers;
12
12
  }
13
- const defs = questions.map((q) => {
14
- const base = {
15
- name: q.name,
16
- message: q.message,
17
- initial: q.default
18
- };
19
- if (q.choices?.length) {
20
- return { type: "select", ...base, choices: q.choices.map((c) => ({ title: c, value: c })) };
21
- }
22
- return { type: "text", ...base };
23
- });
24
- // Sur certains terminaux Windows, prompts peut déclencher onCancel inopinément.
25
- // Stratégie: si cancel -> fallback sur defaults au lieu de crash.
26
- const res = (await prompts(defs, {
27
- onCancel: () => true
28
- }));
29
13
  const out = {};
30
14
  for (const q of questions) {
31
- const v = res[q.name];
32
- out[q.name] = v !== undefined && v !== null && String(v).length > 0 ? String(v) : String(q.default ?? "");
15
+ try {
16
+ if (q.choices?.length) {
17
+ const answer = await select({
18
+ message: q.message,
19
+ default: q.default,
20
+ choices: q.choices.map((c) => ({ name: c, value: c })),
21
+ });
22
+ out[q.name] = String(answer);
23
+ }
24
+ else {
25
+ const answer = await input({
26
+ message: q.message,
27
+ default: String(q.default ?? ""),
28
+ });
29
+ out[q.name] = answer.trim() || String(q.default ?? "");
30
+ }
31
+ }
32
+ catch {
33
+ // User cancelled (Ctrl+C) → fallback to default
34
+ out[q.name] = String(q.default ?? "");
35
+ }
33
36
  }
34
37
  return out;
35
38
  }
36
- // import prompts from "prompts";
37
- // import type { TemplateQuestion } from "./loadTemplate.js";
38
- // export async function askQuestions(
39
- // questions: TemplateQuestion[] | undefined,
40
- // opts: { yes?: boolean } = {}
41
- // ): Promise<Record<string, string>> {
42
- // if (!questions?.length) return {};
43
- // if (opts.yes) {
44
- // const answers: Record<string, string> = {};
45
- // for (const q of questions) {
46
- // answers[q.name] = String(q.default ?? "");
47
- // }
48
- // return answers;
49
- // }
50
- // const defs = questions.map((q) => {
51
- // const base: any = {
52
- // name: q.name,
53
- // message: q.message,
54
- // initial: q.default
55
- // };
56
- // if (q.choices?.length) {
57
- // return { type: "select", ...base, choices: q.choices.map((c) => ({ title: c, value: c })) };
58
- // }
59
- // return { type: "text", ...base };
60
- // });
61
- // const res = await prompts(defs, {
62
- // onCancel: () => {
63
- // throw new Error("Cancelled by user.");
64
- // }
65
- // });
66
- // return res as Record<string, string>;
67
- // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oss-ma/tpl",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "description": "Generate, enforce and maintain clean project architectures",
5
5
  "type": "module",
6
6
  "repository": {
@@ -27,18 +27,17 @@
27
27
  "test:smoke": "node --test dist/tests/smoke.test.js"
28
28
  },
29
29
  "dependencies": {
30
+ "@inquirer/prompts": "^8.2.1",
30
31
  "commander": "^12.1.0",
31
32
  "execa": "^9.3.0",
32
33
  "fs-extra": "^11.2.0",
33
34
  "picocolors": "^1.0.0",
34
- "prompts": "^2.4.2",
35
35
  "yaml": "^2.5.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/fs-extra": "^11.0.4",
39
39
  "@types/node": "^22.7.0",
40
- "@types/prompts": "^2.4.9",
41
40
  "tsx": "^4.16.2",
42
41
  "typescript": "^5.5.4"
43
42
  }
44
- }
43
+ }