@tokamakdev/tok 0.1.0-beta.34

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 ADDED
@@ -0,0 +1,15 @@
1
+ # @tokamakdev/tok
2
+
3
+ The tokamak CLI, published from the tokamak workspace. The version is the
4
+ workspace Cargo version, with a `-beta.N` suffix for automated pre-releases.
5
+
6
+ ```sh
7
+ npm install -g @tokamakdev/tok@beta
8
+ tok targets
9
+ ```
10
+
11
+ The package installs the `tok` binary for the current platform through an
12
+ optional dependency (`@tokamakdev/tok-darwin-arm64`, `-darwin-x64`,
13
+ `-linux-x64`, or `-win32-x64`). Building apps also needs the target packs,
14
+ which the tokamak installer places under `~/.local/share/tokamak`; `tok`
15
+ finds them there, or wherever `TOKAMAK_TARGET_PACK_DIR` points.
package/bin/tok.js ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { spawnSync } = require("node:child_process");
5
+ const { binaryPath } = require("../platform.js");
6
+
7
+ let binary;
8
+ try {
9
+ binary = binaryPath(process.platform, process.arch, require.resolve);
10
+ } catch (error) {
11
+ console.error(error.message);
12
+ process.exit(1);
13
+ }
14
+
15
+ // The terminal delivers Ctrl-C to both processes; tok shuts down gracefully on its own,
16
+ // so the launcher only waits for it.
17
+ for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) process.on(signal, () => {});
18
+
19
+ const result = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
20
+ if (result.error) {
21
+ console.error(`could not run ${binary}: ${result.error.message}`);
22
+ process.exit(1);
23
+ }
24
+ if (result.signal) process.kill(process.pid, result.signal);
25
+ process.exit(result.status ?? 1);
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@tokamakdev/tok",
3
+ "version": "0.1.0-beta.34",
4
+ "description": "The tokamak CLI: build native apps from a Cloudflare Workers codebase",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/mantty/tokamak.git",
8
+ "directory": "tokamak-cli/npm"
9
+ },
10
+ "bin": {
11
+ "tok": "bin/tok.js"
12
+ },
13
+ "files": [
14
+ "bin",
15
+ "platform.js",
16
+ "README.md"
17
+ ],
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "optionalDependencies": {
22
+ "@tokamakdev/tok-darwin-arm64": "0.1.0-beta.34",
23
+ "@tokamakdev/tok-darwin-x64": "0.1.0-beta.34",
24
+ "@tokamakdev/tok-linux-x64": "0.1.0-beta.34",
25
+ "@tokamakdev/tok-win32-x64": "0.1.0-beta.34"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ }
30
+ }
package/platform.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ const PACKAGES = {
4
+ "darwin-arm64": "@tokamakdev/tok-darwin-arm64",
5
+ "darwin-x64": "@tokamakdev/tok-darwin-x64",
6
+ "linux-x64": "@tokamakdev/tok-linux-x64",
7
+ "win32-x64": "@tokamakdev/tok-win32-x64",
8
+ };
9
+
10
+ function packageFor(platform, arch) {
11
+ const name = PACKAGES[`${platform}-${arch}`];
12
+ if (!name) throw new Error(`tokamak does not publish a CLI for ${platform} ${arch}`);
13
+ return name;
14
+ }
15
+
16
+ function binaryPath(platform, arch, resolve) {
17
+ const name = packageFor(platform, arch);
18
+ const file = platform === "win32" ? "bin/tok.exe" : "bin/tok";
19
+ try {
20
+ return resolve(`${name}/${file}`);
21
+ } catch {
22
+ throw new Error(`${name} is not installed; reinstall @tokamakdev/tok with optional dependencies enabled`);
23
+ }
24
+ }
25
+
26
+ module.exports = { packageFor, binaryPath };