neovate-code-wrapped 1.0.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/.releaserc.mjs +28 -0
- package/LICENSE +21 -0
- package/README.md +130 -0
- package/bin/neovate-code-wrapped +79 -0
- package/mise.toml +6 -0
- package/package.json +49 -0
- package/scripts/postinstall.mjs +311 -0
package/.releaserc.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type {import('semantic-release').GlobalConfig}
|
|
3
|
+
*/
|
|
4
|
+
export default {
|
|
5
|
+
branches: [
|
|
6
|
+
"main",
|
|
7
|
+
{ name: "beta", prerelease: true },
|
|
8
|
+
{ name: "alpha", prerelease: true },
|
|
9
|
+
],
|
|
10
|
+
plugins: [
|
|
11
|
+
"@semantic-release/commit-analyzer",
|
|
12
|
+
"@semantic-release/release-notes-generator",
|
|
13
|
+
[
|
|
14
|
+
"@semantic-release/exec",
|
|
15
|
+
{
|
|
16
|
+
publishCmd: "bun run ./scripts/publish.ts ${nextRelease.version}",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
"@semantic-release/git",
|
|
21
|
+
{
|
|
22
|
+
assets: ["package.json"],
|
|
23
|
+
message: "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
"@semantic-release/github",
|
|
27
|
+
],
|
|
28
|
+
};
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Vlad Ivanov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# neovate-code-wrapped
|
|
4
|
+
|
|
5
|
+
**Your year in code, beautifully visualized.**
|
|
6
|
+
|
|
7
|
+
Generate a personalized "Spotify Wrapped"-style summary of your [Neovate](https://neovateai.dev/en) usage.
|
|
8
|
+
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://bun.sh)
|
|
11
|
+
|
|
12
|
+
<img src="./assets/images/demo-wrapped.png" alt="Neovate Wrapped Example" width="600" />
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
### Quick Start
|
|
21
|
+
|
|
22
|
+
Run directly without installing:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npx neovate-code-wrapped # or bunx, or yarn/pnpm dlx
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Global Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install -g neovate-code-wrapped # or bun/yarn/pnpm
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Then run anywhere:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
neovate-wrapped
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage Options
|
|
41
|
+
|
|
42
|
+
| Option | Description |
|
|
43
|
+
| --------------- | ------------------------------------ |
|
|
44
|
+
| `--year, -y` | Generate wrapped for a specific year |
|
|
45
|
+
| `--help, -h` | Show help message |
|
|
46
|
+
| `--version, -v` | Show version number |
|
|
47
|
+
|
|
48
|
+
## Features
|
|
49
|
+
|
|
50
|
+
- Sessions, messages, tokens, projects, and streaks
|
|
51
|
+
- GitHub-style activity heatmap
|
|
52
|
+
- Top models and providers breakdown
|
|
53
|
+
- Estimated cost tracking
|
|
54
|
+
- Shareable PNG image
|
|
55
|
+
- Inline image display (Ghostty, Kitty, iTerm2, WezTerm, Konsole)
|
|
56
|
+
- Auto-copy to clipboard
|
|
57
|
+
|
|
58
|
+
## Terminal Support
|
|
59
|
+
|
|
60
|
+
The wrapped image displays natively in terminals that support inline images:
|
|
61
|
+
|
|
62
|
+
| Terminal | Protocol | Status |
|
|
63
|
+
| ------------------------------------------ | -------------- | --------------------------- |
|
|
64
|
+
| [Ghostty](https://ghostty.org) | Kitty Graphics | ✅ Full support |
|
|
65
|
+
| [Kitty](https://sw.kovidgoyal.net/kitty/) | Kitty Graphics | ✅ Full support |
|
|
66
|
+
| [WezTerm](https://wezfurlong.org/wezterm/) | Kitty + iTerm2 | ✅ Full support |
|
|
67
|
+
| [iTerm2](https://iterm2.com) | iTerm2 Inline | ✅ Full support |
|
|
68
|
+
| [Konsole](https://konsole.kde.org) | Kitty Graphics | ✅ Full support |
|
|
69
|
+
| Other terminals | — | ⚠️ Image saved to file only |
|
|
70
|
+
|
|
71
|
+
## Output
|
|
72
|
+
|
|
73
|
+
The tool generates:
|
|
74
|
+
|
|
75
|
+
1. **Terminal Summary** — Quick stats overview in your terminal
|
|
76
|
+
2. **PNG Image** — A beautiful, shareable wrapped card saved to your home directory
|
|
77
|
+
3. **Clipboard** — Automatically copies the image to your clipboard
|
|
78
|
+
|
|
79
|
+
## Data Source
|
|
80
|
+
|
|
81
|
+
Neovate Wrapped reads data from your local Neovate installation:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
~/.neovate/projects/
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
No data is sent anywhere. Everything is processed locally.
|
|
88
|
+
|
|
89
|
+
## Building
|
|
90
|
+
|
|
91
|
+
### Development
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Run in development mode with hot reload
|
|
95
|
+
bun run dev
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Production Build
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Build for all platforms
|
|
102
|
+
bun run build
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Releasing
|
|
106
|
+
|
|
107
|
+
Releases are automated via [semantic-release](https://semantic-release.gitbook.io). Merging PRs with [conventional commits](https://www.conventionalcommits.org) to `main` triggers a release.
|
|
108
|
+
|
|
109
|
+
## Tech Stack
|
|
110
|
+
|
|
111
|
+
- **Runtime**: [Bun](https://bun.sh)
|
|
112
|
+
- **Image Generation**: [Satori](https://github.com/vercel/satori) + [Resvg](https://github.com/nicolo-ribaudo/resvg-js)
|
|
113
|
+
- **CLI UI**: [@clack/prompts](https://github.com/natemoo-re/clack)
|
|
114
|
+
- **Font**: IBM Plex Mono
|
|
115
|
+
|
|
116
|
+
## Contributing
|
|
117
|
+
|
|
118
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
<div align="center">
|
|
127
|
+
|
|
128
|
+
Made with ❤️ for the [Neovate](https://neovateai.dev/en) community
|
|
129
|
+
|
|
130
|
+
</div>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { platform as osPlatform, arch as osArch } from "node:os";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = dirname(__filename);
|
|
11
|
+
|
|
12
|
+
function run(target) {
|
|
13
|
+
const result = spawnSync(target, process.argv.slice(2), {
|
|
14
|
+
stdio: "inherit",
|
|
15
|
+
});
|
|
16
|
+
if (result.error) {
|
|
17
|
+
console.error(result.error.message);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
const code = typeof result.status === "number" ? result.status : 0;
|
|
21
|
+
process.exit(code);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const platformMap = {
|
|
25
|
+
darwin: "darwin",
|
|
26
|
+
linux: "linux",
|
|
27
|
+
win32: "windows",
|
|
28
|
+
};
|
|
29
|
+
const archMap = {
|
|
30
|
+
x64: "x64",
|
|
31
|
+
arm64: "arm64",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let platform = platformMap[osPlatform()];
|
|
35
|
+
if (!platform) {
|
|
36
|
+
platform = osPlatform();
|
|
37
|
+
}
|
|
38
|
+
let arch = archMap[osArch()];
|
|
39
|
+
if (!arch) {
|
|
40
|
+
arch = osArch();
|
|
41
|
+
}
|
|
42
|
+
const base = "neovate-wrapped-" + platform + "-" + arch;
|
|
43
|
+
const binary = platform === "windows" ? "neovate-wrapped.exe" : "neovate-wrapped";
|
|
44
|
+
|
|
45
|
+
function findBinary(startDir) {
|
|
46
|
+
let current = startDir;
|
|
47
|
+
for (;;) {
|
|
48
|
+
const modules = join(current, "node_modules");
|
|
49
|
+
if (fs.existsSync(modules)) {
|
|
50
|
+
const entries = fs.readdirSync(modules);
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
if (!entry.startsWith(base)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const candidate = join(modules, entry, "bin", binary);
|
|
56
|
+
if (fs.existsSync(candidate)) {
|
|
57
|
+
return candidate;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const parent = dirname(current);
|
|
62
|
+
if (parent === current) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
current = parent;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const resolved = findBinary(__dirname);
|
|
70
|
+
if (!resolved) {
|
|
71
|
+
console.error(
|
|
72
|
+
'It seems that your package manager failed to install the right version of neovate-wrapped CLI for your platform. You can try manually installing "' +
|
|
73
|
+
base +
|
|
74
|
+
'" package'
|
|
75
|
+
);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
run(resolved);
|
package/mise.toml
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "neovate-code-wrapped",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "iamdin",
|
|
6
|
+
"email": "iamdinq@gmail.com"
|
|
7
|
+
},
|
|
8
|
+
"description": "Generate a personalized Spotify Wrapped-style summary of your Neovate usage",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"neovate",
|
|
11
|
+
"wrapped",
|
|
12
|
+
"neovate-wrapped",
|
|
13
|
+
"neovate-code-wrapped"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/iamdin/neovate-code-wrapped.git"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"bin": {
|
|
22
|
+
"neovate-code-wrapped": "./bin/neovate-code-wrapped"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"start": "bun src/index.ts",
|
|
26
|
+
"dev": "bun run --watch src/index.ts",
|
|
27
|
+
"build": "tsgo --noEmit && bun run scripts/build.ts",
|
|
28
|
+
"publish": "bun run scripts/publish.ts",
|
|
29
|
+
"release": "semantic-release",
|
|
30
|
+
"clean": "rm -rf dist"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@clack/prompts": "^0.11.0",
|
|
34
|
+
"@resvg/resvg-wasm": "^2.6.2",
|
|
35
|
+
"react": "^19.2.3",
|
|
36
|
+
"satori": "^0.18.3",
|
|
37
|
+
"xdg-basedir": "^5.1.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@semantic-release/exec": "^7.1.0",
|
|
41
|
+
"@semantic-release/git": "^10.0.1",
|
|
42
|
+
"@types/bun": "latest",
|
|
43
|
+
"@types/react": "^19.2.0",
|
|
44
|
+
"@typescript/native-preview": "^7.0.0-dev.20251223.1",
|
|
45
|
+
"bunup": "^0.16.10",
|
|
46
|
+
"semantic-release": "^25.0.2",
|
|
47
|
+
"typescript": "^5.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Postinstall script for neovate-wrapped
|
|
5
|
+
*
|
|
6
|
+
* This script runs after npm install and symlinks the correct platform-specific
|
|
7
|
+
* binary to the bin directory. It auto-detects:
|
|
8
|
+
* - Platform (darwin, linux, windows)
|
|
9
|
+
* - Architecture (arm64, x64)
|
|
10
|
+
* - Libc (glibc, musl) for Linux
|
|
11
|
+
* - AVX2 support (baseline vs optimized) for x64
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import fs from "fs";
|
|
15
|
+
import path from "path";
|
|
16
|
+
import os from "os";
|
|
17
|
+
import { execSync, spawnSync } from "child_process";
|
|
18
|
+
import { fileURLToPath } from "url";
|
|
19
|
+
import { createRequire } from "module";
|
|
20
|
+
|
|
21
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
const VERSION_CHECK_TIMEOUT_MS = 5000;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Detect if the system uses musl libc (Alpine Linux, etc.)
|
|
27
|
+
*/
|
|
28
|
+
function detectMusl() {
|
|
29
|
+
if (os.platform() !== "linux") return false;
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// Method 1: Check ldd output
|
|
33
|
+
const lddOutput = execSync("ldd --version 2>&1 || true", { encoding: "utf8" });
|
|
34
|
+
if (lddOutput.toLowerCase().includes("musl")) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Method 2: Check for musl loader
|
|
39
|
+
const files = fs.readdirSync("/lib").filter((f) => f.startsWith("ld-musl-"));
|
|
40
|
+
if (files.length > 0) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
// Ignore errors
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Detect if the CPU supports AVX2 instructions
|
|
52
|
+
*/
|
|
53
|
+
function detectAVX2() {
|
|
54
|
+
if (os.arch() !== "x64") return true; // Only relevant for x64
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
if (os.platform() === "linux") {
|
|
58
|
+
const cpuinfo = fs.readFileSync("/proc/cpuinfo", "utf8");
|
|
59
|
+
return cpuinfo.toLowerCase().includes("avx2");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (os.platform() === "darwin") {
|
|
63
|
+
const output = execSync("sysctl -n machdep.cpu.features 2>/dev/null || true", {
|
|
64
|
+
encoding: "utf8",
|
|
65
|
+
});
|
|
66
|
+
return output.toLowerCase().includes("avx2");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (os.platform() === "win32") {
|
|
70
|
+
// Windows: Assume AVX2 support on modern systems
|
|
71
|
+
// A more robust check would require native code
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
} catch {
|
|
75
|
+
// If we can't detect, assume AVX2 is supported
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getPlatformInfo() {
|
|
82
|
+
let platform;
|
|
83
|
+
switch (os.platform()) {
|
|
84
|
+
case "darwin":
|
|
85
|
+
platform = "darwin";
|
|
86
|
+
break;
|
|
87
|
+
case "linux":
|
|
88
|
+
platform = "linux";
|
|
89
|
+
break;
|
|
90
|
+
case "win32":
|
|
91
|
+
platform = "windows";
|
|
92
|
+
break;
|
|
93
|
+
default:
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let arch;
|
|
98
|
+
switch (os.arch()) {
|
|
99
|
+
case "x64":
|
|
100
|
+
arch = "x64";
|
|
101
|
+
break;
|
|
102
|
+
case "arm64":
|
|
103
|
+
arch = "arm64";
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return { platform, arch };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function buildPackageName(platform, arch, { baseline, musl }) {
|
|
113
|
+
return [
|
|
114
|
+
"neovate-wrapped",
|
|
115
|
+
platform,
|
|
116
|
+
arch,
|
|
117
|
+
baseline ? "baseline" : undefined,
|
|
118
|
+
musl ? "musl" : undefined,
|
|
119
|
+
]
|
|
120
|
+
.filter(Boolean)
|
|
121
|
+
.join("-");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function getCandidatePackageNames() {
|
|
125
|
+
const info = getPlatformInfo();
|
|
126
|
+
if (!info) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const { platform, arch } = info;
|
|
131
|
+
const isLinux = platform === "linux";
|
|
132
|
+
const isX64 = arch === "x64";
|
|
133
|
+
const hasMusl = isLinux && detectMusl();
|
|
134
|
+
const hasAvx2 = isX64 ? detectAVX2() : true;
|
|
135
|
+
const candidates = [];
|
|
136
|
+
|
|
137
|
+
const addCandidate = (baseline, musl) => {
|
|
138
|
+
candidates.push(buildPackageName(platform, arch, { baseline, musl }));
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
if (hasMusl) {
|
|
142
|
+
if (isX64) {
|
|
143
|
+
if (hasAvx2) {
|
|
144
|
+
addCandidate(false, true);
|
|
145
|
+
addCandidate(true, true);
|
|
146
|
+
} else {
|
|
147
|
+
addCandidate(true, true);
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
addCandidate(false, true);
|
|
151
|
+
}
|
|
152
|
+
return { candidates, platform, arch, hasMusl, hasAvx2 };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (isX64) {
|
|
156
|
+
if (hasAvx2) {
|
|
157
|
+
addCandidate(false, false);
|
|
158
|
+
addCandidate(true, false);
|
|
159
|
+
} else {
|
|
160
|
+
addCandidate(true, false);
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
addCandidate(false, false);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return { candidates, platform, arch, hasMusl, hasAvx2 };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function testBinary(binaryPath) {
|
|
170
|
+
const result = spawnSync(binaryPath, ["--version"], {
|
|
171
|
+
stdio: "pipe",
|
|
172
|
+
timeout: VERSION_CHECK_TIMEOUT_MS,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
if (result.error) {
|
|
176
|
+
return { ok: false, reason: result.error.message };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (result.signal) {
|
|
180
|
+
return { ok: false, reason: `terminated with ${result.signal}` };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (typeof result.status === "number" && result.status !== 0) {
|
|
184
|
+
return { ok: false, reason: `exited with ${result.status}` };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return { ok: true };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Find the binary from the platform package
|
|
192
|
+
*/
|
|
193
|
+
function findBinary(packageName) {
|
|
194
|
+
const binaryName = os.platform() === "win32" ? "neovate-wrapped.exe" : "neovate-wrapped";
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
198
|
+
const packageDir = path.dirname(packageJsonPath);
|
|
199
|
+
const binaryPath = path.join(packageDir, "bin", binaryName);
|
|
200
|
+
|
|
201
|
+
if (fs.existsSync(binaryPath)) {
|
|
202
|
+
return { binaryPath, binaryName };
|
|
203
|
+
}
|
|
204
|
+
} catch {
|
|
205
|
+
// Package not found via require.resolve
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Fallback: try common paths
|
|
209
|
+
const fallbackPaths = [
|
|
210
|
+
path.join(__dirname, "..", packageName, "bin", binaryName),
|
|
211
|
+
path.join(__dirname, "node_modules", packageName, "bin", binaryName),
|
|
212
|
+
];
|
|
213
|
+
|
|
214
|
+
for (const p of fallbackPaths) {
|
|
215
|
+
if (fs.existsSync(p)) {
|
|
216
|
+
return { binaryPath: p, binaryName };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Prepare the bin directory
|
|
225
|
+
*/
|
|
226
|
+
function prepareBinDirectory(binaryName) {
|
|
227
|
+
const binDir = path.join(__dirname, "bin");
|
|
228
|
+
const targetPath = path.join(binDir, binaryName);
|
|
229
|
+
|
|
230
|
+
// Ensure bin directory exists
|
|
231
|
+
if (!fs.existsSync(binDir)) {
|
|
232
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Remove existing binary/symlink if it exists
|
|
236
|
+
if (fs.existsSync(targetPath)) {
|
|
237
|
+
fs.unlinkSync(targetPath);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return { binDir, targetPath };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Create symlink (or copy on Windows)
|
|
245
|
+
*/
|
|
246
|
+
function linkBinary(sourcePath, binaryName) {
|
|
247
|
+
const { targetPath } = prepareBinDirectory(binaryName);
|
|
248
|
+
|
|
249
|
+
if (os.platform() === "win32") {
|
|
250
|
+
// Windows: copy instead of symlink (symlinks require admin)
|
|
251
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
252
|
+
} else {
|
|
253
|
+
fs.symlinkSync(sourcePath, targetPath);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Verify the file exists
|
|
257
|
+
if (!fs.existsSync(targetPath)) {
|
|
258
|
+
throw new Error(`Failed to create binary at ${targetPath}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async function main() {
|
|
263
|
+
try {
|
|
264
|
+
const selection = getCandidatePackageNames();
|
|
265
|
+
|
|
266
|
+
if (!selection) {
|
|
267
|
+
console.error(`neovate-wrapped: Unsupported platform: ${os.platform()}-${os.arch()}`);
|
|
268
|
+
console.error("Please download the binary manually from:");
|
|
269
|
+
console.error("https://github.com/moddi3/neovate-code-wrapped/releases");
|
|
270
|
+
process.exit(0); // Exit gracefully
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const { candidates, platform, arch, hasMusl, hasAvx2 } = selection;
|
|
274
|
+
const platformLabel = `${platform}-${arch}${hasMusl ? " (musl)" : ""}`;
|
|
275
|
+
const featureLabel = arch === "x64" ? (hasAvx2 ? "avx2" : "baseline") : "default";
|
|
276
|
+
console.log(`neovate-wrapped: Selecting binary for ${platformLabel} (${featureLabel})`);
|
|
277
|
+
|
|
278
|
+
let lastFailure = null;
|
|
279
|
+
for (const packageName of candidates) {
|
|
280
|
+
const result = findBinary(packageName);
|
|
281
|
+
if (!result) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const check = testBinary(result.binaryPath);
|
|
286
|
+
if (!check.ok) {
|
|
287
|
+
lastFailure = `${packageName} ${check.reason}`;
|
|
288
|
+
console.log(`neovate-wrapped: ${packageName} failed (${check.reason}), trying fallback`);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
linkBinary(result.binaryPath, result.binaryName);
|
|
293
|
+
console.log(`neovate-wrapped: Linked ${packageName}`);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
console.error("neovate-wrapped: Could not find a working binary for this platform.");
|
|
298
|
+
if (lastFailure) {
|
|
299
|
+
console.error(`Last error: ${lastFailure}`);
|
|
300
|
+
}
|
|
301
|
+
console.error("The optional dependency may have failed to install.");
|
|
302
|
+
console.error("Please download the binary manually from:");
|
|
303
|
+
console.error("https://github.com/moddi3/neovate-code-wrapped/releases");
|
|
304
|
+
process.exit(0);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
console.error("neovate-wrapped: Postinstall error:", error.message);
|
|
307
|
+
process.exit(0); // Exit gracefully to not break npm install
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
main();
|