@flagdash/cli 0.1.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/install.js +117 -0
- package/package.json +35 -0
package/install.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
const https = require("https");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const { execSync } = require("child_process");
|
|
5
|
+
|
|
6
|
+
const REPO = "flagdash/flagdash-cli";
|
|
7
|
+
const BINARY_NAME = "flagdash";
|
|
8
|
+
const BIN_DIR = path.join(__dirname, "bin");
|
|
9
|
+
|
|
10
|
+
const PLATFORM_MAP = {
|
|
11
|
+
"darwin-arm64": "flagdash-darwin-arm64.tar.gz",
|
|
12
|
+
"darwin-x64": "flagdash-darwin-amd64.tar.gz",
|
|
13
|
+
"linux-arm64": "flagdash-linux-arm64.tar.gz",
|
|
14
|
+
"linux-x64": "flagdash-linux-amd64.tar.gz",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function getPlatformKey() {
|
|
18
|
+
const platform = process.platform;
|
|
19
|
+
const arch = process.arch;
|
|
20
|
+
const key = `${platform}-${arch}`;
|
|
21
|
+
|
|
22
|
+
if (!PLATFORM_MAP[key]) {
|
|
23
|
+
console.error(`Unsupported platform: ${platform}/${arch}`);
|
|
24
|
+
console.error(`Supported platforms: ${Object.keys(PLATFORM_MAP).join(", ")}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return key;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function httpsGet(url) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
https.get(url, { headers: { "User-Agent": "flagdash-cli-npm" } }, (res) => {
|
|
34
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
35
|
+
httpsGet(res.headers.location).then(resolve, reject);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (res.statusCode !== 200) {
|
|
40
|
+
reject(new Error(`HTTP ${res.statusCode} for ${url}`));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const chunks = [];
|
|
45
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
46
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
47
|
+
res.on("error", reject);
|
|
48
|
+
}).on("error", reject);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function fetchLatestVersion() {
|
|
53
|
+
const url = `https://api.github.com/repos/${REPO}/releases/latest`;
|
|
54
|
+
const data = await httpsGet(url);
|
|
55
|
+
const release = JSON.parse(data.toString());
|
|
56
|
+
return release.tag_name;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function main() {
|
|
60
|
+
const platformKey = getPlatformKey();
|
|
61
|
+
const artifactName = PLATFORM_MAP[platformKey];
|
|
62
|
+
|
|
63
|
+
console.log(`Detected platform: ${platformKey}`);
|
|
64
|
+
|
|
65
|
+
let version;
|
|
66
|
+
try {
|
|
67
|
+
version = await fetchLatestVersion();
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.error(`Failed to fetch latest release: ${err.message}`);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
console.log(`Installing ${BINARY_NAME} ${version}...`);
|
|
74
|
+
|
|
75
|
+
const downloadUrl = `https://github.com/${REPO}/releases/download/${version}/${artifactName}`;
|
|
76
|
+
|
|
77
|
+
let archiveBuffer;
|
|
78
|
+
try {
|
|
79
|
+
console.log(`Downloading ${downloadUrl}...`);
|
|
80
|
+
archiveBuffer = await httpsGet(downloadUrl);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.error(`Failed to download binary: ${err.message}`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!fs.existsSync(BIN_DIR)) {
|
|
87
|
+
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const tmpFile = path.join(BIN_DIR, artifactName);
|
|
91
|
+
fs.writeFileSync(tmpFile, archiveBuffer);
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
if (artifactName.endsWith(".tar.gz")) {
|
|
95
|
+
execSync(`tar -xzf "${tmpFile}" -C "${BIN_DIR}"`, { stdio: "pipe" });
|
|
96
|
+
} else if (artifactName.endsWith(".zip")) {
|
|
97
|
+
execSync(`unzip -o "${tmpFile}" -d "${BIN_DIR}"`, { stdio: "pipe" });
|
|
98
|
+
}
|
|
99
|
+
} catch (err) {
|
|
100
|
+
console.error(`Failed to extract archive: ${err.message}`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fs.unlinkSync(tmpFile);
|
|
105
|
+
|
|
106
|
+
const binaryPath = path.join(BIN_DIR, BINARY_NAME);
|
|
107
|
+
if (!fs.existsSync(binaryPath)) {
|
|
108
|
+
console.error(`Binary not found after extraction: ${binaryPath}`);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
113
|
+
|
|
114
|
+
console.log(`${BINARY_NAME} ${version} installed successfully.`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flagdash/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "FlagDash CLI — Interactive terminal UI for feature flag management",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"bin": {
|
|
7
|
+
"flagdash": "./bin/flagdash"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"postinstall": "node install.js"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/flagdash/flagdash.git"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://flagdash.io",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"feature-flags",
|
|
19
|
+
"tui",
|
|
20
|
+
"cli",
|
|
21
|
+
"flagdash",
|
|
22
|
+
"feature-toggles"
|
|
23
|
+
],
|
|
24
|
+
"os": [
|
|
25
|
+
"darwin",
|
|
26
|
+
"linux"
|
|
27
|
+
],
|
|
28
|
+
"cpu": [
|
|
29
|
+
"x64",
|
|
30
|
+
"arm64"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=14"
|
|
34
|
+
}
|
|
35
|
+
}
|