Skip to content

Commit dea348d

Browse files
Tunes of CICD
1 parent 47e7cca commit dea348d

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
},
99
"main": "dist/cli.js",
1010
"scripts": {
11-
"prebuild": "node scripts/generate-version.js",
1211
"build": "tsc",
1312
"watch": "tsc -w",
1413
"start": "node dist/cli.js",

src/cli.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,12 @@ export async function run(argv: string[], options?: RunOptions): Promise<void> {
633633
.scriptName("ocli")
634634
.version(VERSION)
635635
.exitProcess(false)
636+
.fail((msg, err) => {
637+
if (err) {
638+
throw err;
639+
}
640+
throw new Error(msg);
641+
})
636642
.command(
637643
"onboard",
638644
"Add a new profile (alias for profiles add default)",

src/version.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
export const VERSION = "v0.1.0";
1+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2+
const pkg = require("../package.json") as { version: string };
3+
4+
export const VERSION = process.env.OCLI_VERSION ?? `v${pkg.version}`;

tests/version.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
describe("VERSION", () => {
2+
const originalEnv = process.env.OCLI_VERSION;
3+
4+
afterEach(() => {
5+
if (originalEnv === undefined) {
6+
delete process.env.OCLI_VERSION;
7+
} else {
8+
process.env.OCLI_VERSION = originalEnv;
9+
}
10+
jest.resetModules();
11+
});
12+
13+
it("falls back to v<package.json version> when OCLI_VERSION is not set", () => {
14+
delete process.env.OCLI_VERSION;
15+
jest.resetModules();
16+
17+
const { VERSION } = require("../src/version") as { VERSION: string };
18+
const pkg = require("../package.json") as { version: string };
19+
20+
expect(VERSION).toBe(`v${pkg.version}`);
21+
});
22+
23+
it("uses OCLI_VERSION env var when set", () => {
24+
process.env.OCLI_VERSION = "v9.9.9-test";
25+
jest.resetModules();
26+
27+
const { VERSION } = require("../src/version") as { VERSION: string };
28+
29+
expect(VERSION).toBe("v9.9.9-test");
30+
});
31+
});

0 commit comments

Comments
 (0)