electron-cli 0.3.0-alpha.0 → 0.3.0-alpha.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/Cargo.lock +1 -1
- package/Cargo.toml +2 -2
- package/README.md +7 -1
- package/bin/electron-cli.js +6 -3
- package/package.json +7 -5
- package/scripts/install.js +101 -0
package/Cargo.lock
CHANGED
package/Cargo.toml
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "electron-cli"
|
|
3
|
-
version = "0.3.0-alpha.
|
|
3
|
+
version = "0.3.0-alpha.1"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
description = "Experimental Rust CLI for Electron project diagnostics and workflow automation"
|
|
6
6
|
license = "MIT"
|
|
7
|
-
repository = "https://github.com/
|
|
7
|
+
repository = "https://github.com/Ikana/electron-cli"
|
|
8
8
|
|
|
9
9
|
[dependencies]
|
|
10
10
|
anyhow = "1.0"
|
package/README.md
CHANGED
|
@@ -32,13 +32,19 @@ The planned workflow commands may start by wrapping Electron Forge or other esta
|
|
|
32
32
|
|
|
33
33
|
## Install
|
|
34
34
|
|
|
35
|
-
During the experimental phase, the npm package
|
|
35
|
+
During the experimental phase, the npm package downloads a prebuilt binary from GitHub Releases when one is available. If a prebuilt binary is not available for your platform, it falls back to running from Rust source.
|
|
36
36
|
|
|
37
37
|
```sh
|
|
38
38
|
npm install -g electron-cli
|
|
39
39
|
electron-cli doctor
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
To skip binary download and use the Cargo fallback:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
ELECTRON_CLI_SKIP_DOWNLOAD=1 npm install -g electron-cli@alpha
|
|
46
|
+
```
|
|
47
|
+
|
|
42
48
|
For local development:
|
|
43
49
|
|
|
44
50
|
```sh
|
package/bin/electron-cli.js
CHANGED
|
@@ -7,11 +7,14 @@ const path = require("node:path");
|
|
|
7
7
|
const root = path.resolve(__dirname, "..");
|
|
8
8
|
const exe = process.platform === "win32" ? "electron-cli.exe" : "electron-cli";
|
|
9
9
|
const args = process.argv.slice(2);
|
|
10
|
+
const envBinary = process.env.ELECTRON_CLI_BINARY;
|
|
10
11
|
|
|
11
12
|
const candidates = [
|
|
13
|
+
envBinary,
|
|
14
|
+
path.join(root, "bin", "downloaded", exe),
|
|
12
15
|
path.join(root, "target", "release", exe),
|
|
13
16
|
path.join(root, "target", "debug", exe),
|
|
14
|
-
];
|
|
17
|
+
].filter(Boolean);
|
|
15
18
|
|
|
16
19
|
const binary = candidates.find((candidate) => fs.existsSync(candidate));
|
|
17
20
|
|
|
@@ -28,8 +31,8 @@ if (!fs.existsSync(manifest)) {
|
|
|
28
31
|
process.exit(1);
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
console.error("electron-cli
|
|
32
|
-
console.error("Building/running through
|
|
34
|
+
console.error("electron-cli could not find a prebuilt binary for this install.");
|
|
35
|
+
console.error("Building/running through Cargo fallback; install Rust from https://rustup.rs if this fails.");
|
|
33
36
|
|
|
34
37
|
exitWith(
|
|
35
38
|
spawnSync(cargo, ["run", "--quiet", "--manifest-path", manifest, "--", ...args], {
|
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-cli",
|
|
3
|
-
"version": "0.3.0-alpha.
|
|
3
|
+
"version": "0.3.0-alpha.1",
|
|
4
4
|
"description": "Experimental Rust CLI for Electron project diagnostics and workflow automation",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/
|
|
8
|
+
"url": "git+https://github.com/Ikana/electron-cli.git"
|
|
9
9
|
},
|
|
10
|
-
"homepage": "https://github.com/
|
|
10
|
+
"homepage": "https://github.com/Ikana/electron-cli#readme",
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/Ikana/electron-cli/issues"
|
|
13
13
|
},
|
|
14
14
|
"bin": {
|
|
15
15
|
"electron-cli": "bin/electron-cli.js"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
|
-
"bin",
|
|
18
|
+
"bin/electron-cli.js",
|
|
19
|
+
"scripts",
|
|
19
20
|
"src",
|
|
20
21
|
"tests",
|
|
21
22
|
"Cargo.toml",
|
|
@@ -30,6 +31,7 @@
|
|
|
30
31
|
"format": "cargo fmt",
|
|
31
32
|
"lint": "cargo fmt --check && cargo clippy --all-targets -- -D warnings",
|
|
32
33
|
"test": "cargo test",
|
|
34
|
+
"postinstall": "node scripts/install.js",
|
|
33
35
|
"prepack": "cargo build --release"
|
|
34
36
|
},
|
|
35
37
|
"engines": {
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const https = require("node:https");
|
|
5
|
+
const os = require("node:os");
|
|
6
|
+
const path = require("node:path");
|
|
7
|
+
const { spawnSync } = require("node:child_process");
|
|
8
|
+
|
|
9
|
+
const root = path.resolve(__dirname, "..");
|
|
10
|
+
const packageJson = require(path.join(root, "package.json"));
|
|
11
|
+
const version = packageJson.version;
|
|
12
|
+
const installDir = path.join(root, "bin", "downloaded");
|
|
13
|
+
const exe = process.platform === "win32" ? "electron-cli.exe" : "electron-cli";
|
|
14
|
+
const destination = path.join(installDir, exe);
|
|
15
|
+
const target = resolveTarget();
|
|
16
|
+
|
|
17
|
+
if (process.env.ELECTRON_CLI_SKIP_DOWNLOAD === "1") {
|
|
18
|
+
process.exit(0);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!target) {
|
|
22
|
+
warn(`No prebuilt binary is available for ${process.platform}/${process.arch}; Cargo fallback remains available.`);
|
|
23
|
+
process.exit(0);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const assetName = `electron-cli-v${version}-${target}${process.platform === "win32" ? ".exe" : ""}`;
|
|
27
|
+
const baseUrl = process.env.ELECTRON_CLI_DOWNLOAD_BASE_URL || "https://github.com/Ikana/electron-cli/releases/download";
|
|
28
|
+
const url = `${baseUrl}/v${version}/${assetName}`;
|
|
29
|
+
const tempFile = path.join(os.tmpdir(), `${assetName}.${process.pid}.tmp`);
|
|
30
|
+
|
|
31
|
+
main().catch((error) => {
|
|
32
|
+
warn(`Could not install prebuilt binary: ${error.message}`);
|
|
33
|
+
|
|
34
|
+
if (process.env.ELECTRON_CLI_STRICT_INSTALL === "1") {
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
warn("Install completed with Cargo fallback enabled.");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
async function main() {
|
|
42
|
+
fs.mkdirSync(installDir, { recursive: true });
|
|
43
|
+
|
|
44
|
+
await download(url, tempFile);
|
|
45
|
+
fs.renameSync(tempFile, destination);
|
|
46
|
+
|
|
47
|
+
if (process.platform !== "win32") {
|
|
48
|
+
fs.chmodSync(destination, 0o755);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const result = spawnSync(destination, ["--version"], { encoding: "utf8" });
|
|
52
|
+
if (result.error || result.status !== 0) {
|
|
53
|
+
fs.rmSync(destination, { force: true });
|
|
54
|
+
throw new Error(result.error ? result.error.message : result.stderr.trim() || "downloaded binary failed verification");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
console.error(`electron-cli installed prebuilt binary ${assetName}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function resolveTarget() {
|
|
61
|
+
const key = `${process.platform}-${process.arch}`;
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
"darwin-arm64": "darwin-arm64",
|
|
65
|
+
"darwin-x64": "darwin-x64",
|
|
66
|
+
"linux-x64": "linux-x64",
|
|
67
|
+
"win32-x64": "win32-x64",
|
|
68
|
+
}[key];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function download(url, destinationPath) {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
const request = https.get(url, (response) => {
|
|
74
|
+
if ([301, 302, 303, 307, 308].includes(response.statusCode)) {
|
|
75
|
+
response.resume();
|
|
76
|
+
download(response.headers.location, destinationPath).then(resolve, reject);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (response.statusCode !== 200) {
|
|
81
|
+
response.resume();
|
|
82
|
+
reject(new Error(`download failed with HTTP ${response.statusCode}: ${url}`));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const file = fs.createWriteStream(destinationPath, { mode: 0o755 });
|
|
87
|
+
response.pipe(file);
|
|
88
|
+
file.on("finish", () => file.close(resolve));
|
|
89
|
+
file.on("error", reject);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
request.on("error", reject);
|
|
93
|
+
request.setTimeout(30_000, () => {
|
|
94
|
+
request.destroy(new Error("download timed out"));
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function warn(message) {
|
|
100
|
+
console.error(`electron-cli postinstall: ${message}`);
|
|
101
|
+
}
|