Skip to content

Commit 9b9c15d

Browse files
committed
chore: fixed version bug.
1 parent 8b28f80 commit 9b9c15d

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import path from 'path';
2+
import fs from 'fs-extra';
3+
import { readPackageVersion } from '../read-package-version.js';
4+
5+
describe('readPackageVersion', () => {
6+
it('returns the version from the repo package.json', () => {
7+
const pkgPath = path.join(process.cwd(), 'package.json');
8+
const pkg = fs.readJsonSync(pkgPath) as { version: string };
9+
10+
expect(readPackageVersion(pkgPath)).toBe(pkg.version);
11+
expect(pkg.version.length).toBeGreaterThan(0);
12+
});
13+
});

src/cli.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ import { program } from 'commander';
44
import { execa } from 'execa';
55
import fs from 'fs-extra';
66
import path from 'path';
7+
import { fileURLToPath } from 'node:url';
78
import { defaultTemplates } from './templates.js';
89
import { mergeTemplates } from './template-loader.js';
910
import { offerAndCreateGitHubRepo } from './github.js';
1011
import { runCreate } from './create.js';
1112
import { runSave } from './save.js';
1213
import { runLoad } from './load.js';
1314
import { 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 */
1621
program
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 */
7297
program
7398
.command('update')

src/read-package-version.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import fs from 'fs-extra';
2+
3+
export function readPackageVersion(packageJsonPath: string): string {
4+
return (fs.readJsonSync(packageJsonPath) as { version: string }).version;
5+
}

0 commit comments

Comments
 (0)