typeslayer 0.1.0 → 0.1.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  <p align="center">
3
- <img src="./src/assets/typeslayer-nightmare.png">
3
+ <img src="src/assets/typeslayer-nightmare.png">
4
4
  </p>
5
5
 
6
6
  <p align="center">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typeslayer",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Slay your TypeScript types",
5
5
  "private": false,
6
6
  "type": "module",
@@ -27,7 +27,8 @@
27
27
  },
28
28
  "files": [
29
29
  "bin",
30
- "binaries"
30
+ "binaries",
31
+ "scripts"
31
32
  ],
32
33
  "os": [
33
34
  "linux",
@@ -44,6 +45,7 @@
44
45
  },
45
46
  "packageManager": "pnpm@10.6.5",
46
47
  "scripts": {
48
+ "postinstall": "node scripts/postinstall.js",
47
49
  "dev": "vite",
48
50
  "build": "tsc && vite build",
49
51
  "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
+ })();