@gadmin2n/cli 0.0.109 → 0.0.111
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/actions/update.action.js +57 -13
- package/package.json +1 -1
package/actions/update.action.js
CHANGED
|
@@ -17,6 +17,7 @@ const path = require("path");
|
|
|
17
17
|
const inquirer = require("inquirer");
|
|
18
18
|
const child_process_1 = require("child_process");
|
|
19
19
|
const abstract_action_1 = require("./abstract.action");
|
|
20
|
+
const self_update_action_1 = require("./self-update.action");
|
|
20
21
|
const version_check_1 = require("../lib/version-check");
|
|
21
22
|
const merge3way_1 = require("../lib/template-merge/merge3way");
|
|
22
23
|
const binary_detect_1 = require("../lib/template-merge/binary-detect");
|
|
@@ -48,11 +49,19 @@ function formatMaterializeError(schematicsVersion, err) {
|
|
|
48
49
|
/* ------------------------------------------------------------------ *
|
|
49
50
|
* Template config / path resolution
|
|
50
51
|
* ------------------------------------------------------------------ */
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Locate the @gadmin2n/schematics install root, searching:
|
|
54
|
+
* 1. the instance project dir
|
|
55
|
+
* 2. the instance project's server/ subdir (where deps usually live)
|
|
56
|
+
* 3. the CLI's own node_modules (covers globally installed CLI where
|
|
57
|
+
* schematics ships alongside @gadmin2n/cli but is NOT installed in
|
|
58
|
+
* the user's project)
|
|
59
|
+
* Throws a helpful error if none of these resolve.
|
|
60
|
+
*/
|
|
61
|
+
function findSchematicsRoot(instanceDir = process.cwd()) {
|
|
53
62
|
const searchPaths = [
|
|
54
|
-
|
|
55
|
-
path.join(
|
|
63
|
+
instanceDir,
|
|
64
|
+
path.join(instanceDir, 'server'),
|
|
56
65
|
path.resolve(__dirname, '..'),
|
|
57
66
|
];
|
|
58
67
|
for (const searchPath of searchPaths) {
|
|
@@ -60,17 +69,18 @@ function resolveTemplatePath(templateName) {
|
|
|
60
69
|
const pkgPath = require.resolve('@gadmin2n/schematics/package.json', {
|
|
61
70
|
paths: [searchPath],
|
|
62
71
|
});
|
|
63
|
-
|
|
64
|
-
break;
|
|
72
|
+
return path.dirname(pkgPath);
|
|
65
73
|
}
|
|
66
74
|
catch (_a) {
|
|
67
75
|
// continue
|
|
68
76
|
}
|
|
69
77
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
78
|
+
throw new Error('Cannot resolve @gadmin2n/schematics package. ' +
|
|
79
|
+
'Make sure it is installed globally (alongside @gadmin2n/cli) ' +
|
|
80
|
+
'or as a dependency of the project.');
|
|
81
|
+
}
|
|
82
|
+
function resolveTemplatePath(templateName) {
|
|
83
|
+
const schematicsRoot = findSchematicsRoot();
|
|
74
84
|
const nameVariants = [templateName];
|
|
75
85
|
if (templateName.startsWith('gadmin2n-')) {
|
|
76
86
|
nameVariants.push(templateName.replace('gadmin2n-', 'gadmin2-'));
|
|
@@ -664,7 +674,7 @@ function unifiedDiffSimple(a, b) {
|
|
|
664
674
|
* ------------------------------------------------------------------ */
|
|
665
675
|
class UpdateAction extends abstract_action_1.AbstractAction {
|
|
666
676
|
handle(inputs, options) {
|
|
667
|
-
var _a, _b;
|
|
677
|
+
var _a, _b, _c;
|
|
668
678
|
return __awaiter(this, void 0, void 0, function* () {
|
|
669
679
|
const subcommand = (_a = inputs.find((i) => i.name === 'subcommand')) === null || _a === void 0 ? void 0 : _a.value;
|
|
670
680
|
if (subcommand && subcommand !== 'update' && subcommand !== 'diff' && subcommand !== 'status') {
|
|
@@ -687,14 +697,47 @@ class UpdateAction extends abstract_action_1.AbstractAction {
|
|
|
687
697
|
// hard 1.5s timeout, never blocks. Prints a yellow banner if outdated.
|
|
688
698
|
const versionCheckEnabled = ((_b = options.find((o) => o.name === 'version-check')) === null || _b === void 0 ? void 0 : _b.value) !==
|
|
689
699
|
false;
|
|
700
|
+
const autoYes = !!((_c = options.find((o) => o.name === 'yes')) === null || _c === void 0 ? void 0 : _c.value);
|
|
690
701
|
if (versionCheckEnabled) {
|
|
691
702
|
try {
|
|
692
703
|
const info = yield (0, version_check_1.checkVersion)(1500);
|
|
693
704
|
if (info && (0, version_check_1.compareVersions)(info.installed, info.latest) < 0) {
|
|
694
705
|
(0, version_check_1.printOutdatedWarning)(info);
|
|
706
|
+
// For the main `gadmin2 update` (no subcommand), prompt the user to
|
|
707
|
+
// run `gadmin2 self-update` first. The current process is still on
|
|
708
|
+
// the old CLI binary, so silently continuing risks running the old
|
|
709
|
+
// pipeline against fresh templates. We therefore force a choice:
|
|
710
|
+
// - run self-update now → upgrade then exit, ask user to re-run.
|
|
711
|
+
// - cancel → exit without doing anything.
|
|
712
|
+
// In --yes / non-interactive mode, we keep the legacy behaviour:
|
|
713
|
+
// the warning is printed and the update proceeds. `diff` and
|
|
714
|
+
// `status` subcommands are read-only and skip this prompt entirely.
|
|
715
|
+
const isMainUpdate = !subcommand || subcommand === 'update';
|
|
716
|
+
if (isMainUpdate && !autoYes) {
|
|
717
|
+
const { proceedSelfUpdate } = yield inquirer.prompt([
|
|
718
|
+
{
|
|
719
|
+
type: 'confirm',
|
|
720
|
+
name: 'proceedSelfUpdate',
|
|
721
|
+
message: 'A newer gadmin2 CLI version is available. ' +
|
|
722
|
+
'Run `gadmin2 self-update` first before updating the project?',
|
|
723
|
+
default: true,
|
|
724
|
+
},
|
|
725
|
+
]);
|
|
726
|
+
if (proceedSelfUpdate) {
|
|
727
|
+
const selfUpdate = new self_update_action_1.SelfUpdateAction();
|
|
728
|
+
yield selfUpdate.handle([], []);
|
|
729
|
+
console.info(chalk.cyan('\n→ Self-update finished. Please re-run `gadmin2 update` so the new CLI binary drives the merge.\n'));
|
|
730
|
+
process.exit(0);
|
|
731
|
+
}
|
|
732
|
+
else {
|
|
733
|
+
console.info(chalk.gray('\nCancelled — exiting without running update. ' +
|
|
734
|
+
'Re-run when you are ready (or pass `--no-version-check` / `--yes` to bypass this prompt).\n'));
|
|
735
|
+
process.exit(0);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
695
738
|
}
|
|
696
739
|
}
|
|
697
|
-
catch (
|
|
740
|
+
catch (_d) {
|
|
698
741
|
// never let the version check break update
|
|
699
742
|
}
|
|
700
743
|
}
|
|
@@ -912,7 +955,8 @@ class UpdateAction extends abstract_action_1.AbstractAction {
|
|
|
912
955
|
snapshotPackageJson(path.join(instanceDir, 'web'), 'web'),
|
|
913
956
|
snapshotPackageJson(path.join(instanceDir, 'server'), 'server'),
|
|
914
957
|
];
|
|
915
|
-
const
|
|
958
|
+
const schematicsRoot = findSchematicsRoot(instanceDir);
|
|
959
|
+
const schematicsPkg = require(path.join(schematicsRoot, 'package.json'));
|
|
916
960
|
const schematicsVersion = schematicsPkg.version || '0.0.0';
|
|
917
961
|
// First-time bootstrap: meta absent → write meta + README, exit.
|
|
918
962
|
if (!fs.existsSync((0, base_store_1.metaPath)(instanceDir))) {
|