@solid-stack/mason 1.0.24 → 1.0.25
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/dist/bin.cjs +363 -272
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +360 -269
- package/dist/bin.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/commands/env.d.ts +3 -0
- package/dist/commands/env.d.ts.map +1 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/menu.d.ts.map +1 -1
- package/dist/index.cjs +291 -198
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +288 -197
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { cac } from 'cac';
|
|
3
|
-
import * as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import * as p15 from '@clack/prompts';
|
|
4
|
+
import pc15 from 'picocolors';
|
|
5
|
+
import fs10 from 'fs';
|
|
6
6
|
import path2 from 'path';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import Handlebars from 'handlebars';
|
|
@@ -12,7 +12,7 @@ import { createHash } from 'crypto';
|
|
|
12
12
|
function writeFileSafely(absolutePath, content, options = {}) {
|
|
13
13
|
const projectRoot = options.projectRoot || process.cwd();
|
|
14
14
|
const relPath = path2.relative(projectRoot, absolutePath).replace(/\\/g, "/");
|
|
15
|
-
const existedBefore =
|
|
15
|
+
const existedBefore = fs10.existsSync(absolutePath);
|
|
16
16
|
if (options.dryRun) {
|
|
17
17
|
return {
|
|
18
18
|
relativePath: relPath,
|
|
@@ -32,10 +32,10 @@ function writeFileSafely(absolutePath, content, options = {}) {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
const dir = path2.dirname(absolutePath);
|
|
35
|
-
if (!
|
|
36
|
-
|
|
35
|
+
if (!fs10.existsSync(dir)) {
|
|
36
|
+
fs10.mkdirSync(dir, { recursive: true });
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
fs10.writeFileSync(absolutePath, content, "utf-8");
|
|
39
39
|
return {
|
|
40
40
|
relativePath: relPath,
|
|
41
41
|
absolutePath,
|
|
@@ -47,17 +47,17 @@ function writeFileSafely(absolutePath, content, options = {}) {
|
|
|
47
47
|
function printGeneratedFiles(files, isDryRun = false) {
|
|
48
48
|
console.log("");
|
|
49
49
|
if (isDryRun) {
|
|
50
|
-
|
|
50
|
+
p15.log.warn(pc15.yellow(pc15.bold("[DRY RUN PREVIEW] No files were written to disk.")));
|
|
51
51
|
}
|
|
52
52
|
for (const f of files) {
|
|
53
53
|
if (f.action === "created") {
|
|
54
|
-
|
|
54
|
+
p15.log.success(`${pc15.bold(f.relativePath)} ${pc15.dim("(created)")}`);
|
|
55
55
|
} else if (f.action === "overwritten") {
|
|
56
|
-
|
|
56
|
+
p15.log.warn(`${pc15.bold(f.relativePath)} ${pc15.dim("(overwritten)")}`);
|
|
57
57
|
} else if (f.action === "skipped") {
|
|
58
|
-
|
|
58
|
+
p15.log.info(`${pc15.dim(f.relativePath)} ${pc15.dim("(skipped - already exists, pass -o to overwrite)")}`);
|
|
59
59
|
} else {
|
|
60
|
-
|
|
60
|
+
p15.log.info(`${pc15.bold(f.relativePath)} ${pc15.dim("(preview)")}`);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -129,9 +129,9 @@ function loadMasonConfig(startDir = process.cwd()) {
|
|
|
129
129
|
let current = path2.resolve(startDir);
|
|
130
130
|
while (true) {
|
|
131
131
|
const configPath = path2.join(current, "mason.config.json");
|
|
132
|
-
if (
|
|
132
|
+
if (fs10.existsSync(configPath)) {
|
|
133
133
|
try {
|
|
134
|
-
return JSON.parse(
|
|
134
|
+
return JSON.parse(fs10.readFileSync(configPath, "utf-8"));
|
|
135
135
|
} catch {
|
|
136
136
|
return null;
|
|
137
137
|
}
|
|
@@ -146,7 +146,7 @@ function getEffectiveMode(projectRoot, flags) {
|
|
|
146
146
|
if (flags?.registry) return "registry";
|
|
147
147
|
const config = loadMasonConfig(projectRoot);
|
|
148
148
|
if (config?.mode) return config.mode;
|
|
149
|
-
if (
|
|
149
|
+
if (fs10.existsSync(path2.join(projectRoot, "index.json")) && (fs10.existsSync(path2.join(projectRoot, "features")) || fs10.existsSync(path2.join(projectRoot, "shared")) || fs10.existsSync(path2.join(projectRoot, "src/features")) || fs10.existsSync(path2.join(projectRoot, "src/shared")))) {
|
|
150
150
|
return "registry";
|
|
151
151
|
}
|
|
152
152
|
return "app";
|
|
@@ -160,12 +160,12 @@ function getConfiguredFeaturesDir(projectRoot, flags) {
|
|
|
160
160
|
}
|
|
161
161
|
const mode = getEffectiveMode(projectRoot, flags);
|
|
162
162
|
if (mode === "registry") {
|
|
163
|
-
if (
|
|
163
|
+
if (fs10.existsSync(path2.join(projectRoot, "src/features"))) {
|
|
164
164
|
return path2.join(projectRoot, "src/features");
|
|
165
165
|
}
|
|
166
166
|
return path2.join(projectRoot, "features");
|
|
167
167
|
}
|
|
168
|
-
if (
|
|
168
|
+
if (fs10.existsSync(path2.join(projectRoot, "src/features"))) {
|
|
169
169
|
return path2.join(projectRoot, "src/features");
|
|
170
170
|
}
|
|
171
171
|
return path2.join(projectRoot, "features");
|
|
@@ -179,12 +179,12 @@ function getConfiguredSharedDir(projectRoot, flags) {
|
|
|
179
179
|
}
|
|
180
180
|
const mode = getEffectiveMode(projectRoot, flags);
|
|
181
181
|
if (mode === "registry") {
|
|
182
|
-
if (
|
|
182
|
+
if (fs10.existsSync(path2.join(projectRoot, "src/shared"))) {
|
|
183
183
|
return path2.join(projectRoot, "src/shared");
|
|
184
184
|
}
|
|
185
185
|
return path2.join(projectRoot, "shared");
|
|
186
186
|
}
|
|
187
|
-
if (
|
|
187
|
+
if (fs10.existsSync(path2.join(projectRoot, "src/shared"))) {
|
|
188
188
|
return path2.join(projectRoot, "src/shared");
|
|
189
189
|
}
|
|
190
190
|
return path2.join(projectRoot, "shared");
|
|
@@ -194,7 +194,7 @@ function getConfiguredSharedDir(projectRoot, flags) {
|
|
|
194
194
|
function findProjectRoot(startDir = process.cwd()) {
|
|
195
195
|
let current = path2.resolve(startDir);
|
|
196
196
|
while (true) {
|
|
197
|
-
if (
|
|
197
|
+
if (fs10.existsSync(path2.join(current, "package.json"))) {
|
|
198
198
|
return current;
|
|
199
199
|
}
|
|
200
200
|
const parent = path2.dirname(current);
|
|
@@ -212,9 +212,9 @@ function resolveSharedDir(projectRoot, flags) {
|
|
|
212
212
|
}
|
|
213
213
|
function listExistingFeatures(projectRoot) {
|
|
214
214
|
const featuresDir = resolveFeaturesDir(projectRoot);
|
|
215
|
-
if (!
|
|
215
|
+
if (!fs10.existsSync(featuresDir)) return [];
|
|
216
216
|
try {
|
|
217
|
-
const entries =
|
|
217
|
+
const entries = fs10.readdirSync(featuresDir, { withFileTypes: true });
|
|
218
218
|
return entries.filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
219
219
|
} catch {
|
|
220
220
|
return [];
|
|
@@ -225,9 +225,9 @@ function listDomainInterfaces(projectRoot, featureName) {
|
|
|
225
225
|
const features = featureName ? [featureName] : listExistingFeatures(projectRoot);
|
|
226
226
|
for (const feat of features) {
|
|
227
227
|
const domainDir = path2.join(resolveFeaturesDir(projectRoot), feat, "domain");
|
|
228
|
-
if (!
|
|
228
|
+
if (!fs10.existsSync(domainDir)) continue;
|
|
229
229
|
try {
|
|
230
|
-
const files =
|
|
230
|
+
const files = fs10.readdirSync(domainDir);
|
|
231
231
|
for (const file of files) {
|
|
232
232
|
if (file.endsWith(".ts") && !file.endsWith(".test.ts") && !file.endsWith(".d.ts")) {
|
|
233
233
|
const name = file.replace(/\.ts$/, "");
|
|
@@ -240,7 +240,7 @@ function listDomainInterfaces(projectRoot, featureName) {
|
|
|
240
240
|
});
|
|
241
241
|
} else {
|
|
242
242
|
try {
|
|
243
|
-
const content =
|
|
243
|
+
const content = fs10.readFileSync(fullPath, "utf-8");
|
|
244
244
|
if (/export\s+(?:abstract\s+class|interface)\s+(\w+)/.test(content)) {
|
|
245
245
|
results.push({
|
|
246
246
|
name,
|
|
@@ -263,9 +263,9 @@ function listDomainEntities(projectRoot, featureName) {
|
|
|
263
263
|
const features = featureName ? [featureName] : listExistingFeatures(projectRoot);
|
|
264
264
|
for (const feat of features) {
|
|
265
265
|
const domainDir = path2.join(resolveFeaturesDir(projectRoot), feat, "domain");
|
|
266
|
-
if (!
|
|
266
|
+
if (!fs10.existsSync(domainDir)) continue;
|
|
267
267
|
try {
|
|
268
|
-
const files =
|
|
268
|
+
const files = fs10.readdirSync(domainDir);
|
|
269
269
|
for (const file of files) {
|
|
270
270
|
if (file.endsWith(".ts") && !file.endsWith(".test.ts") && !file.endsWith(".d.ts")) {
|
|
271
271
|
const name = file.replace(/\.ts$/, "");
|
|
@@ -288,9 +288,9 @@ function listUseCases(projectRoot, featureName) {
|
|
|
288
288
|
const features = featureName ? [featureName] : listExistingFeatures(projectRoot);
|
|
289
289
|
for (const feat of features) {
|
|
290
290
|
const useCasesDir = path2.join(resolveFeaturesDir(projectRoot), feat, "useCases");
|
|
291
|
-
if (!
|
|
291
|
+
if (!fs10.existsSync(useCasesDir)) continue;
|
|
292
292
|
try {
|
|
293
|
-
const files =
|
|
293
|
+
const files = fs10.readdirSync(useCasesDir);
|
|
294
294
|
for (const file of files) {
|
|
295
295
|
if (file.endsWith(".ts") && !file.endsWith(".test.ts") && !file.endsWith(".d.ts")) {
|
|
296
296
|
const name = file.replace(/\.ts$/, "");
|
|
@@ -322,29 +322,29 @@ hbs.registerHelper("join", (arr, sep) => {
|
|
|
322
322
|
});
|
|
323
323
|
var cachedTemplatesDir = null;
|
|
324
324
|
function getTemplatesDir() {
|
|
325
|
-
if (cachedTemplatesDir &&
|
|
325
|
+
if (cachedTemplatesDir && fs10.existsSync(cachedTemplatesDir)) {
|
|
326
326
|
return cachedTemplatesDir;
|
|
327
327
|
}
|
|
328
328
|
const currentDir = typeof __dirname !== "undefined" ? __dirname : path2.dirname(fileURLToPath(import.meta.url));
|
|
329
329
|
const cand1 = path2.resolve(currentDir, "../../templates");
|
|
330
|
-
if (
|
|
330
|
+
if (fs10.existsSync(cand1)) {
|
|
331
331
|
cachedTemplatesDir = cand1;
|
|
332
332
|
return cand1;
|
|
333
333
|
}
|
|
334
334
|
const cand2 = path2.resolve(currentDir, "../templates");
|
|
335
|
-
if (
|
|
335
|
+
if (fs10.existsSync(cand2)) {
|
|
336
336
|
cachedTemplatesDir = cand2;
|
|
337
337
|
return cand2;
|
|
338
338
|
}
|
|
339
339
|
const cand3 = path2.resolve(currentDir, "templates");
|
|
340
|
-
if (
|
|
340
|
+
if (fs10.existsSync(cand3)) {
|
|
341
341
|
cachedTemplatesDir = cand3;
|
|
342
342
|
return cand3;
|
|
343
343
|
}
|
|
344
344
|
let curr = currentDir;
|
|
345
345
|
while (true) {
|
|
346
346
|
const candTemplates = path2.join(curr, "templates");
|
|
347
|
-
if (
|
|
347
|
+
if (fs10.existsSync(candTemplates)) {
|
|
348
348
|
cachedTemplatesDir = candTemplates;
|
|
349
349
|
return candTemplates;
|
|
350
350
|
}
|
|
@@ -357,7 +357,7 @@ function getTemplatesDir() {
|
|
|
357
357
|
var templateCache = /* @__PURE__ */ new Map();
|
|
358
358
|
function loadTemplate(relativePath) {
|
|
359
359
|
const fullPath = path2.isAbsolute(relativePath) ? relativePath : path2.join(getTemplatesDir(), relativePath);
|
|
360
|
-
return
|
|
360
|
+
return fs10.readFileSync(fullPath, "utf-8");
|
|
361
361
|
}
|
|
362
362
|
function renderTemplateFile(relativePath, context) {
|
|
363
363
|
let compiled = templateCache.get(relativePath);
|
|
@@ -469,7 +469,7 @@ function generateInterfaceCode(ifaceName, kind = "abstractClass", entityName, me
|
|
|
469
469
|
const idKey = `${entityKey}Id`;
|
|
470
470
|
const listKey = `${entityKey}s`;
|
|
471
471
|
const formattedCustomMethods = customMethods.map((m) => {
|
|
472
|
-
const params = m.params && m.params.length > 0 ? m.params.map((
|
|
472
|
+
const params = m.params && m.params.length > 0 ? m.params.map((p18) => `${p18.name}: ${p18.type}`).join("; ") : "";
|
|
473
473
|
const returnType = m.returnType ? `Promise<${m.returnType}>` : "Promise<void>";
|
|
474
474
|
return {
|
|
475
475
|
name: m.name,
|
|
@@ -730,7 +730,7 @@ function parseInterfaceMethodsAndImports(content, targetIfaceName) {
|
|
|
730
730
|
};
|
|
731
731
|
}
|
|
732
732
|
function findInterfaceFile(projectRoot, ifaceName, featureName, customPath) {
|
|
733
|
-
if (customPath &&
|
|
733
|
+
if (customPath && fs10.existsSync(customPath)) {
|
|
734
734
|
return { filePath: customPath, ifaceName };
|
|
735
735
|
}
|
|
736
736
|
const candidateNames = [
|
|
@@ -741,21 +741,21 @@ function findInterfaceFile(projectRoot, ifaceName, featureName, customPath) {
|
|
|
741
741
|
const features = featureName ? [featureName, ...listExistingFeatures(projectRoot).filter((f) => f !== featureName)] : listExistingFeatures(projectRoot);
|
|
742
742
|
for (const feat of features) {
|
|
743
743
|
const domainDir = path2.join(resolveFeaturesDir(projectRoot), feat, "domain");
|
|
744
|
-
if (!
|
|
744
|
+
if (!fs10.existsSync(domainDir)) continue;
|
|
745
745
|
for (const cand of candidateNames) {
|
|
746
746
|
const p1 = path2.join(domainDir, `${cand}.ts`);
|
|
747
|
-
if (
|
|
747
|
+
if (fs10.existsSync(p1)) {
|
|
748
748
|
return { filePath: p1, ifaceName: cand, feature: feat };
|
|
749
749
|
}
|
|
750
750
|
}
|
|
751
751
|
}
|
|
752
752
|
for (const cand of candidateNames) {
|
|
753
753
|
const p1 = path2.join(projectRoot, "domain", `${cand}.ts`);
|
|
754
|
-
if (
|
|
754
|
+
if (fs10.existsSync(p1)) return { filePath: p1, ifaceName: cand };
|
|
755
755
|
const p22 = path2.join(projectRoot, "src", "domain", `${cand}.ts`);
|
|
756
|
-
if (
|
|
756
|
+
if (fs10.existsSync(p22)) return { filePath: p22, ifaceName: cand };
|
|
757
757
|
const p32 = path2.join(projectRoot, "interfaces", `${cand}.ts`);
|
|
758
|
-
if (
|
|
758
|
+
if (fs10.existsSync(p32)) return { filePath: p32, ifaceName: cand };
|
|
759
759
|
}
|
|
760
760
|
return null;
|
|
761
761
|
}
|
|
@@ -778,7 +778,7 @@ function loadInterfaceHierarchy(projectRoot, initialIfaceName, featureName, cust
|
|
|
778
778
|
while (currentFile && !visited.has(currentFile)) {
|
|
779
779
|
visited.add(currentFile);
|
|
780
780
|
try {
|
|
781
|
-
const content =
|
|
781
|
+
const content = fs10.readFileSync(currentFile, "utf-8");
|
|
782
782
|
const parsed = parseInterfaceMethodsAndImports(content, currentName);
|
|
783
783
|
for (const m of parsed.methods) {
|
|
784
784
|
if (!allMethods.some((existing) => existing.name === m.name)) {
|
|
@@ -1050,22 +1050,22 @@ function generateUseCaseCode(useCaseName, dependencies = [], inputProps = [], ou
|
|
|
1050
1050
|
from: /^I[A-Z]/.test(dep) ? `../domain/${dep}.js` : `./${dep}.js`
|
|
1051
1051
|
}));
|
|
1052
1052
|
const domainTypesToImport = new Set(domainImports);
|
|
1053
|
-
for (const
|
|
1054
|
-
const rawType =
|
|
1053
|
+
for (const p18 of [...inputProps, ...outputProps]) {
|
|
1054
|
+
const rawType = p18.type.trim();
|
|
1055
1055
|
const baseType = rawType.replace(/\[\]$/, "").trim();
|
|
1056
1056
|
if (!primitiveTypes.has(baseType) && /^[A-Z][A-Za-z0-9_]*$/.test(baseType) && !dependencies.includes(baseType)) {
|
|
1057
1057
|
domainTypesToImport.add(baseType);
|
|
1058
1058
|
}
|
|
1059
1059
|
}
|
|
1060
|
-
const formattedInputProps = inputProps.map((
|
|
1061
|
-
name:
|
|
1062
|
-
optional:
|
|
1063
|
-
type:
|
|
1060
|
+
const formattedInputProps = inputProps.map((p18) => ({
|
|
1061
|
+
name: p18.name,
|
|
1062
|
+
optional: p18.optional,
|
|
1063
|
+
type: p18.optional && !p18.type.includes("undefined") ? `${p18.type} | undefined` : p18.type
|
|
1064
1064
|
}));
|
|
1065
|
-
const formattedOutputProps = outputProps.map((
|
|
1066
|
-
name:
|
|
1067
|
-
optional:
|
|
1068
|
-
type:
|
|
1065
|
+
const formattedOutputProps = outputProps.map((p18) => ({
|
|
1066
|
+
name: p18.name,
|
|
1067
|
+
optional: p18.optional,
|
|
1068
|
+
type: p18.optional && !p18.type.includes("undefined") ? `${p18.type} | undefined` : p18.type
|
|
1069
1069
|
}));
|
|
1070
1070
|
const formattedDeps = dependencies.map((dep) => ({
|
|
1071
1071
|
key: toCamelCase(dep),
|
|
@@ -1252,7 +1252,7 @@ function generateHttpHandler(options) {
|
|
|
1252
1252
|
const pxDir = path2.join(resolveFeaturesDir(projectRoot), options.feature, "pxExpress");
|
|
1253
1253
|
const handlersDir = path2.join(pxDir, "handlers");
|
|
1254
1254
|
const pxIndexPath = path2.join(pxDir, "index.ts");
|
|
1255
|
-
if (!
|
|
1255
|
+
if (!fs10.existsSync(pxIndexPath)) {
|
|
1256
1256
|
const featurePath = options.routePrefix || `/${options.feature.toLowerCase()}`;
|
|
1257
1257
|
const pxIndexContent = renderTemplate(expressIndexTemplate, {
|
|
1258
1258
|
routePath: featurePath
|
|
@@ -1289,8 +1289,8 @@ function updateOrGenerateDiProvider(featureDir, featureName, bindings = [], opti
|
|
|
1289
1289
|
const providerPath = path2.join(featureDir, "diProvider.ts");
|
|
1290
1290
|
const pascalFeature = toPascalCase(featureName);
|
|
1291
1291
|
const providerModuleName = `${pascalFeature}Provider`;
|
|
1292
|
-
if (
|
|
1293
|
-
let content =
|
|
1292
|
+
if (fs10.existsSync(providerPath) && !options.overwrite) {
|
|
1293
|
+
let content = fs10.readFileSync(providerPath, "utf-8");
|
|
1294
1294
|
content = content.replace(/\n*export\s+const\s+ScaffoldProvider\s*=[^;]+;?/g, "");
|
|
1295
1295
|
for (const b of bindings) {
|
|
1296
1296
|
const ifaceImp = b.ifaceImportPath || `./domain/${b.ifaceName}.js`;
|
|
@@ -1736,23 +1736,23 @@ var PromptCancelledError = class extends Error {
|
|
|
1736
1736
|
}
|
|
1737
1737
|
};
|
|
1738
1738
|
function handleCancel(result) {
|
|
1739
|
-
if (
|
|
1740
|
-
|
|
1739
|
+
if (p15.isCancel(result)) {
|
|
1740
|
+
p15.cancel("Operation cancelled.");
|
|
1741
1741
|
throw new PromptCancelledError();
|
|
1742
1742
|
}
|
|
1743
1743
|
return result;
|
|
1744
1744
|
}
|
|
1745
1745
|
function printBanner() {
|
|
1746
1746
|
console.log("");
|
|
1747
|
-
|
|
1747
|
+
p15.intro(pc15.bgCyan(pc15.black(" @solid-stack/mason ")));
|
|
1748
1748
|
}
|
|
1749
1749
|
async function promptProperties(options = {}) {
|
|
1750
1750
|
const properties = options.defaults ? [...options.defaults] : [];
|
|
1751
1751
|
if (properties.length > 0) {
|
|
1752
|
-
const summary = properties.map((
|
|
1753
|
-
|
|
1752
|
+
const summary = properties.map((p18) => `${p18.name}: ${p18.type}${p18.optional ? "?" : ""}`).join(", ");
|
|
1753
|
+
p15.log.info(pc15.dim(`Pre-configured fields: ${summary}`));
|
|
1754
1754
|
const addMore = handleCancel(
|
|
1755
|
-
await
|
|
1755
|
+
await p15.confirm({
|
|
1756
1756
|
message: "Would you like to add custom fields/properties?",
|
|
1757
1757
|
initialValue: false
|
|
1758
1758
|
})
|
|
@@ -1761,10 +1761,10 @@ async function promptProperties(options = {}) {
|
|
|
1761
1761
|
return properties;
|
|
1762
1762
|
}
|
|
1763
1763
|
}
|
|
1764
|
-
|
|
1764
|
+
p15.log.info(pc15.cyan("Enter properties (leave name blank when finished):"));
|
|
1765
1765
|
while (true) {
|
|
1766
1766
|
const name = handleCancel(
|
|
1767
|
-
await
|
|
1767
|
+
await p15.text({
|
|
1768
1768
|
message: "Property name (or press Enter to finish):",
|
|
1769
1769
|
placeholder: "e.g. title, email, status"
|
|
1770
1770
|
})
|
|
@@ -1773,7 +1773,7 @@ async function promptProperties(options = {}) {
|
|
|
1773
1773
|
break;
|
|
1774
1774
|
}
|
|
1775
1775
|
const type = handleCancel(
|
|
1776
|
-
await
|
|
1776
|
+
await p15.select({
|
|
1777
1777
|
message: `Type for property "${name.trim()}":`,
|
|
1778
1778
|
options: [
|
|
1779
1779
|
{ value: "string", label: "string" },
|
|
@@ -1790,7 +1790,7 @@ async function promptProperties(options = {}) {
|
|
|
1790
1790
|
let finalType = type;
|
|
1791
1791
|
if (type === "custom") {
|
|
1792
1792
|
finalType = handleCancel(
|
|
1793
|
-
await
|
|
1793
|
+
await p15.text({
|
|
1794
1794
|
message: `Enter custom type for "${name.trim()}":`,
|
|
1795
1795
|
placeholder: "e.g. UserRole, string | null",
|
|
1796
1796
|
validate: (val) => val && val.trim() ? void 0 : "Type cannot be empty"
|
|
@@ -1798,7 +1798,7 @@ async function promptProperties(options = {}) {
|
|
|
1798
1798
|
);
|
|
1799
1799
|
}
|
|
1800
1800
|
const optional = handleCancel(
|
|
1801
|
-
await
|
|
1801
|
+
await p15.confirm({
|
|
1802
1802
|
message: `Is "${name.trim()}" optional?`,
|
|
1803
1803
|
initialValue: false
|
|
1804
1804
|
})
|
|
@@ -1808,8 +1808,8 @@ async function promptProperties(options = {}) {
|
|
|
1808
1808
|
type: finalType.trim(),
|
|
1809
1809
|
optional
|
|
1810
1810
|
});
|
|
1811
|
-
|
|
1812
|
-
|
|
1811
|
+
p15.log.success(
|
|
1812
|
+
pc15.green(`Added: ${name.trim()}${optional ? "?" : ""}: ${finalType.trim()}`)
|
|
1813
1813
|
);
|
|
1814
1814
|
}
|
|
1815
1815
|
return properties;
|
|
@@ -1825,7 +1825,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
1825
1825
|
}
|
|
1826
1826
|
if (!name) {
|
|
1827
1827
|
name = handleCancel(
|
|
1828
|
-
await
|
|
1828
|
+
await p15.text({
|
|
1829
1829
|
message: "What is the feature name?",
|
|
1830
1830
|
placeholder: "e.g. users, auth, orders, billing",
|
|
1831
1831
|
validate: (val) => {
|
|
@@ -1841,7 +1841,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
1841
1841
|
let targetDirRel = defaultDir;
|
|
1842
1842
|
if (!flags.yes && !flags.target && !flags.dest) {
|
|
1843
1843
|
targetDirRel = handleCancel(
|
|
1844
|
-
await
|
|
1844
|
+
await p15.text({
|
|
1845
1845
|
message: "Target directory for the feature:",
|
|
1846
1846
|
initialValue: defaultDir,
|
|
1847
1847
|
defaultValue: defaultDir
|
|
@@ -1863,14 +1863,14 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
1863
1863
|
const customUseCases = [];
|
|
1864
1864
|
if (!flags.yes) {
|
|
1865
1865
|
includeExpress = handleCancel(
|
|
1866
|
-
await
|
|
1866
|
+
await p15.confirm({
|
|
1867
1867
|
message: "Include Express Presentation layer (pxExpress routes & handlers)?",
|
|
1868
1868
|
initialValue: true
|
|
1869
1869
|
})
|
|
1870
1870
|
);
|
|
1871
1871
|
if (includeExpress) {
|
|
1872
1872
|
routePath = handleCancel(
|
|
1873
|
-
await
|
|
1873
|
+
await p15.text({
|
|
1874
1874
|
message: "Express route prefix:",
|
|
1875
1875
|
initialValue: `/${normalizedName}`,
|
|
1876
1876
|
defaultValue: `/${normalizedName}`
|
|
@@ -1878,14 +1878,14 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
1878
1878
|
).trim();
|
|
1879
1879
|
}
|
|
1880
1880
|
includeDomain = handleCancel(
|
|
1881
|
-
await
|
|
1881
|
+
await p15.confirm({
|
|
1882
1882
|
message: "Include Domain Entity/Entities?",
|
|
1883
1883
|
initialValue: true
|
|
1884
1884
|
})
|
|
1885
1885
|
);
|
|
1886
1886
|
if (includeDomain) {
|
|
1887
1887
|
const domainInput = handleCancel(
|
|
1888
|
-
await
|
|
1888
|
+
await p15.text({
|
|
1889
1889
|
message: "Domain entity name(s) (comma-separated):",
|
|
1890
1890
|
initialValue: defaultEntity,
|
|
1891
1891
|
defaultValue: defaultEntity,
|
|
@@ -1904,21 +1904,21 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
1904
1904
|
entityNames = [defaultEntity];
|
|
1905
1905
|
}
|
|
1906
1906
|
includeInterface = handleCancel(
|
|
1907
|
-
await
|
|
1907
|
+
await p15.confirm({
|
|
1908
1908
|
message: `Include Domain Repository interface(s) for ${entityNames.join(", ")}?`,
|
|
1909
1909
|
initialValue: true
|
|
1910
1910
|
})
|
|
1911
1911
|
);
|
|
1912
1912
|
if (includeInterface) {
|
|
1913
1913
|
includeInfra = handleCancel(
|
|
1914
|
-
await
|
|
1914
|
+
await p15.confirm({
|
|
1915
1915
|
message: `Include Infrastructure Stub implementation(s) for ${entityNames.join(", ")}?`,
|
|
1916
1916
|
initialValue: true
|
|
1917
1917
|
})
|
|
1918
1918
|
);
|
|
1919
1919
|
}
|
|
1920
1920
|
includeUseCase = handleCancel(
|
|
1921
|
-
await
|
|
1921
|
+
await p15.confirm({
|
|
1922
1922
|
message: "Include Domain Use Cases?",
|
|
1923
1923
|
initialValue: true
|
|
1924
1924
|
})
|
|
@@ -1932,7 +1932,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
1932
1932
|
{ value: "delete", label: "Delete (Delete<Entity>)", hint: "DELETE /:id" }
|
|
1933
1933
|
];
|
|
1934
1934
|
crudOperations = handleCancel(
|
|
1935
|
-
await
|
|
1935
|
+
await p15.multiselect({
|
|
1936
1936
|
message: "Select standard CRUD use cases to generate:",
|
|
1937
1937
|
options: crudChoices,
|
|
1938
1938
|
initialValues: ["create", "read", "list", "update", "delete"],
|
|
@@ -1940,13 +1940,13 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
1940
1940
|
})
|
|
1941
1941
|
);
|
|
1942
1942
|
includeTests = handleCancel(
|
|
1943
|
-
await
|
|
1943
|
+
await p15.confirm({
|
|
1944
1944
|
message: "Generate Vitest unit tests for use cases?",
|
|
1945
1945
|
initialValue: true
|
|
1946
1946
|
})
|
|
1947
1947
|
);
|
|
1948
1948
|
const wantCustom = handleCancel(
|
|
1949
|
-
await
|
|
1949
|
+
await p15.confirm({
|
|
1950
1950
|
message: "Do you want to add any custom use cases to this feature?",
|
|
1951
1951
|
initialValue: false
|
|
1952
1952
|
})
|
|
@@ -1956,7 +1956,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
1956
1956
|
const availableIfaces = entityNames.map((e) => `I${e}Repository`);
|
|
1957
1957
|
while (addMore) {
|
|
1958
1958
|
const customName = handleCancel(
|
|
1959
|
-
await
|
|
1959
|
+
await p15.text({
|
|
1960
1960
|
message: "Custom Use Case name:",
|
|
1961
1961
|
placeholder: "e.g. ResetPassword, VerifyEmail, AssignRole",
|
|
1962
1962
|
validate: (v) => v && v.trim() ? void 0 : "Use Case name cannot be empty"
|
|
@@ -1966,7 +1966,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
1966
1966
|
let selectedDeps = [];
|
|
1967
1967
|
if (availableIfaces.length > 0) {
|
|
1968
1968
|
selectedDeps = handleCancel(
|
|
1969
|
-
await
|
|
1969
|
+
await p15.multiselect({
|
|
1970
1970
|
message: `Select domain interfaces to inject into ${customUcName}:`,
|
|
1971
1971
|
options: availableIfaces.map((i) => ({ value: i, label: i })),
|
|
1972
1972
|
required: false
|
|
@@ -1975,7 +1975,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
1975
1975
|
}
|
|
1976
1976
|
let customInputProps = [];
|
|
1977
1977
|
const hasInput = handleCancel(
|
|
1978
|
-
await
|
|
1978
|
+
await p15.confirm({
|
|
1979
1979
|
message: `Does ${customUcName} accept input arguments?`,
|
|
1980
1980
|
initialValue: true
|
|
1981
1981
|
})
|
|
@@ -1986,7 +1986,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
1986
1986
|
}
|
|
1987
1987
|
let customOutputProps = [];
|
|
1988
1988
|
const hasCustomOutput = handleCancel(
|
|
1989
|
-
await
|
|
1989
|
+
await p15.confirm({
|
|
1990
1990
|
message: `Does ${customUcName} return custom output data?`,
|
|
1991
1991
|
initialValue: false
|
|
1992
1992
|
})
|
|
@@ -1996,7 +1996,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
1996
1996
|
});
|
|
1997
1997
|
}
|
|
1998
1998
|
const customIncludeTest = handleCancel(
|
|
1999
|
-
await
|
|
1999
|
+
await p15.confirm({
|
|
2000
2000
|
message: `Generate Vitest unit test for ${customUcName}?`,
|
|
2001
2001
|
initialValue: true
|
|
2002
2002
|
})
|
|
@@ -2006,14 +2006,14 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
2006
2006
|
let customHttpPath = `/${toKebabCase(customUcName)}`;
|
|
2007
2007
|
if (includeExpress) {
|
|
2008
2008
|
customCreateHttp = handleCancel(
|
|
2009
|
-
await
|
|
2009
|
+
await p15.confirm({
|
|
2010
2010
|
message: `Generate a matching ExpressRoute HTTP handler for ${customUcName}?`,
|
|
2011
2011
|
initialValue: true
|
|
2012
2012
|
})
|
|
2013
2013
|
);
|
|
2014
2014
|
if (customCreateHttp) {
|
|
2015
2015
|
customHttpMethod = handleCancel(
|
|
2016
|
-
await
|
|
2016
|
+
await p15.select({
|
|
2017
2017
|
message: "HTTP method for route:",
|
|
2018
2018
|
options: [
|
|
2019
2019
|
{ value: "post", label: "POST" },
|
|
@@ -2026,7 +2026,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
2026
2026
|
})
|
|
2027
2027
|
);
|
|
2028
2028
|
customHttpPath = handleCancel(
|
|
2029
|
-
await
|
|
2029
|
+
await p15.text({
|
|
2030
2030
|
message: "Route subpath (relative to feature prefix):",
|
|
2031
2031
|
initialValue: `/${toKebabCase(customUcName)}`,
|
|
2032
2032
|
defaultValue: `/${toKebabCase(customUcName)}`
|
|
@@ -2047,7 +2047,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
2047
2047
|
validationFields: customInputProps
|
|
2048
2048
|
});
|
|
2049
2049
|
addMore = handleCancel(
|
|
2050
|
-
await
|
|
2050
|
+
await p15.confirm({
|
|
2051
2051
|
message: "Add another custom use case?",
|
|
2052
2052
|
initialValue: false
|
|
2053
2053
|
})
|
|
@@ -2056,7 +2056,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
2056
2056
|
}
|
|
2057
2057
|
}
|
|
2058
2058
|
includeDiProvider = handleCancel(
|
|
2059
|
-
await
|
|
2059
|
+
await p15.confirm({
|
|
2060
2060
|
message: "Generate / update feature DI provider (diProvider.ts)?",
|
|
2061
2061
|
initialValue: true
|
|
2062
2062
|
})
|
|
@@ -2068,8 +2068,8 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
2068
2068
|
entityNames = [defaultEntity];
|
|
2069
2069
|
}
|
|
2070
2070
|
}
|
|
2071
|
-
const s =
|
|
2072
|
-
s.start(`Generating feature '${
|
|
2071
|
+
const s = p15.spinner();
|
|
2072
|
+
s.start(`Generating feature '${pc15.cyan(normalizedName)}'...`);
|
|
2073
2073
|
const options = {
|
|
2074
2074
|
name: normalizedName,
|
|
2075
2075
|
projectRoot,
|
|
@@ -2091,7 +2091,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
2091
2091
|
const files = generateFeature(options);
|
|
2092
2092
|
if (isRegistry) {
|
|
2093
2093
|
const registryPath = path2.join(targetDir, "registry.json");
|
|
2094
|
-
if (!
|
|
2094
|
+
if (!fs10.existsSync(registryPath)) {
|
|
2095
2095
|
const manifest = {
|
|
2096
2096
|
name: toKebabCase(normalizedName),
|
|
2097
2097
|
type: "feature",
|
|
@@ -2115,8 +2115,8 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
2115
2115
|
}
|
|
2116
2116
|
s.stop("Feature scaffolded successfully!");
|
|
2117
2117
|
printGeneratedFiles(files, options.dryRun);
|
|
2118
|
-
|
|
2119
|
-
|
|
2118
|
+
p15.outro(
|
|
2119
|
+
pc15.green(
|
|
2120
2120
|
`\u2713 Feature '${normalizedName}' initialized in ${path2.relative(projectRoot, targetDir)} (uncommitted, unregistered)`
|
|
2121
2121
|
)
|
|
2122
2122
|
);
|
|
@@ -2230,7 +2230,7 @@ async function runSharedCommand(sharedNameArg, flags = {}) {
|
|
|
2230
2230
|
}
|
|
2231
2231
|
if (!name) {
|
|
2232
2232
|
name = handleCancel(
|
|
2233
|
-
await
|
|
2233
|
+
await p15.text({
|
|
2234
2234
|
message: "What is the shared module name?",
|
|
2235
2235
|
placeholder: "e.g. hasher, time, uuid, cache, logger",
|
|
2236
2236
|
validate: (val) => {
|
|
@@ -2246,7 +2246,7 @@ async function runSharedCommand(sharedNameArg, flags = {}) {
|
|
|
2246
2246
|
let targetDirRel = defaultDir;
|
|
2247
2247
|
if (!flags.yes && !flags.target && !flags.dest) {
|
|
2248
2248
|
targetDirRel = handleCancel(
|
|
2249
|
-
await
|
|
2249
|
+
await p15.text({
|
|
2250
2250
|
message: "Target directory for the shared module:",
|
|
2251
2251
|
initialValue: defaultDir,
|
|
2252
2252
|
defaultValue: defaultDir
|
|
@@ -2258,21 +2258,21 @@ async function runSharedCommand(sharedNameArg, flags = {}) {
|
|
|
2258
2258
|
let includeStub = true;
|
|
2259
2259
|
if (!flags.yes) {
|
|
2260
2260
|
description = handleCancel(
|
|
2261
|
-
await
|
|
2261
|
+
await p15.text({
|
|
2262
2262
|
message: "Module description (optional):",
|
|
2263
2263
|
placeholder: "e.g. In-memory caching and Redis port abstraction",
|
|
2264
2264
|
initialValue: ""
|
|
2265
2265
|
})
|
|
2266
2266
|
).trim();
|
|
2267
2267
|
includeStub = handleCancel(
|
|
2268
|
-
await
|
|
2268
|
+
await p15.confirm({
|
|
2269
2269
|
message: "Include stub implementation in infrastructure/?",
|
|
2270
2270
|
initialValue: true
|
|
2271
2271
|
})
|
|
2272
2272
|
);
|
|
2273
2273
|
}
|
|
2274
|
-
const s =
|
|
2275
|
-
s.start(`Generating shared module '${
|
|
2274
|
+
const s = p15.spinner();
|
|
2275
|
+
s.start(`Generating shared module '${pc15.cyan(normalizedName)}'...`);
|
|
2276
2276
|
const files = generateShared({
|
|
2277
2277
|
name: normalizedName,
|
|
2278
2278
|
description,
|
|
@@ -2285,8 +2285,8 @@ async function runSharedCommand(sharedNameArg, flags = {}) {
|
|
|
2285
2285
|
});
|
|
2286
2286
|
s.stop("Shared module generated successfully!");
|
|
2287
2287
|
printGeneratedFiles(files, Boolean(flags.dryRun));
|
|
2288
|
-
|
|
2289
|
-
|
|
2288
|
+
p15.outro(
|
|
2289
|
+
pc15.green(
|
|
2290
2290
|
`\u2713 Shared module '${normalizedName}' initialized in ${path2.relative(projectRoot, targetDir)} (uncommitted, unregistered)`
|
|
2291
2291
|
)
|
|
2292
2292
|
);
|
|
@@ -2300,14 +2300,14 @@ async function runUseCaseCommand(useCaseNameArg, flags = {}) {
|
|
|
2300
2300
|
const featureOptions = existingFeatures.map((f) => ({ value: f, label: f }));
|
|
2301
2301
|
featureOptions.push({ value: "__custom__", label: "\u270F\uFE0F Enter custom feature name..." });
|
|
2302
2302
|
const selected = handleCancel(
|
|
2303
|
-
await
|
|
2303
|
+
await p15.select({
|
|
2304
2304
|
message: "Select target feature:",
|
|
2305
2305
|
options: featureOptions
|
|
2306
2306
|
})
|
|
2307
2307
|
);
|
|
2308
2308
|
if (selected === "__custom__") {
|
|
2309
2309
|
feature = handleCancel(
|
|
2310
|
-
await
|
|
2310
|
+
await p15.text({
|
|
2311
2311
|
message: "Enter feature name:",
|
|
2312
2312
|
validate: (v) => v && v.trim() ? void 0 : "Feature name cannot be empty"
|
|
2313
2313
|
})
|
|
@@ -2317,7 +2317,7 @@ async function runUseCaseCommand(useCaseNameArg, flags = {}) {
|
|
|
2317
2317
|
}
|
|
2318
2318
|
} else {
|
|
2319
2319
|
feature = handleCancel(
|
|
2320
|
-
await
|
|
2320
|
+
await p15.text({
|
|
2321
2321
|
message: "Enter target feature name:",
|
|
2322
2322
|
validate: (v) => v && v.trim() ? void 0 : "Feature name cannot be empty"
|
|
2323
2323
|
})
|
|
@@ -2328,7 +2328,7 @@ async function runUseCaseCommand(useCaseNameArg, flags = {}) {
|
|
|
2328
2328
|
let name = useCaseNameArg?.trim();
|
|
2329
2329
|
if (!name) {
|
|
2330
2330
|
name = handleCancel(
|
|
2331
|
-
await
|
|
2331
|
+
await p15.text({
|
|
2332
2332
|
message: "Use Case name:",
|
|
2333
2333
|
placeholder: "e.g. CreateUser, GetUser, CancelOrder",
|
|
2334
2334
|
validate: (v) => v && v.trim() ? void 0 : "Use Case name cannot be empty"
|
|
@@ -2344,7 +2344,7 @@ async function runUseCaseCommand(useCaseNameArg, flags = {}) {
|
|
|
2344
2344
|
label: i.name
|
|
2345
2345
|
}));
|
|
2346
2346
|
selectedDeps = handleCancel(
|
|
2347
|
-
await
|
|
2347
|
+
await p15.multiselect({
|
|
2348
2348
|
message: "Select domain interfaces to inject into use case:",
|
|
2349
2349
|
options: multiOptions,
|
|
2350
2350
|
required: false
|
|
@@ -2359,7 +2359,7 @@ async function runUseCaseCommand(useCaseNameArg, flags = {}) {
|
|
|
2359
2359
|
let httpPath = "/";
|
|
2360
2360
|
if (!flags.yes) {
|
|
2361
2361
|
const hasInput = handleCancel(
|
|
2362
|
-
await
|
|
2362
|
+
await p15.confirm({
|
|
2363
2363
|
message: "Does this use case accept input arguments?",
|
|
2364
2364
|
initialValue: true
|
|
2365
2365
|
})
|
|
@@ -2369,7 +2369,7 @@ async function runUseCaseCommand(useCaseNameArg, flags = {}) {
|
|
|
2369
2369
|
});
|
|
2370
2370
|
}
|
|
2371
2371
|
const hasCustomOutput = handleCancel(
|
|
2372
|
-
await
|
|
2372
|
+
await p15.confirm({
|
|
2373
2373
|
message: "Does this use case return custom output data?",
|
|
2374
2374
|
initialValue: false
|
|
2375
2375
|
})
|
|
@@ -2379,20 +2379,20 @@ async function runUseCaseCommand(useCaseNameArg, flags = {}) {
|
|
|
2379
2379
|
});
|
|
2380
2380
|
}
|
|
2381
2381
|
includeTest = handleCancel(
|
|
2382
|
-
await
|
|
2382
|
+
await p15.confirm({
|
|
2383
2383
|
message: "Generate Vitest unit test skeleton (.test.ts)?",
|
|
2384
2384
|
initialValue: true
|
|
2385
2385
|
})
|
|
2386
2386
|
);
|
|
2387
2387
|
createHttp = handleCancel(
|
|
2388
|
-
await
|
|
2388
|
+
await p15.confirm({
|
|
2389
2389
|
message: "Generate a matching ExpressRoute HTTP handler?",
|
|
2390
2390
|
initialValue: false
|
|
2391
2391
|
})
|
|
2392
2392
|
);
|
|
2393
2393
|
if (createHttp) {
|
|
2394
2394
|
httpMethod = handleCancel(
|
|
2395
|
-
await
|
|
2395
|
+
await p15.select({
|
|
2396
2396
|
message: "HTTP method for route:",
|
|
2397
2397
|
options: [
|
|
2398
2398
|
{ value: "post", label: "POST" },
|
|
@@ -2405,7 +2405,7 @@ async function runUseCaseCommand(useCaseNameArg, flags = {}) {
|
|
|
2405
2405
|
})
|
|
2406
2406
|
);
|
|
2407
2407
|
httpPath = handleCancel(
|
|
2408
|
-
await
|
|
2408
|
+
await p15.text({
|
|
2409
2409
|
message: "Route subpath (relative to feature prefix):",
|
|
2410
2410
|
initialValue: "/",
|
|
2411
2411
|
defaultValue: "/"
|
|
@@ -2413,8 +2413,8 @@ async function runUseCaseCommand(useCaseNameArg, flags = {}) {
|
|
|
2413
2413
|
).trim();
|
|
2414
2414
|
}
|
|
2415
2415
|
}
|
|
2416
|
-
const s =
|
|
2417
|
-
s.start(`Generating use case '${
|
|
2416
|
+
const s = p15.spinner();
|
|
2417
|
+
s.start(`Generating use case '${pc15.cyan(ucName)}'...`);
|
|
2418
2418
|
const options = {
|
|
2419
2419
|
name: ucName,
|
|
2420
2420
|
feature,
|
|
@@ -2446,7 +2446,7 @@ async function runUseCaseCommand(useCaseNameArg, flags = {}) {
|
|
|
2446
2446
|
}
|
|
2447
2447
|
s.stop("Use case generated successfully!");
|
|
2448
2448
|
printGeneratedFiles(files, options.dryRun);
|
|
2449
|
-
|
|
2449
|
+
p15.outro(pc15.green(`Use case '${ucName}' created in feature '${feature}'!`));
|
|
2450
2450
|
}
|
|
2451
2451
|
async function runDomainCommand(domainNameArg, flags = {}) {
|
|
2452
2452
|
const projectRoot = findProjectRoot();
|
|
@@ -2457,14 +2457,14 @@ async function runDomainCommand(domainNameArg, flags = {}) {
|
|
|
2457
2457
|
const featureOptions = existingFeatures.map((f) => ({ value: f, label: f }));
|
|
2458
2458
|
featureOptions.push({ value: "__custom__", label: "\u270F\uFE0F Enter custom feature name..." });
|
|
2459
2459
|
const selected = handleCancel(
|
|
2460
|
-
await
|
|
2460
|
+
await p15.select({
|
|
2461
2461
|
message: "Select target feature:",
|
|
2462
2462
|
options: featureOptions
|
|
2463
2463
|
})
|
|
2464
2464
|
);
|
|
2465
2465
|
if (selected === "__custom__") {
|
|
2466
2466
|
feature = handleCancel(
|
|
2467
|
-
await
|
|
2467
|
+
await p15.text({
|
|
2468
2468
|
message: "Enter feature name:",
|
|
2469
2469
|
validate: (v) => v && v.trim() ? void 0 : "Feature name cannot be empty"
|
|
2470
2470
|
})
|
|
@@ -2474,7 +2474,7 @@ async function runDomainCommand(domainNameArg, flags = {}) {
|
|
|
2474
2474
|
}
|
|
2475
2475
|
} else {
|
|
2476
2476
|
feature = handleCancel(
|
|
2477
|
-
await
|
|
2477
|
+
await p15.text({
|
|
2478
2478
|
message: "Enter target feature name:",
|
|
2479
2479
|
validate: (v) => v && v.trim() ? void 0 : "Feature name cannot be empty"
|
|
2480
2480
|
})
|
|
@@ -2485,7 +2485,7 @@ async function runDomainCommand(domainNameArg, flags = {}) {
|
|
|
2485
2485
|
let name = domainNameArg?.trim();
|
|
2486
2486
|
if (!name) {
|
|
2487
2487
|
name = handleCancel(
|
|
2488
|
-
await
|
|
2488
|
+
await p15.text({
|
|
2489
2489
|
message: "Domain model / entity name:",
|
|
2490
2490
|
placeholder: "e.g. User, Order, Product, Address",
|
|
2491
2491
|
validate: (v) => v && v.trim() ? void 0 : "Domain name cannot be empty"
|
|
@@ -2497,7 +2497,7 @@ async function runDomainCommand(domainNameArg, flags = {}) {
|
|
|
2497
2497
|
let properties = [];
|
|
2498
2498
|
if (!flags.yes) {
|
|
2499
2499
|
kind = handleCancel(
|
|
2500
|
-
await
|
|
2500
|
+
await p15.select({
|
|
2501
2501
|
message: "Select domain model type:",
|
|
2502
2502
|
options: [
|
|
2503
2503
|
{ value: "interface", label: "TypeScript Interface (pure data structure)" },
|
|
@@ -2516,8 +2516,8 @@ async function runDomainCommand(domainNameArg, flags = {}) {
|
|
|
2516
2516
|
defaults: kind === "valueObject" ? [{ name: "value", type: "string" }] : defaultProps
|
|
2517
2517
|
});
|
|
2518
2518
|
}
|
|
2519
|
-
const s =
|
|
2520
|
-
s.start(`Generating domain model '${
|
|
2519
|
+
const s = p15.spinner();
|
|
2520
|
+
s.start(`Generating domain model '${pc15.cyan(entityName)}'...`);
|
|
2521
2521
|
const options = {
|
|
2522
2522
|
name: entityName,
|
|
2523
2523
|
feature,
|
|
@@ -2530,7 +2530,7 @@ async function runDomainCommand(domainNameArg, flags = {}) {
|
|
|
2530
2530
|
const file = generateDomain(options);
|
|
2531
2531
|
s.stop("Domain model generated successfully!");
|
|
2532
2532
|
printGeneratedFiles([file], options.dryRun);
|
|
2533
|
-
|
|
2533
|
+
p15.outro(pc15.green(`Domain model '${entityName}' created in feature '${feature}'!`));
|
|
2534
2534
|
}
|
|
2535
2535
|
async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
2536
2536
|
const projectRoot = findProjectRoot();
|
|
@@ -2539,7 +2539,7 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2539
2539
|
let feature = flags.feature?.trim();
|
|
2540
2540
|
if (!flags.yes && !flags.global && !flags.feature) {
|
|
2541
2541
|
scope = handleCancel(
|
|
2542
|
-
await
|
|
2542
|
+
await p15.select({
|
|
2543
2543
|
message: "Where should this infrastructure implementation be placed?",
|
|
2544
2544
|
options: [
|
|
2545
2545
|
{ value: "feature", label: "Feature-level (features/<feature>/infrastructure)" },
|
|
@@ -2554,14 +2554,14 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2554
2554
|
const featureOptions = existingFeatures.map((f) => ({ value: f, label: f }));
|
|
2555
2555
|
featureOptions.push({ value: "__custom__", label: "\u270F\uFE0F Enter custom feature name..." });
|
|
2556
2556
|
const selected = handleCancel(
|
|
2557
|
-
await
|
|
2557
|
+
await p15.select({
|
|
2558
2558
|
message: "Select target feature:",
|
|
2559
2559
|
options: featureOptions
|
|
2560
2560
|
})
|
|
2561
2561
|
);
|
|
2562
2562
|
if (selected === "__custom__") {
|
|
2563
2563
|
feature = handleCancel(
|
|
2564
|
-
await
|
|
2564
|
+
await p15.text({
|
|
2565
2565
|
message: "Enter feature name:",
|
|
2566
2566
|
validate: (v) => v && v.trim() ? void 0 : "Feature name cannot be empty"
|
|
2567
2567
|
})
|
|
@@ -2571,7 +2571,7 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2571
2571
|
}
|
|
2572
2572
|
} else {
|
|
2573
2573
|
feature = handleCancel(
|
|
2574
|
-
await
|
|
2574
|
+
await p15.text({
|
|
2575
2575
|
message: "Enter target feature name:",
|
|
2576
2576
|
validate: (v) => v && v.trim() ? void 0 : "Feature name cannot be empty"
|
|
2577
2577
|
})
|
|
@@ -2584,7 +2584,7 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2584
2584
|
let name = classNameArg?.trim();
|
|
2585
2585
|
if (!name) {
|
|
2586
2586
|
name = handleCancel(
|
|
2587
|
-
await
|
|
2587
|
+
await p15.text({
|
|
2588
2588
|
message: "Infrastructure class name:",
|
|
2589
2589
|
placeholder: "e.g. StubUserRepository, PostgresUserRepository, S3FileStorage",
|
|
2590
2590
|
validate: (v) => v && v.trim() ? void 0 : "Class name cannot be empty"
|
|
@@ -2603,7 +2603,7 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2603
2603
|
(i) => className.toLowerCase().includes(removeInterfacePrefix(i.name).toLowerCase())
|
|
2604
2604
|
);
|
|
2605
2605
|
const ifaceChoice = handleCancel(
|
|
2606
|
-
await
|
|
2606
|
+
await p15.select({
|
|
2607
2607
|
message: "Does this class implement a domain interface or abstract class?",
|
|
2608
2608
|
options: [
|
|
2609
2609
|
...interfaces.map((i) => ({ value: i.name, label: i.name })),
|
|
@@ -2615,7 +2615,7 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2615
2615
|
);
|
|
2616
2616
|
if (ifaceChoice === "__custom__") {
|
|
2617
2617
|
implementsInterface = handleCancel(
|
|
2618
|
-
await
|
|
2618
|
+
await p15.text({
|
|
2619
2619
|
message: "Enter interface or abstract class name:",
|
|
2620
2620
|
placeholder: "e.g. IUserRepository, BaseStorageAdapter",
|
|
2621
2621
|
validate: (v) => v && v.trim() ? void 0 : "Name cannot be empty"
|
|
@@ -2626,14 +2626,14 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2626
2626
|
}
|
|
2627
2627
|
} else {
|
|
2628
2628
|
const wantImpl = handleCancel(
|
|
2629
|
-
await
|
|
2629
|
+
await p15.confirm({
|
|
2630
2630
|
message: "Does this class implement a domain interface or abstract class?",
|
|
2631
2631
|
initialValue: false
|
|
2632
2632
|
})
|
|
2633
2633
|
);
|
|
2634
2634
|
if (wantImpl) {
|
|
2635
2635
|
implementsInterface = handleCancel(
|
|
2636
|
-
await
|
|
2636
|
+
await p15.text({
|
|
2637
2637
|
message: "Enter interface or abstract class name:",
|
|
2638
2638
|
placeholder: "e.g. IUserRepository, BaseStorageAdapter",
|
|
2639
2639
|
validate: (v) => v && v.trim() ? void 0 : "Name cannot be empty"
|
|
@@ -2653,7 +2653,7 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2653
2653
|
const allInterfaces = listDomainInterfaces(projectRoot);
|
|
2654
2654
|
if (allInterfaces.length > 0) {
|
|
2655
2655
|
const ifaceChoice = handleCancel(
|
|
2656
|
-
await
|
|
2656
|
+
await p15.select({
|
|
2657
2657
|
message: "Does this class implement an interface or abstract class?",
|
|
2658
2658
|
options: [
|
|
2659
2659
|
...allInterfaces.map((i) => ({ value: i.name, label: `${i.name} (${i.feature})` })),
|
|
@@ -2665,7 +2665,7 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2665
2665
|
);
|
|
2666
2666
|
if (ifaceChoice === "__custom__") {
|
|
2667
2667
|
implementsInterface = handleCancel(
|
|
2668
|
-
await
|
|
2668
|
+
await p15.text({
|
|
2669
2669
|
message: "Enter interface or abstract class name:",
|
|
2670
2670
|
placeholder: "e.g. IAuthRepository",
|
|
2671
2671
|
validate: (v) => v && v.trim() ? void 0 : "Name cannot be empty"
|
|
@@ -2678,7 +2678,7 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2678
2678
|
}
|
|
2679
2679
|
if (!flags.yes && !flags.kind) {
|
|
2680
2680
|
kind = handleCancel(
|
|
2681
|
-
await
|
|
2681
|
+
await p15.select({
|
|
2682
2682
|
message: "Select implementation kind:",
|
|
2683
2683
|
options: [
|
|
2684
2684
|
{ value: "stub", label: "In-Memory Stub (with in-memory store and test helper methods)" },
|
|
@@ -2689,7 +2689,7 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2689
2689
|
);
|
|
2690
2690
|
if (scope === "feature" && feature && implementsInterface) {
|
|
2691
2691
|
registerInProvider = handleCancel(
|
|
2692
|
-
await
|
|
2692
|
+
await p15.confirm({
|
|
2693
2693
|
message: "Register this implementation in feature diProvider.ts?",
|
|
2694
2694
|
initialValue: true
|
|
2695
2695
|
})
|
|
@@ -2698,8 +2698,8 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2698
2698
|
} else if (flags.yes && scope === "feature" && feature && implementsInterface) {
|
|
2699
2699
|
registerInProvider = !flags.noProvider;
|
|
2700
2700
|
}
|
|
2701
|
-
const s =
|
|
2702
|
-
s.start(`Generating infrastructure class '${
|
|
2701
|
+
const s = p15.spinner();
|
|
2702
|
+
s.start(`Generating infrastructure class '${pc15.cyan(className)}'...`);
|
|
2703
2703
|
const files = [];
|
|
2704
2704
|
const options = {
|
|
2705
2705
|
name: className,
|
|
@@ -2734,7 +2734,7 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2734
2734
|
}
|
|
2735
2735
|
s.stop("Infrastructure class generated successfully!");
|
|
2736
2736
|
printGeneratedFiles(files, options.dryRun);
|
|
2737
|
-
|
|
2737
|
+
p15.outro(pc15.green(`Infrastructure class '${className}' created!`));
|
|
2738
2738
|
}
|
|
2739
2739
|
async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
2740
2740
|
const projectRoot = findProjectRoot();
|
|
@@ -2745,14 +2745,14 @@ async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
|
2745
2745
|
const featureOptions = existingFeatures.map((f) => ({ value: f, label: f }));
|
|
2746
2746
|
featureOptions.push({ value: "__custom__", label: "\u270F\uFE0F Enter custom feature name..." });
|
|
2747
2747
|
const selected = handleCancel(
|
|
2748
|
-
await
|
|
2748
|
+
await p15.select({
|
|
2749
2749
|
message: "Select target feature:",
|
|
2750
2750
|
options: featureOptions
|
|
2751
2751
|
})
|
|
2752
2752
|
);
|
|
2753
2753
|
if (selected === "__custom__") {
|
|
2754
2754
|
feature = handleCancel(
|
|
2755
|
-
await
|
|
2755
|
+
await p15.text({
|
|
2756
2756
|
message: "Enter feature name:",
|
|
2757
2757
|
validate: (v) => v && v.trim() ? void 0 : "Feature name cannot be empty"
|
|
2758
2758
|
})
|
|
@@ -2762,7 +2762,7 @@ async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
|
2762
2762
|
}
|
|
2763
2763
|
} else {
|
|
2764
2764
|
feature = handleCancel(
|
|
2765
|
-
await
|
|
2765
|
+
await p15.text({
|
|
2766
2766
|
message: "Enter target feature name:",
|
|
2767
2767
|
validate: (v) => v && v.trim() ? void 0 : "Feature name cannot be empty"
|
|
2768
2768
|
})
|
|
@@ -2773,7 +2773,7 @@ async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
|
2773
2773
|
let name = interfaceNameArg?.trim();
|
|
2774
2774
|
if (!name) {
|
|
2775
2775
|
name = handleCancel(
|
|
2776
|
-
await
|
|
2776
|
+
await p15.text({
|
|
2777
2777
|
message: "Domain interface name:",
|
|
2778
2778
|
placeholder: "e.g. IUserRepository, IPaymentService",
|
|
2779
2779
|
validate: (v) => v && v.trim() ? void 0 : "Interface name cannot be empty"
|
|
@@ -2791,7 +2791,7 @@ async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
|
2791
2791
|
if (!flags.yes) {
|
|
2792
2792
|
if (existingEntities.length > 0) {
|
|
2793
2793
|
const selectedEntity = handleCancel(
|
|
2794
|
-
await
|
|
2794
|
+
await p15.select({
|
|
2795
2795
|
message: "Select domain entity associated with this interface:",
|
|
2796
2796
|
options: [
|
|
2797
2797
|
...existingEntities.map((e) => ({ value: e.name, label: e.name })),
|
|
@@ -2802,7 +2802,7 @@ async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
|
2802
2802
|
);
|
|
2803
2803
|
if (selectedEntity === "__custom__") {
|
|
2804
2804
|
entityName = handleCancel(
|
|
2805
|
-
await
|
|
2805
|
+
await p15.text({
|
|
2806
2806
|
message: "Enter entity name:",
|
|
2807
2807
|
defaultValue: removeInterfacePrefix(ifaceName).replace(/Repository$|Service$/, "")
|
|
2808
2808
|
})
|
|
@@ -2812,7 +2812,7 @@ async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
|
2812
2812
|
}
|
|
2813
2813
|
}
|
|
2814
2814
|
kind = handleCancel(
|
|
2815
|
-
await
|
|
2815
|
+
await p15.select({
|
|
2816
2816
|
message: "Interface definition style:",
|
|
2817
2817
|
options: [
|
|
2818
2818
|
{ value: "abstractClass", label: "Abstract Class (Recommended - acts as DI token & type)" },
|
|
@@ -2822,7 +2822,7 @@ async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
|
2822
2822
|
})
|
|
2823
2823
|
);
|
|
2824
2824
|
methodsPreset = handleCancel(
|
|
2825
|
-
await
|
|
2825
|
+
await p15.select({
|
|
2826
2826
|
message: "Method signature preset:",
|
|
2827
2827
|
options: [
|
|
2828
2828
|
{ value: "crud", label: "Standard CRUD (GetById, List, Create, Update, Delete)" },
|
|
@@ -2832,22 +2832,22 @@ async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
|
2832
2832
|
})
|
|
2833
2833
|
);
|
|
2834
2834
|
generateStub = handleCancel(
|
|
2835
|
-
await
|
|
2835
|
+
await p15.confirm({
|
|
2836
2836
|
message: "Auto-generate Infrastructure Stub implementation?",
|
|
2837
2837
|
initialValue: true
|
|
2838
2838
|
})
|
|
2839
2839
|
);
|
|
2840
2840
|
if (generateStub) {
|
|
2841
2841
|
registerInProvider = handleCancel(
|
|
2842
|
-
await
|
|
2842
|
+
await p15.confirm({
|
|
2843
2843
|
message: "Auto-register interface & stub in feature diProvider.ts?",
|
|
2844
2844
|
initialValue: true
|
|
2845
2845
|
})
|
|
2846
2846
|
);
|
|
2847
2847
|
}
|
|
2848
2848
|
}
|
|
2849
|
-
const s =
|
|
2850
|
-
s.start(`Generating interface '${
|
|
2849
|
+
const s = p15.spinner();
|
|
2850
|
+
s.start(`Generating interface '${pc15.cyan(ifaceName)}'...`);
|
|
2851
2851
|
const files = [];
|
|
2852
2852
|
const options = {
|
|
2853
2853
|
name: ifaceName,
|
|
@@ -2896,7 +2896,7 @@ async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
|
2896
2896
|
}
|
|
2897
2897
|
s.stop("Interface generated successfully!");
|
|
2898
2898
|
printGeneratedFiles(files, options.dryRun);
|
|
2899
|
-
|
|
2899
|
+
p15.outro(pc15.green(`Interface '${ifaceName}' created in feature '${feature}'!`));
|
|
2900
2900
|
}
|
|
2901
2901
|
async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
2902
2902
|
const projectRoot = findProjectRoot();
|
|
@@ -2907,14 +2907,14 @@ async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
|
2907
2907
|
const featureOptions = existingFeatures.map((f) => ({ value: f, label: f }));
|
|
2908
2908
|
featureOptions.push({ value: "__custom__", label: "\u270F\uFE0F Enter custom feature name..." });
|
|
2909
2909
|
const selected = handleCancel(
|
|
2910
|
-
await
|
|
2910
|
+
await p15.select({
|
|
2911
2911
|
message: "Select target feature:",
|
|
2912
2912
|
options: featureOptions
|
|
2913
2913
|
})
|
|
2914
2914
|
);
|
|
2915
2915
|
if (selected === "__custom__") {
|
|
2916
2916
|
feature = handleCancel(
|
|
2917
|
-
await
|
|
2917
|
+
await p15.text({
|
|
2918
2918
|
message: "Enter feature name:",
|
|
2919
2919
|
validate: (v) => v && v.trim() ? void 0 : "Feature name cannot be empty"
|
|
2920
2920
|
})
|
|
@@ -2924,7 +2924,7 @@ async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
|
2924
2924
|
}
|
|
2925
2925
|
} else {
|
|
2926
2926
|
feature = handleCancel(
|
|
2927
|
-
await
|
|
2927
|
+
await p15.text({
|
|
2928
2928
|
message: "Enter target feature name:",
|
|
2929
2929
|
validate: (v) => v && v.trim() ? void 0 : "Feature name cannot be empty"
|
|
2930
2930
|
})
|
|
@@ -2935,7 +2935,7 @@ async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
|
2935
2935
|
let name = handlerNameArg?.trim();
|
|
2936
2936
|
if (!name) {
|
|
2937
2937
|
name = handleCancel(
|
|
2938
|
-
await
|
|
2938
|
+
await p15.text({
|
|
2939
2939
|
message: "HTTP Route Handler class name:",
|
|
2940
2940
|
placeholder: "e.g. CreateUserHttp, GetUserHttp, HealthHttp",
|
|
2941
2941
|
validate: (v) => v && v.trim() ? void 0 : "Handler name cannot be empty"
|
|
@@ -2954,7 +2954,7 @@ async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
|
2954
2954
|
let validationFields = [];
|
|
2955
2955
|
if (!flags.yes) {
|
|
2956
2956
|
method = handleCancel(
|
|
2957
|
-
await
|
|
2957
|
+
await p15.select({
|
|
2958
2958
|
message: "HTTP Method:",
|
|
2959
2959
|
options: [
|
|
2960
2960
|
{ value: "get", label: "GET" },
|
|
@@ -2968,7 +2968,7 @@ async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
|
2968
2968
|
);
|
|
2969
2969
|
const defaultPath = method === "get" ? "/" : "/";
|
|
2970
2970
|
subPath = handleCancel(
|
|
2971
|
-
await
|
|
2971
|
+
await p15.text({
|
|
2972
2972
|
message: "Route subpath (relative to feature prefix):",
|
|
2973
2973
|
initialValue: defaultPath,
|
|
2974
2974
|
defaultValue: defaultPath
|
|
@@ -2979,7 +2979,7 @@ async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
|
2979
2979
|
const ucOptions = useCases.map((u) => ({ value: u.name, label: u.name }));
|
|
2980
2980
|
ucOptions.push({ value: "__none__", label: "None / Standalone Handler" });
|
|
2981
2981
|
const chosenUc = handleCancel(
|
|
2982
|
-
await
|
|
2982
|
+
await p15.select({
|
|
2983
2983
|
message: "Connect this handler to a domain Use Case?",
|
|
2984
2984
|
options: ucOptions,
|
|
2985
2985
|
initialValue: ucOptions[0]?.value
|
|
@@ -2990,7 +2990,7 @@ async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
|
2990
2990
|
}
|
|
2991
2991
|
}
|
|
2992
2992
|
includeValidation = handleCancel(
|
|
2993
|
-
await
|
|
2993
|
+
await p15.confirm({
|
|
2994
2994
|
message: "Include Zod inbound request validation?",
|
|
2995
2995
|
initialValue: method !== "delete"
|
|
2996
2996
|
})
|
|
@@ -2998,7 +2998,7 @@ async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
|
2998
2998
|
if (includeValidation) {
|
|
2999
2999
|
const defaultSource = method === "get" ? "query" : "body";
|
|
3000
3000
|
validationSource = handleCancel(
|
|
3001
|
-
await
|
|
3001
|
+
await p15.select({
|
|
3002
3002
|
message: "Validation data source:",
|
|
3003
3003
|
options: [
|
|
3004
3004
|
{ value: "body", label: "req.body (for POST / PUT / PATCH payloads)" },
|
|
@@ -3012,8 +3012,8 @@ async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
|
3012
3012
|
});
|
|
3013
3013
|
}
|
|
3014
3014
|
}
|
|
3015
|
-
const s =
|
|
3016
|
-
s.start(`Generating HTTP handler '${
|
|
3015
|
+
const s = p15.spinner();
|
|
3016
|
+
s.start(`Generating HTTP handler '${pc15.cyan(className)}'...`);
|
|
3017
3017
|
const options = {
|
|
3018
3018
|
name: className,
|
|
3019
3019
|
feature,
|
|
@@ -3031,7 +3031,7 @@ async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
|
3031
3031
|
const files = generateHttpHandler(options);
|
|
3032
3032
|
s.stop("HTTP handler generated successfully!");
|
|
3033
3033
|
printGeneratedFiles(files, options.dryRun);
|
|
3034
|
-
|
|
3034
|
+
p15.outro(pc15.green(`HTTP handler '${className}' created in feature '${feature}'!`));
|
|
3035
3035
|
}
|
|
3036
3036
|
function generateInjectableCode(className, dependencies = [], methods = [], implementsInterface) {
|
|
3037
3037
|
const formattedDeps = dependencies.map((dep) => ({
|
|
@@ -3041,7 +3041,7 @@ function generateInjectableCode(className, dependencies = [], methods = [], impl
|
|
|
3041
3041
|
const formattedMethods = methods.map((m) => {
|
|
3042
3042
|
const isAsync = m.async !== false;
|
|
3043
3043
|
const retType = m.returnType ? isAsync ? `Promise<${m.returnType}>` : m.returnType : isAsync ? "Promise<void>" : "void";
|
|
3044
|
-
const params = m.params && m.params.length > 0 ? m.params.map((
|
|
3044
|
+
const params = m.params && m.params.length > 0 ? m.params.map((p18) => `${p18.name}: ${p18.type}`).join(", ") : "";
|
|
3045
3045
|
return {
|
|
3046
3046
|
name: m.name,
|
|
3047
3047
|
isAsync,
|
|
@@ -3111,7 +3111,7 @@ async function runInjectableCommand(classNameArg, flags = {}) {
|
|
|
3111
3111
|
let name = classNameArg?.trim();
|
|
3112
3112
|
if (!name) {
|
|
3113
3113
|
name = handleCancel(
|
|
3114
|
-
await
|
|
3114
|
+
await p15.text({
|
|
3115
3115
|
message: "Injectable class name:",
|
|
3116
3116
|
placeholder: "e.g. PasswordHasher, TokenService, UserTransformer",
|
|
3117
3117
|
validate: (v) => v && v.trim() ? void 0 : "Class name cannot be empty"
|
|
@@ -3124,7 +3124,7 @@ async function runInjectableCommand(classNameArg, flags = {}) {
|
|
|
3124
3124
|
let customPath;
|
|
3125
3125
|
if (!flags.yes) {
|
|
3126
3126
|
location = handleCancel(
|
|
3127
|
-
await
|
|
3127
|
+
await p15.select({
|
|
3128
3128
|
message: "Select target architectural location:",
|
|
3129
3129
|
options: [
|
|
3130
3130
|
{ value: "feature-service", label: "Feature Service (features/<feature>/services/)" },
|
|
@@ -3142,14 +3142,14 @@ async function runInjectableCommand(classNameArg, flags = {}) {
|
|
|
3142
3142
|
const featureOptions = existingFeatures.map((f) => ({ value: f, label: f }));
|
|
3143
3143
|
featureOptions.push({ value: "__custom__", label: "\u270F\uFE0F Enter custom feature name..." });
|
|
3144
3144
|
const selected = handleCancel(
|
|
3145
|
-
await
|
|
3145
|
+
await p15.select({
|
|
3146
3146
|
message: "Select target feature:",
|
|
3147
3147
|
options: featureOptions
|
|
3148
3148
|
})
|
|
3149
3149
|
);
|
|
3150
3150
|
if (selected === "__custom__") {
|
|
3151
3151
|
feature = handleCancel(
|
|
3152
|
-
await
|
|
3152
|
+
await p15.text({
|
|
3153
3153
|
message: "Enter feature name:",
|
|
3154
3154
|
validate: (v) => v && v.trim() ? void 0 : "Feature name cannot be empty"
|
|
3155
3155
|
})
|
|
@@ -3159,7 +3159,7 @@ async function runInjectableCommand(classNameArg, flags = {}) {
|
|
|
3159
3159
|
}
|
|
3160
3160
|
} else {
|
|
3161
3161
|
feature = handleCancel(
|
|
3162
|
-
await
|
|
3162
|
+
await p15.text({
|
|
3163
3163
|
message: "Enter target feature name:",
|
|
3164
3164
|
validate: (v) => v && v.trim() ? void 0 : "Feature name cannot be empty"
|
|
3165
3165
|
})
|
|
@@ -3169,7 +3169,7 @@ async function runInjectableCommand(classNameArg, flags = {}) {
|
|
|
3169
3169
|
feature = toCamelCase(feature);
|
|
3170
3170
|
} else if (location === "custom") {
|
|
3171
3171
|
customPath = handleCancel(
|
|
3172
|
-
await
|
|
3172
|
+
await p15.text({
|
|
3173
3173
|
message: "Enter destination directory path:",
|
|
3174
3174
|
placeholder: "e.g. src/services or lib/utils",
|
|
3175
3175
|
validate: (v) => v && v.trim() ? void 0 : "Path cannot be empty"
|
|
@@ -3180,14 +3180,14 @@ async function runInjectableCommand(classNameArg, flags = {}) {
|
|
|
3180
3180
|
let generateInterface2 = false;
|
|
3181
3181
|
if (!flags.yes) {
|
|
3182
3182
|
generateInterface2 = handleCancel(
|
|
3183
|
-
await
|
|
3183
|
+
await p15.confirm({
|
|
3184
3184
|
message: `Generate abstract class interface (I${className}) as runtime DI token?`,
|
|
3185
3185
|
initialValue: false
|
|
3186
3186
|
})
|
|
3187
3187
|
);
|
|
3188
3188
|
}
|
|
3189
|
-
const s =
|
|
3190
|
-
s.start(`Generating injectable '${
|
|
3189
|
+
const s = p15.spinner();
|
|
3190
|
+
s.start(`Generating injectable '${pc15.cyan(className)}'...`);
|
|
3191
3191
|
const options = {
|
|
3192
3192
|
name: className,
|
|
3193
3193
|
feature,
|
|
@@ -3201,12 +3201,44 @@ async function runInjectableCommand(classNameArg, flags = {}) {
|
|
|
3201
3201
|
const files = generateInjectable(options);
|
|
3202
3202
|
s.stop("Injectable class generated successfully!");
|
|
3203
3203
|
printGeneratedFiles(files, options.dryRun);
|
|
3204
|
-
|
|
3204
|
+
p15.outro(pc15.green(`Injectable '${className}' created successfully!`));
|
|
3205
3205
|
}
|
|
3206
|
+
async function runEnvCommand(flags = {}) {
|
|
3207
|
+
const projectRoot = flags.cwd || flags.targetDir || findProjectRoot();
|
|
3208
|
+
const s = p15.spinner();
|
|
3209
|
+
s.start("Scanning for .example environment files...");
|
|
3210
|
+
const files = fs10.readdirSync(projectRoot);
|
|
3211
|
+
const exampleFiles = files.filter((file) => file.startsWith(".env") && file.endsWith(".example")).sort();
|
|
3212
|
+
if (exampleFiles.length === 0) {
|
|
3213
|
+
s.stop("No .example files found.");
|
|
3214
|
+
p15.log.info(pc15.yellow(`No files matching '.env*.example' were found in ${projectRoot}`));
|
|
3215
|
+
return [];
|
|
3216
|
+
}
|
|
3217
|
+
s.message(`Found ${exampleFiles.length} template(s). Generating...`);
|
|
3218
|
+
const generatedFiles = [];
|
|
3219
|
+
for (const exampleFile of exampleFiles) {
|
|
3220
|
+
const sourcePath = path2.join(projectRoot, exampleFile);
|
|
3221
|
+
const targetFile = exampleFile.replace(/\.example$/, "");
|
|
3222
|
+
const targetPath = path2.join(projectRoot, targetFile);
|
|
3223
|
+
const content = fs10.readFileSync(sourcePath, "utf-8");
|
|
3224
|
+
const genFile = writeFileSafely(targetPath, content, {
|
|
3225
|
+
projectRoot,
|
|
3226
|
+
dryRun: Boolean(flags.dryRun),
|
|
3227
|
+
overwrite: Boolean(flags.overwrite)
|
|
3228
|
+
});
|
|
3229
|
+
generatedFiles.push(genFile);
|
|
3230
|
+
}
|
|
3231
|
+
s.stop("Environment files processed!");
|
|
3232
|
+
printGeneratedFiles(generatedFiles, Boolean(flags.dryRun));
|
|
3233
|
+
p15.outro(pc15.green("\u2713 Local environment files are ready!"));
|
|
3234
|
+
return generatedFiles;
|
|
3235
|
+
}
|
|
3236
|
+
|
|
3237
|
+
// src/commands/menu.ts
|
|
3206
3238
|
async function runInteractiveMenu(flags = {}) {
|
|
3207
3239
|
printBanner();
|
|
3208
3240
|
const choice = handleCancel(
|
|
3209
|
-
await
|
|
3241
|
+
await p15.select({
|
|
3210
3242
|
message: "What would you like to create in your architecture?",
|
|
3211
3243
|
options: [
|
|
3212
3244
|
{
|
|
@@ -3248,6 +3280,11 @@ async function runInteractiveMenu(flags = {}) {
|
|
|
3248
3280
|
value: "injectable",
|
|
3249
3281
|
label: "Injectable Service",
|
|
3250
3282
|
hint: "Generic @MakeInjectable class for services, transformers, or modules"
|
|
3283
|
+
},
|
|
3284
|
+
{
|
|
3285
|
+
value: "env",
|
|
3286
|
+
label: "Generate Env Files",
|
|
3287
|
+
hint: "Clone .env*.example files to local .env equivalents"
|
|
3251
3288
|
}
|
|
3252
3289
|
]
|
|
3253
3290
|
})
|
|
@@ -3277,6 +3314,9 @@ async function runInteractiveMenu(flags = {}) {
|
|
|
3277
3314
|
case "injectable":
|
|
3278
3315
|
await runInjectableCommand(void 0, flags);
|
|
3279
3316
|
break;
|
|
3317
|
+
case "env":
|
|
3318
|
+
await runEnvCommand(flags);
|
|
3319
|
+
break;
|
|
3280
3320
|
}
|
|
3281
3321
|
}
|
|
3282
3322
|
|
|
@@ -3314,8 +3354,8 @@ async function handleCreate(type, name, flags = {}) {
|
|
|
3314
3354
|
await runInjectableCommand(name, flags);
|
|
3315
3355
|
break;
|
|
3316
3356
|
default:
|
|
3317
|
-
|
|
3318
|
-
|
|
3357
|
+
p15.log.error(
|
|
3358
|
+
pc15.red(
|
|
3319
3359
|
`Unknown component type: "${type}". Allowed types: feature, shared, usecase, domain, infrastructure, interface, httpHandler, injectable.`
|
|
3320
3360
|
)
|
|
3321
3361
|
);
|
|
@@ -3347,7 +3387,7 @@ function findLocalRegistry(startDir = process.cwd()) {
|
|
|
3347
3387
|
let current = path2.resolve(startDir);
|
|
3348
3388
|
while (true) {
|
|
3349
3389
|
const candidate = path2.join(current, "mason-registry");
|
|
3350
|
-
if (
|
|
3390
|
+
if (fs10.existsSync(candidate) && fs10.existsSync(path2.join(candidate, "index.json"))) {
|
|
3351
3391
|
return candidate;
|
|
3352
3392
|
}
|
|
3353
3393
|
const parent = path2.dirname(current);
|
|
@@ -3369,9 +3409,9 @@ function getRegistryBase(projectRoot, override) {
|
|
|
3369
3409
|
path2.join(process.cwd(), "mason.config.json")
|
|
3370
3410
|
];
|
|
3371
3411
|
for (const configPath of configLocations) {
|
|
3372
|
-
if (
|
|
3412
|
+
if (fs10.existsSync(configPath)) {
|
|
3373
3413
|
try {
|
|
3374
|
-
const config = JSON.parse(
|
|
3414
|
+
const config = JSON.parse(fs10.readFileSync(configPath, "utf-8"));
|
|
3375
3415
|
if (config.registry && typeof config.registry === "string") {
|
|
3376
3416
|
return normalizeRegistryUrl(config.registry.trim(), path2.dirname(configPath));
|
|
3377
3417
|
}
|
|
@@ -3384,9 +3424,9 @@ function getRegistryBase(projectRoot, override) {
|
|
|
3384
3424
|
path2.join(process.cwd(), "package.json")
|
|
3385
3425
|
];
|
|
3386
3426
|
for (const pkgPath of pkgLocations) {
|
|
3387
|
-
if (
|
|
3427
|
+
if (fs10.existsSync(pkgPath)) {
|
|
3388
3428
|
try {
|
|
3389
|
-
const pkg = JSON.parse(
|
|
3429
|
+
const pkg = JSON.parse(fs10.readFileSync(pkgPath, "utf-8"));
|
|
3390
3430
|
if (pkg.mason?.registry && typeof pkg.mason.registry === "string") {
|
|
3391
3431
|
return normalizeRegistryUrl(pkg.mason.registry.trim(), path2.dirname(pkgPath));
|
|
3392
3432
|
}
|
|
@@ -3437,15 +3477,15 @@ async function fetchRegistryFile(registryBase, relPath) {
|
|
|
3437
3477
|
baseDir = fileURLToPath(baseDir);
|
|
3438
3478
|
}
|
|
3439
3479
|
let filePath = path2.resolve(baseDir, cleanRelPath);
|
|
3440
|
-
if (!
|
|
3480
|
+
if (!fs10.existsSync(filePath)) {
|
|
3441
3481
|
const inSrcPath = path2.resolve(baseDir, "src", cleanRelPath);
|
|
3442
|
-
if (
|
|
3482
|
+
if (fs10.existsSync(inSrcPath)) {
|
|
3443
3483
|
filePath = inSrcPath;
|
|
3444
3484
|
} else {
|
|
3445
3485
|
throw new Error(`Registry file not found at ${filePath}`);
|
|
3446
3486
|
}
|
|
3447
3487
|
}
|
|
3448
|
-
return
|
|
3488
|
+
return fs10.promises.readFile(filePath, "utf-8");
|
|
3449
3489
|
}
|
|
3450
3490
|
async function fetchRegistryIndex(registryBase) {
|
|
3451
3491
|
const content = await fetchRegistryFile(registryBase, "index.json");
|
|
@@ -3507,26 +3547,26 @@ function findClosestMatch(target, candidates) {
|
|
|
3507
3547
|
return null;
|
|
3508
3548
|
}
|
|
3509
3549
|
function detectPackageManager(projectRoot) {
|
|
3510
|
-
if (
|
|
3511
|
-
if (
|
|
3512
|
-
if (
|
|
3550
|
+
if (fs10.existsSync(path2.join(projectRoot, "pnpm-lock.yaml"))) return "pnpm";
|
|
3551
|
+
if (fs10.existsSync(path2.join(projectRoot, "yarn.lock"))) return "yarn";
|
|
3552
|
+
if (fs10.existsSync(path2.join(projectRoot, "bun.lockb")) || fs10.existsSync(path2.join(projectRoot, "bun.lock"))) return "bun";
|
|
3513
3553
|
return "npm";
|
|
3514
3554
|
}
|
|
3515
3555
|
function getMissingNpmPackages(projectRoot, requiredPackages) {
|
|
3516
3556
|
if (!requiredPackages || requiredPackages.length === 0) return [];
|
|
3517
3557
|
const pkgJsonPath = path2.join(projectRoot, "package.json");
|
|
3518
|
-
if (!
|
|
3558
|
+
if (!fs10.existsSync(pkgJsonPath)) {
|
|
3519
3559
|
return requiredPackages;
|
|
3520
3560
|
}
|
|
3521
3561
|
try {
|
|
3522
|
-
const pkg = JSON.parse(
|
|
3562
|
+
const pkg = JSON.parse(fs10.readFileSync(pkgJsonPath, "utf-8"));
|
|
3523
3563
|
const installed = /* @__PURE__ */ new Set([
|
|
3524
3564
|
...Object.keys(pkg.dependencies || {}),
|
|
3525
3565
|
...Object.keys(pkg.devDependencies || {}),
|
|
3526
3566
|
...Object.keys(pkg.peerDependencies || {})
|
|
3527
3567
|
]);
|
|
3528
|
-
return requiredPackages.filter((
|
|
3529
|
-
const nameOnly =
|
|
3568
|
+
return requiredPackages.filter((p18) => {
|
|
3569
|
+
const nameOnly = p18.startsWith("@") ? `@${p18.slice(1).split("@")[0] || ""}` : p18.split("@")[0] || p18;
|
|
3530
3570
|
return !installed.has(nameOnly);
|
|
3531
3571
|
});
|
|
3532
3572
|
} catch {
|
|
@@ -3551,15 +3591,15 @@ function installNpmPackages(projectRoot, packages, pm) {
|
|
|
3551
3591
|
installCmd = `npm install ${packages.join(" ")}`;
|
|
3552
3592
|
break;
|
|
3553
3593
|
}
|
|
3554
|
-
|
|
3594
|
+
p15.log.info(`Installing missing dependencies with ${manager}: ${pc15.cyan(packages.join(", "))}`);
|
|
3555
3595
|
execSync(installCmd, {
|
|
3556
3596
|
cwd: projectRoot,
|
|
3557
3597
|
stdio: "inherit"
|
|
3558
3598
|
});
|
|
3559
3599
|
}
|
|
3560
3600
|
function getAllFiles(dir, baseDir = dir) {
|
|
3561
|
-
if (!
|
|
3562
|
-
const entries =
|
|
3601
|
+
if (!fs10.existsSync(dir)) return [];
|
|
3602
|
+
const entries = fs10.readdirSync(dir, { withFileTypes: true });
|
|
3563
3603
|
const files = [];
|
|
3564
3604
|
for (const entry of entries) {
|
|
3565
3605
|
const fullPath = path2.join(dir, entry.name);
|
|
@@ -3579,13 +3619,13 @@ function getAllFiles(dir, baseDir = dir) {
|
|
|
3579
3619
|
return files.sort();
|
|
3580
3620
|
}
|
|
3581
3621
|
function computeDirectoryHash(dirPath, files) {
|
|
3582
|
-
if (!
|
|
3622
|
+
if (!fs10.existsSync(dirPath)) return "";
|
|
3583
3623
|
const hash = createHash("sha256");
|
|
3584
3624
|
const fileList = (getAllFiles(dirPath)).sort();
|
|
3585
3625
|
for (const relativePath of fileList) {
|
|
3586
3626
|
const absolutePath = path2.join(dirPath, relativePath);
|
|
3587
|
-
if (!
|
|
3588
|
-
const content =
|
|
3627
|
+
if (!fs10.existsSync(absolutePath)) continue;
|
|
3628
|
+
const content = fs10.readFileSync(absolutePath, "utf8");
|
|
3589
3629
|
const normalizedContent = content.replace(/\r\n/g, "\n");
|
|
3590
3630
|
hash.update(relativePath);
|
|
3591
3631
|
hash.update(normalizedContent);
|
|
@@ -3595,9 +3635,9 @@ function computeDirectoryHash(dirPath, files) {
|
|
|
3595
3635
|
|
|
3596
3636
|
// src/commands/import.ts
|
|
3597
3637
|
var importPrompts = {
|
|
3598
|
-
select:
|
|
3599
|
-
text:
|
|
3600
|
-
confirm:
|
|
3638
|
+
select: p15.select,
|
|
3639
|
+
text: p15.text,
|
|
3640
|
+
confirm: p15.confirm
|
|
3601
3641
|
};
|
|
3602
3642
|
function isTestFile(filePath) {
|
|
3603
3643
|
const normalized = filePath.replace(/\\/g, "/");
|
|
@@ -3629,11 +3669,11 @@ function getExistingModuleDir(projectRoot, modType, modName) {
|
|
|
3629
3669
|
const folder = modType === "shared" ? "shared" : "features";
|
|
3630
3670
|
const configuredDir = modType === "shared" ? getConfiguredSharedDir(projectRoot) : getConfiguredFeaturesDir(projectRoot);
|
|
3631
3671
|
const inConfigured = path2.join(configuredDir, modName);
|
|
3632
|
-
if (
|
|
3672
|
+
if (fs10.existsSync(inConfigured)) return inConfigured;
|
|
3633
3673
|
const inSrc = path2.join(projectRoot, "src", folder, modName);
|
|
3634
|
-
if (
|
|
3674
|
+
if (fs10.existsSync(inSrc)) return inSrc;
|
|
3635
3675
|
const inRoot = path2.join(projectRoot, folder, modName);
|
|
3636
|
-
if (
|
|
3676
|
+
if (fs10.existsSync(inRoot)) return inRoot;
|
|
3637
3677
|
return null;
|
|
3638
3678
|
}
|
|
3639
3679
|
function checkModuleExists(projectRoot, modType, modName) {
|
|
@@ -3649,9 +3689,9 @@ function getAvailableLocalModules(projectRoot, modType) {
|
|
|
3649
3689
|
];
|
|
3650
3690
|
const set = /* @__PURE__ */ new Set();
|
|
3651
3691
|
for (const dir of dirs) {
|
|
3652
|
-
if (
|
|
3692
|
+
if (fs10.existsSync(dir)) {
|
|
3653
3693
|
try {
|
|
3654
|
-
const entries =
|
|
3694
|
+
const entries = fs10.readdirSync(dir, { withFileTypes: true });
|
|
3655
3695
|
for (const e of entries) {
|
|
3656
3696
|
if (e.isDirectory() && !e.name.startsWith(".")) {
|
|
3657
3697
|
set.add(e.name);
|
|
@@ -3707,19 +3747,19 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3707
3747
|
);
|
|
3708
3748
|
}
|
|
3709
3749
|
if (type !== "shared" && type !== "feature") {
|
|
3710
|
-
|
|
3750
|
+
p15.log.error(pc15.red(`Invalid module type: "${typeArg}". Must be "shared" or "feature".`));
|
|
3711
3751
|
process.exit(1);
|
|
3712
3752
|
}
|
|
3713
3753
|
const registryBase = getRegistryBase(projectRoot, flags.registry);
|
|
3714
|
-
const s =
|
|
3715
|
-
s.start(`Connecting to registry at ${
|
|
3754
|
+
const s = p15.spinner();
|
|
3755
|
+
s.start(`Connecting to registry at ${pc15.dim(registryBase)}...`);
|
|
3716
3756
|
let index;
|
|
3717
3757
|
try {
|
|
3718
3758
|
index = await fetchRegistryIndex(registryBase);
|
|
3719
3759
|
s.stop("Registry index loaded.");
|
|
3720
3760
|
} catch (err) {
|
|
3721
|
-
s.stop(
|
|
3722
|
-
|
|
3761
|
+
s.stop(pc15.red("Failed to load registry index."));
|
|
3762
|
+
p15.log.error(pc15.red(err.message || String(err)));
|
|
3723
3763
|
process.exit(1);
|
|
3724
3764
|
}
|
|
3725
3765
|
const availableList = type === "shared" ? index.shared : index.features;
|
|
@@ -3727,7 +3767,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3727
3767
|
let name = nameArg?.trim();
|
|
3728
3768
|
if (!name) {
|
|
3729
3769
|
if (availableList.length === 0) {
|
|
3730
|
-
|
|
3770
|
+
p15.log.warn(`No ${type} modules available in the registry.`);
|
|
3731
3771
|
return;
|
|
3732
3772
|
}
|
|
3733
3773
|
name = handleCancel(
|
|
@@ -3743,9 +3783,9 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3743
3783
|
}
|
|
3744
3784
|
if (!candidateNames.includes(name)) {
|
|
3745
3785
|
const closest = findClosestMatch(name, candidateNames);
|
|
3746
|
-
|
|
3786
|
+
p15.log.error(pc15.red(`\u274C Module '${name}' not found in the ${type} registry.`));
|
|
3747
3787
|
if (closest) {
|
|
3748
|
-
|
|
3788
|
+
p15.log.info(pc15.yellow(`Did you mean '${pc15.cyan(closest)}'?`));
|
|
3749
3789
|
}
|
|
3750
3790
|
process.exit(1);
|
|
3751
3791
|
}
|
|
@@ -3757,7 +3797,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3757
3797
|
try {
|
|
3758
3798
|
manifest = await fetchModuleManifest(registryBase, modType, modName);
|
|
3759
3799
|
} catch (err) {
|
|
3760
|
-
|
|
3800
|
+
p15.log.error(pc15.red(`Failed to fetch manifest for ${modType} '${modName}': ${err.message}`));
|
|
3761
3801
|
process.exit(1);
|
|
3762
3802
|
}
|
|
3763
3803
|
nodes.set(key, {
|
|
@@ -3797,7 +3837,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3797
3837
|
buildTopologicalOrder(rootKey);
|
|
3798
3838
|
const resolutions = /* @__PURE__ */ new Map();
|
|
3799
3839
|
const globalAliasMap = /* @__PURE__ */ new Map();
|
|
3800
|
-
|
|
3840
|
+
p15.log.step(`Importing ${type}: ${pc15.cyan(name)}...`);
|
|
3801
3841
|
for (const key of orderedKeys) {
|
|
3802
3842
|
const node = nodes.get(key);
|
|
3803
3843
|
const { type: modType, name: registryName, manifest } = node;
|
|
@@ -3829,8 +3869,8 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3829
3869
|
const programmaticPointTo = pointToMap[registryName] || pointToMap[`${modType}/${registryName}`];
|
|
3830
3870
|
if (programmaticPointTo) {
|
|
3831
3871
|
if (!checkModuleExists(projectRoot, modType, programmaticPointTo)) {
|
|
3832
|
-
|
|
3833
|
-
|
|
3872
|
+
p15.log.error(
|
|
3873
|
+
pc15.red(
|
|
3834
3874
|
`Module '${programmaticPointTo}' specified in --point-to does not exist in ${folder}.`
|
|
3835
3875
|
)
|
|
3836
3876
|
);
|
|
@@ -3838,7 +3878,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3838
3878
|
}
|
|
3839
3879
|
globalAliasMap.set(`@/${folder}/${registryName}/`, `@/${folder}/${programmaticPointTo}/`);
|
|
3840
3880
|
globalAliasMap.set(`@/${folder}/${registryName}`, `@/${folder}/${programmaticPointTo}`);
|
|
3841
|
-
|
|
3881
|
+
p15.log.step(`Pointing '${modType}/${registryName}' to existing '${folder}/${programmaticPointTo}'`);
|
|
3842
3882
|
resolutions.set(key, {
|
|
3843
3883
|
type: modType,
|
|
3844
3884
|
registryName,
|
|
@@ -3854,7 +3894,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3854
3894
|
globalAliasMap.set(`@/${folder}/${registryName}`, `@/${folder}/${programmaticAlias}`);
|
|
3855
3895
|
const baseDir = getModuleBaseDir(projectRoot, modType);
|
|
3856
3896
|
const displayDest = path2.relative(projectRoot, path2.join(baseDir, programmaticAlias));
|
|
3857
|
-
|
|
3897
|
+
p15.log.step(`Importing '${registryName}' into '${displayDest}'...`);
|
|
3858
3898
|
resolutions.set(key, {
|
|
3859
3899
|
type: modType,
|
|
3860
3900
|
registryName,
|
|
@@ -3866,7 +3906,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3866
3906
|
}
|
|
3867
3907
|
const existingDir = getExistingModuleDir(projectRoot, modType, registryName);
|
|
3868
3908
|
if (!existingDir) {
|
|
3869
|
-
|
|
3909
|
+
p15.log.info(` \u21B3 Resolving required ${modType} dependency: ${pc15.cyan(registryName)}`);
|
|
3870
3910
|
resolutions.set(key, {
|
|
3871
3911
|
type: modType,
|
|
3872
3912
|
registryName,
|
|
@@ -3882,7 +3922,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3882
3922
|
const remoteIntegrity = manifest.integrity || entry?.integrity;
|
|
3883
3923
|
const localHash = computeDirectoryHash(existingDir);
|
|
3884
3924
|
if (remoteIntegrity && localHash === remoteIntegrity) {
|
|
3885
|
-
|
|
3925
|
+
p15.log.step(`\u2713 ${modType}/${registryName} is up to date (reusing existing)`);
|
|
3886
3926
|
resolutions.set(key, {
|
|
3887
3927
|
type: modType,
|
|
3888
3928
|
registryName,
|
|
@@ -3893,7 +3933,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3893
3933
|
continue;
|
|
3894
3934
|
}
|
|
3895
3935
|
if (flags.overwrite) {
|
|
3896
|
-
|
|
3936
|
+
p15.log.step(`Overwriting '${modType}/${registryName}' with registry version (--overwrite)...`);
|
|
3897
3937
|
resolutions.set(key, {
|
|
3898
3938
|
type: modType,
|
|
3899
3939
|
registryName,
|
|
@@ -3904,7 +3944,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3904
3944
|
continue;
|
|
3905
3945
|
}
|
|
3906
3946
|
if (flags.yes) {
|
|
3907
|
-
|
|
3947
|
+
p15.log.info(`Using existing '${modType}/${registryName}'`);
|
|
3908
3948
|
resolutions.set(key, {
|
|
3909
3949
|
type: modType,
|
|
3910
3950
|
registryName,
|
|
@@ -3938,7 +3978,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3938
3978
|
})
|
|
3939
3979
|
);
|
|
3940
3980
|
if (choice === "keep_existing" || choice === "use_existing") {
|
|
3941
|
-
|
|
3981
|
+
p15.log.step(`Skipping '${modType}/${registryName}' (keeping existing)`);
|
|
3942
3982
|
resolutions.set(key, {
|
|
3943
3983
|
type: modType,
|
|
3944
3984
|
registryName,
|
|
@@ -4010,7 +4050,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
4010
4050
|
chosenName = chosenName.replace(/^@\/(shared|features)\//, "").replace(/^(src\/)?(shared|features)\//, "").replace(/^\/+|\/+$/g, "").trim();
|
|
4011
4051
|
globalAliasMap.set(`@/${folder}/${registryName}/`, `@/${folder}/${chosenName}/`);
|
|
4012
4052
|
globalAliasMap.set(`@/${folder}/${registryName}`, `@/${folder}/${chosenName}`);
|
|
4013
|
-
|
|
4053
|
+
p15.log.step(`Pointing '${modType}/${registryName}' to existing '${folder}/${chosenName}'`);
|
|
4014
4054
|
resolutions.set(key, {
|
|
4015
4055
|
type: modType,
|
|
4016
4056
|
registryName,
|
|
@@ -4042,7 +4082,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
4042
4082
|
globalAliasMap.set(`@/${folder}/${registryName}`, `@/${folder}/${newName}`);
|
|
4043
4083
|
const baseDir = getModuleBaseDir(projectRoot, modType);
|
|
4044
4084
|
const displayDest = path2.relative(projectRoot, path2.join(baseDir, newName));
|
|
4045
|
-
|
|
4085
|
+
p15.log.step(`Importing '${registryName}' into '${displayDest}'...`);
|
|
4046
4086
|
resolutions.set(key, {
|
|
4047
4087
|
type: modType,
|
|
4048
4088
|
registryName,
|
|
@@ -4053,7 +4093,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
4053
4093
|
continue;
|
|
4054
4094
|
}
|
|
4055
4095
|
if (choice === "overwrite") {
|
|
4056
|
-
|
|
4096
|
+
p15.log.step(`Overwriting '${modType}/${registryName}' with registry version...`);
|
|
4057
4097
|
resolutions.set(key, {
|
|
4058
4098
|
type: modType,
|
|
4059
4099
|
registryName,
|
|
@@ -4096,17 +4136,17 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
4096
4136
|
const targetDir = path2.join(getModuleBaseDir(projectRoot, res.type), res.targetName);
|
|
4097
4137
|
const isOverwrite = Boolean(flags.overwrite || res.action === "overwrite");
|
|
4098
4138
|
if (key !== rootKey) {
|
|
4099
|
-
|
|
4100
|
-
`Importing ${res.type}: ${
|
|
4139
|
+
p15.log.step(
|
|
4140
|
+
`Importing ${res.type}: ${pc15.cyan(res.targetName)}${res.targetName !== res.registryName ? pc15.dim(` (from ${res.registryName})`) : ""}...`
|
|
4101
4141
|
);
|
|
4102
4142
|
}
|
|
4103
4143
|
if (res.action === "overwrite" && !flags.dryRun) {
|
|
4104
4144
|
const existingDir = getExistingModuleDir(projectRoot, res.type, res.targetName);
|
|
4105
4145
|
if (existingDir && existingDir !== targetDir) {
|
|
4106
|
-
|
|
4146
|
+
fs10.rmSync(existingDir, { recursive: true, force: true });
|
|
4107
4147
|
}
|
|
4108
|
-
if (
|
|
4109
|
-
|
|
4148
|
+
if (fs10.existsSync(targetDir)) {
|
|
4149
|
+
fs10.rmSync(targetDir, { recursive: true, force: true });
|
|
4110
4150
|
}
|
|
4111
4151
|
}
|
|
4112
4152
|
for (const file of res.manifest.files || []) {
|
|
@@ -4114,32 +4154,32 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
4114
4154
|
if (!includeTests && isTestFile(file)) continue;
|
|
4115
4155
|
const remoteFilePath = `${folder}/${res.registryName}/${file}`;
|
|
4116
4156
|
const localFilePath = path2.join(targetDir, file);
|
|
4117
|
-
if (
|
|
4118
|
-
|
|
4119
|
-
` \u21B3 Skipping existing file: ${
|
|
4157
|
+
if (fs10.existsSync(localFilePath) && !isOverwrite) {
|
|
4158
|
+
p15.log.warn(
|
|
4159
|
+
` \u21B3 Skipping existing file: ${pc15.dim(path2.relative(projectRoot, localFilePath))} (use --overwrite to replace)`
|
|
4120
4160
|
);
|
|
4121
4161
|
continue;
|
|
4122
4162
|
}
|
|
4123
4163
|
let content = await fetchRegistryFile(registryBase, remoteFilePath);
|
|
4124
4164
|
content = rewriteImports(content, globalAliasMap);
|
|
4125
4165
|
if (!flags.dryRun) {
|
|
4126
|
-
|
|
4127
|
-
|
|
4166
|
+
fs10.mkdirSync(path2.dirname(localFilePath), { recursive: true });
|
|
4167
|
+
fs10.writeFileSync(localFilePath, content, "utf-8");
|
|
4128
4168
|
}
|
|
4129
4169
|
const displayPath = path2.relative(projectRoot, localFilePath);
|
|
4130
4170
|
totalWrittenFiles.push(displayPath);
|
|
4131
|
-
|
|
4171
|
+
p15.log.message(` ${pc15.green("+")} ${displayPath}`);
|
|
4132
4172
|
}
|
|
4133
4173
|
}
|
|
4134
4174
|
const missingNpm = getMissingNpmPackages(projectRoot, Array.from(requiredNpmPackages));
|
|
4135
4175
|
if (missingNpm.length > 0) {
|
|
4136
4176
|
if (flags.skipInstall || flags.dryRun) {
|
|
4137
|
-
|
|
4177
|
+
p15.log.info(`Required npm dependencies to install: ${pc15.cyan(missingNpm.join(", "))}`);
|
|
4138
4178
|
} else {
|
|
4139
4179
|
try {
|
|
4140
4180
|
installNpmPackages(projectRoot, missingNpm);
|
|
4141
4181
|
} catch (err) {
|
|
4142
|
-
|
|
4182
|
+
p15.log.warn(
|
|
4143
4183
|
`Could not automatically install packages (${err.message}). Please run: npm install ${missingNpm.join(
|
|
4144
4184
|
" "
|
|
4145
4185
|
)}`
|
|
@@ -4148,13 +4188,13 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
4148
4188
|
}
|
|
4149
4189
|
}
|
|
4150
4190
|
if (flags.dryRun) {
|
|
4151
|
-
|
|
4191
|
+
p15.log.info(pc15.yellow("Dry run complete: No files were written to disk."));
|
|
4152
4192
|
} else {
|
|
4153
4193
|
const rootRes = resolutions.get(rootKey);
|
|
4154
4194
|
const baseDir = getModuleBaseDir(projectRoot, type);
|
|
4155
4195
|
const displayTarget = path2.relative(projectRoot, path2.join(baseDir, rootRes.targetName));
|
|
4156
|
-
|
|
4157
|
-
|
|
4196
|
+
p15.log.success(
|
|
4197
|
+
pc15.green(
|
|
4158
4198
|
`Successfully imported ${type} '${name}' (${totalWrittenFiles.length} file${totalWrittenFiles.length === 1 ? "" : "s"} placed in ${displayTarget})`
|
|
4159
4199
|
)
|
|
4160
4200
|
);
|
|
@@ -4176,8 +4216,8 @@ function isTestFile2(filePath, projectRoot) {
|
|
|
4176
4216
|
return base.endsWith(".test.ts") || base.endsWith(".test.js") || base.endsWith(".spec.ts") || base.endsWith(".spec.js") || base.endsWith(".d.ts") || norm.includes("/__tests__/") || norm.startsWith("__tests__/") || /(?:^|\/)tests?\//.test(norm);
|
|
4177
4217
|
}
|
|
4178
4218
|
function scanDirFiles(dir, projectRoot) {
|
|
4179
|
-
if (!
|
|
4180
|
-
const entries =
|
|
4219
|
+
if (!fs10.existsSync(dir)) return [];
|
|
4220
|
+
const entries = fs10.readdirSync(dir, { withFileTypes: true });
|
|
4181
4221
|
const files = [];
|
|
4182
4222
|
for (const entry of entries) {
|
|
4183
4223
|
if (entry.name === "node_modules" || entry.name === "dist" || entry.name === "__tests__" || entry.name.startsWith(".")) {
|
|
@@ -4377,10 +4417,10 @@ var FeatureDependencyGraph = class {
|
|
|
4377
4417
|
if (cycle) return cycle;
|
|
4378
4418
|
} else if (inStack.has(next)) {
|
|
4379
4419
|
const cycle = [next];
|
|
4380
|
-
let
|
|
4381
|
-
while (
|
|
4382
|
-
cycle.push(
|
|
4383
|
-
|
|
4420
|
+
let p18 = curr;
|
|
4421
|
+
while (p18 !== next) {
|
|
4422
|
+
cycle.push(p18);
|
|
4423
|
+
p18 = parent.get(p18) || next;
|
|
4384
4424
|
}
|
|
4385
4425
|
cycle.push(next);
|
|
4386
4426
|
cycle.reverse();
|
|
@@ -4396,8 +4436,8 @@ var FeatureDependencyGraph = class {
|
|
|
4396
4436
|
};
|
|
4397
4437
|
function discoverAllFeatures(projectRoot) {
|
|
4398
4438
|
const featuresBase = resolveFeaturesDir(projectRoot);
|
|
4399
|
-
if (!
|
|
4400
|
-
const entries =
|
|
4439
|
+
if (!fs10.existsSync(featuresBase)) return [];
|
|
4440
|
+
const entries = fs10.readdirSync(featuresBase, { withFileTypes: true });
|
|
4401
4441
|
return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".") && e.name !== "__tests__" && e.name !== "tests").map((e) => ({
|
|
4402
4442
|
name: e.name,
|
|
4403
4443
|
dir: path2.join(featuresBase, e.name)
|
|
@@ -4788,7 +4828,7 @@ Code: ${v.code}`;
|
|
|
4788
4828
|
const relPath = path2.relative(projectRoot, file).replace(/\\/g, "/");
|
|
4789
4829
|
const { layer } = classifyFile(file, projectRoot);
|
|
4790
4830
|
if (!layer) continue;
|
|
4791
|
-
const content =
|
|
4831
|
+
const content = fs10.readFileSync(file, "utf-8");
|
|
4792
4832
|
const statements = extractImportStatements(content);
|
|
4793
4833
|
const baseName = path2.basename(file);
|
|
4794
4834
|
const isBarrel = baseName === "index.ts" || baseName === "index.js";
|
|
@@ -5282,15 +5322,15 @@ ${compiledDetails}
|
|
|
5282
5322
|
// src/commands/lint.ts
|
|
5283
5323
|
function formatViolation(v) {
|
|
5284
5324
|
const lines = [];
|
|
5285
|
-
lines.push(
|
|
5325
|
+
lines.push(pc15.underline(pc15.cyan(v.relativePath)) + pc15.dim(":") + pc15.yellow(String(v.line)));
|
|
5286
5326
|
const gutter = `${String(v.line).padStart(4, " ")} | `;
|
|
5287
|
-
lines.push(
|
|
5327
|
+
lines.push(pc15.dim(gutter) + v.code);
|
|
5288
5328
|
const categoryShort = v.category.replace(" Violation", "");
|
|
5289
5329
|
lines.push(
|
|
5290
|
-
" " +
|
|
5330
|
+
" " + pc15.red(pc15.bold("\u2716")) + " " + pc15.red(`[${categoryShort}]`) + " " + v.advice
|
|
5291
5331
|
);
|
|
5292
5332
|
if (v.fixExample?.good) {
|
|
5293
|
-
lines.push(" " +
|
|
5333
|
+
lines.push(" " + pc15.dim("\u2192") + " " + pc15.dim(v.fixExample.good));
|
|
5294
5334
|
}
|
|
5295
5335
|
return lines.join("\n");
|
|
5296
5336
|
}
|
|
@@ -5315,7 +5355,7 @@ async function handleLint(flags = {}) {
|
|
|
5315
5355
|
console.log("");
|
|
5316
5356
|
}
|
|
5317
5357
|
console.log(
|
|
5318
|
-
|
|
5358
|
+
pc15.red(
|
|
5319
5359
|
`\u2716 Dependency rules check failed with ${summary.totalViolations} error${summary.totalViolations > 1 ? "s" : ""} across ${summary.violatedFeatures} feature${summary.violatedFeatures > 1 ? "s" : ""} (${summary.totalFeatures} features scanned).`
|
|
5320
5360
|
)
|
|
5321
5361
|
);
|
|
@@ -5334,7 +5374,7 @@ ${compiledDetails}
|
|
|
5334
5374
|
}
|
|
5335
5375
|
if (!quiet) {
|
|
5336
5376
|
console.log(
|
|
5337
|
-
|
|
5377
|
+
pc15.green(
|
|
5338
5378
|
`\u2714 Dependency rules verified across ${summary.totalFeatures} feature${summary.totalFeatures === 1 ? "" : "s"}.`
|
|
5339
5379
|
)
|
|
5340
5380
|
);
|
|
@@ -5349,21 +5389,55 @@ ${compiledDetails}
|
|
|
5349
5389
|
console.log(formatViolation(v));
|
|
5350
5390
|
console.log("");
|
|
5351
5391
|
}
|
|
5352
|
-
console.log(
|
|
5392
|
+
console.log(pc15.red(`\u2716 Dependency rules check failed (1 error).`));
|
|
5353
5393
|
console.log("");
|
|
5354
5394
|
}
|
|
5355
5395
|
}
|
|
5356
5396
|
throw err;
|
|
5357
5397
|
}
|
|
5358
5398
|
}
|
|
5399
|
+
async function handleInit(type, flags = {}) {
|
|
5400
|
+
if (!type) {
|
|
5401
|
+
const choice = handleCancel(
|
|
5402
|
+
await p15.select({
|
|
5403
|
+
message: "What would you like to initialize?",
|
|
5404
|
+
options: [
|
|
5405
|
+
{
|
|
5406
|
+
value: "env",
|
|
5407
|
+
label: "Environment Files",
|
|
5408
|
+
hint: "Generate local .env files from .env*.example templates"
|
|
5409
|
+
}
|
|
5410
|
+
]
|
|
5411
|
+
})
|
|
5412
|
+
);
|
|
5413
|
+
if (choice === "env") {
|
|
5414
|
+
await runEnvCommand(flags);
|
|
5415
|
+
}
|
|
5416
|
+
return;
|
|
5417
|
+
}
|
|
5418
|
+
const normalized = type.trim().toLowerCase();
|
|
5419
|
+
if (normalized === "env") {
|
|
5420
|
+
await runEnvCommand(flags);
|
|
5421
|
+
} else {
|
|
5422
|
+
p15.log.error(
|
|
5423
|
+
pc15.red(
|
|
5424
|
+
`Unknown init target: "${type}". Allowed targets: env.`
|
|
5425
|
+
)
|
|
5426
|
+
);
|
|
5427
|
+
if (process.env.VITEST) {
|
|
5428
|
+
throw new Error(`Unknown init target: "${type}". Allowed targets: env.`);
|
|
5429
|
+
}
|
|
5430
|
+
process.exit(1);
|
|
5431
|
+
}
|
|
5432
|
+
}
|
|
5359
5433
|
|
|
5360
5434
|
// src/cli.ts
|
|
5361
5435
|
function createCli() {
|
|
5362
5436
|
const cli = cac("mason");
|
|
5363
5437
|
cli.command("[...args]", "Interactive scaffolding and import wizard").option("-d, --dry-run", "Preview changes without writing to disk").option("-o, --overwrite", "Overwrite existing files").option("-y, --yes", "Accept defaults and skip interactive prompts").option("--registry", "Run in registry mode").option("--point-to <mapping>", "Point a dependency to an existing local module (e.g. --point-to time:mytime)").option("--alias <mapping>", "Import a dependency fresh under an alias name (e.g. --alias time:time-mason)").option("--tests", "Include test files (use --no-tests to exclude)").action(async (args, flags) => {
|
|
5364
5438
|
if (args && args.length > 0) {
|
|
5365
|
-
|
|
5366
|
-
|
|
5439
|
+
p15.log.error(
|
|
5440
|
+
pc15.red(
|
|
5367
5441
|
`Unknown command: "${args.join(" ")}". Use --help to list available commands.`
|
|
5368
5442
|
)
|
|
5369
5443
|
);
|
|
@@ -5374,7 +5448,7 @@ function createCli() {
|
|
|
5374
5448
|
const mode = getEffectiveMode(projectRoot, flags);
|
|
5375
5449
|
if (mode === "registry") {
|
|
5376
5450
|
const choice2 = handleCancel(
|
|
5377
|
-
await
|
|
5451
|
+
await p15.select({
|
|
5378
5452
|
message: "\u{1F3DB}\uFE0F Mason (Registry Mode): What would you like to scaffold?",
|
|
5379
5453
|
options: [
|
|
5380
5454
|
{
|
|
@@ -5417,7 +5491,7 @@ function createCli() {
|
|
|
5417
5491
|
return;
|
|
5418
5492
|
}
|
|
5419
5493
|
const choice = handleCancel(
|
|
5420
|
-
await
|
|
5494
|
+
await p15.select({
|
|
5421
5495
|
message: "\u{1F9F1} Mason: What would you like to do?",
|
|
5422
5496
|
options: [
|
|
5423
5497
|
{
|
|
@@ -5434,6 +5508,11 @@ function createCli() {
|
|
|
5434
5508
|
value: "lint",
|
|
5435
5509
|
label: "Lint dependency rules",
|
|
5436
5510
|
hint: "Scan codebase and verify Clean Architecture dependency rules"
|
|
5511
|
+
},
|
|
5512
|
+
{
|
|
5513
|
+
value: "init",
|
|
5514
|
+
label: "Initialize environment",
|
|
5515
|
+
hint: "Generate local .env files from .env*.example templates"
|
|
5437
5516
|
}
|
|
5438
5517
|
]
|
|
5439
5518
|
})
|
|
@@ -5444,6 +5523,8 @@ function createCli() {
|
|
|
5444
5523
|
await handleImport(void 0, void 0, flags);
|
|
5445
5524
|
} else if (choice === "lint") {
|
|
5446
5525
|
await handleLint(flags);
|
|
5526
|
+
} else if (choice === "init") {
|
|
5527
|
+
await handleInit("env", flags);
|
|
5447
5528
|
}
|
|
5448
5529
|
} catch (err) {
|
|
5449
5530
|
handleCliError(err);
|
|
@@ -5491,6 +5572,16 @@ function createCli() {
|
|
|
5491
5572
|
handleCliError(err);
|
|
5492
5573
|
}
|
|
5493
5574
|
});
|
|
5575
|
+
cli.command(
|
|
5576
|
+
"init [type]",
|
|
5577
|
+
"Initialize project configurations and resources (e.g. 'mason init env')"
|
|
5578
|
+
).option("-d, --dry-run", "Preview changes without writing to disk").option("-o, --overwrite", "Overwrite existing .env files").example("mason init env").example("mason init env --overwrite").example("mason init env --dry-run").action(async (type, flags = {}) => {
|
|
5579
|
+
try {
|
|
5580
|
+
await handleInit(type, flags);
|
|
5581
|
+
} catch (err) {
|
|
5582
|
+
handleCliError(err);
|
|
5583
|
+
}
|
|
5584
|
+
});
|
|
5494
5585
|
const createSubtypes = [
|
|
5495
5586
|
"feature",
|
|
5496
5587
|
"shared",
|
|
@@ -5522,7 +5613,7 @@ function handleCliError(err) {
|
|
|
5522
5613
|
process.exit(0);
|
|
5523
5614
|
}
|
|
5524
5615
|
const message = err instanceof Error ? err.message : String(err);
|
|
5525
|
-
|
|
5616
|
+
p15.log.error(pc15.red(`Error: ${message}`));
|
|
5526
5617
|
if (process.env.VITEST) {
|
|
5527
5618
|
throw err;
|
|
5528
5619
|
}
|