@@ -11,17 +11,30 @@ import { exec } from 'child_process';
11
11
12
12
import Handlebars from 'handlebars' ;
13
13
import { promisify } from 'util' ;
14
+ import { getVersion } from '../cli.js' ;
14
15
15
16
const execAsync = promisify ( exec ) ;
16
17
17
18
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
+ }
23
34
}
24
35
36
+ const adminforthVersion = detectAdminforthVersion ( ) ;
37
+
25
38
26
39
export function parseArgumentsIntoOptions ( rawArgs ) {
27
40
const args = arg (
@@ -67,7 +80,6 @@ export async function promptForMissingOptions(options) {
67
80
...options ,
68
81
appName : options . appName || answers . appName ,
69
82
db : options . db || answers . db ,
70
- adminforthVersion : detectAdminforthVersion ( ) ,
71
83
} ;
72
84
}
73
85
@@ -215,7 +227,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
215
227
dest : 'package.json' ,
216
228
data : {
217
229
appName,
218
- adminforthVersion : options . adminforthVersion || 'latest'
230
+ adminforthVersion : adminforthVersion ,
219
231
} ,
220
232
} ,
221
233
{
0 commit comments