@prevsh/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/bin/prev +17 -0
- package/install.js +83 -0
- package/package.json +32 -0
package/bin/prev
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execFileSync } = require("child_process");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
7
|
+
const binary = path.join(__dirname, `prev${ext}`);
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
execFileSync(binary, process.argv.slice(2), { stdio: "inherit" });
|
|
11
|
+
} catch (err) {
|
|
12
|
+
if (err.status !== undefined) {
|
|
13
|
+
process.exit(err.status);
|
|
14
|
+
}
|
|
15
|
+
console.error(`Failed to run prev: ${err.message}`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
package/install.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
|
|
8
|
+
const REPO = "pepperpark/apt";
|
|
9
|
+
const BINARY_DIR = path.join(__dirname, "bin");
|
|
10
|
+
|
|
11
|
+
const PLATFORM_MAP = {
|
|
12
|
+
darwin: "darwin",
|
|
13
|
+
linux: "linux",
|
|
14
|
+
win32: "windows",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const ARCH_MAP = {
|
|
18
|
+
x64: "amd64",
|
|
19
|
+
arm64: "arm64",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function getBinaryName() {
|
|
23
|
+
const platform = PLATFORM_MAP[process.platform];
|
|
24
|
+
const arch = ARCH_MAP[process.arch];
|
|
25
|
+
|
|
26
|
+
if (!platform || !arch) {
|
|
27
|
+
console.error(`Unsupported platform: ${process.platform}/${process.arch}`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const name = `prev-${platform}-${arch}`;
|
|
32
|
+
return process.platform === "win32" ? `${name}.exe` : name;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getVersion() {
|
|
36
|
+
const pkg = JSON.parse(
|
|
37
|
+
fs.readFileSync(path.join(__dirname, "package.json"), "utf8")
|
|
38
|
+
);
|
|
39
|
+
return `v${pkg.version}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function download(url) {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
https
|
|
45
|
+
.get(url, (res) => {
|
|
46
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
47
|
+
return download(res.headers.location).then(resolve).catch(reject);
|
|
48
|
+
}
|
|
49
|
+
if (res.statusCode !== 200) {
|
|
50
|
+
return reject(new Error(`Download failed: HTTP ${res.statusCode}`));
|
|
51
|
+
}
|
|
52
|
+
const chunks = [];
|
|
53
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
54
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
55
|
+
res.on("error", reject);
|
|
56
|
+
})
|
|
57
|
+
.on("error", reject);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function main() {
|
|
62
|
+
const binaryName = getBinaryName();
|
|
63
|
+
const version = getVersion();
|
|
64
|
+
const url = `https://github.com/${REPO}/releases/download/${version}/${binaryName}`;
|
|
65
|
+
|
|
66
|
+
const destName = process.platform === "win32" ? "prev.exe" : "prev";
|
|
67
|
+
const dest = path.join(BINARY_DIR, destName);
|
|
68
|
+
|
|
69
|
+
console.log(`Downloading prev ${version} for ${process.platform}/${process.arch}...`);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const data = await download(url);
|
|
73
|
+
fs.mkdirSync(BINARY_DIR, { recursive: true });
|
|
74
|
+
fs.writeFileSync(dest, data);
|
|
75
|
+
fs.chmodSync(dest, 0o755);
|
|
76
|
+
console.log(`Installed prev to ${dest}`);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
console.error(`Failed to download prev: ${err.message}`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prevsh/cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Prev CLI - Preview environments for web projects",
|
|
5
|
+
"homepage": "https://prev.sh",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/pepperpark/apt"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"bin": {
|
|
12
|
+
"prev": "bin/prev"
|
|
13
|
+
},
|
|
14
|
+
"os": [
|
|
15
|
+
"darwin",
|
|
16
|
+
"linux",
|
|
17
|
+
"win32"
|
|
18
|
+
],
|
|
19
|
+
"cpu": [
|
|
20
|
+
"x64",
|
|
21
|
+
"arm64"
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"prev",
|
|
25
|
+
"preview",
|
|
26
|
+
"deploy",
|
|
27
|
+
"cli"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"postinstall": "node install.js"
|
|
31
|
+
}
|
|
32
|
+
}
|