nalet 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/index.js +22 -0
- package/install.js +89 -0
- package/package.json +37 -0
package/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execFileSync } = require("child_process");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const os = require("os");
|
|
6
|
+
|
|
7
|
+
const binaryName = os.platform() === "win32" ? "nalet.exe" : "nalet";
|
|
8
|
+
const binaryPath = path.join(__dirname, binaryName);
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
execFileSync(binaryPath, process.argv.slice(2), {
|
|
12
|
+
stdio: "inherit",
|
|
13
|
+
env: process.env,
|
|
14
|
+
});
|
|
15
|
+
} catch (err) {
|
|
16
|
+
if (err.status !== undefined) {
|
|
17
|
+
process.exit(err.status);
|
|
18
|
+
}
|
|
19
|
+
console.error(`Failed to run nalet: ${err.message}`);
|
|
20
|
+
console.error("Try reinstalling: npm install -g nalet");
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
package/install.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execSync } = require("child_process");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const https = require("https");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
|
|
9
|
+
const VERSION = require("./package.json").version;
|
|
10
|
+
const REPO = "MohmmedAshraf/nalet";
|
|
11
|
+
|
|
12
|
+
function getPlatform() {
|
|
13
|
+
const platform = os.platform();
|
|
14
|
+
const arch = os.arch();
|
|
15
|
+
|
|
16
|
+
const platforms = {
|
|
17
|
+
"darwin-arm64": "aarch64-apple-darwin",
|
|
18
|
+
"darwin-x64": "x86_64-apple-darwin",
|
|
19
|
+
"linux-x64": "x86_64-unknown-linux-gnu",
|
|
20
|
+
"linux-arm64": "aarch64-unknown-linux-gnu",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const key = `${platform}-${arch}`;
|
|
24
|
+
const target = platforms[key];
|
|
25
|
+
|
|
26
|
+
if (!target) {
|
|
27
|
+
console.error(`Unsupported platform: ${key}`);
|
|
28
|
+
console.error("Nalet currently supports: macOS (arm64, x64), Linux (x64, arm64)");
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return target;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getBinaryName() {
|
|
36
|
+
return os.platform() === "win32" ? "nalet.exe" : "nalet";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function download(url) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
https
|
|
42
|
+
.get(url, (res) => {
|
|
43
|
+
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
44
|
+
return download(res.headers.location).then(resolve).catch(reject);
|
|
45
|
+
}
|
|
46
|
+
if (res.statusCode !== 200) {
|
|
47
|
+
return reject(new Error(`Download failed: HTTP ${res.statusCode}`));
|
|
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 target = getPlatform();
|
|
60
|
+
const binaryName = getBinaryName();
|
|
61
|
+
const binaryPath = path.join(__dirname, binaryName);
|
|
62
|
+
|
|
63
|
+
// Skip if binary already exists
|
|
64
|
+
if (fs.existsSync(binaryPath)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/nalet-${target}.tar.gz`;
|
|
69
|
+
|
|
70
|
+
console.log(`Downloading nalet v${VERSION} for ${target}...`);
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const data = await download(url);
|
|
74
|
+
const tmpFile = path.join(os.tmpdir(), `nalet-${Date.now()}.tar.gz`);
|
|
75
|
+
fs.writeFileSync(tmpFile, data);
|
|
76
|
+
|
|
77
|
+
execSync(`tar xzf "${tmpFile}" -C "${__dirname}"`, { stdio: "pipe" });
|
|
78
|
+
fs.unlinkSync(tmpFile);
|
|
79
|
+
|
|
80
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
81
|
+
console.log("nalet installed successfully!");
|
|
82
|
+
} catch (err) {
|
|
83
|
+
console.error(`Failed to download nalet: ${err.message}`);
|
|
84
|
+
console.error("You can build from source: cargo install nalet");
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nalet",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A Valet-like dev environment manager for Node.js frameworks",
|
|
5
|
+
"author": "Mohamed Ashraf <cupo.ashraf@gmail.com>",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/MohmmedAshraf/nalet"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/MohmmedAshraf/nalet",
|
|
11
|
+
"bin": {
|
|
12
|
+
"nalet": "index.js"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"postinstall": "node install.js"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"dev",
|
|
19
|
+
"environment",
|
|
20
|
+
"valet",
|
|
21
|
+
"nextjs",
|
|
22
|
+
"nuxt",
|
|
23
|
+
"remix",
|
|
24
|
+
"astro",
|
|
25
|
+
"sveltekit",
|
|
26
|
+
"gatsby",
|
|
27
|
+
"eleventy",
|
|
28
|
+
"vite",
|
|
29
|
+
"proxy",
|
|
30
|
+
"dns",
|
|
31
|
+
"https"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18"
|
|
36
|
+
}
|
|
37
|
+
}
|