@go-tapd/tapd 0.1.5
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 +21 -0
- package/README.md +13 -0
- package/bin/tapd.js +23 -0
- package/package.json +41 -0
- package/scripts/install.js +218 -0
- package/scripts/set-version.js +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 flc1125 (https://github.com/flc1125, https://flc.io)
|
|
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,13 @@
|
|
|
1
|
+
# TAPD CLI
|
|
2
|
+
|
|
3
|
+
This npm package installs the `tapd` command line client from the matching
|
|
4
|
+
GitHub Release binary.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm install -g @go-tapd/tapd
|
|
8
|
+
tapd --help
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The installer downloads the archive for the current operating system and CPU
|
|
12
|
+
architecture, verifies it with the release checksum, and exposes the `tapd`
|
|
13
|
+
binary through npm's global bin path.
|
package/bin/tapd.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawnSync } = require("node:child_process");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
|
|
6
|
+
const binaryName = process.platform === "win32" ? "tapd.exe" : "tapd";
|
|
7
|
+
const binaryPath = path.join(__dirname, "..", "vendor", binaryName);
|
|
8
|
+
|
|
9
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
if (result.error) {
|
|
14
|
+
console.error(`Failed to run tapd binary at ${binaryPath}: ${result.error.message}`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (result.signal) {
|
|
19
|
+
console.error(`tapd exited because of signal ${result.signal}`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
process.exit(result.status ?? 0);
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@go-tapd/tapd",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "TAPD command line client",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/go-tapd/cli",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/go-tapd/cli.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/go-tapd/cli/issues"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"tapd": "bin/tapd.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin/",
|
|
19
|
+
"scripts/",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"postinstall": "node scripts/install.js"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"os": [
|
|
30
|
+
"darwin",
|
|
31
|
+
"linux",
|
|
32
|
+
"win32"
|
|
33
|
+
],
|
|
34
|
+
"cpu": [
|
|
35
|
+
"x64",
|
|
36
|
+
"arm64"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const childProcess = require("node:child_process");
|
|
4
|
+
const crypto = require("node:crypto");
|
|
5
|
+
const fs = require("node:fs");
|
|
6
|
+
const https = require("node:https");
|
|
7
|
+
const os = require("node:os");
|
|
8
|
+
const path = require("node:path");
|
|
9
|
+
|
|
10
|
+
const packageJson = require("../package.json");
|
|
11
|
+
|
|
12
|
+
const repo = "go-tapd/cli";
|
|
13
|
+
const version = process.env.TAPD_VERSION || packageJson.version;
|
|
14
|
+
const tag = version.startsWith("v") ? version : `v${version}`;
|
|
15
|
+
|
|
16
|
+
const platformNames = {
|
|
17
|
+
darwin: "Darwin",
|
|
18
|
+
linux: "Linux",
|
|
19
|
+
win32: "Windows",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const archNames = {
|
|
23
|
+
x64: "x86_64",
|
|
24
|
+
arm64: "arm64",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function fail(message) {
|
|
28
|
+
console.error(`tapd npm install failed: ${message}`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function assetName() {
|
|
33
|
+
const platform = platformNames[process.platform];
|
|
34
|
+
const arch = archNames[process.arch];
|
|
35
|
+
|
|
36
|
+
if (!platform || !arch) {
|
|
37
|
+
fail(`unsupported platform ${process.platform}/${process.arch}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const extension = process.platform === "win32" ? "zip" : "tar.gz";
|
|
41
|
+
return `tapd_${version.replace(/^v/, "")}_${platform}_${arch}.${extension}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function request(url, redirects = 0) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
https
|
|
47
|
+
.get(
|
|
48
|
+
url,
|
|
49
|
+
{
|
|
50
|
+
headers: {
|
|
51
|
+
"User-Agent": "@go-tapd/tapd npm installer",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
(response) => {
|
|
55
|
+
const statusCode = response.statusCode || 0;
|
|
56
|
+
const location = response.headers.location;
|
|
57
|
+
|
|
58
|
+
if (statusCode >= 300 && statusCode < 400 && location) {
|
|
59
|
+
response.resume();
|
|
60
|
+
if (redirects > 5) {
|
|
61
|
+
reject(new Error(`too many redirects while downloading ${url}`));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
resolve(request(new URL(location, url).toString(), redirects + 1));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (statusCode < 200 || statusCode >= 300) {
|
|
69
|
+
response.resume();
|
|
70
|
+
reject(new Error(`download failed with HTTP ${statusCode}: ${url}`));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
resolve(response);
|
|
75
|
+
},
|
|
76
|
+
)
|
|
77
|
+
.on("error", reject);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function downloadText(url) {
|
|
82
|
+
const response = await request(url);
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
const chunks = [];
|
|
85
|
+
response.on("data", (chunk) => chunks.push(chunk));
|
|
86
|
+
response.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
|
87
|
+
response.on("error", reject);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function downloadFile(url, destination) {
|
|
92
|
+
const response = await request(url);
|
|
93
|
+
await new Promise((resolve, reject) => {
|
|
94
|
+
const file = fs.createWriteStream(destination);
|
|
95
|
+
response.pipe(file);
|
|
96
|
+
file.on("finish", () => file.close(resolve));
|
|
97
|
+
file.on("error", reject);
|
|
98
|
+
response.on("error", reject);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function checksumFor(checksums, name) {
|
|
103
|
+
const line = checksums
|
|
104
|
+
.split(/\r?\n/)
|
|
105
|
+
.find((entry) => entry.includes(name));
|
|
106
|
+
|
|
107
|
+
if (!line) {
|
|
108
|
+
fail(`could not find ${name} in checksums.txt`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const match = line.match(/[a-f0-9]{64}/i);
|
|
112
|
+
if (!match) {
|
|
113
|
+
fail(`could not parse checksum for ${name}`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return match[0].toLowerCase();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function sha256(file) {
|
|
120
|
+
const hash = crypto.createHash("sha256");
|
|
121
|
+
hash.update(fs.readFileSync(file));
|
|
122
|
+
return hash.digest("hex");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function extractArchive(archive, destination) {
|
|
126
|
+
if (process.platform === "win32") {
|
|
127
|
+
childProcess.execFileSync(
|
|
128
|
+
"powershell",
|
|
129
|
+
[
|
|
130
|
+
"-NoProfile",
|
|
131
|
+
"-ExecutionPolicy",
|
|
132
|
+
"Bypass",
|
|
133
|
+
"-Command",
|
|
134
|
+
"Expand-Archive -LiteralPath $args[0] -DestinationPath $args[1] -Force",
|
|
135
|
+
archive,
|
|
136
|
+
destination,
|
|
137
|
+
],
|
|
138
|
+
{ stdio: "inherit" },
|
|
139
|
+
);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
childProcess.execFileSync("tar", ["-xzf", archive, "-C", destination], {
|
|
144
|
+
stdio: "inherit",
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function findBinary(directory) {
|
|
149
|
+
const binaryName = process.platform === "win32" ? "tapd.exe" : "tapd";
|
|
150
|
+
const entries = fs.readdirSync(directory, { withFileTypes: true });
|
|
151
|
+
|
|
152
|
+
for (const entry of entries) {
|
|
153
|
+
const entryPath = path.join(directory, entry.name);
|
|
154
|
+
if (entry.isFile() && entry.name === binaryName) {
|
|
155
|
+
return entryPath;
|
|
156
|
+
}
|
|
157
|
+
if (entry.isDirectory()) {
|
|
158
|
+
const found = findBinary(entryPath);
|
|
159
|
+
if (found) {
|
|
160
|
+
return found;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return "";
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function main() {
|
|
169
|
+
if (process.env.TAPD_SKIP_DOWNLOAD) {
|
|
170
|
+
console.log("Skipping tapd binary download because TAPD_SKIP_DOWNLOAD is set.");
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const name = assetName();
|
|
175
|
+
const baseUrl = `https://github.com/${repo}/releases/download/${tag}`;
|
|
176
|
+
const archiveUrl = `${baseUrl}/${name}`;
|
|
177
|
+
const checksumsUrl = `${baseUrl}/checksums.txt`;
|
|
178
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "tapd-npm-"));
|
|
179
|
+
const archivePath = path.join(tempDir, name);
|
|
180
|
+
const extractDir = path.join(tempDir, "extract");
|
|
181
|
+
|
|
182
|
+
fs.mkdirSync(extractDir);
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
console.log(`Downloading ${archiveUrl}`);
|
|
186
|
+
await downloadFile(archiveUrl, archivePath);
|
|
187
|
+
|
|
188
|
+
const expected = checksumFor(await downloadText(checksumsUrl), name);
|
|
189
|
+
const actual = sha256(archivePath);
|
|
190
|
+
|
|
191
|
+
if (actual !== expected) {
|
|
192
|
+
fail(`checksum mismatch for ${name}: expected ${expected}, got ${actual}`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
extractArchive(archivePath, extractDir);
|
|
196
|
+
|
|
197
|
+
const binary = findBinary(extractDir);
|
|
198
|
+
if (!binary) {
|
|
199
|
+
fail(`tapd binary not found in ${name}`);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const vendorDir = path.join(__dirname, "..", "vendor");
|
|
203
|
+
const target = path.join(vendorDir, process.platform === "win32" ? "tapd.exe" : "tapd");
|
|
204
|
+
fs.rmSync(vendorDir, { force: true, recursive: true });
|
|
205
|
+
fs.mkdirSync(vendorDir, { recursive: true });
|
|
206
|
+
fs.copyFileSync(binary, target);
|
|
207
|
+
|
|
208
|
+
if (process.platform !== "win32") {
|
|
209
|
+
fs.chmodSync(target, 0o755);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
console.log(`Installed tapd ${version} to ${target}`);
|
|
213
|
+
} finally {
|
|
214
|
+
fs.rmSync(tempDir, { force: true, recursive: true });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
main().catch((error) => fail(error.message));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
|
|
6
|
+
const rawVersion = process.argv[2] || process.env.GITHUB_REF_NAME || process.env.RELEASE_VERSION || "";
|
|
7
|
+
const version = rawVersion.replace(/^refs\/tags\//, "").replace(/^v/, "");
|
|
8
|
+
|
|
9
|
+
if (!/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(version)) {
|
|
10
|
+
console.error(`Invalid release version: ${rawVersion}`);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const packagePath = path.join(__dirname, "..", "package.json");
|
|
15
|
+
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
|
|
16
|
+
|
|
17
|
+
packageJson.version = version;
|
|
18
|
+
fs.writeFileSync(packagePath, `${JSON.stringify(packageJson, null, 2)}\n`);
|
|
19
|
+
|
|
20
|
+
console.log(`Set npm package version to ${version}`);
|