@getnote/cli 1.0.0 → 1.0.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/package.json +1 -1
- package/scripts/postinstall.js +34 -0
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -43,6 +43,17 @@ async function main() {
|
|
|
43
43
|
const url = getDownloadURL(platform);
|
|
44
44
|
const tmpFile = path.join(os.tmpdir(), `getnote-download-${Date.now()}`);
|
|
45
45
|
|
|
46
|
+
// Skip download if binary already matches current version
|
|
47
|
+
if (fs.existsSync(binaryPath)) {
|
|
48
|
+
try {
|
|
49
|
+
const out = execSync(`"${binaryPath}" version 2>/dev/null || "${binaryPath}" --version 2>/dev/null`, { encoding: 'utf8' }).trim();
|
|
50
|
+
if (out.includes(VERSION)) {
|
|
51
|
+
console.log(`getnote v${VERSION} already installed, skipping download.`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
} catch (_) { /* binary exists but can't run (wrong arch etc.), re-download */ }
|
|
55
|
+
}
|
|
56
|
+
|
|
46
57
|
console.log(`Downloading getnote v${VERSION} for ${platform.platform}/${platform.arch}...`);
|
|
47
58
|
console.log(`URL: ${url}`);
|
|
48
59
|
|
|
@@ -63,6 +74,9 @@ async function main() {
|
|
|
63
74
|
|
|
64
75
|
fs.chmodSync(binaryPath, 0o755);
|
|
65
76
|
console.log(`getnote installed at ${binaryPath}`);
|
|
77
|
+
|
|
78
|
+
// Create symlink in npm global bin directory so `getnote` is on PATH
|
|
79
|
+
createSymlink(binaryPath, binaryName);
|
|
66
80
|
} catch (err) {
|
|
67
81
|
console.error('Failed to install getnote:', err.message);
|
|
68
82
|
process.exit(1);
|
|
@@ -72,3 +86,23 @@ async function main() {
|
|
|
72
86
|
}
|
|
73
87
|
|
|
74
88
|
main();
|
|
89
|
+
|
|
90
|
+
// Create a symlink in the npm global bin directory after download.
|
|
91
|
+
// npm only creates the symlink at install time when the file already exists;
|
|
92
|
+
// since we download the binary in postinstall, we need to do it ourselves.
|
|
93
|
+
function createSymlink(binaryPath, binaryName) {
|
|
94
|
+
try {
|
|
95
|
+
const npmPrefix = execSync('npm prefix -g', { encoding: 'utf8' }).trim();
|
|
96
|
+
const globalBin = path.join(npmPrefix, 'bin');
|
|
97
|
+
const symlinkPath = path.join(globalBin, binaryName);
|
|
98
|
+
|
|
99
|
+
if (fs.existsSync(globalBin)) {
|
|
100
|
+
try { fs.unlinkSync(symlinkPath); } catch (_) {}
|
|
101
|
+
fs.symlinkSync(binaryPath, symlinkPath);
|
|
102
|
+
console.log(`Symlink created: ${symlinkPath} -> ${binaryPath}`);
|
|
103
|
+
}
|
|
104
|
+
} catch (err) {
|
|
105
|
+
// Non-fatal: user can run the binary directly or add it to PATH manually
|
|
106
|
+
console.warn(`Could not create symlink (you may need to add ${path.dirname(binaryPath)} to PATH): ${err.message}`);
|
|
107
|
+
}
|
|
108
|
+
}
|