Skip to content

Commit 3d94bd7

Browse files
Another attempt
1 parent d3c9acf commit 3d94bd7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1586
-658
lines changed
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
export type SupportedPlatform = Extract<
2-
NodeJS.Platform,
3-
"linux" | "darwin" | "win32"
4-
>;
1+
export type SupportedPlatform = Extract<NodeJS.Platform, "linux" | "darwin" | "win32">;
52
export declare const archMap: Record<string, string>;
6-
export declare const cliUrlBuilder: Record<
7-
SupportedPlatform,
8-
(version: string, arch?: string) => string
9-
>;
3+
export declare const cliUrlBuilder: Record<SupportedPlatform, (version: string, arch?: string) => string>;
104
export declare class CliInstaller {
11-
readonly version: string;
12-
readonly arch: string;
13-
constructor(version: string);
14-
install(url: string): Promise<void>;
15-
private getArch;
5+
readonly version: string;
6+
readonly arch: string;
7+
constructor(version: string);
8+
install(url: string): Promise<void>;
9+
private getArch;
1610
}
Lines changed: 72 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,77 @@
1-
import os from "os";
2-
import * as core from "@actions/core";
3-
import * as tc from "@actions/tool-cache";
1+
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __importStar = (this && this.__importStar) || (function () {
19+
var ownKeys = function(o) {
20+
ownKeys = Object.getOwnPropertyNames || function (o) {
21+
var ar = [];
22+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23+
return ar;
24+
};
25+
return ownKeys(o);
26+
};
27+
return function (mod) {
28+
if (mod && mod.__esModule) return mod;
29+
var result = {};
30+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31+
__setModuleDefault(result, mod);
32+
return result;
33+
};
34+
})();
35+
var __importDefault = (this && this.__importDefault) || function (mod) {
36+
return (mod && mod.__esModule) ? mod : { "default": mod };
37+
};
38+
Object.defineProperty(exports, "__esModule", { value: true });
39+
exports.CliInstaller = exports.cliUrlBuilder = exports.archMap = void 0;
40+
const os_1 = __importDefault(require("os"));
41+
const core = __importStar(require("@actions/core"));
42+
const tc = __importStar(require("@actions/tool-cache"));
443
// maps OS architecture names to 1Password CLI installer architecture names
5-
export const archMap = {
6-
ia32: "386",
7-
x64: "amd64",
8-
arm: "arm",
9-
arm64: "arm64",
44+
exports.archMap = {
45+
ia32: "386",
46+
x64: "amd64",
47+
arm: "arm",
48+
arm64: "arm64",
1049
};
1150
// Builds the download URL for the 1Password CLI based on the platform and version.
12-
export const cliUrlBuilder = {
13-
linux: (version, arch) =>
14-
`https://cache.agilebits.com/dist/1P/op2/pkg/${version}/op_linux_${arch}_${version}.zip`,
15-
darwin: (version) =>
16-
`https://cache.agilebits.com/dist/1P/op2/pkg/${version}/op_apple_universal_${version}.pkg`,
17-
win32: (version, arch) =>
18-
`https://cache.agilebits.com/dist/1P/op2/pkg/${version}/op_windows_${arch}_${version}.zip`,
51+
exports.cliUrlBuilder = {
52+
linux: (version, arch) => `https://cache.agilebits.com/dist/1P/op2/pkg/${version}/op_linux_${arch}_${version}.zip`,
53+
darwin: (version) => `https://cache.agilebits.com/dist/1P/op2/pkg/${version}/op_apple_universal_${version}.pkg`,
54+
win32: (version, arch) => `https://cache.agilebits.com/dist/1P/op2/pkg/${version}/op_windows_${arch}_${version}.zip`,
1955
};
20-
export class CliInstaller {
21-
version;
22-
arch;
23-
constructor(version) {
24-
this.version = version;
25-
this.arch = this.getArch();
26-
}
27-
async install(url) {
28-
console.info(`Downloading 1Password CLI from: ${url}`);
29-
const downloadPath = await tc.downloadTool(url);
30-
console.info("Installing 1Password CLI");
31-
const extractedPath = await tc.extractZip(downloadPath);
32-
core.addPath(extractedPath);
33-
core.info("1Password CLI installed");
34-
}
35-
getArch() {
36-
const arch = archMap[os.arch()];
37-
if (!arch) {
38-
throw new Error("Unsupported architecture");
39-
}
40-
return arch;
41-
}
56+
class CliInstaller {
57+
constructor(version) {
58+
this.version = version;
59+
this.arch = this.getArch();
60+
}
61+
async install(url) {
62+
console.info(`Downloading 1Password CLI from: ${url}`);
63+
const downloadPath = await tc.downloadTool(url);
64+
console.info("Installing 1Password CLI");
65+
const extractedPath = await tc.extractZip(downloadPath);
66+
core.addPath(extractedPath);
67+
core.info("1Password CLI installed");
68+
}
69+
getArch() {
70+
const arch = exports.archMap[os_1.default.arch()];
71+
if (!arch) {
72+
throw new Error("Unsupported architecture");
73+
}
74+
return arch;
75+
}
4276
}
77+
exports.CliInstaller = CliInstaller;

dist-lib/cli-installer/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export { newCliInstaller } from "./installer";
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.newCliInstaller = void 0;
4+
var installer_1 = require("./installer");
5+
Object.defineProperty(exports, "newCliInstaller", { enumerable: true, get: function () { return installer_1.newCliInstaller; } });
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export interface Installer {
2-
installCli(): Promise<void>;
2+
installCli(): Promise<void>;
33
}
44
export declare const newCliInstaller: (version: string) => Installer;
Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
import os from "os";
2-
import { LinuxInstaller } from "./linux";
3-
import { MacOsInstaller } from "./macos";
4-
import { WindowsInstaller } from "./windows";
5-
export const newCliInstaller = (version) => {
6-
const platform = os.platform();
7-
switch (platform) {
8-
case "linux":
9-
return new LinuxInstaller(version);
10-
case "darwin":
11-
return new MacOsInstaller(version);
12-
case "win32":
13-
return new WindowsInstaller(version);
14-
default:
15-
throw new Error(`Unsupported platform: ${platform}`);
16-
}
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
174
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.newCliInstaller = void 0;
7+
const os_1 = __importDefault(require("os"));
8+
const linux_1 = require("./linux");
9+
const macos_1 = require("./macos");
10+
const windows_1 = require("./windows");
11+
const newCliInstaller = (version) => {
12+
const platform = os_1.default.platform();
13+
switch (platform) {
14+
case "linux":
15+
return new linux_1.LinuxInstaller(version);
16+
case "darwin":
17+
return new macos_1.MacOsInstaller(version);
18+
case "win32":
19+
return new windows_1.WindowsInstaller(version);
20+
default:
21+
throw new Error(`Unsupported platform: ${platform}`);
22+
}
23+
};
24+
exports.newCliInstaller = newCliInstaller;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os from "os";
2+
import { newCliInstaller } from "./installer";
3+
import { LinuxInstaller } from "./linux";
4+
import { MacOsInstaller } from "./macos";
5+
import { WindowsInstaller } from "./windows";
6+
afterEach(() => {
7+
jest.restoreAllMocks();
8+
});
9+
describe("newCliInstaller", () => {
10+
const version = "1.0.0";
11+
afterEach(() => {
12+
jest.resetAllMocks();
13+
});
14+
it("should return LinuxInstaller for linux platform", () => {
15+
jest.spyOn(os, "platform").mockReturnValue("linux");
16+
const installer = newCliInstaller(version);
17+
expect(installer).toBeInstanceOf(LinuxInstaller);
18+
});
19+
it("should return MacOsInstaller for darwin platform", () => {
20+
jest.spyOn(os, "platform").mockReturnValue("darwin");
21+
const installer = newCliInstaller(version);
22+
expect(installer).toBeInstanceOf(MacOsInstaller);
23+
});
24+
it("should return WindowsInstaller for win32 platform", () => {
25+
jest.spyOn(os, "platform").mockReturnValue("win32");
26+
const installer = newCliInstaller(version);
27+
expect(installer).toBeInstanceOf(WindowsInstaller);
28+
});
29+
it("should throw error for unsupported platform", () => {
30+
jest.spyOn(os, "platform").mockReturnValue("sunos");
31+
expect(() => newCliInstaller(version)).toThrow("Unsupported platform: sunos");
32+
});
33+
});

dist-lib/cli-installer/linux.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CliInstaller } from "./cli-installer";
22
import type { Installer } from "./installer";
33
export declare class LinuxInstaller extends CliInstaller implements Installer {
4-
private readonly platform;
5-
constructor(version: string);
6-
installCli(): Promise<void>;
4+
private readonly platform;
5+
constructor(version: string);
6+
installCli(): Promise<void>;
77
}

dist-lib/cli-installer/linux.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import { CliInstaller, cliUrlBuilder } from "./cli-installer";
2-
export class LinuxInstaller extends CliInstaller {
3-
platform = "linux"; // Node.js platform identifier for Linux
4-
constructor(version) {
5-
super(version);
6-
}
7-
async installCli() {
8-
const urlBuilder = cliUrlBuilder[this.platform];
9-
await super.install(urlBuilder(this.version, this.arch));
10-
}
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.LinuxInstaller = void 0;
4+
const cli_installer_1 = require("./cli-installer");
5+
class LinuxInstaller extends cli_installer_1.CliInstaller {
6+
constructor(version) {
7+
super(version);
8+
this.platform = "linux"; // Node.js platform identifier for Linux
9+
}
10+
async installCli() {
11+
const urlBuilder = cli_installer_1.cliUrlBuilder[this.platform];
12+
await super.install(urlBuilder(this.version, this.arch));
13+
}
1114
}
15+
exports.LinuxInstaller = LinuxInstaller;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

0 commit comments

Comments
 (0)