@@ -2,6 +2,7 @@ import assert from 'assert';
22import  fs  from  'fs' ; 
33import  {  instagram  }  from  'gradient-string' ; 
44import  path  from  'pathe' ; 
5+ import  {  fileURLToPath  }  from  'url' ; 
56import  yargsParser  from  'yargs-parser' ; 
67import  {  loadConfig  }  from  './config/config.js' ; 
78import  {  ConfigSchema  }  from  './config/types.js' ; 
@@ -19,6 +20,9 @@ import { reactScan } from './funplugins/react_scan/react_scan.js';
1920import  {  PluginHookType ,  PluginManager  }  from  './plugin/plugin_manager.js' ; 
2021import  {  type  Context ,  Mode  }  from  './types/index.js' ; 
2122
23+ const  __filename  =  fileURLToPath ( import . meta. url ) ; 
24+ const  __dirname  =  path . dirname ( __filename ) ; 
25+ 
2226async  function  buildContext ( cwd : string ) : Promise < Context >  { 
2327  const  argv  =  yargsParser ( process . argv . slice ( 2 ) ) ; 
2428  const  command  =  argv . _ [ 0 ] ; 
@@ -98,7 +102,13 @@ async function run(cwd: string) {
98102
99103  const  context  =  await  buildContext ( cwd ) ; 
100104
101-   const  cmd  =  context . argv . _ [ 0 ] ; 
105+   let  cmd  =  context . argv . _ [ 0 ] ; 
106+   if  ( context . argv . v  ||  context . argv . version )  { 
107+     cmd  =  'version' ; 
108+   } 
109+   if  ( context . argv . h  ||  context . argv . help )  { 
110+     cmd  =  'help' ; 
111+   } 
102112  assert ( cmd ,  'Command is required' ) ; 
103113
104114  if  ( cmd  ===  'build'  ||  cmd  ===  'dev' )  { 
@@ -111,6 +121,13 @@ async function run(cwd: string) {
111121  } 
112122
113123  switch  ( cmd )  { 
124+     case  'version' :
125+       const  pkgPath  =  path . join ( __dirname ,  '../package.json' ) ; 
126+       const  pkg  =  JSON . parse ( fs . readFileSync ( pkgPath ,  'utf-8' ) ) ; 
127+       console . log ( pkg . version ) ; 
128+       return ; 
129+     case  'help' :
130+       throw  new  Error ( 'Not implemented' ) ; 
114131    case  'build' :
115132      const  {  build }  =  await  import ( './build.js' ) ; 
116133      return  build ( {  context } ) ; 
0 commit comments