Skip to content

Commit 6bc3459

Browse files
author
yaroslav8765
committed
fix: Move function getVertion to the cli.js
1 parent 880e00b commit 6bc3459

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

adminforth/commands/cli.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,19 @@ export function currentFileDir(importMetaUrl) {
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: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,10 @@ import { exec } from 'child_process';
1111

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

1616
const execAsync = promisify(exec);
1717

18-
19-
function getVersion() {
20-
const ADMIN_FORTH_ABSOLUTE_PATH = path.join(currentFileDir(import.meta.url), '..', '..');
21-
22-
const package_json = JSON.parse(fs.readFileSync(path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'package.json'), 'utf8'));
23-
24-
const ADMINFORTH_VERSION = package_json.version;
25-
26-
return ADMINFORTH_VERSION;
27-
}
28-
2918
function detectAdminforthVersion() {
3019
try {
3120
const version = getVersion();
@@ -35,18 +24,16 @@ function detectAdminforthVersion() {
3524
}
3625

3726
if (version.includes('next')) {
38-
console.log("Installing next version of AdminForth");
3927
return 'next';
4028
}
41-
console.log("Installing latest version of AdminForth");
4229
return 'latest';
4330
} catch (err) {
4431
console.warn('⚠️ Could not detect AdminForth version, defaulting to "latest".');
4532
return 'latest';
4633
}
4734
}
4835

49-
const getAdminforthVersion = detectAdminforthVersion();
36+
const adminforthVersion = detectAdminforthVersion();
5037

5138

5239
export function parseArgumentsIntoOptions(rawArgs) {
@@ -240,7 +227,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
240227
dest: 'package.json',
241228
data: {
242229
appName,
243-
adminforthVersion: getAdminforthVersion,
230+
adminforthVersion: adminforthVersion,
244231
},
245232
},
246233
{

0 commit comments

Comments
 (0)