Skip to content

Commit

Permalink
Merge pull request #275 from pantheon-systems/PCC-1374-cli-version-co…
Browse files Browse the repository at this point in the history
…mmand-just-says-unknown

PCC-1374 Manually handle printing the CLI version to work-around monorepo issues.
  • Loading branch information
kevinstubbs authored Jun 17, 2024
2 parents 5f3437b + 0c75736 commit 6dd9f45
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-crabs-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pantheon-systems/pcc-cli": patch
---

CLI replaces "--version" command with "version"
9 changes: 8 additions & 1 deletion packages/cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import ora from "ora";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import checkUpdate from "../lib/checkUpdate";
import checkUpdate, { getPackageDetails } from "../lib/checkUpdate";
import { isProgramInstalled } from "../lib/utils";
import {
printConfigurationData,
Expand Down Expand Up @@ -59,6 +59,13 @@ yargs(hideBin(process.argv))
.middleware(configureMiddleware(checkUpdate))
.strictCommands()
.demandCommand()
.version(false)
.command(
"version",
"Prints the version of this CLI",
() => void 0,
() => console.log(getPackageDetails().version),
)
.command(
"init <project_directory> [options]",
"Sets up project with required files.",
Expand Down
9 changes: 7 additions & 2 deletions packages/cli/src/lib/checkUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import semver from "semver";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const checkUpdate = async () => {
export function getPackageDetails() {
const { name, version } = JSON.parse(
fs.readFileSync(__dirname + "/../package.json").toString(),
);
const { version: latestVersion } = await pkgJson(name);

return { name, version };
}

const checkUpdate = async () => {
const { name, version } = getPackageDetails();
const { version: latestVersion } = await pkgJson(name);
const updateAvailable = semver.lt(version, latestVersion as string);
if (updateAvailable) {
const msg = {
Expand Down

0 comments on commit 6dd9f45

Please sign in to comment.