@effijs/forge 1.0.0-alpha.1 → 1.0.0-alpha.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effijs/forge",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.3",
4
4
  "type": "module",
5
5
  "description": "Modern scaffolding engine for EffiJS",
6
6
  "author": "Yevhenii Kyrychok",
package/src/Forge.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import path from "path";
2
+ import "./shims/repairInquirer.js";
2
3
  import inquirer from "inquirer";
3
4
  import chalk from "chalk";
4
5
  import { compileHandlebars, registerHandlebarsHelpers } from "./engines/handlebars.js";
@@ -13,6 +14,15 @@ import { addFile } from "./fs/addFile.js";
13
14
  import { modifyFile, appendToFile } from "./fs/modifyFile.js";
14
15
  import { processTemplate, processDirectory } from "./fs/processTemplate.js";
15
16
 
17
+ function collectActionErrors(result, errors = []) {
18
+ if (!result || typeof result !== "object") return errors;
19
+ if (result.success === false && result.error) errors.push(String(result.error));
20
+ if (Array.isArray(result.results)) {
21
+ for (const child of result.results) collectActionErrors(child, errors);
22
+ }
23
+ return errors;
24
+ }
25
+
16
26
  async function applyPromptDefaults(questions, options) {
17
27
  const answers = {};
18
28
  const list = Array.isArray(questions) ? questions : [];
@@ -145,9 +155,15 @@ export class Forge {
145
155
  typeof generator.prompts === "function"
146
156
  ? await generator.prompts(this)
147
157
  : generator.prompts;
148
- answers = yes
158
+ const useDefaults = yes || dryRun;
159
+ answers = useDefaults
149
160
  ? await applyPromptDefaults(questions, options)
150
161
  : await this.prompt(questions);
162
+ if (dryRun && !yes && Array.isArray(questions) && questions.length) {
163
+ console.log(
164
+ chalk.dim("Dry run is using prompt defaults. Pass flags to override.\n"),
165
+ );
166
+ }
151
167
  }
152
168
 
153
169
  const data = { ...answers, ...options };
@@ -166,9 +182,16 @@ export class Forge {
166
182
  const { results, hasFailure } = await runActions(generator, ctx);
167
183
 
168
184
  if (hasFailure) {
185
+ const errors = [
186
+ ...new Set(results.flatMap((result) => collectActionErrors(result))),
187
+ ];
169
188
  console.error(
170
189
  chalk.red("\n❌ Generation failed — one or more actions failed\n"),
171
190
  );
191
+ for (const error of errors) {
192
+ console.error(chalk.red(`• ${error}`));
193
+ }
194
+ if (errors.length) console.error("");
172
195
  return { success: false, results };
173
196
  }
174
197
 
@@ -1,4 +1,5 @@
1
1
  import { Command } from "commander";
2
+ import "../shims/repairInquirer.js";
2
3
  import inquirer from "inquirer";
3
4
  import fs from "fs/promises";
4
5
  import path from "path";
@@ -44,7 +45,8 @@ export class ForgeCLI {
44
45
 
45
46
  Object.assign(runOptions, parseUnknownFlags(this.argv ?? process.argv));
46
47
 
47
- await this.forge.run(generator, runOptions);
48
+ const result = await this.forge.run(generator, runOptions);
49
+ if (result?.success === false) process.exitCode = 1;
48
50
  });
49
51
 
50
52
  this.program
@@ -0,0 +1,18 @@
1
+ import Module from "node:module";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const shim = fileURLToPath(new URL("./strip-ansi.cjs", import.meta.url));
6
+ const inquirerDir = `${path.sep}inquirer${path.sep}`;
7
+ const original = Module._resolveFilename;
8
+
9
+ if (!original.__forgeStripAnsi) {
10
+ function resolveFilename(request, parent, ...rest) {
11
+ if (request === "strip-ansi" && parent?.filename?.includes(inquirerDir)) {
12
+ return shim;
13
+ }
14
+ return original.call(this, request, parent, ...rest);
15
+ }
16
+ resolveFilename.__forgeStripAnsi = true;
17
+ Module._resolveFilename = resolveFilename;
18
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ // inquirer 9's nested ora@5 does require("strip-ansi") and expects the v6 function.
4
+ // A hoisted strip-ansi v7 is ESM, so Node's require() returns a module namespace.
5
+ function ansiRegex() {
6
+ const pattern = [
7
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
8
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
9
+ ].join("|");
10
+ return new RegExp(pattern, "g");
11
+ }
12
+
13
+ module.exports = function stripAnsi(string) {
14
+ if (typeof string !== "string") return string;
15
+ return string.replace(ansiRegex(), "");
16
+ };