@harness-engineering/cli 1.3.0 → 1.4.0
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/dist/bin/harness.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
|
|
10
10
|
// src/index.ts
|
|
11
11
|
import { Command as Command33 } from "commander";
|
|
12
|
-
import { VERSION
|
|
12
|
+
import { VERSION } from "@harness-engineering/core";
|
|
13
13
|
|
|
14
14
|
// src/commands/validate.ts
|
|
15
15
|
import { Command } from "commander";
|
|
@@ -3362,7 +3362,6 @@ import { execSync as execSync3 } from "child_process";
|
|
|
3362
3362
|
import { realpathSync } from "fs";
|
|
3363
3363
|
import readline3 from "readline";
|
|
3364
3364
|
import chalk4 from "chalk";
|
|
3365
|
-
import { VERSION } from "@harness-engineering/core";
|
|
3366
3365
|
function detectPackageManager() {
|
|
3367
3366
|
try {
|
|
3368
3367
|
const argv1 = process.argv[1];
|
|
@@ -3378,13 +3377,26 @@ function detectPackageManager() {
|
|
|
3378
3377
|
}
|
|
3379
3378
|
return "npm";
|
|
3380
3379
|
}
|
|
3381
|
-
function getLatestVersion() {
|
|
3382
|
-
const output = execSync3(
|
|
3380
|
+
function getLatestVersion(pkg = "@harness-engineering/cli") {
|
|
3381
|
+
const output = execSync3(`npm view ${pkg} dist-tags.latest`, {
|
|
3383
3382
|
encoding: "utf-8",
|
|
3384
3383
|
timeout: 15e3
|
|
3385
3384
|
});
|
|
3386
3385
|
return output.trim();
|
|
3387
3386
|
}
|
|
3387
|
+
function getInstalledVersion(pm) {
|
|
3388
|
+
try {
|
|
3389
|
+
const output = execSync3(`${pm} list -g @harness-engineering/cli --json`, {
|
|
3390
|
+
encoding: "utf-8",
|
|
3391
|
+
timeout: 15e3
|
|
3392
|
+
});
|
|
3393
|
+
const data = JSON.parse(output);
|
|
3394
|
+
const deps = data.dependencies ?? {};
|
|
3395
|
+
return deps["@harness-engineering/cli"]?.version ?? null;
|
|
3396
|
+
} catch {
|
|
3397
|
+
return null;
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3388
3400
|
function getInstalledPackages(pm) {
|
|
3389
3401
|
try {
|
|
3390
3402
|
const output = execSync3(`${pm} list -g --json`, {
|
|
@@ -3411,37 +3423,43 @@ function prompt(question) {
|
|
|
3411
3423
|
});
|
|
3412
3424
|
}
|
|
3413
3425
|
function createUpdateCommand() {
|
|
3414
|
-
return new Command32("update").description("Update all @harness-engineering packages to the latest version").option("--version <semver>", "
|
|
3426
|
+
return new Command32("update").description("Update all @harness-engineering packages to the latest version").option("--version <semver>", "Pin @harness-engineering/cli to a specific version").action(async (opts, cmd) => {
|
|
3415
3427
|
const globalOpts = cmd.optsWithGlobals();
|
|
3416
3428
|
const pm = detectPackageManager();
|
|
3417
3429
|
if (globalOpts.verbose) {
|
|
3418
3430
|
logger.info(`Detected package manager: ${pm}`);
|
|
3419
3431
|
}
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
} else {
|
|
3432
|
+
const currentVersion = getInstalledVersion(pm);
|
|
3433
|
+
let latestCliVersion;
|
|
3434
|
+
if (!opts.version) {
|
|
3424
3435
|
logger.info("Checking for updates...");
|
|
3425
3436
|
try {
|
|
3426
|
-
|
|
3437
|
+
latestCliVersion = getLatestVersion();
|
|
3427
3438
|
} catch {
|
|
3428
3439
|
logger.error("Failed to fetch latest version from npm registry");
|
|
3429
3440
|
return process.exit(ExitCode.ERROR);
|
|
3430
3441
|
}
|
|
3442
|
+
if (currentVersion && currentVersion === latestCliVersion) {
|
|
3443
|
+
logger.success(`Already up to date (v${currentVersion})`);
|
|
3444
|
+
process.exit(ExitCode.SUCCESS);
|
|
3445
|
+
}
|
|
3446
|
+
if (currentVersion) {
|
|
3447
|
+
console.log("");
|
|
3448
|
+
logger.info(`Current CLI version: ${chalk4.dim(`v${currentVersion}`)}`);
|
|
3449
|
+
logger.info(`Latest CLI version: ${chalk4.green(`v${latestCliVersion}`)}`);
|
|
3450
|
+
console.log("");
|
|
3451
|
+
}
|
|
3431
3452
|
}
|
|
3432
|
-
if (VERSION === targetVersion) {
|
|
3433
|
-
logger.success(`Already up to date (v${VERSION})`);
|
|
3434
|
-
process.exit(ExitCode.SUCCESS);
|
|
3435
|
-
}
|
|
3436
|
-
console.log("");
|
|
3437
|
-
logger.info(`Current version: ${chalk4.dim(`v${VERSION}`)}`);
|
|
3438
|
-
logger.info(`Target version: ${chalk4.green(`v${targetVersion}`)}`);
|
|
3439
|
-
console.log("");
|
|
3440
3453
|
const packages = getInstalledPackages(pm);
|
|
3441
3454
|
if (globalOpts.verbose) {
|
|
3442
3455
|
logger.info(`Installed packages: ${packages.join(", ")}`);
|
|
3443
3456
|
}
|
|
3444
|
-
const installArgs = packages.map((pkg) =>
|
|
3457
|
+
const installArgs = packages.map((pkg) => {
|
|
3458
|
+
if (opts.version && pkg === "@harness-engineering/cli") {
|
|
3459
|
+
return `${pkg}@${opts.version}`;
|
|
3460
|
+
}
|
|
3461
|
+
return `${pkg}@latest`;
|
|
3462
|
+
}).join(" ");
|
|
3445
3463
|
const installCmd = `${pm} install -g ${installArgs}`;
|
|
3446
3464
|
if (globalOpts.verbose) {
|
|
3447
3465
|
logger.info(`Running: ${installCmd}`);
|
|
@@ -3450,7 +3468,7 @@ function createUpdateCommand() {
|
|
|
3450
3468
|
logger.info("Updating packages...");
|
|
3451
3469
|
execSync3(installCmd, { stdio: "inherit", timeout: 12e4 });
|
|
3452
3470
|
console.log("");
|
|
3453
|
-
logger.success(
|
|
3471
|
+
logger.success("Update complete");
|
|
3454
3472
|
} catch {
|
|
3455
3473
|
console.log("");
|
|
3456
3474
|
logger.error("Update failed. You can try manually:");
|
|
@@ -3476,7 +3494,7 @@ function createUpdateCommand() {
|
|
|
3476
3494
|
// src/index.ts
|
|
3477
3495
|
function createProgram() {
|
|
3478
3496
|
const program = new Command33();
|
|
3479
|
-
program.name("harness").description("CLI for Harness Engineering toolkit").version(
|
|
3497
|
+
program.name("harness").description("CLI for Harness Engineering toolkit").version(VERSION).option("-c, --config <path>", "Path to config file").option("--json", "Output as JSON").option("--verbose", "Verbose output").option("--quiet", "Minimal output");
|
|
3480
3498
|
program.addCommand(createValidateCommand());
|
|
3481
3499
|
program.addCommand(createCheckDepsCommand());
|
|
3482
3500
|
program.addCommand(createCheckDocsCommand());
|
package/dist/index.js
CHANGED