@gadmin2n/cli 0.0.90 → 0.0.92
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/.circleci/config.yml +62 -0
- package/.github/ISSUE_TEMPLATE/Bug_report.yml +106 -0
- package/.github/ISSUE_TEMPLATE/Feature_request.yml +52 -0
- package/.github/ISSUE_TEMPLATE/Regression.yml +78 -0
- package/.github/ISSUE_TEMPLATE/config.yml +7 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +41 -0
- package/actions/index.d.ts +1 -1
- package/actions/index.js +1 -1
- package/actions/self-update.action.d.ts +5 -0
- package/actions/self-update.action.js +93 -0
- package/actions/update.action.d.ts +2 -0
- package/actions/update.action.js +945 -6
- package/commands/command.loader.js +2 -2
- package/commands/{template.command.d.ts → self-update.command.d.ts} +1 -1
- package/commands/self-update.command.js +35 -0
- package/commands/update.command.js +25 -8
- package/lib/install-manager.d.ts +48 -0
- package/lib/install-manager.js +125 -0
- package/lib/template-merge/config-loader.d.ts +15 -0
- package/lib/template-merge/config-loader.js +38 -0
- package/lib/template-merge/env-merger.d.ts +5 -0
- package/lib/template-merge/env-merger.js +57 -0
- package/lib/template-merge/glob.d.ts +5 -0
- package/lib/template-merge/glob.js +78 -0
- package/lib/template-merge/index.d.ts +8 -0
- package/lib/template-merge/index.js +24 -0
- package/lib/template-merge/json-merger.d.ts +5 -0
- package/lib/template-merge/json-merger.js +252 -0
- package/lib/template-merge/merger.d.ts +30 -0
- package/lib/template-merge/merger.js +2 -0
- package/lib/template-merge/prisma-merger.d.ts +5 -0
- package/lib/template-merge/prisma-merger.js +112 -0
- package/lib/template-merge/registry.d.ts +25 -0
- package/lib/template-merge/registry.js +42 -0
- package/lib/template-merge/ts-module-merger.d.ts +16 -0
- package/lib/template-merge/ts-module-merger.js +193 -0
- package/lib/version-check.d.ts +39 -0
- package/lib/version-check.js +157 -0
- package/package.json +2 -2
- package/test/lib/compiler/hooks/__snapshots__/tsconfig-paths.hook.spec.ts.snap +68 -0
- package/test/lib/compiler/hooks/fixtures/aliased-imports/src/bar.tsx +1 -0
- package/test/lib/compiler/hooks/fixtures/aliased-imports/src/baz.js +1 -0
- package/test/lib/compiler/hooks/fixtures/aliased-imports/src/qux.jsx +1 -0
- package/actions/template.action.d.ts +0 -7
- package/actions/template.action.js +0 -570
- package/commands/template.command.js +0 -42
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface InstalledInfo {
|
|
2
|
+
name: string;
|
|
3
|
+
version: string;
|
|
4
|
+
}
|
|
5
|
+
export interface VersionInfo {
|
|
6
|
+
packageName: string;
|
|
7
|
+
installed: string;
|
|
8
|
+
latest: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Read the CLI's own installed version by walking up from __dirname looking
|
|
12
|
+
* for the closest package.json. Returns null if not found.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getInstalledVersion(): InstalledInfo | null;
|
|
15
|
+
/**
|
|
16
|
+
* HTTPS GET https://registry.npmjs.org/<name>/latest with a hard timeout.
|
|
17
|
+
* Returns the latest version string on success, or null on any failure
|
|
18
|
+
* (network error, non-200, parse error, timeout). Never throws.
|
|
19
|
+
*/
|
|
20
|
+
export declare function fetchLatestVersion(packageName: string, timeoutMs?: number): Promise<string | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Numeric compare of dotted version strings. Strips any prerelease suffix
|
|
23
|
+
* (`-alpha.1`, `-rc.0`, etc.) before comparing. Returns positive if a > b,
|
|
24
|
+
* negative if a < b, 0 if equal.
|
|
25
|
+
*/
|
|
26
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
27
|
+
/**
|
|
28
|
+
* Convenience wrapper: read installed version + fetch latest. Returns
|
|
29
|
+
* null on any failure (no installed pkg.json located, network failure,
|
|
30
|
+
* timeout). Never throws.
|
|
31
|
+
*/
|
|
32
|
+
export declare function checkVersion(timeoutMs?: number): Promise<VersionInfo | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Print a yellow warning banner explaining that the CLI is outdated and
|
|
35
|
+
* how to upgrade. Uses the auto-detected install manager to suggest the
|
|
36
|
+
* matching upgrade command (npm install -g / yarn global add / pnpm add -g).
|
|
37
|
+
* Non-blocking — caller decides whether to continue.
|
|
38
|
+
*/
|
|
39
|
+
export declare function printOutdatedWarning(info: VersionInfo): void;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.printOutdatedWarning = exports.checkVersion = exports.compareVersions = exports.fetchLatestVersion = exports.getInstalledVersion = void 0;
|
|
13
|
+
const chalk = require("chalk");
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
const https = require("https");
|
|
16
|
+
const path = require("path");
|
|
17
|
+
const install_manager_1 = require("./install-manager");
|
|
18
|
+
const REGISTRY_URL = 'https://registry.npmjs.org';
|
|
19
|
+
/**
|
|
20
|
+
* Read the CLI's own installed version by walking up from __dirname looking
|
|
21
|
+
* for the closest package.json. Returns null if not found.
|
|
22
|
+
*/
|
|
23
|
+
function getInstalledVersion() {
|
|
24
|
+
let dir = __dirname;
|
|
25
|
+
for (let i = 0; i < 8; i++) {
|
|
26
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
27
|
+
if (fs.existsSync(pkgPath)) {
|
|
28
|
+
try {
|
|
29
|
+
const json = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
30
|
+
if (json.name && json.version) {
|
|
31
|
+
return { name: json.name, version: json.version };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (_a) {
|
|
35
|
+
// ignore and keep walking
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const parent = path.dirname(dir);
|
|
39
|
+
if (parent === dir)
|
|
40
|
+
break;
|
|
41
|
+
dir = parent;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
exports.getInstalledVersion = getInstalledVersion;
|
|
46
|
+
/**
|
|
47
|
+
* HTTPS GET https://registry.npmjs.org/<name>/latest with a hard timeout.
|
|
48
|
+
* Returns the latest version string on success, or null on any failure
|
|
49
|
+
* (network error, non-200, parse error, timeout). Never throws.
|
|
50
|
+
*/
|
|
51
|
+
function fetchLatestVersion(packageName, timeoutMs = 1500) {
|
|
52
|
+
return new Promise((resolve) => {
|
|
53
|
+
const url = `${REGISTRY_URL}/${encodeURIComponent(packageName).replace('%40', '@')}/latest`;
|
|
54
|
+
let settled = false;
|
|
55
|
+
const finish = (v) => {
|
|
56
|
+
if (settled)
|
|
57
|
+
return;
|
|
58
|
+
settled = true;
|
|
59
|
+
resolve(v);
|
|
60
|
+
};
|
|
61
|
+
const req = https.get(url, { timeout: timeoutMs }, (res) => {
|
|
62
|
+
if (res.statusCode !== 200) {
|
|
63
|
+
res.resume();
|
|
64
|
+
finish(null);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const chunks = [];
|
|
68
|
+
res.on('data', (c) => chunks.push(c));
|
|
69
|
+
res.on('end', () => {
|
|
70
|
+
try {
|
|
71
|
+
const json = JSON.parse(Buffer.concat(chunks).toString('utf-8'));
|
|
72
|
+
finish(typeof json.version === 'string' ? json.version : null);
|
|
73
|
+
}
|
|
74
|
+
catch (_a) {
|
|
75
|
+
finish(null);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
res.on('error', () => finish(null));
|
|
79
|
+
});
|
|
80
|
+
req.on('error', () => finish(null));
|
|
81
|
+
req.on('timeout', () => {
|
|
82
|
+
req.destroy();
|
|
83
|
+
finish(null);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
exports.fetchLatestVersion = fetchLatestVersion;
|
|
88
|
+
/**
|
|
89
|
+
* Numeric compare of dotted version strings. Strips any prerelease suffix
|
|
90
|
+
* (`-alpha.1`, `-rc.0`, etc.) before comparing. Returns positive if a > b,
|
|
91
|
+
* negative if a < b, 0 if equal.
|
|
92
|
+
*/
|
|
93
|
+
function compareVersions(a, b) {
|
|
94
|
+
const parse = (v) => v.split('.').map((n) => parseInt(n.split('-')[0], 10) || 0);
|
|
95
|
+
const pa = parse(a);
|
|
96
|
+
const pb = parse(b);
|
|
97
|
+
const len = Math.max(pa.length, pb.length);
|
|
98
|
+
for (let i = 0; i < len; i++) {
|
|
99
|
+
const da = pa[i] || 0;
|
|
100
|
+
const db = pb[i] || 0;
|
|
101
|
+
if (da !== db)
|
|
102
|
+
return da - db;
|
|
103
|
+
}
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
exports.compareVersions = compareVersions;
|
|
107
|
+
/**
|
|
108
|
+
* Convenience wrapper: read installed version + fetch latest. Returns
|
|
109
|
+
* null on any failure (no installed pkg.json located, network failure,
|
|
110
|
+
* timeout). Never throws.
|
|
111
|
+
*/
|
|
112
|
+
function checkVersion(timeoutMs = 1500) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const installed = getInstalledVersion();
|
|
115
|
+
if (!installed)
|
|
116
|
+
return null;
|
|
117
|
+
const latest = yield fetchLatestVersion(installed.name, timeoutMs);
|
|
118
|
+
if (!latest)
|
|
119
|
+
return null;
|
|
120
|
+
return {
|
|
121
|
+
packageName: installed.name,
|
|
122
|
+
installed: installed.version,
|
|
123
|
+
latest,
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
exports.checkVersion = checkVersion;
|
|
128
|
+
/**
|
|
129
|
+
* Print a yellow warning banner explaining that the CLI is outdated and
|
|
130
|
+
* how to upgrade. Uses the auto-detected install manager to suggest the
|
|
131
|
+
* matching upgrade command (npm install -g / yarn global add / pnpm add -g).
|
|
132
|
+
* Non-blocking — caller decides whether to continue.
|
|
133
|
+
*/
|
|
134
|
+
function printOutdatedWarning(info) {
|
|
135
|
+
const detection = (0, install_manager_1.detectInstallManager)();
|
|
136
|
+
const upgradeCmd = (0, install_manager_1.buildUpgradeCommand)(detection.manager, info.packageName, 'latest');
|
|
137
|
+
const bar = '═══════════════════════════════════════════════════';
|
|
138
|
+
console.warn();
|
|
139
|
+
console.warn(chalk.yellow.bold(bar));
|
|
140
|
+
console.warn(chalk.yellow.bold('⚠️ CLI is outdated:') +
|
|
141
|
+
chalk.yellow(` installed ${info.installed}, latest ${info.latest}`));
|
|
142
|
+
console.warn(chalk.yellow(' Templates ship bundled with the CLI — using an outdated CLI'));
|
|
143
|
+
console.warn(chalk.yellow(' means updating against an outdated template.'));
|
|
144
|
+
console.warn();
|
|
145
|
+
console.warn(chalk.yellow(' Upgrade with:'));
|
|
146
|
+
console.warn(chalk.cyan(` gadmin2 self-update`));
|
|
147
|
+
console.warn(chalk.gray(` (or: ${upgradeCmd})`));
|
|
148
|
+
console.warn(chalk.gray(` detected manager: ${detection.manager}` +
|
|
149
|
+
(detection.pathHint !== detection.manager
|
|
150
|
+
? ` (path hint: ${detection.pathHint})`
|
|
151
|
+
: '')));
|
|
152
|
+
console.warn();
|
|
153
|
+
console.warn(chalk.gray(' To skip this check: gadmin2 update --no-version-check'));
|
|
154
|
+
console.warn(chalk.yellow.bold(bar));
|
|
155
|
+
console.warn();
|
|
156
|
+
}
|
|
157
|
+
exports.printOutdatedWarning = printOutdatedWarning;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gadmin2n/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.92",
|
|
4
4
|
"description": "Gadmin - modern, fast, powerful node.js web framework (@cli)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@angular-devkit/core": "13.3.2",
|
|
48
48
|
"@angular-devkit/schematics": "13.3.2",
|
|
49
49
|
"@angular-devkit/schematics-cli": "13.3.2",
|
|
50
|
-
"@gadmin2n/schematics": "^0.0.
|
|
50
|
+
"@gadmin2n/schematics": "^0.0.74",
|
|
51
51
|
"abc": "^0.6.1",
|
|
52
52
|
"chalk": "3.0.0",
|
|
53
53
|
"chokidar": "3.5.3",
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`tsconfig paths hooks should remove unused imports 1`] = `
|
|
4
|
+
Map {
|
|
5
|
+
"dist/foo.js" => "\\"use strict\\";
|
|
6
|
+
Object.defineProperty(exports, \\"__esModule\\", { value: true });
|
|
7
|
+
exports.Foo = void 0;
|
|
8
|
+
class Foo {
|
|
9
|
+
}
|
|
10
|
+
exports.Foo = Foo;
|
|
11
|
+
",
|
|
12
|
+
"dist/bar.js" => "\\"use strict\\";
|
|
13
|
+
Object.defineProperty(exports, \\"__esModule\\", { value: true });
|
|
14
|
+
exports.Bar = void 0;
|
|
15
|
+
class Bar {
|
|
16
|
+
}
|
|
17
|
+
exports.Bar = Bar;
|
|
18
|
+
",
|
|
19
|
+
"dist/main.js" => "\\"use strict\\";
|
|
20
|
+
Object.defineProperty(exports, \\"__esModule\\", { value: true });
|
|
21
|
+
",
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
exports[`tsconfig paths hooks should replace path of every import using a path alias by its relative path 1`] = `
|
|
26
|
+
Map {
|
|
27
|
+
"dist/foo.js" => "\\"use strict\\";
|
|
28
|
+
Object.defineProperty(exports, \\"__esModule\\", { value: true });
|
|
29
|
+
exports.Foo = void 0;
|
|
30
|
+
class Foo {
|
|
31
|
+
}
|
|
32
|
+
exports.Foo = Foo;
|
|
33
|
+
",
|
|
34
|
+
"dist/bar.jsx" => "\\"use strict\\";
|
|
35
|
+
Object.defineProperty(exports, \\"__esModule\\", { value: true });
|
|
36
|
+
exports.Bar = void 0;
|
|
37
|
+
class Bar {
|
|
38
|
+
}
|
|
39
|
+
exports.Bar = Bar;
|
|
40
|
+
",
|
|
41
|
+
"dist/baz.js" => "\\"use strict\\";
|
|
42
|
+
Object.defineProperty(exports, \\"__esModule\\", { value: true });
|
|
43
|
+
exports.Baz = void 0;
|
|
44
|
+
class Baz {
|
|
45
|
+
}
|
|
46
|
+
exports.Baz = Baz;
|
|
47
|
+
",
|
|
48
|
+
"dist/qux.jsx" => "\\"use strict\\";
|
|
49
|
+
Object.defineProperty(exports, \\"__esModule\\", { value: true });
|
|
50
|
+
exports.Qux = void 0;
|
|
51
|
+
class Qux {
|
|
52
|
+
}
|
|
53
|
+
exports.Qux = Qux;
|
|
54
|
+
",
|
|
55
|
+
"dist/main.js" => "\\"use strict\\";
|
|
56
|
+
Object.defineProperty(exports, \\"__esModule\\", { value: true });
|
|
57
|
+
const foo_1 = require(\\"./foo\\");
|
|
58
|
+
const bar_1 = require(\\"./bar\\");
|
|
59
|
+
const baz_1 = require(\\"./baz\\");
|
|
60
|
+
const qux_1 = require(\\"./qux\\");
|
|
61
|
+
// use the imports so they do not get eliminated
|
|
62
|
+
console.log(foo_1.Foo);
|
|
63
|
+
console.log(bar_1.Bar);
|
|
64
|
+
console.log(baz_1.Baz);
|
|
65
|
+
console.log(qux_1.Qux);
|
|
66
|
+
",
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class Bar {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class Baz {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class Qux {}
|