@govuk-pay/cli 0.0.38 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@govuk-pay/cli",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "description": "GOV.UK Pay Command Line Interface",
5
5
  "bin": {
6
6
  "pay": "bin/cli.js",
@@ -30,7 +30,6 @@ const builder = (yargs) => {
30
30
  exports.builder = builder;
31
31
  exports.handler = browseHandler;
32
32
  async function browseHandler(argv) {
33
- console.log(argv);
34
33
  await (0, standardContent_js_1.showHeader)();
35
34
  const location = argv.location;
36
35
  const requestedItem = requestableItems.get(location);
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.desc = exports.command = void 0;
4
+ const standardContent_js_1 = require("../core/standardContent.js");
5
+ const node_child_process_1 = require("node:child_process");
6
+ const commandRouter_js_1 = require("../core/commandRouter.js");
7
+ exports.command = 'update';
8
+ exports.desc = 'Update the pay cli by running `npm install -g @govuk-pay/cli` on your behalf';
9
+ exports.handler = updateHandler;
10
+ async function updateHandler(_argv) {
11
+ await (0, standardContent_js_1.showHeader)();
12
+ if (await (0, commandRouter_js_1.isLatestVersion)()) {
13
+ console.error('Pay cli is already the latest version available in npm');
14
+ return;
15
+ }
16
+ console.log('Running `npm install -g @govuk-pay/cli');
17
+ (0, node_child_process_1.spawnSync)('npm', ['install', '-g', '@govuk-pay/cli'], { shell: true, stdio: 'inherit' });
18
+ }
19
+ exports.default = updateHandler;
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isLatestVersion = void 0;
6
7
  const package_json_1 = __importDefault(require("../../package.json"));
7
8
  const semver_1 = __importDefault(require("semver"));
8
9
  const yargs_1 = __importDefault(require("yargs/yargs"));
@@ -22,16 +23,24 @@ async function runCommand() {
22
23
  exports.default = runCommand;
23
24
  async function checkVersion() {
24
25
  try {
25
- const { version: currentVersion, engines: { node: requiredNodeVersion } } = package_json_1.default;
26
+ const { engines: { node: requiredNodeVersion } } = package_json_1.default;
26
27
  if (!semver_1.default.satisfies(process.version, requiredNodeVersion)) {
27
28
  console.log(`Required Node.js version is ${requiredNodeVersion}, you are running ${process.version}. Please upgrade before continuing.`);
28
29
  }
29
- const { version: remoteVersion } = await fetch('https://registry.npmjs.org/@govuk-pay/cli/latest')
30
- .then(async (r) => await r.json());
31
- if (currentVersion !== remoteVersion) {
32
- console.log(`You are running pay-cli version ${currentVersion}, the latest version is ${remoteVersion}.`);
33
- console.log('Run `npm install -g @govuk-pay/cli` to upgrade.');
30
+ if (!await isLatestVersion()) {
31
+ console.log('Run `pay update` or `npm install -g @govuk-pay/cli` to upgrade.');
34
32
  }
35
33
  }
36
34
  catch { }
37
35
  }
36
+ async function isLatestVersion() {
37
+ const { version: currentVersion } = package_json_1.default;
38
+ const { version: remoteVersion } = await fetch('https://registry.npmjs.org/@govuk-pay/cli/latest')
39
+ .then(async (r) => await r.json());
40
+ if (currentVersion !== remoteVersion) {
41
+ console.log(`You are running pay-cli version ${currentVersion}, the latest version is ${remoteVersion}.`);
42
+ return false;
43
+ }
44
+ return true;
45
+ }
46
+ exports.isLatestVersion = isLatestVersion;