@gadmin2n/cli 0.0.110 → 0.0.112

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.
@@ -25,6 +25,10 @@ const schematics_1 = require("../lib/schematics");
25
25
  const ui_1 = require("../lib/ui");
26
26
  const formatting_1 = require("../lib/utils/formatting");
27
27
  const abstract_action_1 = require("./abstract.action");
28
+ const schematics_root_1 = require("../lib/schematics-root");
29
+ const base_store_1 = require("../lib/template-merge/base-store");
30
+ const types_1 = require("../lib/template-merge/types");
31
+ const executable_paths_1 = require("../lib/executable-paths");
28
32
  class NewAction extends abstract_action_1.AbstractAction {
29
33
  handle(inputs, options) {
30
34
  return __awaiter(this, void 0, void 0, function* () {
@@ -42,6 +46,32 @@ class NewAction extends abstract_action_1.AbstractAction {
42
46
  yield applyEnvConfig(projectDirectory, options).catch((err) => {
43
47
  console.error(chalk.yellow(`[warn] Failed to apply env config: ${err && err.message ? err.message : err}`));
44
48
  });
49
+ // Pin the 3-way merge base at project init time. Recording the exact
50
+ // schematics version that scaffolded this project means the FIRST
51
+ // `gadmin2 update` can immediately do a real 3-way merge — no
52
+ // bootstrap-then-rerun dance. Failure is non-fatal: if meta can't be
53
+ // written here, `gadmin2 update` still has its bootstrap fallback.
54
+ try {
55
+ const projectAbsDir = (0, path_1.join)(process.cwd(), projectDirectory);
56
+ const schematicsVersion = (0, schematics_root_1.getSchematicsVersion)();
57
+ (0, base_store_1.writeMeta)(projectAbsDir, {
58
+ schematicsVersion,
59
+ schemaVersion: types_1.CURRENT_META_SCHEMA_VERSION,
60
+ });
61
+ (0, base_store_1.writeReadme)(projectAbsDir);
62
+ }
63
+ catch (err) {
64
+ console.warn(chalk.yellow(`[warn] Failed to write .gadmin/.meta.json (first \`gadmin2 update\` will bootstrap instead): ${err && err.message ? err.message : err}`));
65
+ }
66
+ // @angular-devkit/schematics drops the source mode bits when writing
67
+ // generated files, so executable scripts (compose-ctl.sh, etc.) come
68
+ // out as 0644. Re-apply +x for known entry points.
69
+ try {
70
+ (0, executable_paths_1.ensureExecutableBits)((0, path_1.join)(process.cwd(), projectDirectory));
71
+ }
72
+ catch (_a) {
73
+ // best-effort, never fatal
74
+ }
45
75
  }
46
76
  if (!shouldSkipInstall) {
47
77
  console.info('Begin to install server dependence ...');
@@ -19,6 +19,8 @@ const child_process_1 = require("child_process");
19
19
  const abstract_action_1 = require("./abstract.action");
20
20
  const self_update_action_1 = require("./self-update.action");
21
21
  const version_check_1 = require("../lib/version-check");
22
+ const schematics_root_1 = require("../lib/schematics-root");
23
+ const executable_paths_1 = require("../lib/executable-paths");
22
24
  const merge3way_1 = require("../lib/template-merge/merge3way");
23
25
  const binary_detect_1 = require("../lib/template-merge/binary-detect");
24
26
  const residual_scan_1 = require("../lib/template-merge/residual-scan");
@@ -50,28 +52,7 @@ function formatMaterializeError(schematicsVersion, err) {
50
52
  * Template config / path resolution
51
53
  * ------------------------------------------------------------------ */
52
54
  function resolveTemplatePath(templateName) {
53
- let schematicsRoot;
54
- const searchPaths = [
55
- process.cwd(),
56
- path.join(process.cwd(), 'server'),
57
- path.resolve(__dirname, '..'),
58
- ];
59
- for (const searchPath of searchPaths) {
60
- try {
61
- const pkgPath = require.resolve('@gadmin2n/schematics/package.json', {
62
- paths: [searchPath],
63
- });
64
- schematicsRoot = path.dirname(pkgPath);
65
- break;
66
- }
67
- catch (_a) {
68
- // continue
69
- }
70
- }
71
- if (!schematicsRoot) {
72
- throw new Error('Cannot resolve @gadmin2n/schematics package. ' +
73
- 'Make sure it is installed.');
74
- }
55
+ const schematicsRoot = (0, schematics_root_1.findSchematicsRoot)();
75
56
  const nameVariants = [templateName];
76
57
  if (templateName.startsWith('gadmin2n-')) {
77
58
  nameVariants.push(templateName.replace('gadmin2n-', 'gadmin2-'));
@@ -575,19 +556,79 @@ function applyPlan(plan, baseRoot, oursRoot, theirsRoot, opts) {
575
556
  /* ------------------------------------------------------------------ *
576
557
  * Print summary
577
558
  * ------------------------------------------------------------------ */
578
- function printPlanCounts(plan) {
579
- console.info(` ${plan.update.length} files cleanly merged or 3-way merged\n` +
580
- ` ${plan.add.length} files added (template-only)\n` +
581
- ` ${plan.delete.length} files deleted (template removed)`);
582
- if (plan.keep.length > 0) {
583
- console.info(chalk.gray(` ${plan.keep.length} files kept (instance-only or identical)`));
559
+ /**
560
+ * Unified file-list printer for a `ClassifiedPlan`. Used by both pre-apply
561
+ * preview / dry-run output AND post-apply summary so the wording stays
562
+ * consistent across the three call sites.
563
+ *
564
+ * Sections that have zero files are skipped entirely (no "0 files added"
565
+ * noise). Structural conflicts (add/add, modify/delete, delete/modify) are
566
+ * shown together because they're all "needs decision" situations the user
567
+ * should see before applying.
568
+ *
569
+ * The "kept" footer (`plan.keep + plan.noop`) is shown by default; pass
570
+ * `{ showKept: false }` to suppress it.
571
+ */
572
+ function printPlanFileLists(plan, opts) {
573
+ var _a;
574
+ const showKept = (_a = opts === null || opts === void 0 ? void 0 : opts.showKept) !== null && _a !== void 0 ? _a : true;
575
+ const plural = (n) => (n === 1 ? '' : 's');
576
+ if (plan.update.length > 0) {
577
+ console.info(chalk.yellow(`📝 Updated (3-way merged) — ${plan.update.length} file${plural(plan.update.length)}`));
578
+ for (const f of plan.update)
579
+ console.info(` ${f}`);
580
+ console.info();
581
+ }
582
+ if (plan.add.length > 0) {
583
+ console.info(chalk.green(`➕ Added (template-only) — ${plan.add.length} file${plural(plan.add.length)}`));
584
+ for (const f of plan.add)
585
+ console.info(` ${f}`);
586
+ console.info();
587
+ }
588
+ if (plan.delete.length > 0) {
589
+ console.info(chalk.red(`🗑 Deleted (template removed) — ${plan.delete.length} file${plural(plan.delete.length)}`));
590
+ for (const f of plan.delete)
591
+ console.info(` ${f}`);
592
+ console.info();
593
+ }
594
+ const structural = [
595
+ ...plan.addAddConflict.map((p) => ['add/add', p]),
596
+ ...plan.modifyDeleteConflict.map((p) => ['modify/delete', p]),
597
+ ...plan.deleteModifyConflict.map((p) => ['delete/modify', p]),
598
+ ];
599
+ if (structural.length > 0) {
600
+ console.info(chalk.magenta(`⚠️ Structural conflicts — ${structural.length} file${plural(structural.length)}`));
601
+ const padKind = (k) => k.padEnd(16);
602
+ for (const [kind, p] of structural) {
603
+ console.info(` ${chalk.magenta(padKind(`[${kind}]`))} ${p}`);
604
+ }
605
+ console.info();
606
+ }
607
+ if (showKept) {
608
+ const keptCount = plan.keep.length + plan.noop.length;
609
+ if (keptCount > 0) {
610
+ console.info(chalk.gray(` ${keptCount} file${plural(keptCount)} kept (instance-only or identical)`));
611
+ }
612
+ }
613
+ }
614
+ /**
615
+ * Print post-apply conflict records (output of `applyPlan`). These differ
616
+ * from a `ClassifiedPlan` because they include `kind: 'content' | 'binary'`
617
+ * which is only known after the merge actually runs.
618
+ */
619
+ function printConflictRecords(conflicts) {
620
+ const padKind = (k) => k.padEnd(16);
621
+ for (const c of conflicts) {
622
+ const kindLabel = `[${c.kind}]`;
623
+ console.info(` ${chalk.yellow(padKind(kindLabel))} ${c.path}` +
624
+ (c.detail ? chalk.gray(` (${c.detail})`) : ''));
584
625
  }
585
626
  }
586
627
  function printSummary(plan, conflicts, templateName, schematicsVersion) {
587
628
  console.info(chalk.bold('\n═══════════════════════════════════════════════════'));
588
629
  console.info(chalk.bold(' Template Update Summary'));
589
630
  console.info(chalk.bold('═══════════════════════════════════════════════════\n'));
590
- printPlanCounts(plan);
631
+ printPlanFileLists(plan);
591
632
  console.info();
592
633
  if (conflicts.length === 0) {
593
634
  console.info(chalk.green('✅ Template update complete — no conflicts.'));
@@ -595,12 +636,7 @@ function printSummary(plan, conflicts, templateName, schematicsVersion) {
595
636
  return;
596
637
  }
597
638
  console.info(chalk.yellow(`⚠️ ${conflicts.length} conflict(s) need your attention:\n`));
598
- const padKind = (k) => k.padEnd(16);
599
- for (const c of conflicts) {
600
- const kindLabel = `[${c.kind}]`;
601
- console.info(` ${chalk.yellow(padKind(kindLabel))} ${c.path}` +
602
- (c.detail ? chalk.gray(` (${c.detail})`) : ''));
603
- }
639
+ printConflictRecords(conflicts);
604
640
  console.info();
605
641
  console.info(chalk.gray(' Recommended workflow:'));
606
642
  console.info(chalk.gray(' $ git status # see all modified files'));
@@ -946,8 +982,7 @@ class UpdateAction extends abstract_action_1.AbstractAction {
946
982
  snapshotPackageJson(path.join(instanceDir, 'web'), 'web'),
947
983
  snapshotPackageJson(path.join(instanceDir, 'server'), 'server'),
948
984
  ];
949
- const schematicsPkg = require(require.resolve('@gadmin2n/schematics/package.json', { paths: [instanceDir, path.join(instanceDir, 'server')] }));
950
- const schematicsVersion = schematicsPkg.version || '0.0.0';
985
+ const schematicsVersion = (0, schematics_root_1.getSchematicsVersion)(instanceDir);
951
986
  // First-time bootstrap: meta absent → write meta + README, exit.
952
987
  if (!fs.existsSync((0, base_store_1.metaPath)(instanceDir))) {
953
988
  if (dryRun) {
@@ -996,28 +1031,56 @@ class UpdateAction extends abstract_action_1.AbstractAction {
996
1031
  console.info(chalk.bold('═══════════════════════════════════════════════════'));
997
1032
  console.info(chalk.bold(' Template Update Plan (dry-run)'));
998
1033
  console.info(chalk.bold('═══════════════════════════════════════════════════\n'));
999
- for (const f of plan.add)
1000
- console.info(chalk.green(` add ${f}`));
1001
- for (const f of plan.delete)
1002
- console.info(chalk.red(` delete ${f}`));
1003
- for (const f of plan.update)
1004
- console.info(chalk.yellow(` update ${f}`));
1005
- for (const f of plan.addAddConflict)
1006
- console.info(chalk.magenta(` add/add ${f}`));
1007
- for (const f of plan.modifyDeleteConflict)
1008
- console.info(chalk.magenta(` modify/delete ${f}`));
1009
- for (const f of plan.deleteModifyConflict)
1010
- console.info(chalk.magenta(` delete/modify ${f}`));
1034
+ printPlanFileLists(plan);
1011
1035
  console.info();
1012
1036
  }
1013
1037
  else {
1014
- const conflicts = applyPlan(plan, baseRoot, instanceDir, theirsRoot, mergeOpts);
1015
- // Always advance meta to new version, even when conflicts present (invariant #2).
1016
- (0, base_store_1.writeMeta)(instanceDir, {
1017
- schematicsVersion,
1018
- schemaVersion: types_1.CURRENT_META_SCHEMA_VERSION,
1019
- });
1020
- printSummary(plan, conflicts, templateName, schematicsVersion);
1038
+ // Pre-apply preview + confirm (skipped under --yes).
1039
+ const applyAndReport = () => {
1040
+ const conflicts = applyPlan(plan, baseRoot, instanceDir, theirsRoot, mergeOpts);
1041
+ // Always advance meta to new version, even when conflicts present (invariant #2).
1042
+ (0, base_store_1.writeMeta)(instanceDir, {
1043
+ schematicsVersion,
1044
+ schemaVersion: types_1.CURRENT_META_SCHEMA_VERSION,
1045
+ });
1046
+ // Re-apply +x to known script entry points: applyPlan uses
1047
+ // fs.copyFileSync for newly-added files, which does not preserve
1048
+ // the source template's mode bits.
1049
+ try {
1050
+ (0, executable_paths_1.ensureExecutableBits)(instanceDir);
1051
+ }
1052
+ catch (_a) {
1053
+ // best-effort, never fatal
1054
+ }
1055
+ printSummary(plan, conflicts, templateName, schematicsVersion);
1056
+ };
1057
+ if (autoYes) {
1058
+ applyAndReport();
1059
+ }
1060
+ else {
1061
+ console.info(chalk.bold('\n═══════════════════════════════════════════════════'));
1062
+ console.info(chalk.bold(' Template Update Preview'));
1063
+ console.info(chalk.bold('═══════════════════════════════════════════════════\n'));
1064
+ printPlanFileLists(plan);
1065
+ console.info();
1066
+ const { proceedTemplate } = yield inquirer.prompt([
1067
+ {
1068
+ type: 'confirm',
1069
+ name: 'proceedTemplate',
1070
+ message: 'Apply this template update to your instance?',
1071
+ default: true,
1072
+ },
1073
+ ]);
1074
+ if (proceedTemplate) {
1075
+ applyAndReport();
1076
+ }
1077
+ else {
1078
+ console.info(chalk.gray('\nTemplate update skipped — base & files unchanged.\n'));
1079
+ // Fall through to stage 2 (.claude sync) and stage 3 (install).
1080
+ // pkgSnapshots are already captured but package.json is unchanged,
1081
+ // so maybeInstallChangedDeps will naturally find no diff and skip.
1082
+ }
1083
+ }
1021
1084
  }
1022
1085
  }
1023
1086
  }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Files (relative to instance / project root) that must carry the executable
3
+ * bit. Both `gadmin2 n` and `gadmin2 update` re-apply this set after writing
4
+ * files because:
5
+ *
6
+ * - @angular-devkit/schematics writes generated files via fs.writeFile, which
7
+ * does NOT preserve the source template's mode.
8
+ * - update.action's applyPlan uses fs.copyFileSync for "added" files, which
9
+ * also does not preserve mode.
10
+ *
11
+ * Without this step the user has to `chmod +x compose-ctl.sh` manually after
12
+ * every `gadmin2 n` / `gadmin2 update`.
13
+ *
14
+ * KEEP IN SYNC with the schematics templates: any new shell entry point added
15
+ * to schematics that the user is expected to invoke directly should be listed
16
+ * here too.
17
+ */
18
+ export declare const EXECUTABLE_PATHS: ReadonlyArray<string>;
19
+ /**
20
+ * Best-effort: add the executable bit to known script entry points under
21
+ * `projectDir`. Only files that actually exist are touched. Failures are
22
+ * silently swallowed — chmod is a no-op on Windows and in containers without
23
+ * permission, but neither is a reason to abort the broader command.
24
+ *
25
+ * Returns the list of paths that were updated, suitable for verbose logging.
26
+ */
27
+ export declare function ensureExecutableBits(projectDir: string): string[];
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureExecutableBits = exports.EXECUTABLE_PATHS = void 0;
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ /**
7
+ * Files (relative to instance / project root) that must carry the executable
8
+ * bit. Both `gadmin2 n` and `gadmin2 update` re-apply this set after writing
9
+ * files because:
10
+ *
11
+ * - @angular-devkit/schematics writes generated files via fs.writeFile, which
12
+ * does NOT preserve the source template's mode.
13
+ * - update.action's applyPlan uses fs.copyFileSync for "added" files, which
14
+ * also does not preserve mode.
15
+ *
16
+ * Without this step the user has to `chmod +x compose-ctl.sh` manually after
17
+ * every `gadmin2 n` / `gadmin2 update`.
18
+ *
19
+ * KEEP IN SYNC with the schematics templates: any new shell entry point added
20
+ * to schematics that the user is expected to invoke directly should be listed
21
+ * here too.
22
+ */
23
+ exports.EXECUTABLE_PATHS = [
24
+ 'compose-ctl.sh',
25
+ 'server/start-prod.sh',
26
+ ];
27
+ /**
28
+ * Best-effort: add the executable bit to known script entry points under
29
+ * `projectDir`. Only files that actually exist are touched. Failures are
30
+ * silently swallowed — chmod is a no-op on Windows and in containers without
31
+ * permission, but neither is a reason to abort the broader command.
32
+ *
33
+ * Returns the list of paths that were updated, suitable for verbose logging.
34
+ */
35
+ function ensureExecutableBits(projectDir) {
36
+ const updated = [];
37
+ for (const rel of exports.EXECUTABLE_PATHS) {
38
+ const abs = path.join(projectDir, rel);
39
+ if (!fs.existsSync(abs))
40
+ continue;
41
+ try {
42
+ const cur = fs.statSync(abs).mode;
43
+ const next = cur | 0o111; // owner+group+other +x
44
+ if (next !== cur) {
45
+ fs.chmodSync(abs, next);
46
+ updated.push(rel);
47
+ }
48
+ }
49
+ catch (_a) {
50
+ // ignore — Windows / restricted FS
51
+ }
52
+ }
53
+ return updated;
54
+ }
55
+ exports.ensureExecutableBits = ensureExecutableBits;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Locate the @gadmin2n/schematics install root, searching:
3
+ * 1. the supplied instance dir (defaults to process.cwd())
4
+ * 2. <instanceDir>/server (where deps are usually hoisted)
5
+ * 3. the CLI's own node_modules — covers globally installed CLI where
6
+ * schematics ships alongside @gadmin2n/cli but is NOT installed in
7
+ * the user's project.
8
+ *
9
+ * Throws a helpful error if none of these resolve.
10
+ *
11
+ * Used by:
12
+ * - update.action (resolveTemplatePath, schematics version pin)
13
+ * - new.action (meta bootstrap at project init)
14
+ */
15
+ export declare function findSchematicsRoot(instanceDir?: string): string;
16
+ /**
17
+ * Convenience wrapper: returns the version field of @gadmin2n/schematics's
18
+ * package.json. Falls back to '0.0.0' if the field is missing.
19
+ */
20
+ export declare function getSchematicsVersion(instanceDir?: string): string;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSchematicsVersion = exports.findSchematicsRoot = void 0;
4
+ const path = require("path");
5
+ /**
6
+ * Locate the @gadmin2n/schematics install root, searching:
7
+ * 1. the supplied instance dir (defaults to process.cwd())
8
+ * 2. <instanceDir>/server (where deps are usually hoisted)
9
+ * 3. the CLI's own node_modules — covers globally installed CLI where
10
+ * schematics ships alongside @gadmin2n/cli but is NOT installed in
11
+ * the user's project.
12
+ *
13
+ * Throws a helpful error if none of these resolve.
14
+ *
15
+ * Used by:
16
+ * - update.action (resolveTemplatePath, schematics version pin)
17
+ * - new.action (meta bootstrap at project init)
18
+ */
19
+ function findSchematicsRoot(instanceDir = process.cwd()) {
20
+ const searchPaths = [
21
+ instanceDir,
22
+ path.join(instanceDir, 'server'),
23
+ path.resolve(__dirname, '..'),
24
+ ];
25
+ for (const searchPath of searchPaths) {
26
+ try {
27
+ const pkgPath = require.resolve('@gadmin2n/schematics/package.json', {
28
+ paths: [searchPath],
29
+ });
30
+ return path.dirname(pkgPath);
31
+ }
32
+ catch (_a) {
33
+ // continue
34
+ }
35
+ }
36
+ throw new Error('Cannot resolve @gadmin2n/schematics package. ' +
37
+ 'Make sure it is installed globally (alongside @gadmin2n/cli) ' +
38
+ 'or as a dependency of the project.');
39
+ }
40
+ exports.findSchematicsRoot = findSchematicsRoot;
41
+ /**
42
+ * Convenience wrapper: returns the version field of @gadmin2n/schematics's
43
+ * package.json. Falls back to '0.0.0' if the field is missing.
44
+ */
45
+ function getSchematicsVersion(instanceDir) {
46
+ const root = findSchematicsRoot(instanceDir);
47
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
48
+ const pkg = require(path.join(root, 'package.json'));
49
+ return (pkg && pkg.version) || '0.0.0';
50
+ }
51
+ exports.getSchematicsVersion = getSchematicsVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gadmin2n/cli",
3
- "version": "0.0.110",
3
+ "version": "0.0.112",
4
4
  "description": "Gadmin - modern, fast, powerful node.js web framework (@cli)",
5
5
  "publishConfig": {
6
6
  "access": "public"