scaffoldrite 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scaffoldrite",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "A project structure validator and generator CLI tool.",
5
5
  "author": "Isaac Anasonye",
6
6
  "license": "MIT",
package/dist/ast.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,632 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.commandHandlers = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const validator_1 = require("./validator");
10
- const parser_1 = require("./parser");
11
- const generator_1 = require("./generator");
12
- const structure_1 = require("./structure");
13
- const validateFS_1 = require("./validateFS");
14
- const fsToAst_1 = require("./fsToAst");
15
- const index_1 = require("./data/index");
16
- const pkg = require("../package.json");
17
- const index_2 = require("./utils/index");
18
- const progress_1 = require("./progress");
19
- const index_3 = require("./utils/index");
20
- // import { structureToSRString } from "./utils/index";
21
- // import { v4 as uuidv4 } from "uuid";
22
- // import chalk from "chalk";
23
- const index_4 = require("./data/index");
24
- const index_5 = require("./utils/index");
25
- const index_6 = require("./utils/index");
26
- const index_7 = require("./utils/index");
27
- const args = process.argv.slice(3).filter((a) => !a.startsWith("--"));
28
- const arg3 = args[0];
29
- const arg4 = args[1];
30
- // commandHandler.ts
31
- const command = process.argv[2];
32
- const passedFlags = (0, index_3.getPassedFlags)();
33
- const allowedFlags = index_3.ALLOWED_FLAGS[command];
34
- const dryRun = (0, index_3.hasFlag)("--dry-run");
35
- const bar = (0, progress_1.createProgressBar)();
36
- const verbose = (0, index_3.hasFlag)("--verbose");
37
- const summary = (0, index_3.hasFlag)("--summary");
38
- const ignoreTooling = (0, index_3.hasFlag)("--ignore-tooling");
39
- const requiresInit = ["update", "merge", "validate", "generate", "create", "delete", "rename", "list"];
40
- if (requiresInit.includes(command)) {
41
- if (!fs_1.default.existsSync(index_6.SCAFFOLDRITE_DIR) || !fs_1.default.existsSync(index_6.STRUCTURE_PATH)) {
42
- console.error(index_4.theme.error.bold(`${index_4.icons.error} Error: Scaffoldrite is not initialized.\n`) +
43
- index_4.theme.primary(`Please run:\n scaffoldrite init [dir]`));
44
- (0, index_3.printUsage)("init");
45
- process.exit(1);
46
- }
47
- }
48
- const isStructure = (0, index_3.hasFlag)("--structure") || (0, index_3.hasFlag)("--sr");
49
- const isFS = (0, index_3.hasFlag)("--fs");
50
- const isDiff = (0, index_3.hasFlag)("--diff");
51
- const withIcons = (0, index_3.hasFlag)('--with-icon');
52
- const empty = (0, index_3.hasFlag)("--empty");
53
- const fromFs = (0, index_3.hasFlag)("--from-fs");
54
- const force = (0, index_3.hasFlag)("--force");
55
- const ifNotExists = (0, index_3.hasFlag)("--if-not-exists");
56
- const allowExtraPaths = (0, index_3.getFlagValuesAfter)("--allow-extra");
57
- const allowExtra = (0, index_3.hasFlag)("--allow-extra") && allowExtraPaths.length === 0;
58
- const parsed = (0, parser_1.parseStructure)(index_1.DEFAULT_TEMPLATE);
59
- const copyContents = (0, index_3.hasFlag)("--copy");
60
- if (!command || command === "--help" || command === "-h") {
61
- (0, index_3.printUsage)();
62
- process.exit(0);
63
- }
64
- if (!allowedFlags) {
65
- console.error(index_4.theme.error.bold(`${index_4.icons.error} Unknown command: ${command}`));
66
- process.exit(1);
67
- }
68
- const invalidFlags = passedFlags.filter((flag) => !allowedFlags.includes(flag));
69
- if (invalidFlags.length > 0) {
70
- console.error(index_4.theme.error.bold(`${index_4.icons.error} Unknown flag(s) for '${command}': `) +
71
- index_4.theme.warning(invalidFlags.join(", ")));
72
- (0, index_3.printUsage)(command);
73
- process.exit(1);
74
- }
75
- (0, index_5.checkMutuallyExclusiveFlags)({
76
- command,
77
- summary,
78
- verbose,
79
- empty,
80
- fromFs,
81
- ignoreTooling,
82
- copyContents,
83
- isFS,
84
- isStructure,
85
- isDiff,
86
- theme: index_4.theme,
87
- icons: index_4.icons,
88
- });
89
- (0, index_5.runRequirements)({
90
- command,
91
- arg3,
92
- arg4,
93
- fromFs,
94
- printUsage: index_3.printUsage,
95
- });
96
- exports.commandHandlers = {
97
- version: () => {
98
- console.log(index_4.theme.primary.bold('Scaffoldrite') +
99
- index_4.theme.muted(' v') +
100
- index_4.theme.light.bold(pkg.version));
101
- process.exit(0);
102
- },
103
- // history:async()=> {
104
- // if (!fs.existsSync(HISTORY_DIR)) {
105
- // console.log(chalk.red("āŒ No history found."));
106
- // process.exit(0);
107
- // }
108
- // const files = fs.readdirSync(HISTORY_DIR).filter(f => f.endsWith(".json"));
109
- // if (files.length === 0) {
110
- // console.log(chalk.yellow("āš ļø No history entries found."));
111
- // process.exit(0);
112
- // }
113
- // console.log(chalk.cyanBright.bold("šŸ“œ Scaffoldrite History Entries:\n"));
114
- // for (const file of files.sort()) {
115
- // const fullPath = path.join(HISTORY_DIR, file);
116
- // const entry: HistoryEntry = JSON.parse(fs.readFileSync(fullPath, "utf-8"));
117
- // console.log(`${chalk.green("ID:")} ${chalk.whiteBright(entry.id)}`);
118
- // console.log(`${chalk.green("Command:")} ${chalk.blueBright(entry.command)}`);
119
- // console.log(`${chalk.green("Args:")} ${chalk.magenta(entry.args.join(" "))}`);
120
- // console.log(`${chalk.green("Flags:")} ${chalk.yellow(entry.flags.join(", "))}`);
121
- // console.log(`${chalk.green("Timestamp:")} ${chalk.gray(new Date(entry.timestamp).toLocaleString())}`);
122
- // console.log(chalk.gray("-".repeat(40)));
123
- // }
124
- // console.log(chalk.cyanBright.bold(`Total entries: ${files.length}`));
125
- // return;
126
- // }
127
- // },
128
- init: async () => {
129
- const shouldOverwrite = force;
130
- const sDir = path_1.default.join(index_7.baseDir, ".scaffoldrite");
131
- // Create folder if missing
132
- if (!fs_1.default.existsSync(sDir)) {
133
- fs_1.default.mkdirSync(sDir, { recursive: true });
134
- }
135
- /* ===============================
136
- * OVERWRITE GUARDS
137
- * =============================== */
138
- const existingConfigs = [];
139
- if (fs_1.default.existsSync(index_6.STRUCTURE_PATH))
140
- existingConfigs.push("structure.sr");
141
- if (fs_1.default.existsSync(index_6.IGNORE_PATH))
142
- existingConfigs.push(".scaffoldignore");
143
- if (!shouldOverwrite && existingConfigs.length > 0) {
144
- console.error(index_4.theme.error.bold(`${index_4.icons.error} The following files already exist:\n`) +
145
- existingConfigs.map(f => index_4.theme.muted(` - ${f}`)).join("\n") +
146
- index_4.theme.warning(`\n\nUse --force to overwrite everything.`));
147
- process.exit(1);
148
- }
149
- /* ===============================
150
- * FLAG VALIDATION
151
- * =============================== */
152
- /* ===============================
153
- * EMPTY INIT
154
- * =============================== */
155
- if (empty) {
156
- const root = {
157
- type: "folder",
158
- name: ".",
159
- children: [],
160
- };
161
- (0, index_3.saveStructure)(root, parsed.rawConstraints, index_6.STRUCTURE_PATH);
162
- if (shouldOverwrite || !fs_1.default.existsSync(index_6.IGNORE_PATH)) {
163
- if (shouldOverwrite && (fs_1.default.existsSync(index_6.IGNORE_PATH) || fs_1.default.existsSync(index_6.STRUCTURE_PATH))) {
164
- console.warn(index_4.theme.warning(`${index_4.icons.warning} Overwriting existing due to --force`));
165
- }
166
- fs_1.default.writeFileSync(index_6.IGNORE_PATH, index_1.DEFAULT_IGNORE_TEMPLATE);
167
- }
168
- console.log(index_4.theme.success(`${index_4.icons.success} Empty structure.sr created`));
169
- return;
170
- }
171
- /* ===============================
172
- * INIT FROM FILESYSTEM
173
- * =============================== */
174
- if (fromFs) {
175
- const targetDir = path_1.default.resolve(arg3 ?? index_7.baseDir);
176
- const ignoreList = (0, index_2.getIgnoreList)(targetDir);
177
- const ast = (0, fsToAst_1.buildASTFromFS)(targetDir, ignoreList);
178
- (0, index_3.saveStructure)(ast, parsed.rawConstraints, index_6.STRUCTURE_PATH);
179
- if (shouldOverwrite || !fs_1.default.existsSync(index_6.IGNORE_PATH)) {
180
- if (shouldOverwrite && (fs_1.default.existsSync(index_6.IGNORE_PATH) || fs_1.default.existsSync(index_6.STRUCTURE_PATH))) {
181
- console.warn(index_4.theme.warning(`${index_4.icons.warning} Overwriting existing due to --force`));
182
- }
183
- fs_1.default.writeFileSync(index_6.IGNORE_PATH, index_1.DEFAULT_IGNORE_TEMPLATE);
184
- }
185
- console.log(index_4.theme.success(`${index_4.icons.success} structure.sr generated from filesystem: `) + index_4.theme.light(targetDir));
186
- return;
187
- }
188
- /* ===============================
189
- * DEFAULT INIT (TEMPLATE)
190
- * =============================== */
191
- (0, index_3.saveStructure)(parsed.root, parsed.rawConstraints, index_6.STRUCTURE_PATH);
192
- if (shouldOverwrite || !fs_1.default.existsSync(index_6.IGNORE_PATH)) {
193
- if (shouldOverwrite && (fs_1.default.existsSync(index_6.IGNORE_PATH) || fs_1.default.existsSync(index_6.STRUCTURE_PATH))) {
194
- console.warn(index_4.theme.warning(`${index_4.icons.warning} Overwriting existing due to --force`));
195
- }
196
- fs_1.default.writeFileSync(index_6.IGNORE_PATH, index_1.DEFAULT_IGNORE_TEMPLATE);
197
- }
198
- console.log(index_4.theme.success(`${index_4.icons.success} structure.sr created`));
199
- return;
200
- },
201
- update: async () => {
202
- // FAIL if structure.sr does not exist
203
- if (!fs_1.default.existsSync(index_6.STRUCTURE_PATH)) {
204
- console.error(index_4.theme.error.bold(`${index_4.icons.error} Error: structure.sr not found. Run \`scaffoldrite init\` first.`));
205
- process.exit(1);
206
- }
207
- const targetDir = path_1.default.resolve(arg3 ?? index_7.baseDir);
208
- const ignoreList = (0, index_2.getIgnoreList)(targetDir);
209
- const ast = (0, fsToAst_1.buildASTFromFS)(targetDir, ignoreList);
210
- const constraints = (0, index_3.loadConstraints)();
211
- // confirmation
212
- if (!(await (0, index_3.confirmProceed)(targetDir))) {
213
- console.log(index_4.theme.muted(`${index_4.icons.info} Update cancelled.`));
214
- return;
215
- }
216
- (0, index_3.saveStructure)(ast, constraints, index_6.STRUCTURE_PATH);
217
- console.log(index_4.theme.success(`${index_4.icons.success} structure.sr updated from filesystem: `) + index_4.theme.light(targetDir));
218
- return;
219
- },
220
- merge: async () => {
221
- // FAIL if structure.sr does not exist
222
- if (!fs_1.default.existsSync(index_6.STRUCTURE_PATH)) {
223
- console.error(index_4.theme.error.bold(`${index_4.icons.error} Error: structure.sr not found. Run \`scaffoldrite init\` first.`));
224
- process.exit(1);
225
- }
226
- const targetDir = path_1.default.resolve(arg3 ?? index_7.baseDir);
227
- const ignoreList = (0, index_2.getIgnoreList)(targetDir);
228
- const fsAst = (0, fsToAst_1.buildASTFromFS)(targetDir, ignoreList);
229
- const structure = (0, index_3.loadAST)();
230
- // Merge logic
231
- const mergeNodes = (existing, incoming) => {
232
- for (const child of incoming.children) {
233
- if (child.type === "folder") {
234
- const found = existing.children.find((c) => c.type === "folder" && c.name === child.name);
235
- if (found)
236
- mergeNodes(found, child);
237
- else
238
- existing.children.push(child);
239
- }
240
- else {
241
- const exists = existing.children.some((c) => c.type === "file" && c.name === child.name);
242
- if (!exists)
243
- existing.children.push(child);
244
- }
245
- }
246
- };
247
- mergeNodes(structure.root, fsAst);
248
- // confirmation
249
- if (!(await (0, index_3.confirmProceed)(targetDir))) {
250
- console.log(index_4.theme.muted(`${index_4.icons.info} Merge cancelled.`));
251
- return;
252
- }
253
- (0, index_3.saveStructure)(structure.root, structure.rawConstraints, index_6.STRUCTURE_PATH);
254
- console.log(index_4.theme.success(`${index_4.icons.success} structure.sr merged with filesystem: `) + index_4.theme.light(targetDir));
255
- return;
256
- },
257
- list: async () => {
258
- const isDefault = !isFS && !isDiff && !isStructure;
259
- const targetDir = path_1.default.resolve(index_7.baseDir);
260
- /* ================= DEFAULT (NO IGNORE) ================= */
261
- if (isDefault) {
262
- if (!fs_1.default.existsSync(index_6.STRUCTURE_PATH)) {
263
- console.error(index_4.theme.error.bold(`${index_4.icons.error} structure.sr not found. Run \`scaffoldrite init\` first.`));
264
- process.exit(1);
265
- }
266
- const structure = (0, index_3.loadAST)();
267
- console.log(index_4.theme.primary.bold(`${index_4.icons.file} structure.sr\n`));
268
- if (withIcons) {
269
- (0, index_3.printTreeWithIcons)(structure.root);
270
- }
271
- else {
272
- (0, index_3.printTree)(structure.root);
273
- }
274
- return;
275
- }
276
- const ignoreList = (0, index_2.getIgnoreList)(targetDir);
277
- /* ================= STRUCTURE.SR (WITH IGNORE) ================= */
278
- if (isStructure) {
279
- if (!fs_1.default.existsSync(index_6.STRUCTURE_PATH)) {
280
- console.error(index_4.theme.error.bold(`${index_4.icons.error} structure.sr not found. Run \`scaffoldrite init\` first.`));
281
- process.exit(1);
282
- }
283
- const structure = (0, index_3.loadAST)();
284
- const filtered = (0, index_3.filterTreeByIgnore)(structure.root, ignoreList);
285
- console.log(index_4.theme.primary.bold(`${index_4.icons.file} structure.sr`));
286
- console.log(index_4.theme.muted(`Ignoring: `) + index_4.theme.accent(ignoreList.join(", ")) + index_4.theme.muted(`\n`));
287
- (0, index_3.printTreeWithIcons)(filtered);
288
- return;
289
- }
290
- /* ================= FILESYSTEM (WITH IGNORE) ================= */
291
- if (isFS) {
292
- const fsAst = (0, fsToAst_1.buildASTFromFS)(targetDir, ignoreList);
293
- console.log(index_4.theme.secondary.bold(`${index_4.icons.folder} filesystem (`) + index_4.theme.light(targetDir) + index_4.theme.secondary.bold(`)`));
294
- console.log(index_4.theme.muted(`Ignoring: `) + index_4.theme.accent(ignoreList.join(", ")) + index_4.theme.muted(`\n`));
295
- if (withIcons) {
296
- (0, index_3.printTreeWithIcons)(fsAst);
297
- }
298
- else {
299
- (0, index_3.printTree)(fsAst);
300
- }
301
- return;
302
- }
303
- /* ================= DIFF (MEANINGFUL + IGNORE) ================= */
304
- if (isDiff) {
305
- if (!fs_1.default.existsSync(index_6.STRUCTURE_PATH)) {
306
- console.error(index_4.theme.error.bold(`${index_4.icons.error} structure.sr not found. Run \`scaffoldrite init\` first.`));
307
- process.exit(1);
308
- }
309
- const structure = (0, index_3.loadAST)();
310
- const filteredStructure = (0, index_3.filterTreeByIgnore)(structure.root, ignoreList);
311
- const fsAst = (0, fsToAst_1.buildASTFromFS)(targetDir, ignoreList);
312
- const structMap = (0, index_3.flattenTree)(filteredStructure);
313
- const fsMap = (0, index_3.flattenTree)(fsAst);
314
- console.log(index_4.theme.highlight.bold(`${index_4.icons.file} structure.sr ${index_4.icons.arrow} ${index_4.icons.folder} filesystem diff`));
315
- console.log(index_4.theme.muted(`Ignoring: `) + index_4.theme.accent(ignoreList.join(", ")) + index_4.theme.muted(`\n`));
316
- for (const p of Array.from(new Set([...structMap.keys(), ...fsMap.keys()])).sort()) {
317
- const inStruct = structMap.has(p);
318
- const inFS = fsMap.has(p);
319
- if (inStruct && !inFS) {
320
- console.log(index_4.theme.error(`āŒ Missing in filesystem: `) + index_4.theme.light(p));
321
- }
322
- else if (!inStruct && inFS) {
323
- console.log(index_4.theme.warning(`āž• Extra in filesystem: `) + index_4.theme.light(p));
324
- }
325
- }
326
- return;
327
- }
328
- },
329
- validate: () => {
330
- const structure = (0, index_3.loadAST)();
331
- const outputDir = path_1.default.resolve(index_7.baseDir);
332
- const ignoreList = (0, index_2.getIgnoreList)(outputDir);
333
- try {
334
- (0, validator_1.validateConstraints)(structure.root, structure.constraints);
335
- (0, validateFS_1.validateFS)(structure.root, outputDir, {
336
- ignoreList,
337
- allowExtra,
338
- allowExtraPaths,
339
- });
340
- console.log(index_4.theme.success.bold(`${index_4.icons.success} All constraints and filesystem structure are valid`));
341
- }
342
- catch (err) {
343
- console.error(index_4.theme.error.bold(`${index_4.icons.error} Validation failed: `) + index_4.theme.light(err.message));
344
- process.exit(1);
345
- }
346
- return;
347
- },
348
- generate: async () => {
349
- const structure = (0, index_3.loadAST)();
350
- (0, validator_1.validateConstraints)(structure.root, structure.constraints);
351
- const outputDir = path_1.default.resolve(arg3 ?? index_7.baseDir);
352
- const bDir = path_1.default.resolve(index_7.baseDir);
353
- if (!(await (0, index_3.confirmProceed)(outputDir))) {
354
- console.log(index_4.theme.muted(`${index_4.icons.info} Generation cancelled.`));
355
- return;
356
- }
357
- const ignoreList = (0, index_2.getIgnoreList)(bDir);
358
- const logLines = [];
359
- let totalOps = 0;
360
- await (0, generator_1.generateFS)(structure.root, outputDir, {
361
- dryRun,
362
- ignoreList,
363
- copyContents,
364
- onStart(total) {
365
- totalOps = total;
366
- bar.start(total);
367
- },
368
- onProgress(e) {
369
- bar.update({
370
- type: e.type.toUpperCase(),
371
- path: e.path,
372
- count: e.count,
373
- });
374
- logLines.push(`${e.type.toUpperCase()} ${e.path}`);
375
- },
376
- });
377
- bar.stop();
378
- const scaffoldOutput = path_1.default.join(outputDir, '.scaffoldrite');
379
- if (!dryRun) {
380
- if (ignoreTooling) {
381
- // DELETE the .scaffoldrite directory
382
- if (fs_1.default.existsSync(scaffoldOutput)) {
383
- fs_1.default.rmSync(scaffoldOutput, {
384
- recursive: true,
385
- force: true,
386
- });
387
- }
388
- }
389
- else {
390
- const structureSrc = path_1.default.join(process.cwd(), ".scaffoldrite", "structure.sr");
391
- const ignoreSrc = path_1.default.join(process.cwd(), ".scaffoldrite", ".scaffoldignore");
392
- // Destination folder (inside outputDir)
393
- const scaffoldDir = path_1.default.join(outputDir, ".scaffoldrite");
394
- if (!fs_1.default.existsSync(scaffoldDir))
395
- fs_1.default.mkdirSync(scaffoldDir, { recursive: true });
396
- // Copy
397
- fs_1.default.copyFileSync(structureSrc, path_1.default.join(scaffoldDir, "structure.sr"));
398
- fs_1.default.copyFileSync(ignoreSrc, path_1.default.join(scaffoldDir, ".scaffoldignore"));
399
- }
400
- }
401
- if (verbose) {
402
- console.log(index_4.theme.primary.bold(`\nšŸ“‹ Detailed Operations:`));
403
- console.log(index_4.theme.muted(`─`.repeat(40)));
404
- for (const line of logLines) {
405
- if (line.startsWith("CREATE")) {
406
- console.log(index_4.theme.success(` ${index_4.icons.success} ${line}`));
407
- }
408
- else if (line.startsWith("SKIP")) {
409
- console.log(index_4.theme.muted(` ${index_4.icons.info} ${line}`));
410
- }
411
- else {
412
- console.log(index_4.theme.info(` ${index_4.icons.info} ${line}`));
413
- }
414
- }
415
- }
416
- else if (summary) {
417
- console.log(index_4.theme.primary.bold(`\nšŸ“Š Summary:`));
418
- console.log(index_4.theme.muted(`─`.repeat(40)));
419
- for (const line of logLines.filter(l => !l.startsWith("SKIP"))) {
420
- if (line.startsWith("CREATE")) {
421
- console.log(index_4.theme.success(` ${index_4.icons.success} ${line}`));
422
- }
423
- else {
424
- console.log(index_4.theme.info(` ${index_4.icons.info} ${line}`));
425
- }
426
- }
427
- }
428
- console.log(index_4.theme.success.bold(`\n${index_4.icons.check} Generation completed successfully!`));
429
- return;
430
- },
431
- create: async () => {
432
- const structure = (0, index_3.loadAST)();
433
- const outputDir = path_1.default.resolve(index_7.baseDir);
434
- // const beforeStructureSR = structureToSRString(structure.root, structure.rawConstraints);
435
- const ignoreList = (0, index_2.getIgnoreList)(outputDir);
436
- // const beforeFSSnapshotSR = structureToSRString(buildASTFromFS(outputDir, ignoreList), []);
437
- // const operations: Operation[] = [];
438
- (0, validator_1.validateConstraints)(structure.root, structure.constraints);
439
- const fullPath = path_1.default.join(outputDir, arg3);
440
- // If force and the path exists, stash it first
441
- // if (force && fs.existsSync(fullPath)) {
442
- // const backupPath = path.join(SCAFFOLDRITE_DIR, 'history', crypto.randomUUID());
443
- // fs.cpSync(fullPath, backupPath, { recursive: true });
444
- // operations.push({
445
- // type: 'delete',
446
- // path: arg3,
447
- // backupPath
448
- // });
449
- // fs.rmSync(fullPath, { recursive: true, force: true });
450
- // }
451
- // Add node to structure
452
- (0, structure_1.addNode)(structure.root, arg3, arg4, { force, ifNotExists });
453
- // Record create operation AFTER handling force
454
- // operations.push({
455
- // type: "create",
456
- // path: arg3,
457
- // nodeType: arg4 as "file" | "folder",
458
- // });
459
- (0, validator_1.validateConstraints)(structure.root, structure.constraints);
460
- if (!(await (0, index_3.confirmProceed)(outputDir))) {
461
- console.log(index_4.theme.muted(`${index_4.icons.info} Creation cancelled.`));
462
- return;
463
- }
464
- (0, index_3.saveStructure)(structure.root, structure.rawConstraints, index_6.STRUCTURE_PATH);
465
- const logLines = [];
466
- await (0, generator_1.generateFS)(structure.root, outputDir, {
467
- dryRun,
468
- ignoreList,
469
- onProgress(e) {
470
- logLines.push(`${e.type.toUpperCase()} ${e.path}`);
471
- },
472
- });
473
- if (verbose) {
474
- console.log(index_4.theme.primary.bold(`\nšŸ“‹ Operations:`));
475
- console.log(index_4.theme.muted(`─`.repeat(40)));
476
- for (const line of logLines) {
477
- if (line.startsWith("CREATE")) {
478
- console.log(index_4.theme.success(` ${index_4.icons.success} ${line}`));
479
- }
480
- else if (line.startsWith("SKIP")) {
481
- console.log(index_4.theme.muted(` ${index_4.icons.info} ${line}`));
482
- }
483
- else {
484
- console.log(index_4.theme.info(` ${index_4.icons.info} ${line}`));
485
- }
486
- }
487
- }
488
- else if (summary) {
489
- console.log(index_4.theme.primary.bold(`\nšŸ“Š Summary:`));
490
- console.log(index_4.theme.muted(`─`.repeat(40)));
491
- for (const line of logLines.filter(l => !l.startsWith("SKIP"))) {
492
- console.log(index_4.theme.success(` ${index_4.icons.success} ${line}`));
493
- }
494
- }
495
- // const afterStructureSR = structureToSRString(structure.root, structure.rawConstraints);
496
- // const afterFSSnapshotSR = structureToSRString(buildASTFromFS(outputDir, ignoreList), []);
497
- // Write history
498
- // if (!dryRun) {
499
- // writeHistory({
500
- // id: uuidv4(),
501
- // command,
502
- // args: process.argv.slice(3),
503
- // flags: passedFlags,
504
- // timestamp: Date.now(),
505
- // operations,
506
- // before: {
507
- // structure: beforeStructureSR,
508
- // fsSnapshot: beforeFSSnapshotSR
509
- // },
510
- // after: {
511
- // structure: afterStructureSR,
512
- // fsSnapshot: afterFSSnapshotSR
513
- // },
514
- // });
515
- // }
516
- process.stdout.write("\n");
517
- console.log(index_4.theme.success.bold(`${index_4.icons.check} Created successfully.`));
518
- return;
519
- },
520
- delete: async () => {
521
- const structure = (0, index_3.loadAST)();
522
- (0, validator_1.validateConstraints)(structure.root, structure.constraints);
523
- (0, structure_1.deleteNode)(structure.root, arg3);
524
- (0, validator_1.validateConstraints)(structure.root, structure.constraints);
525
- const outputDir = path_1.default.resolve(index_7.baseDir);
526
- if (!(await (0, index_3.confirmProceed)(outputDir))) {
527
- console.log(index_4.theme.muted(`${index_4.icons.info} Deletion cancelled.`));
528
- return;
529
- }
530
- (0, index_3.saveStructure)(structure.root, structure.rawConstraints, index_6.STRUCTURE_PATH);
531
- const logLines = [];
532
- const ignoreList = (0, index_2.getIgnoreList)(outputDir);
533
- await (0, generator_1.generateFS)(structure.root, outputDir, {
534
- dryRun,
535
- ignoreList,
536
- onProgress(e) {
537
- logLines.push(`${e.type.toUpperCase()} ${e.path}`);
538
- },
539
- });
540
- if (verbose) {
541
- console.log(index_4.theme.primary.bold(`\nšŸ“‹ Operations:`));
542
- console.log(index_4.theme.muted(`─`.repeat(40)));
543
- for (const line of logLines) {
544
- if (line.startsWith("DELETE")) {
545
- console.log(index_4.theme.error(` ${index_4.icons.cross} ${line}`));
546
- }
547
- else if (line.startsWith("SKIP")) {
548
- console.log(index_4.theme.muted(` ${index_4.icons.info} ${line}`));
549
- }
550
- else {
551
- console.log(index_4.theme.info(` ${index_4.icons.info} ${line}`));
552
- }
553
- }
554
- }
555
- else if (summary) {
556
- console.log(index_4.theme.primary.bold(`\nšŸ“Š Summary:`));
557
- console.log(index_4.theme.muted(`─`.repeat(40)));
558
- for (const line of logLines.filter(l => !l.startsWith("SKIP"))) {
559
- console.log(index_4.theme.error(` ${index_4.icons.cross} ${line}`));
560
- }
561
- }
562
- process.stdout.write("\n");
563
- console.log(index_4.theme.success.bold(`${index_4.icons.check} Deleted successfully.`));
564
- return;
565
- },
566
- rename: async () => {
567
- const structure = (0, index_3.loadAST)();
568
- (0, validator_1.validateConstraints)(structure.root, structure.constraints);
569
- // 1ļøāƒ£ determine old path and new path
570
- const oldPath = arg3;
571
- const newName = arg4;
572
- const outputDir = path_1.default.resolve(index_7.baseDir);
573
- // Build full paths
574
- const oldFullPath = path_1.default.join(outputDir, oldPath);
575
- const newFullPath = path_1.default.join(outputDir, path_1.default.join(path_1.default.dirname(oldPath), newName));
576
- // 2ļøāƒ£ Rename on filesystem first (safe)
577
- const renamed = (0, index_3.renameFSItem)(oldFullPath, newFullPath);
578
- if (!renamed) {
579
- console.warn(index_4.theme.warning(`${index_4.icons.warning} Warning: Item not found in filesystem, will create new based on structure.sr.`));
580
- }
581
- // 3ļøāƒ£ Rename in structure.sr
582
- (0, structure_1.renameNode)(structure.root, oldPath, newName);
583
- (0, validator_1.validateConstraints)(structure.root, structure.constraints);
584
- if (!(await (0, index_3.confirmProceed)(outputDir))) {
585
- console.log(index_4.theme.muted(`${index_4.icons.info} Rename cancelled.`));
586
- return;
587
- }
588
- (0, index_3.saveStructure)(structure.root, structure.rawConstraints, index_6.STRUCTURE_PATH);
589
- const logLines = [];
590
- const ignoreList = (0, index_2.getIgnoreList)(outputDir);
591
- await (0, generator_1.generateFS)(structure.root, outputDir, {
592
- dryRun,
593
- ignoreList,
594
- onProgress(e) {
595
- logLines.push(`${e.type.toUpperCase()} ${e.path}`);
596
- },
597
- });
598
- if (verbose) {
599
- console.log(index_4.theme.primary.bold(`\nšŸ“‹ Operations:`));
600
- console.log(index_4.theme.muted(`─`.repeat(40)));
601
- for (const line of logLines) {
602
- if (line.startsWith("CREATE")) {
603
- console.log(index_4.theme.success(` ${index_4.icons.success} ${line}`));
604
- }
605
- else if (line.startsWith("DELETE")) {
606
- console.log(index_4.theme.error(` ${index_4.icons.cross} ${line}`));
607
- }
608
- else if (line.startsWith("SKIP")) {
609
- console.log(index_4.theme.muted(` ${index_4.icons.info} ${line}`));
610
- }
611
- else {
612
- console.log(index_4.theme.info(` ${index_4.icons.info} ${line}`));
613
- }
614
- }
615
- }
616
- else if (summary) {
617
- console.log(index_4.theme.primary.bold(`\nšŸ“Š Summary:`));
618
- console.log(index_4.theme.muted(`─`.repeat(40)));
619
- for (const line of logLines.filter(l => !l.startsWith("SKIP"))) {
620
- if (line.startsWith("CREATE")) {
621
- console.log(index_4.theme.success(` ${index_4.icons.success} ${line}`));
622
- }
623
- else if (line.startsWith("DELETE")) {
624
- console.log(index_4.theme.error(` ${index_4.icons.cross} ${line}`));
625
- }
626
- }
627
- }
628
- process.stdout.write("\n");
629
- console.log(index_4.theme.success.bold(`${index_4.icons.check} Renamed successfully.`));
630
- return;
631
- }
632
- };