@effijs/forge 1.0.0-alpha.1 → 1.0.0-alpha.2
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 +1 -1
- package/src/Forge.js +23 -1
- package/src/cli/ForgeCLI.js +2 -1
package/package.json
CHANGED
package/src/Forge.js
CHANGED
|
@@ -13,6 +13,15 @@ import { addFile } from "./fs/addFile.js";
|
|
|
13
13
|
import { modifyFile, appendToFile } from "./fs/modifyFile.js";
|
|
14
14
|
import { processTemplate, processDirectory } from "./fs/processTemplate.js";
|
|
15
15
|
|
|
16
|
+
function collectActionErrors(result, errors = []) {
|
|
17
|
+
if (!result || typeof result !== "object") return errors;
|
|
18
|
+
if (result.success === false && result.error) errors.push(String(result.error));
|
|
19
|
+
if (Array.isArray(result.results)) {
|
|
20
|
+
for (const child of result.results) collectActionErrors(child, errors);
|
|
21
|
+
}
|
|
22
|
+
return errors;
|
|
23
|
+
}
|
|
24
|
+
|
|
16
25
|
async function applyPromptDefaults(questions, options) {
|
|
17
26
|
const answers = {};
|
|
18
27
|
const list = Array.isArray(questions) ? questions : [];
|
|
@@ -145,9 +154,15 @@ export class Forge {
|
|
|
145
154
|
typeof generator.prompts === "function"
|
|
146
155
|
? await generator.prompts(this)
|
|
147
156
|
: generator.prompts;
|
|
148
|
-
|
|
157
|
+
const useDefaults = yes || dryRun;
|
|
158
|
+
answers = useDefaults
|
|
149
159
|
? await applyPromptDefaults(questions, options)
|
|
150
160
|
: await this.prompt(questions);
|
|
161
|
+
if (dryRun && !yes && Array.isArray(questions) && questions.length) {
|
|
162
|
+
console.log(
|
|
163
|
+
chalk.dim("Dry run is using prompt defaults. Pass flags to override.\n"),
|
|
164
|
+
);
|
|
165
|
+
}
|
|
151
166
|
}
|
|
152
167
|
|
|
153
168
|
const data = { ...answers, ...options };
|
|
@@ -166,9 +181,16 @@ export class Forge {
|
|
|
166
181
|
const { results, hasFailure } = await runActions(generator, ctx);
|
|
167
182
|
|
|
168
183
|
if (hasFailure) {
|
|
184
|
+
const errors = [
|
|
185
|
+
...new Set(results.flatMap((result) => collectActionErrors(result))),
|
|
186
|
+
];
|
|
169
187
|
console.error(
|
|
170
188
|
chalk.red("\n❌ Generation failed — one or more actions failed\n"),
|
|
171
189
|
);
|
|
190
|
+
for (const error of errors) {
|
|
191
|
+
console.error(chalk.red(`• ${error}`));
|
|
192
|
+
}
|
|
193
|
+
if (errors.length) console.error("");
|
|
172
194
|
return { success: false, results };
|
|
173
195
|
}
|
|
174
196
|
|
package/src/cli/ForgeCLI.js
CHANGED
|
@@ -44,7 +44,8 @@ export class ForgeCLI {
|
|
|
44
44
|
|
|
45
45
|
Object.assign(runOptions, parseUnknownFlags(this.argv ?? process.argv));
|
|
46
46
|
|
|
47
|
-
await this.forge.run(generator, runOptions);
|
|
47
|
+
const result = await this.forge.run(generator, runOptions);
|
|
48
|
+
if (result?.success === false) process.exitCode = 1;
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
this.program
|