typeslayer 0.1.0 → 0.1.2
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 +1 -1
- package/bin/typeslayer.js +19 -6
- package/package.json +3 -2
- package/scripts/postinstall.js +111 -0
package/README.md
CHANGED
package/bin/typeslayer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { spawn } from "node:child_process";
|
|
3
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { arch, platform } from "node:os";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
@@ -45,11 +45,24 @@ try {
|
|
|
45
45
|
const binaryInfo = getBinaryInfo();
|
|
46
46
|
|
|
47
47
|
if (!existsSync(binaryInfo.path)) {
|
|
48
|
-
console.error(`\n
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
console.error(`\n⚠️ Binary not found for ${binaryInfo.platform}. Attempting download...`);
|
|
49
|
+
const postinstallPath = join(__dirname, "..", "scripts", "postinstall.js");
|
|
50
|
+
const res = spawnSync(process.execPath, [postinstallPath], {
|
|
51
|
+
stdio: "inherit",
|
|
52
|
+
env: process.env,
|
|
53
|
+
});
|
|
54
|
+
if (res.status !== 0) {
|
|
55
|
+
console.error("\n❌ Failed to download platform binary.");
|
|
56
|
+
}
|
|
57
|
+
if (!existsSync(binaryInfo.path)) {
|
|
58
|
+
console.error(
|
|
59
|
+
`\n❌ Binary still unavailable at ${binaryInfo.path}. Please check the release assets or your network.`,
|
|
60
|
+
);
|
|
61
|
+
console.error(
|
|
62
|
+
"You can manually download from: https://github.com/dimitropoulos/typeslayer/releases",
|
|
63
|
+
);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
53
66
|
}
|
|
54
67
|
|
|
55
68
|
const proc = spawn(binaryInfo.path, [], {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeslayer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Slay your TypeScript types",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"bin",
|
|
30
|
-
"
|
|
30
|
+
"scripts"
|
|
31
31
|
],
|
|
32
32
|
"os": [
|
|
33
33
|
"linux",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"packageManager": "pnpm@10.6.5",
|
|
46
46
|
"scripts": {
|
|
47
|
+
"postinstall": "node scripts/postinstall.js",
|
|
47
48
|
"dev": "vite",
|
|
48
49
|
"build": "tsc && vite build",
|
|
49
50
|
"preview": "vite preview",
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { chmodSync, createWriteStream, existsSync, mkdirSync } from "node:fs";
|
|
4
|
+
import { get } from "node:https";
|
|
5
|
+
import { arch, platform } from "node:os";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = dirname(__filename);
|
|
11
|
+
|
|
12
|
+
const PACKAGE_VERSION = process.env.npm_package_version;
|
|
13
|
+
|
|
14
|
+
const getBinaryInfo = () => {
|
|
15
|
+
const plat = platform();
|
|
16
|
+
const architecture = arch();
|
|
17
|
+
|
|
18
|
+
let platformDir, binaryName;
|
|
19
|
+
|
|
20
|
+
if (plat === "linux" && architecture === "x64") {
|
|
21
|
+
platformDir = "linux-x64";
|
|
22
|
+
binaryName = "typeslayer";
|
|
23
|
+
} else if (plat === "darwin" && architecture === "x64") {
|
|
24
|
+
platformDir = "darwin-x64";
|
|
25
|
+
binaryName = "typeslayer";
|
|
26
|
+
} else if (plat === "darwin" && architecture === "arm64") {
|
|
27
|
+
platformDir = "darwin-arm64";
|
|
28
|
+
binaryName = "typeslayer";
|
|
29
|
+
} else if (plat === "win32" && architecture === "x64") {
|
|
30
|
+
platformDir = "win32-x64";
|
|
31
|
+
binaryName = "typeslayer.exe";
|
|
32
|
+
} else {
|
|
33
|
+
console.warn(`⚠️ Platform ${plat}-${architecture} is not supported`);
|
|
34
|
+
process.exit(0); // Don't fail the install, just skip
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return { platformDir, binaryName };
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const downloadBinary = (url, destPath) => {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
console.log(`📦 Downloading binary from ${url}...`);
|
|
43
|
+
|
|
44
|
+
get(url, (response) => {
|
|
45
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
46
|
+
// Follow redirect
|
|
47
|
+
return downloadBinary(response.headers.location, destPath).then(
|
|
48
|
+
resolve,
|
|
49
|
+
reject,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (response.statusCode !== 200) {
|
|
54
|
+
reject(
|
|
55
|
+
new Error(
|
|
56
|
+
`Failed to download: ${response.statusCode} ${response.statusMessage}`,
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const fileStream = createWriteStream(destPath);
|
|
63
|
+
response.pipe(fileStream);
|
|
64
|
+
|
|
65
|
+
fileStream.on("finish", () => {
|
|
66
|
+
fileStream.close();
|
|
67
|
+
// Make executable on Unix-like systems
|
|
68
|
+
if (process.platform !== "win32") {
|
|
69
|
+
chmodSync(destPath, 0o755);
|
|
70
|
+
}
|
|
71
|
+
console.log("✅ Binary downloaded successfully");
|
|
72
|
+
resolve();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
fileStream.on("error", (err) => {
|
|
76
|
+
reject(err);
|
|
77
|
+
});
|
|
78
|
+
}).on("error", (err) => {
|
|
79
|
+
reject(err);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
(async () => {
|
|
85
|
+
try {
|
|
86
|
+
const { platformDir, binaryName } = getBinaryInfo();
|
|
87
|
+
const binariesDir = join(__dirname, "..", "binaries", platformDir);
|
|
88
|
+
const binaryPath = join(binariesDir, binaryName);
|
|
89
|
+
|
|
90
|
+
// Skip if binary already exists
|
|
91
|
+
if (existsSync(binaryPath)) {
|
|
92
|
+
console.log("✅ Binary already present, skipping download");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Create directory if it doesn't exist
|
|
97
|
+
mkdirSync(binariesDir, { recursive: true });
|
|
98
|
+
|
|
99
|
+
// Download from GitHub release
|
|
100
|
+
const releaseUrl = `https://github.com/dimitropoulos/typeslayer/releases/download/typeslayer-v${PACKAGE_VERSION}/${binaryName}`;
|
|
101
|
+
|
|
102
|
+
await downloadBinary(releaseUrl, binaryPath);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error("❌ Failed to download binary:", error.message);
|
|
105
|
+
console.error(
|
|
106
|
+
"You can manually download the binary from: https://github.com/dimitropoulos/typeslayer/releases",
|
|
107
|
+
);
|
|
108
|
+
// Don't fail the install, just warn
|
|
109
|
+
process.exit(0);
|
|
110
|
+
}
|
|
111
|
+
})();
|