File tree Expand file tree Collapse file tree
snap-tests/cli-helper-message Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,7 +31,9 @@ Options:
3131 -V, --version Print version
3232
3333> vp -V # show version
34- vite-plus-global-cli <semver>
34+ Vite+ Version:
35+ - Local: Not found
36+ - Global: v<semver>
3537
3638> vp install -h # show install help message
3739Install all dependencies, or add packages if package names are provided
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ if (command === 'gen' || command === 'g' || command === 'generate' || command ==
1111 import ( './migration/bin.js' ) ;
1212} else if ( LOCAL_CLI_COMMANDS . includes ( command ) ) {
1313 import ( './local/bin.js' ) ;
14+ } else if ( command === '--version' || command === '-V' ) {
15+ import ( './version.js' ) ;
1416} else {
1517 // Delegate to rust commands
1618 import ( './global/bin.js' ) ;
Original file line number Diff line number Diff line change 1+ import { createRequire } from 'node:module' ;
2+
3+ import { detectPackageMetadata , VITE_PLUS_NAME } from './utils/index.js' ;
4+
5+ const require = createRequire ( import . meta. url ) ;
6+
7+ interface GlobalPackageJson {
8+ version : string ;
9+ }
10+
11+ /**
12+ * Get the global CLI version from package.json
13+ */
14+ export function getGlobalVersion ( ) : string {
15+ const pkg : GlobalPackageJson = require ( '../package.json' ) ;
16+ return pkg . version ;
17+ }
18+
19+ /**
20+ * Get the local CLI version if installed in the given directory
21+ */
22+ export function getLocalVersion ( cwd : string ) : string | null {
23+ const metadata = detectPackageMetadata ( cwd , VITE_PLUS_NAME ) ;
24+ return metadata ?. version ?? null ;
25+ }
26+
27+ /**
28+ * Print version information for both local and global CLI
29+ */
30+ export function printVersion ( cwd : string ) : void {
31+ const globalVersion = getGlobalVersion ( ) ;
32+ const localVersion = getLocalVersion ( cwd ) ;
33+
34+ console . log ( 'Vite+ Version:' ) ;
35+ console . log ( `- Local: ${ localVersion ? `v${ localVersion } ` : 'Not found' } ` ) ;
36+ console . log ( `- Global: v${ globalVersion } ` ) ;
37+ }
38+
39+ printVersion ( process . cwd ( ) ) ;
You can’t perform that action at this time.
0 commit comments