@@ -4,17 +4,22 @@ import { program } from 'commander';
44import { execa } from 'execa' ;
55import fs from 'fs-extra' ;
66import path from 'path' ;
7+ import { fileURLToPath } from 'node:url' ;
78import { defaultTemplates } from './templates.js' ;
89import { mergeTemplates } from './template-loader.js' ;
910import { offerAndCreateGitHubRepo } from './github.js' ;
1011import { runCreate } from './create.js' ;
1112import { runSave } from './save.js' ;
1213import { runLoad } from './load.js' ;
1314import { runDeployToGitHubPages } from './gh-pages.js' ;
15+ import { readPackageVersion } from './read-package-version.js' ;
16+
17+ const packageJsonPath = path . join ( path . dirname ( fileURLToPath ( import . meta. url ) ) , '..' , 'package.json' ) ;
18+ const packageVersion = readPackageVersion ( packageJsonPath ) ;
1419
1520/** Command to create a new project */
1621program
17- . version ( '1.0.0' )
22+ . version ( packageVersion )
1823 . command ( 'create' )
1924 . description ( 'Create a new project from a git template' )
2025 . argument ( '[project-directory]' , 'The directory to create the project in' )
@@ -68,6 +73,26 @@ program
6873 console . log ( '' ) ;
6974 } ) ;
7075
76+ const PACKAGE_NAME = '@patternfly/patternfly-cli' ;
77+
78+ /** Update this CLI to the latest published npm version */
79+ program
80+ . command ( 'cli-upgrade' )
81+ . description ( 'Upgrade patternfly-cli to the latest version (npm global install)' )
82+ . action ( async ( ) => {
83+ console . log ( `Installing latest ${ PACKAGE_NAME } ...\n` ) ;
84+ try {
85+ await execa ( 'npm' , [ 'install' , '-g' , `${ PACKAGE_NAME } @latest` ] , { stdio : 'inherit' } ) ;
86+ console . log ( '\n✅ patternfly-cli is up to date.' ) ;
87+ } catch {
88+ console . error (
89+ '\n❌ Could not upgrade patternfly-cli. If you use another global package manager, run the equivalent of:' ,
90+ `\n npm install -g ${ PACKAGE_NAME } @latest\n` ,
91+ ) ;
92+ process . exit ( 1 ) ;
93+ }
94+ } ) ;
95+
7196/** Command to run PatternFly codemods on a directory */
7297program
7398 . command ( 'update' )
0 commit comments