adminforth 3.6.12 → 3.6.13
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/commands/cli.js
CHANGED
|
@@ -42,6 +42,61 @@ export function getVersion() {
|
|
|
42
42
|
return ADMINFORTH_VERSION;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Resolves the adminforth version range to write into a scaffolded package.json.
|
|
47
|
+
*
|
|
48
|
+
* Returns a caret range pinned to the latest published release of the dist-tag
|
|
49
|
+
* matching the running CLI, e.g. "^3.6.12" (installs the latest 3.x.x, never a
|
|
50
|
+
* major upgrade). For "next" builds the moving "next" tag is kept, since
|
|
51
|
+
* prerelease versions do not caret cleanly. Falls back to a major-only range
|
|
52
|
+
* (e.g. "^3.0.0"), and finally to "latest", when the registry is unreachable.
|
|
53
|
+
*/
|
|
54
|
+
export async function resolveAdminforthVersionRange() {
|
|
55
|
+
// Determine which dist-tag matches the CLI currently running, and derive an
|
|
56
|
+
// offline fallback range from the CLI's own major version.
|
|
57
|
+
let tag = 'latest';
|
|
58
|
+
let offlineFallback = 'latest';
|
|
59
|
+
try {
|
|
60
|
+
const version = getVersion();
|
|
61
|
+
if (typeof version === 'string') {
|
|
62
|
+
if (version.includes('next')) {
|
|
63
|
+
tag = 'next';
|
|
64
|
+
}
|
|
65
|
+
const major = version.split('.')[0];
|
|
66
|
+
if (/^\d+$/.test(major)) {
|
|
67
|
+
offlineFallback = `^${major}.0.0`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
// Ignore; fall back to "latest" below.
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// "next" builds keep the moving tag — prerelease versions don't caret cleanly.
|
|
75
|
+
if (tag === 'next') {
|
|
76
|
+
return 'next';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const res = await fetch('https://registry.npmjs.org/-/package/adminforth/dist-tags', {
|
|
81
|
+
signal: AbortSignal.timeout(5000),
|
|
82
|
+
});
|
|
83
|
+
if (!res.ok) {
|
|
84
|
+
throw new Error(`registry responded with ${res.status}`);
|
|
85
|
+
}
|
|
86
|
+
const distTags = await res.json();
|
|
87
|
+
const latest = distTags[tag];
|
|
88
|
+
if (typeof latest !== 'string' || !/^\d+\.\d+\.\d+/.test(latest)) {
|
|
89
|
+
throw new Error('invalid version received from registry');
|
|
90
|
+
}
|
|
91
|
+
return `^${latest}`;
|
|
92
|
+
} catch (err) {
|
|
93
|
+
console.warn(
|
|
94
|
+
`⚠️ Could not resolve AdminForth version from npm registry (${err.message}); defaulting to "${offlineFallback}".`
|
|
95
|
+
);
|
|
96
|
+
return offlineFallback;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
45
100
|
function showVersion() {
|
|
46
101
|
const ADMINFORTH_VERSION = getVersion();
|
|
47
102
|
|
|
@@ -11,33 +11,14 @@ import { exec } from 'child_process';
|
|
|
11
11
|
|
|
12
12
|
import Handlebars from 'handlebars';
|
|
13
13
|
import { promisify } from 'util';
|
|
14
|
-
import {
|
|
14
|
+
import { resolveAdminforthVersionRange } from '../cli.js';
|
|
15
15
|
|
|
16
16
|
import { URL } from 'url'
|
|
17
17
|
import net from 'net'
|
|
18
18
|
|
|
19
19
|
const execAsync = promisify(exec);
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const version = getVersion();
|
|
24
|
-
|
|
25
|
-
if (typeof version !== 'string') {
|
|
26
|
-
throw new Error('Invalid version format');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (version.includes('next')) {
|
|
30
|
-
return 'next';
|
|
31
|
-
}
|
|
32
|
-
return 'latest';
|
|
33
|
-
} catch (err) {
|
|
34
|
-
console.warn('⚠️ Could not detect AdminForth version, defaulting to "latest".');
|
|
35
|
-
return 'latest';
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const adminforthVersion = detectAdminforthVersion();
|
|
40
|
-
const SUPPORTED_DB_URL_SCHEMES = ['sqlite://', 'postgresql://', 'mongodb://', 'mysql://', 'clickhouse://'];
|
|
21
|
+
const SUPPORTED_DB_URL_SCHEMES =['sqlite://', 'postgresql://', 'mongodb://', 'mysql://', 'clickhouse://'];
|
|
41
22
|
const PRISMA_MIGRATION_DB_PROTOCOLS = ['sqlite', 'postgres', 'postgresql', 'mysql'];
|
|
42
23
|
|
|
43
24
|
|
|
@@ -314,6 +295,7 @@ async function writeTemplateFiles(dirname, cwd, useNpm, includePrismaMigrations,
|
|
|
314
295
|
dbUrlProd, prismaDbUrlProd, sqliteFile
|
|
315
296
|
} = options;
|
|
316
297
|
const packageManagerTemplateData = getPackageManagerTemplateData(useNpm, nodeMajor);
|
|
298
|
+
const adminforthVersion = await resolveAdminforthVersionRange();
|
|
317
299
|
const resolvedPrismaDbUrl = includePrismaMigrations ? prismaDbUrl : null;
|
|
318
300
|
const resolvedPrismaDbUrlProd = includePrismaMigrations ? prismaDbUrlProd : null;
|
|
319
301
|
const connectorProvider = provider === 'postgresql' ? 'postgres' :
|
|
@@ -8,6 +8,7 @@ import { Listr } from 'listr2';
|
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
9
|
import { execa } from 'execa';
|
|
10
10
|
import Handlebars from 'handlebars';
|
|
11
|
+
import { resolveAdminforthVersionRange } from '../cli.js';
|
|
11
12
|
|
|
12
13
|
export function parseArgumentsIntoOptions(rawArgs) {
|
|
13
14
|
const args = arg(
|
|
@@ -102,6 +103,7 @@ async function scaffoldProject(ctx, options, cwd) {
|
|
|
102
103
|
|
|
103
104
|
async function writeTemplateFiles(dirname, cwd, options) {
|
|
104
105
|
const { pluginName } = options;
|
|
106
|
+
const adminforthVersion = await resolveAdminforthVersionRange();
|
|
105
107
|
|
|
106
108
|
// Build a list of files to generate
|
|
107
109
|
const templateTasks = [
|
|
@@ -113,7 +115,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
|
|
|
113
115
|
{
|
|
114
116
|
src: "package.json.hbs",
|
|
115
117
|
dest: "package.json",
|
|
116
|
-
data: { pluginName },
|
|
118
|
+
data: { pluginName, adminforthVersion },
|
|
117
119
|
},
|
|
118
120
|
{
|
|
119
121
|
src: "index.ts.hbs",
|