@cloudops-tools/cli 0.1.1 → 0.1.3
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/bin/cloudops-tools.js +29 -11
- package/package.json +13 -6
- package/scripts/install-native.js +0 -151
package/bin/cloudops-tools.js
CHANGED
|
@@ -1,24 +1,42 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { spawnSync } from "node:child_process";
|
|
4
|
-
import {
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
5
|
import { dirname, resolve } from "node:path";
|
|
6
6
|
import process from "node:process";
|
|
7
|
-
import { fileURLToPath } from "node:url";
|
|
8
7
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const PLATFORMS = {
|
|
9
|
+
"darwin-arm64": { pkg: "@cloudops-tools/cli-darwin-arm64", bin: "cloudops-tools" },
|
|
10
|
+
"linux-x64": { pkg: "@cloudops-tools/cli-linux-x64", bin: "cloudops-tools" },
|
|
11
|
+
"win32-x64": { pkg: "@cloudops-tools/cli-win32-x64", bin: "cloudops-tools.exe" },
|
|
12
|
+
};
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const platformKey = `${process.platform}-${process.arch}`;
|
|
15
|
+
|
|
16
|
+
if (!(platformKey in PLATFORMS)) {
|
|
17
|
+
console.error(
|
|
18
|
+
`cloudops-tools: unsupported platform ${process.platform}/${process.arch}.\n` +
|
|
19
|
+
`Supported: ${Object.keys(PLATFORMS).join(", ")}`,
|
|
20
|
+
);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const platform = PLATFORMS[/** @type {keyof typeof PLATFORMS} */ (platformKey)];
|
|
25
|
+
|
|
26
|
+
let binaryPath;
|
|
27
|
+
try {
|
|
28
|
+
const require = createRequire(import.meta.url);
|
|
29
|
+
const pkgDir = dirname(require.resolve(`${platform.pkg}/package.json`));
|
|
30
|
+
binaryPath = resolve(pkgDir, platform.bin);
|
|
31
|
+
} catch {
|
|
32
|
+
console.error(
|
|
33
|
+
`cloudops-tools: could not find package "${platform.pkg}".\n` +
|
|
34
|
+
"Make sure optional dependencies are installed (do not use --no-optional).",
|
|
35
|
+
);
|
|
16
36
|
process.exit(1);
|
|
17
37
|
}
|
|
18
38
|
|
|
19
|
-
const result = spawnSync(binaryPath, process.argv.slice(2), {
|
|
20
|
-
stdio: "inherit",
|
|
21
|
-
});
|
|
39
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
|
|
22
40
|
|
|
23
41
|
if (result.error) {
|
|
24
42
|
console.error(result.error.message);
|
package/package.json
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudops-tools/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/jfalava/cloudops-tools.git",
|
|
7
|
+
"directory": "cli"
|
|
8
|
+
},
|
|
4
9
|
"bin": {
|
|
5
10
|
"cloudops-tools": "./bin/cloudops-tools.js"
|
|
6
11
|
},
|
|
7
12
|
"files": [
|
|
8
|
-
"bin"
|
|
9
|
-
"scripts"
|
|
13
|
+
"bin"
|
|
10
14
|
],
|
|
11
15
|
"type": "module",
|
|
12
16
|
"module": "./src/app.ts",
|
|
13
17
|
"scripts": {
|
|
14
18
|
"build:all": "bun run check && bun run build:windows-x64 && bun run build:linux-x64 && bun run build:macOS-arm",
|
|
15
19
|
"build:linux-x64": "bun build --compile --minify --sourcemap --bytecode --target=bun-linux-x64-modern --define BUILD_VERSION='\"'${BUILD_VERSION:-0.5}'\"' ./src/app.ts --outfile dist/cloudops-tools && cd dist && zip cloudops-tools-linux-x64.zip cloudops-tools",
|
|
16
|
-
"build:macOS-arm": "bun build --compile --minify --sourcemap --bytecode --target=bun-darwin-arm64 --define BUILD_VERSION='\"'${BUILD_VERSION:-0.5}'\"' ./src/app.ts --outfile dist/cloudops-tools
|
|
20
|
+
"build:macOS-arm": "bun build --compile --minify --sourcemap --bytecode --target=bun-darwin-arm64 --define BUILD_VERSION='\"'${BUILD_VERSION:-0.5}'\"' ./src/app.ts --outfile dist/cloudops-tools && cd dist && zip cloudops-tools-macos-arm.zip cloudops-tools",
|
|
17
21
|
"build:windows-x64": "bun build --compile --minify --sourcemap --bytecode --target=bun-windows-x64-modern --define BUILD_VERSION='\"'${BUILD_VERSION:-0.5}'\"' ./src/app.ts --outfile dist/cloudops-tools.exe && cd dist && zip cloudops-tools-windows-x64.zip cloudops-tools.exe",
|
|
18
22
|
"check": "tsgo --noEmit && oxlint --fix --type-aware",
|
|
19
23
|
"format": "oxfmt",
|
|
20
24
|
"lint": "oxlint --type-aware",
|
|
21
|
-
"postinstall": "node ./scripts/install-native.js",
|
|
22
25
|
"typecheck": "tsgo --noEmit"
|
|
23
26
|
},
|
|
24
|
-
"dependencies": {},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"@cloudops-tools/sdk": "workspace:*",
|
|
27
29
|
"@effect/cli": "catalog:effect",
|
|
@@ -41,5 +43,10 @@
|
|
|
41
43
|
"oxlint-tsgolint": "catalog:build",
|
|
42
44
|
"picocolors": "1.1.1",
|
|
43
45
|
"typescript": "catalog:build"
|
|
46
|
+
},
|
|
47
|
+
"optionalDependencies": {
|
|
48
|
+
"@cloudops-tools/cli-darwin-arm64": "0.1.3",
|
|
49
|
+
"@cloudops-tools/cli-linux-x64": "0.1.3",
|
|
50
|
+
"@cloudops-tools/cli-win32-x64": "0.1.3"
|
|
44
51
|
}
|
|
45
52
|
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/* eslint-disable no-console */
|
|
3
|
-
|
|
4
|
-
import { createWriteStream, existsSync, mkdirSync, readFileSync, rmSync, chmodSync } from "node:fs";
|
|
5
|
-
import { get } from "node:https";
|
|
6
|
-
import { dirname, resolve } from "node:path";
|
|
7
|
-
import process from "node:process";
|
|
8
|
-
import { pipeline } from "node:stream/promises";
|
|
9
|
-
import { fileURLToPath } from "node:url";
|
|
10
|
-
|
|
11
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
const cliDir = resolve(here, "..");
|
|
13
|
-
const repoRoot = resolve(cliDir, "..");
|
|
14
|
-
const pkgJsonPath = resolve(cliDir, "package.json");
|
|
15
|
-
const distDir = resolve(cliDir, "dist-native");
|
|
16
|
-
|
|
17
|
-
const shouldSkipInstall = () => {
|
|
18
|
-
if (process.env.CLOUDOPS_TOOLS_SKIP_NATIVE_INSTALL === "1") {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Do not auto-download when working from the monorepo checkout.
|
|
23
|
-
if (
|
|
24
|
-
existsSync(resolve(repoRoot, ".git")) &&
|
|
25
|
-
process.env.CLOUDOPS_TOOLS_FORCE_NATIVE_INSTALL !== "1"
|
|
26
|
-
) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return false;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const platformAssetName = () => {
|
|
34
|
-
if (process.platform === "linux" && process.arch === "x64") {
|
|
35
|
-
return "cloudops-tools-linux-x64";
|
|
36
|
-
}
|
|
37
|
-
if (process.platform === "win32" && process.arch === "x64") {
|
|
38
|
-
return "cloudops-tools-windows-x64.exe";
|
|
39
|
-
}
|
|
40
|
-
if (process.platform === "darwin" && process.arch === "arm64") {
|
|
41
|
-
return "cloudops-tools-macos-arm64";
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
throw new Error(
|
|
45
|
-
`Unsupported platform for prebuilt binary: ${process.platform}/${process.arch}. ` +
|
|
46
|
-
"Build from source or use a supported platform.",
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const readVersion = () => {
|
|
51
|
-
const packageJsonText = readFileSync(pkgJsonPath, "utf8");
|
|
52
|
-
const versionMatch = packageJsonText.match(/"version"\s*:\s*"([^"]+)"/);
|
|
53
|
-
const version = versionMatch?.[1];
|
|
54
|
-
if (!version) {
|
|
55
|
-
throw new Error("Failed to read package version from package.json");
|
|
56
|
-
}
|
|
57
|
-
return version;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const downloadToFile = (url, outputPath) =>
|
|
61
|
-
new Promise((resolvePromise, rejectPromise) => {
|
|
62
|
-
const request = get(
|
|
63
|
-
url,
|
|
64
|
-
{
|
|
65
|
-
headers: {
|
|
66
|
-
"User-Agent": "cloudops-tools-cli-installer",
|
|
67
|
-
Accept: "application/octet-stream",
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
async (response) => {
|
|
71
|
-
const statusCode = response.statusCode ?? 0;
|
|
72
|
-
|
|
73
|
-
if ([301, 302, 303, 307, 308].includes(statusCode)) {
|
|
74
|
-
const location = response.headers.location;
|
|
75
|
-
response.resume();
|
|
76
|
-
if (!location) {
|
|
77
|
-
rejectPromise(new Error(`Redirect without location for ${url}`));
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
await downloadToFile(location, outputPath);
|
|
82
|
-
resolvePromise();
|
|
83
|
-
} catch (error) {
|
|
84
|
-
rejectPromise(error);
|
|
85
|
-
}
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (statusCode < 200 || statusCode >= 300) {
|
|
90
|
-
response.resume();
|
|
91
|
-
rejectPromise(new Error(`HTTP ${statusCode} while downloading ${url}`));
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const file = createWriteStream(outputPath);
|
|
96
|
-
try {
|
|
97
|
-
await pipeline(response, file);
|
|
98
|
-
resolvePromise();
|
|
99
|
-
} catch (error) {
|
|
100
|
-
rejectPromise(error);
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
request.on("error", rejectPromise);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
const install = async () => {
|
|
109
|
-
if (shouldSkipInstall()) {
|
|
110
|
-
console.log("[cloudops-tools] Skipping native binary install in local workspace.");
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
mkdirSync(distDir, { recursive: true });
|
|
115
|
-
|
|
116
|
-
const version = readVersion();
|
|
117
|
-
const repo = process.env.CLOUDOPS_TOOLS_GITHUB_REPO ?? "jfalava/cloudops-tools-draft";
|
|
118
|
-
const assetName = platformAssetName();
|
|
119
|
-
const targetName = process.platform === "win32" ? "cloudops-tools.exe" : "cloudops-tools";
|
|
120
|
-
const targetPath = resolve(distDir, targetName);
|
|
121
|
-
|
|
122
|
-
const candidateTags = [`v${version}`, version];
|
|
123
|
-
let lastError;
|
|
124
|
-
|
|
125
|
-
for (const tag of candidateTags) {
|
|
126
|
-
const assetUrl = `https://github.com/${repo}/releases/download/${tag}/${assetName}`;
|
|
127
|
-
try {
|
|
128
|
-
rmSync(targetPath, { force: true });
|
|
129
|
-
await downloadToFile(assetUrl, targetPath);
|
|
130
|
-
|
|
131
|
-
if (process.platform !== "win32") {
|
|
132
|
-
chmodSync(targetPath, 0o755);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
console.log(`[cloudops-tools] Installed native binary from ${assetUrl}`);
|
|
136
|
-
return;
|
|
137
|
-
} catch (error) {
|
|
138
|
-
lastError = error;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
throw new Error(
|
|
143
|
-
`[cloudops-tools] Failed to download native binary for version ${version}. ` +
|
|
144
|
-
`Last error: ${String(lastError)}`,
|
|
145
|
-
);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
install().catch((error) => {
|
|
149
|
-
console.error(String(error));
|
|
150
|
-
process.exit(1);
|
|
151
|
-
});
|