Skip to content

Commit bde97e2

Browse files
authored
Merge pull request #247 from devforth/improving-win-installation-speed
feat: Add auto-select for AdminForth version in create-app template package.json
2 parents 308d902 + 6bc3459 commit bde97e2

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

adminforth/commands/cli.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,25 @@ function showHelp() {
2525
);
2626
}
2727

28-
function currentFileDir(importMetaUrl) {
28+
export function currentFileDir(importMetaUrl) {
2929
const filePath = importMetaUrl.replace("file://", "");
3030
const fileDir = path.dirname(filePath);
3131
return fileDir;
3232
}
3333

34-
function showVersion() {
34+
export function getVersion() {
3535
const ADMIN_FORTH_ABSOLUTE_PATH = path.join(currentFileDir(import.meta.url), '..');
3636

3737
const package_json = JSON.parse(fs.readFileSync(path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'package.json'), 'utf8'));
3838

3939
const ADMINFORTH_VERSION = package_json.version;
4040

41+
return ADMINFORTH_VERSION;
42+
}
43+
44+
function showVersion() {
45+
const ADMINFORTH_VERSION = getVersion();
46+
4147
console.log(
4248
chalk.white('AdminForth CLI version: ') +
4349
chalk.cyan.bold(ADMINFORTH_VERSION)

adminforth/commands/createApp/utils.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,30 @@ import { exec } from 'child_process';
1111

1212
import Handlebars from 'handlebars';
1313
import { promisify } from 'util';
14+
import { getVersion } from '../cli.js';
1415

1516
const execAsync = promisify(exec);
1617

1718
function detectAdminforthVersion() {
18-
const userAgent = process.env.npm_config_user_agent || '';
19-
if (userAgent.includes('adminforth@next')) {
20-
return 'next'
21-
};
22-
return 'main';
19+
try {
20+
const version = getVersion();
21+
22+
if (typeof version !== 'string') {
23+
throw new Error('Invalid version format');
24+
}
25+
26+
if (version.includes('next')) {
27+
return 'next';
28+
}
29+
return 'latest';
30+
} catch (err) {
31+
console.warn('⚠️ Could not detect AdminForth version, defaulting to "latest".');
32+
return 'latest';
33+
}
2334
}
2435

36+
const adminforthVersion = detectAdminforthVersion();
37+
2538

2639
export function parseArgumentsIntoOptions(rawArgs) {
2740
const args = arg(
@@ -67,7 +80,6 @@ export async function promptForMissingOptions(options) {
6780
...options,
6881
appName: options.appName || answers.appName,
6982
db: options.db || answers.db,
70-
adminforthVersion: detectAdminforthVersion(),
7183
};
7284
}
7385

@@ -215,7 +227,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
215227
dest: 'package.json',
216228
data: {
217229
appName,
218-
adminforthVersion: options.adminforthVersion || 'latest'
230+
adminforthVersion: adminforthVersion,
219231
},
220232
},
221233
{

0 commit comments

Comments
 (0)