@osvaldoandrade/tikti-cli 0.2.4
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/LICENSE +22 -0
- package/README.md +19 -0
- package/bin/tikti-cli +24 -0
- package/package.json +30 -0
- package/scripts/postinstall.js +191 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Osvaldo Andrade
|
|
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.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @osvaldoandrade/tikti-cli
|
|
2
|
+
|
|
3
|
+
Tikti admin CLI distributed as a prebuilt Go binary downloaded from GitHub Releases during `npm install`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install -g @osvaldoandrade/tikti-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Upgrade
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install -g @osvaldoandrade/tikti-cli@latest
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Notes
|
|
18
|
+
|
|
19
|
+
- If the repository is private, you may need `GITHUB_TOKEN`/`GH_TOKEN` set so the postinstall binary download can authenticate.
|
package/bin/tikti-cli
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { spawnSync } = require('child_process');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
9
|
+
const binPath = path.join(__dirname, `tikti-cli-bin${ext}`);
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
fs.accessSync(binPath, fs.constants.X_OK);
|
|
13
|
+
} catch {
|
|
14
|
+
console.error('tikti-cli: binary is missing. Try reinstalling the package.');
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const res = spawnSync(binPath, process.argv.slice(2), { stdio: 'inherit' });
|
|
19
|
+
if (res.error) {
|
|
20
|
+
console.error(`tikti-cli: failed to run binary: ${res.error.message}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
process.exit(res.status == null ? 1 : res.status);
|
|
24
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@osvaldoandrade/tikti-cli",
|
|
3
|
+
"version": "0.2.4",
|
|
4
|
+
"description": "Tikti admin CLI (installs a prebuilt Go binary from GitHub Releases)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/osvaldoandrade/tikti.git",
|
|
9
|
+
"directory": "npm/tikti-cli"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/osvaldoandrade/tikti/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/osvaldoandrade/tikti#readme",
|
|
15
|
+
"bin": {
|
|
16
|
+
"tikti-cli": "bin/tikti-cli"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin/",
|
|
20
|
+
"scripts/",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"postinstall": "node scripts/postinstall.js"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const crypto = require('crypto');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const https = require('https');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
function log(msg) {
|
|
10
|
+
console.log(`[tikti-cli] ${msg}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function warn(msg) {
|
|
14
|
+
console.warn(`[tikti-cli] warning: ${msg}`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function fail(msg) {
|
|
18
|
+
console.error(`[tikti-cli] error: ${msg}`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getGoOS() {
|
|
23
|
+
switch (process.platform) {
|
|
24
|
+
case 'darwin':
|
|
25
|
+
return 'darwin';
|
|
26
|
+
case 'linux':
|
|
27
|
+
return 'linux';
|
|
28
|
+
case 'win32':
|
|
29
|
+
return 'windows';
|
|
30
|
+
default:
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getGoArch() {
|
|
36
|
+
switch (process.arch) {
|
|
37
|
+
case 'x64':
|
|
38
|
+
return 'amd64';
|
|
39
|
+
case 'arm64':
|
|
40
|
+
return 'arm64';
|
|
41
|
+
default:
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function authHeaders() {
|
|
47
|
+
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN || '';
|
|
48
|
+
const headers = {
|
|
49
|
+
'User-Agent': '@osvaldoandrade/tikti-cli postinstall',
|
|
50
|
+
Accept: '*/*',
|
|
51
|
+
};
|
|
52
|
+
if (token) {
|
|
53
|
+
headers.Authorization = `token ${token}`;
|
|
54
|
+
}
|
|
55
|
+
return headers;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function request(url, headers, redirectsLeft) {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const req = https.request(url, { headers }, (res) => {
|
|
61
|
+
const code = res.statusCode || 0;
|
|
62
|
+
const location = res.headers.location;
|
|
63
|
+
|
|
64
|
+
if (code >= 300 && code < 400 && location && redirectsLeft > 0) {
|
|
65
|
+
// GitHub release downloads redirect to a signed URL.
|
|
66
|
+
res.resume();
|
|
67
|
+
resolve(request(location, headers, redirectsLeft - 1));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (code < 200 || code >= 300) {
|
|
72
|
+
let body = '';
|
|
73
|
+
res.setEncoding('utf8');
|
|
74
|
+
res.on('data', (d) => {
|
|
75
|
+
body += d;
|
|
76
|
+
});
|
|
77
|
+
res.on('end', () => {
|
|
78
|
+
reject(new Error(`HTTP ${code} for ${url}${body ? `: ${body.slice(0, 200)}` : ''}`));
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
resolve(res);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
req.on('error', reject);
|
|
87
|
+
req.end();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function downloadText(url) {
|
|
92
|
+
const res = await request(url, authHeaders(), 5);
|
|
93
|
+
return await new Promise((resolve, reject) => {
|
|
94
|
+
let out = '';
|
|
95
|
+
res.setEncoding('utf8');
|
|
96
|
+
res.on('data', (d) => {
|
|
97
|
+
out += d;
|
|
98
|
+
});
|
|
99
|
+
res.on('end', () => resolve(out));
|
|
100
|
+
res.on('error', reject);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function parseExpectedSha256(sumText, assetName) {
|
|
105
|
+
const lines = sumText.split(/\r?\n/);
|
|
106
|
+
for (const line of lines) {
|
|
107
|
+
const trimmed = line.trim();
|
|
108
|
+
if (!trimmed) continue;
|
|
109
|
+
const parts = trimmed.split(/\s+/);
|
|
110
|
+
if (parts.length < 2) continue;
|
|
111
|
+
const sha = parts[0];
|
|
112
|
+
const file = parts[1].replace(/^dist\//, '');
|
|
113
|
+
if (file === assetName) {
|
|
114
|
+
return sha.toLowerCase();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function downloadFileWithSha256(url, outPath, expectedSha256) {
|
|
121
|
+
const res = await request(url, authHeaders(), 5);
|
|
122
|
+
|
|
123
|
+
await fs.promises.mkdir(path.dirname(outPath), { recursive: true });
|
|
124
|
+
const tmpPath = `${outPath}.tmp`;
|
|
125
|
+
|
|
126
|
+
const hash = crypto.createHash('sha256');
|
|
127
|
+
const ws = fs.createWriteStream(tmpPath, { mode: 0o755 });
|
|
128
|
+
|
|
129
|
+
await new Promise((resolve, reject) => {
|
|
130
|
+
res.on('data', (chunk) => hash.update(chunk));
|
|
131
|
+
res.pipe(ws);
|
|
132
|
+
res.on('error', reject);
|
|
133
|
+
ws.on('error', reject);
|
|
134
|
+
ws.on('finish', resolve);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const got = hash.digest('hex').toLowerCase();
|
|
138
|
+
if (expectedSha256 && got !== expectedSha256) {
|
|
139
|
+
await fs.promises.rm(tmpPath, { force: true });
|
|
140
|
+
throw new Error(`sha256 mismatch for ${path.basename(outPath)}: expected ${expectedSha256}, got ${got}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
await fs.promises.rename(tmpPath, outPath);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function main() {
|
|
147
|
+
const goos = getGoOS();
|
|
148
|
+
const goarch = getGoArch();
|
|
149
|
+
if (!goos) fail(`unsupported platform: ${process.platform}`);
|
|
150
|
+
if (!goarch) fail(`unsupported arch: ${process.arch}`);
|
|
151
|
+
|
|
152
|
+
const pkgPath = path.join(__dirname, '..', 'package.json');
|
|
153
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
154
|
+
const pkg = require(pkgPath);
|
|
155
|
+
const version = pkg.version;
|
|
156
|
+
|
|
157
|
+
if (!version || typeof version !== 'string') fail('missing package version');
|
|
158
|
+
|
|
159
|
+
const owner = process.env.TIKTI_GH_OWNER || 'osvaldoandrade';
|
|
160
|
+
const repo = process.env.TIKTI_GH_REPO || 'tikti';
|
|
161
|
+
const tag = `v${version}`;
|
|
162
|
+
|
|
163
|
+
const ext = goos === 'windows' ? '.exe' : '';
|
|
164
|
+
const assetName = `tikti-cli-${goos}-${goarch}${ext}`;
|
|
165
|
+
const base = `https://github.com/${owner}/${repo}/releases/download/${tag}`;
|
|
166
|
+
const checksumUrl = `${base}/SHA256SUMS.txt`;
|
|
167
|
+
const binUrl = `${base}/${assetName}`;
|
|
168
|
+
|
|
169
|
+
const outPath = path.join(__dirname, '..', 'bin', `tikti-cli-bin${ext}`);
|
|
170
|
+
log(`downloading ${assetName} (${tag})`);
|
|
171
|
+
|
|
172
|
+
let expected = null;
|
|
173
|
+
try {
|
|
174
|
+
const txt = await downloadText(checksumUrl);
|
|
175
|
+
expected = parseExpectedSha256(txt, assetName);
|
|
176
|
+
if (!expected) warn(`checksum entry not found for ${assetName}; continuing without verification`);
|
|
177
|
+
} catch (e) {
|
|
178
|
+
warn(`failed to download checksums (${e.message}); continuing without verification`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
await downloadFileWithSha256(binUrl, outPath, expected);
|
|
182
|
+
|
|
183
|
+
if (goos !== 'windows') {
|
|
184
|
+
await fs.promises.chmod(outPath, 0o755);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
log(`installed ${path.relative(process.cwd(), outPath)}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
main().catch((e) => fail(e.message));
|
|
191
|
+
|