turnout-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.
- package/README.md +12 -0
- package/install.js +68 -0
- package/package.json +24 -0
- package/run.js +12 -0
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# turnout-cli
|
|
2
|
+
|
|
3
|
+
npm distribution of [turnout](https://github.com/lacodda/turnout) - a developer's switchyard: point local apps at any backend stand, keep servers and secrets at hand, build and deploy from any directory.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm i -g turnout-cli
|
|
7
|
+
turnout setup
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
The package downloads the prebuilt binary for your platform (Windows x86_64, Linux x86_64, macOS arm64) from GitHub Releases on install. On other platforms use `cargo install turnout`.
|
|
11
|
+
|
|
12
|
+
Documentation: https://lacodda.github.io/turnout/
|
package/install.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Downloads the turnout binary matching this package version from GitHub Releases.
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const https = require("https");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { spawnSync } = require("child_process");
|
|
6
|
+
|
|
7
|
+
const { version } = require("./package.json");
|
|
8
|
+
const REPO = "lacodda/turnout";
|
|
9
|
+
const TAG = `v${version}`;
|
|
10
|
+
|
|
11
|
+
const TARGETS = {
|
|
12
|
+
"win32-x64": ["x86_64-pc-windows-msvc", "zip"],
|
|
13
|
+
"linux-x64": ["x86_64-unknown-linux-gnu", "tar.gz"],
|
|
14
|
+
"darwin-arm64": ["aarch64-apple-darwin", "tar.gz"],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const key = `${process.platform}-${process.arch}`;
|
|
18
|
+
const entry = TARGETS[key];
|
|
19
|
+
if (!entry) {
|
|
20
|
+
console.error(`turnout-cli: no prebuilt binary for ${key}; install with: cargo install turnout`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
const [target, ext] = entry;
|
|
24
|
+
const name = `turnout-${TAG}-${target}`;
|
|
25
|
+
const url = `https://github.com/${REPO}/releases/download/${TAG}/${name}.${ext}`;
|
|
26
|
+
const exe = process.platform === "win32" ? "turnout.exe" : "turnout";
|
|
27
|
+
const archive = path.join(__dirname, `archive.${ext}`);
|
|
28
|
+
|
|
29
|
+
function download(url, file, redirects, done) {
|
|
30
|
+
if (redirects > 5) return done(new Error("too many redirects"));
|
|
31
|
+
https
|
|
32
|
+
.get(url, { headers: { "user-agent": "turnout-cli" } }, (res) => {
|
|
33
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
34
|
+
res.resume();
|
|
35
|
+
return download(res.headers.location, file, redirects + 1, done);
|
|
36
|
+
}
|
|
37
|
+
if (res.statusCode !== 200) {
|
|
38
|
+
res.resume();
|
|
39
|
+
return done(new Error(`HTTP ${res.statusCode} for ${url}`));
|
|
40
|
+
}
|
|
41
|
+
const out = fs.createWriteStream(file);
|
|
42
|
+
res.pipe(out);
|
|
43
|
+
out.on("finish", () => out.close(done));
|
|
44
|
+
out.on("error", done);
|
|
45
|
+
})
|
|
46
|
+
.on("error", done);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log(`turnout-cli: downloading ${url}`);
|
|
50
|
+
download(url, archive, 0, (err) => {
|
|
51
|
+
if (err) {
|
|
52
|
+
console.error(`turnout-cli: download failed: ${err.message}`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
// bsdtar (shipped with Windows 10+, macOS and most Linux distros) reads both formats.
|
|
56
|
+
const result = spawnSync("tar", ["-xf", archive, "-C", __dirname], { stdio: "inherit" });
|
|
57
|
+
if (result.status !== 0) {
|
|
58
|
+
console.error("turnout-cli: cannot extract the archive (is `tar` available?)");
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
fs.renameSync(path.join(__dirname, name, exe), path.join(__dirname, exe));
|
|
62
|
+
fs.rmSync(path.join(__dirname, name), { recursive: true, force: true });
|
|
63
|
+
fs.rmSync(archive, { force: true });
|
|
64
|
+
if (process.platform !== "win32") {
|
|
65
|
+
fs.chmodSync(path.join(__dirname, exe), 0o755);
|
|
66
|
+
}
|
|
67
|
+
console.log(`turnout-cli: installed turnout ${TAG}`);
|
|
68
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "turnout-cli",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A developer's switchyard: point local apps at any backend stand, keep servers and secrets at hand, build and deploy from any directory",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Kirill Lakhtachev <lahtachev@gmail.com> (https://lacodda.com)",
|
|
7
|
+
"homepage": "https://lacodda.github.io/turnout/",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/lacodda/turnout.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": ["cli", "proxy", "gateway", "deploy", "dev-environment", "stands"],
|
|
13
|
+
"bin": {
|
|
14
|
+
"turnout": "run.js"
|
|
15
|
+
},
|
|
16
|
+
"files": ["install.js", "run.js"],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"postinstall": "node install.js"
|
|
19
|
+
},
|
|
20
|
+
"os": ["win32", "darwin", "linux"],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/run.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Thin launcher: forwards everything to the downloaded turnout binary.
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const { spawnSync } = require("child_process");
|
|
5
|
+
|
|
6
|
+
const exe = path.join(__dirname, process.platform === "win32" ? "turnout.exe" : "turnout");
|
|
7
|
+
if (!require("fs").existsSync(exe)) {
|
|
8
|
+
console.error("turnout-cli: binary missing - reinstall the package (npm i -g turnout-cli)");
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
const result = spawnSync(exe, process.argv.slice(2), { stdio: "inherit" });
|
|
12
|
+
process.exit(result.status === null ? 1 : result.status);
|