@strscp/cli 0.2.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.
Files changed (3) hide show
  1. package/index.js +23 -0
  2. package/install.js +95 -0
  3. package/package.json +22 -0
package/index.js ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execFileSync } = require("child_process");
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+
7
+ const ext = process.platform === "win32" ? ".exe" : "";
8
+ const binary = path.join(__dirname, "bin", `starscope-cli${ext}`);
9
+
10
+ if (!fs.existsSync(binary)) {
11
+ console.error(
12
+ "starscope-cli binary not found. Try reinstalling: npm install -g @strscp/cli"
13
+ );
14
+ process.exit(1);
15
+ }
16
+
17
+ try {
18
+ const result = execFileSync(binary, process.argv.slice(2), {
19
+ stdio: "inherit",
20
+ });
21
+ } catch (err) {
22
+ process.exit(err.status || 1);
23
+ }
package/install.js ADDED
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+
3
+ const https = require("https");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const { execSync } = require("child_process");
7
+ const os = require("os");
8
+
9
+ const VERSION = require("./package.json").version;
10
+ const REPO = "strscp/cli";
11
+
12
+ const PLATFORM_MAP = {
13
+ darwin: "darwin",
14
+ linux: "linux",
15
+ win32: "windows",
16
+ };
17
+
18
+ const ARCH_MAP = {
19
+ x64: "amd64",
20
+ arm64: "arm64",
21
+ };
22
+
23
+ function getBinaryName() {
24
+ const platform = PLATFORM_MAP[process.platform];
25
+ const arch = ARCH_MAP[process.arch];
26
+
27
+ if (!platform || !arch) {
28
+ console.error(
29
+ `Unsupported platform: ${process.platform}-${process.arch}`
30
+ );
31
+ process.exit(1);
32
+ }
33
+
34
+ const ext = platform === "windows" ? "zip" : "tar.gz";
35
+ return `starscope-cli_${VERSION}_${platform}_${arch}.${ext}`;
36
+ }
37
+
38
+ function download(url) {
39
+ return new Promise((resolve, reject) => {
40
+ https
41
+ .get(url, (res) => {
42
+ if (res.statusCode === 302 || res.statusCode === 301) {
43
+ return download(res.headers.location).then(resolve).catch(reject);
44
+ }
45
+ if (res.statusCode !== 200) {
46
+ reject(new Error(`Download failed: HTTP ${res.statusCode}`));
47
+ return;
48
+ }
49
+ const chunks = [];
50
+ res.on("data", (chunk) => chunks.push(chunk));
51
+ res.on("end", () => resolve(Buffer.concat(chunks)));
52
+ res.on("error", reject);
53
+ })
54
+ .on("error", reject);
55
+ });
56
+ }
57
+
58
+ async function main() {
59
+ const binaryName = getBinaryName();
60
+ const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${binaryName}`;
61
+ const binDir = path.join(__dirname, "bin");
62
+
63
+ console.log(`Downloading starscope-cli v${VERSION}...`);
64
+
65
+ try {
66
+ const data = await download(url);
67
+ fs.mkdirSync(binDir, { recursive: true });
68
+
69
+ const archivePath = path.join(binDir, binaryName);
70
+ fs.writeFileSync(archivePath, data);
71
+
72
+ if (binaryName.endsWith(".tar.gz")) {
73
+ execSync(`tar -xzf "${archivePath}" -C "${binDir}"`, { stdio: "pipe" });
74
+ } else {
75
+ execSync(`unzip -o "${archivePath}" -d "${binDir}"`, { stdio: "pipe" });
76
+ }
77
+
78
+ fs.unlinkSync(archivePath);
79
+
80
+ const binary = path.join(
81
+ binDir,
82
+ process.platform === "win32" ? "starscope-cli.exe" : "starscope-cli"
83
+ );
84
+ if (process.platform !== "win32") {
85
+ fs.chmodSync(binary, 0o755);
86
+ }
87
+
88
+ console.log("starscope-cli installed successfully.");
89
+ } catch (err) {
90
+ console.error(`Failed to install starscope-cli: ${err.message}`);
91
+ process.exit(1);
92
+ }
93
+ }
94
+
95
+ main();
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@strscp/cli",
3
+ "version": "0.2.0",
4
+ "description": "CLI for the Starscope review analytics API",
5
+ "license": "MIT",
6
+ "bin": {
7
+ "starscope-cli": "./index.js"
8
+ },
9
+ "scripts": {
10
+ "postinstall": "node install.js"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/strscp/cli"
15
+ },
16
+ "keywords": [
17
+ "starscope",
18
+ "reviews",
19
+ "analytics",
20
+ "cli"
21
+ ]
22
+ }