@@ -2,6 +2,8 @@ import assert from 'assert';
22import fs from 'fs' ;
33import { instagram } from 'gradient-string' ;
44import path from 'pathe' ;
5+ import { fileURLToPath } from 'url' ;
6+ import { ar } from 'vitest/dist/chunks/reporters.D7Jzd9GS.js' ;
57import yargsParser from 'yargs-parser' ;
68import { loadConfig } from './config/config.js' ;
79import { ConfigSchema } from './config/types.js' ;
@@ -19,6 +21,9 @@ import { reactScan } from './funplugins/react_scan/react_scan.js';
1921import { PluginHookType , PluginManager } from './plugin/plugin_manager.js' ;
2022import { type Context , Mode } from './types/index.js' ;
2123
24+ const __filename = fileURLToPath ( import . meta. url ) ;
25+ const __dirname = path . dirname ( __filename ) ;
26+
2227async function buildContext ( cwd : string ) : Promise < Context > {
2328 const argv = yargsParser ( process . argv . slice ( 2 ) ) ;
2429 const command = argv . _ [ 0 ] ;
@@ -98,7 +103,13 @@ async function run(cwd: string) {
98103
99104 const context = await buildContext ( cwd ) ;
100105
101- const cmd = context . argv . _ [ 0 ] ;
106+ let cmd = context . argv . _ [ 0 ] ;
107+ if ( context . argv . v || context . argv . version ) {
108+ cmd = 'version' ;
109+ }
110+ if ( context . argv . h || context . argv . help ) {
111+ cmd = 'help' ;
112+ }
102113 assert ( cmd , 'Command is required' ) ;
103114
104115 if ( cmd === 'build' || cmd === 'dev' ) {
@@ -111,6 +122,13 @@ async function run(cwd: string) {
111122 }
112123
113124 switch ( cmd ) {
125+ case 'version' :
126+ const pkgPath = path . join ( __dirname , '../package.json' ) ;
127+ const pkg = JSON . parse ( fs . readFileSync ( pkgPath , 'utf-8' ) ) ;
128+ console . log ( pkg . version ) ;
129+ return ;
130+ case 'help' :
131+ throw new Error ( 'Not implemented' ) ;
114132 case 'build' :
115133 const { build } = await import ( './build.js' ) ;
116134 return build ( { context } ) ;
0 commit comments