@flagify/cli 0.0.1
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 +104 -0
- package/package.json +29 -0
package/install.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const { execSync } = require("child_process");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const https = require("https");
|
|
5
|
+
const http = require("http");
|
|
6
|
+
const { createGunzip } = require("zlib");
|
|
7
|
+
const tar = require("tar");
|
|
8
|
+
|
|
9
|
+
const REPO = "flagifyhq/cli";
|
|
10
|
+
const BIN_DIR = path.join(__dirname, "bin");
|
|
11
|
+
const BIN_PATH = path.join(BIN_DIR, process.platform === "win32" ? "flagify.exe" : "flagify");
|
|
12
|
+
|
|
13
|
+
const PLATFORM_MAP = {
|
|
14
|
+
darwin: "darwin",
|
|
15
|
+
linux: "linux",
|
|
16
|
+
win32: "windows",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ARCH_MAP = {
|
|
20
|
+
x64: "amd64",
|
|
21
|
+
arm64: "arm64",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function getDownloadURL(version) {
|
|
25
|
+
const platform = PLATFORM_MAP[process.platform];
|
|
26
|
+
const arch = ARCH_MAP[process.arch];
|
|
27
|
+
|
|
28
|
+
if (!platform || !arch) {
|
|
29
|
+
throw new Error(`Unsupported platform: ${process.platform} ${process.arch}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const name = `flagify_${platform}_${arch}`;
|
|
33
|
+
const ext = process.platform === "win32" ? "zip" : "tar.gz";
|
|
34
|
+
|
|
35
|
+
return `https://github.com/${REPO}/releases/download/v${version}/${name}.${ext}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getVersion() {
|
|
39
|
+
const pkg = require("./package.json");
|
|
40
|
+
return pkg.version;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function fetch(url) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const client = url.startsWith("https") ? https : http;
|
|
46
|
+
client
|
|
47
|
+
.get(url, { headers: { "User-Agent": "flagify-cli-npm" } }, (res) => {
|
|
48
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
49
|
+
return fetch(res.headers.location).then(resolve).catch(reject);
|
|
50
|
+
}
|
|
51
|
+
if (res.statusCode !== 200) {
|
|
52
|
+
return reject(new Error(`Download failed: HTTP ${res.statusCode} from ${url}`));
|
|
53
|
+
}
|
|
54
|
+
resolve(res);
|
|
55
|
+
})
|
|
56
|
+
.on("error", reject);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function extractTarGz(stream, destDir) {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
stream
|
|
63
|
+
.pipe(createGunzip())
|
|
64
|
+
.pipe(tar.extract({ cwd: destDir, strip: 0 }))
|
|
65
|
+
.on("finish", resolve)
|
|
66
|
+
.on("error", reject);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function extractZip(stream, destDir) {
|
|
71
|
+
const AdmZip = require("adm-zip");
|
|
72
|
+
const chunks = [];
|
|
73
|
+
for await (const chunk of stream) chunks.push(chunk);
|
|
74
|
+
const buffer = Buffer.concat(chunks);
|
|
75
|
+
const zip = new AdmZip(buffer);
|
|
76
|
+
zip.extractAllTo(destDir, true);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function install() {
|
|
80
|
+
const version = getVersion();
|
|
81
|
+
const url = getDownloadURL(version);
|
|
82
|
+
|
|
83
|
+
console.log(`Downloading flagify v${version}...`);
|
|
84
|
+
|
|
85
|
+
if (!fs.existsSync(BIN_DIR)) {
|
|
86
|
+
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const stream = await fetch(url);
|
|
90
|
+
|
|
91
|
+
if (process.platform === "win32") {
|
|
92
|
+
await extractZip(stream, BIN_DIR);
|
|
93
|
+
} else {
|
|
94
|
+
await extractTarGz(stream, BIN_DIR);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fs.chmodSync(BIN_PATH, 0o755);
|
|
98
|
+
console.log(`Installed flagify v${version} to ${BIN_PATH}`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
install().catch((err) => {
|
|
102
|
+
console.error(`Failed to install flagify: ${err.message}`);
|
|
103
|
+
process.exit(1);
|
|
104
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flagify/cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Flagify CLI — manage feature flags from the terminal",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"bin": {
|
|
7
|
+
"flagify": "bin/flagify"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"postinstall": "node install.js"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/flagifyhq/cli"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://flagify.dev",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"feature-flags",
|
|
19
|
+
"flagify",
|
|
20
|
+
"cli"
|
|
21
|
+
],
|
|
22
|
+
"files": [
|
|
23
|
+
"bin/",
|
|
24
|
+
"install.js"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"tar": "^7.5.13"
|
|
28
|
+
}
|
|
29
|
+
}
|