@tokamakdev/tok 0.1.1-beta.56 → 0.1.1-beta.58

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 CHANGED
@@ -1,13 +1,32 @@
1
1
  # @tokamakdev/tok
2
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.
3
+ The tokamak CLI, Vite plugin and app API, published from the tokamak
4
+ workspace. The version is the workspace Cargo version, with a `-beta.N` suffix
5
+ for automated pre-releases.
5
6
 
6
7
  ```sh
7
8
  npm install --save-dev @tokamakdev/tok
8
9
  npx tok targets
9
10
  ```
10
11
 
12
+ | Entry | Contents |
13
+ | --- | --- |
14
+ | `@tokamakdev/tok` | The `Config` type of `src/tokamak.ts` |
15
+ | `@tokamakdev/tok/vite` | The Vite plugin, `tokamak()` |
16
+ | `tok` | The CLI |
17
+
18
+ The Vite plugin goes next to Cloudflare's:
19
+
20
+ ```ts
21
+ import { cloudflare } from "@cloudflare/vite-plugin";
22
+ import { tokamak } from "@tokamakdev/tok/vite";
23
+ import { defineConfig } from "vite";
24
+
25
+ export default defineConfig({ plugins: [cloudflare(), tokamak()] });
26
+ ```
27
+
28
+ It does nothing unless `tok` runs the build or development command.
29
+
11
30
  The package installs the `tok` binary for the current machine through an
12
31
  optional dependency (`@tokamakdev/tok-darwin-arm64`, `-darwin-x64`,
13
32
  `-linux-x64`, or `-win32-x64`), and the platform packs the machine can build
@@ -0,0 +1,28 @@
1
+ /** A setting value. */
2
+ export type Value = string | number | boolean;
3
+ /** One platform's settings: the shared keys and the settings its platform pack declares. */
4
+ export interface PlatformConfig {
5
+ /** Display name. */
6
+ name?: string;
7
+ /** Application identifier. */
8
+ identifier?: string;
9
+ /** Icon in the platform's format, relative to the configuration file. */
10
+ icon?: string;
11
+ /** A setting the platform pack declares; `tok` validates it. */
12
+ [key: string]: Value | undefined;
13
+ }
14
+ /** The app's tokamak configuration, exported as `config` from `src/tokamak.ts`. */
15
+ export interface Config {
16
+ /** Display name for every platform. */
17
+ name?: string;
18
+ /** Application identifier for every platform. */
19
+ identifier?: string;
20
+ /** Icon for every platform, relative to the configuration file. */
21
+ icon?: string;
22
+ /** App version. */
23
+ version?: string;
24
+ android?: PlatformConfig;
25
+ ios?: PlatformConfig;
26
+ macos?: PlatformConfig;
27
+ windows?: PlatformConfig;
28
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { type Plugin } from "vite";
2
+ /**
3
+ * Reports the build's tokamak configuration and development server address to
4
+ * `tok`. Without `TOKAMAK_VITE_OUTPUT`, which `tok` sets, it adds no hooks.
5
+ */
6
+ export declare function tokamak(): Plugin[];
package/dist/vite.mjs ADDED
@@ -0,0 +1,77 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { normalizePath, runnerImport } from "vite";
4
+ /** Configuration files tried in order when `tok` names none. */
5
+ const CONFIG_FILES = ["src/tokamak.ts", "src/tokamak.js"];
6
+ /** The files each output directory's `config.json` was read from, once written. */
7
+ const written = new Map();
8
+ /**
9
+ * Reports the build's tokamak configuration and development server address to
10
+ * `tok`. Without `TOKAMAK_VITE_OUTPUT`, which `tok` sets, it adds no hooks.
11
+ */
12
+ export function tokamak() {
13
+ const output = process.env.TOKAMAK_VITE_OUTPUT;
14
+ if (!output) {
15
+ return [];
16
+ }
17
+ let config;
18
+ const write = () => {
19
+ const file = findConfigFile(config.root);
20
+ const files = writeConfig(output, file, config);
21
+ // A file that fails to load stays watched, so fixing it rewrites `config.json`.
22
+ written.set(output, files.catch(() => (file ? [file] : [])));
23
+ return files;
24
+ };
25
+ return [
26
+ {
27
+ name: "tokamak",
28
+ async configResolved(resolved) {
29
+ config = resolved;
30
+ await (written.has(output) ? written.get(output) : write());
31
+ },
32
+ async watchChange(id) {
33
+ if ((await written.get(output))?.includes(id)) {
34
+ await write();
35
+ }
36
+ },
37
+ configureServer(server) {
38
+ server.httpServer?.on("listening", () => {
39
+ const urls = server.resolvedUrls;
40
+ writeJson(output, "server.json", { url: urls?.local[0] ?? urls?.network[0] });
41
+ });
42
+ },
43
+ },
44
+ ];
45
+ }
46
+ /** The configuration file `TOKAMAK_CONFIG` names, or the first default under `root` that exists. */
47
+ function findConfigFile(root) {
48
+ const named = process.env.TOKAMAK_CONFIG;
49
+ if (named) {
50
+ if (!fs.existsSync(named)) {
51
+ throw new Error(`tokamak configuration file not found: ${named}`);
52
+ }
53
+ return normalizePath(path.resolve(named));
54
+ }
55
+ const file = CONFIG_FILES.map((name) => path.resolve(root, name)).find((candidate) => fs.existsSync(candidate));
56
+ return file && normalizePath(file);
57
+ }
58
+ /**
59
+ * Writes the file's `config` export, with the file's path, to `config.json`,
60
+ * returning the files it was read from.
61
+ */
62
+ async function writeConfig(output, file, config) {
63
+ if (!file) {
64
+ writeJson(output, "config.json", { config: {} });
65
+ return [];
66
+ }
67
+ const { module, dependencies } = await runnerImport(file, {
68
+ root: config.root,
69
+ resolve: { alias: config.resolve.alias, tsconfigPaths: config.resolve.tsconfigPaths },
70
+ });
71
+ writeJson(output, "config.json", { file, config: module.config ?? {} });
72
+ return [file, ...dependencies.map(normalizePath)];
73
+ }
74
+ function writeJson(output, name, value) {
75
+ fs.mkdirSync(output, { recursive: true });
76
+ fs.writeFileSync(path.join(output, name), `${JSON.stringify(value, null, 2)}\n`);
77
+ }
package/package.json CHANGED
@@ -1,35 +1,66 @@
1
1
  {
2
2
  "name": "@tokamakdev/tok",
3
- "version": "0.1.1-beta.56",
4
- "description": "The tokamak CLI: build native apps from a Cloudflare Workers codebase",
3
+ "version": "0.1.1-beta.58",
4
+ "description": "The tokamak CLI, Vite plugin and app API: build native apps from a Cloudflare Workers codebase",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/mantty/tokamak.git",
8
8
  "directory": "tokamak-cli/npm"
9
9
  },
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.mts",
13
+ "default": "./dist/index.mjs"
14
+ },
15
+ "./vite": {
16
+ "types": "./dist/vite.d.mts",
17
+ "default": "./dist/vite.mjs"
18
+ }
19
+ },
10
20
  "bin": {
11
21
  "tok": "bin/tok.js"
12
22
  },
13
23
  "files": [
14
24
  "bin",
25
+ "dist",
15
26
  "platform.js",
16
27
  "README.md"
17
28
  ],
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "prepack": "npm run build",
32
+ "test": "node --test"
33
+ },
18
34
  "engines": {
19
35
  "node": ">=18"
20
36
  },
37
+ "peerDependencies": {
38
+ "@cloudflare/vite-plugin": "^1.0.0",
39
+ "vite": "^7.0.0 || ^8.0.0"
40
+ },
41
+ "peerDependenciesMeta": {
42
+ "@cloudflare/vite-plugin": {
43
+ "optional": true
44
+ }
45
+ },
46
+ "devDependencies": {
47
+ "@cloudflare/vite-plugin": "1.62.5",
48
+ "@types/node": "22.19.15",
49
+ "typescript": "5.9.3",
50
+ "vite": "8.3.2"
51
+ },
21
52
  "optionalDependencies": {
22
- "@tokamakdev/platform-android-arm64": "0.1.1-beta.56",
23
- "@tokamakdev/platform-ios-arm64": "0.1.1-beta.56",
24
- "@tokamakdev/platform-ios-simulator-arm64": "0.1.1-beta.56",
25
- "@tokamakdev/platform-ios-simulator-x64": "0.1.1-beta.56",
26
- "@tokamakdev/platform-macos-arm64": "0.1.1-beta.56",
27
- "@tokamakdev/platform-macos-x64": "0.1.1-beta.56",
28
- "@tokamakdev/platform-windows-x64": "0.1.1-beta.56",
29
- "@tokamakdev/tok-darwin-arm64": "0.1.1-beta.56",
30
- "@tokamakdev/tok-darwin-x64": "0.1.1-beta.56",
31
- "@tokamakdev/tok-linux-x64": "0.1.1-beta.56",
32
- "@tokamakdev/tok-win32-x64": "0.1.1-beta.56"
53
+ "@tokamakdev/platform-android-arm64": "0.1.1-beta.58",
54
+ "@tokamakdev/platform-ios-arm64": "0.1.1-beta.58",
55
+ "@tokamakdev/platform-ios-simulator-arm64": "0.1.1-beta.58",
56
+ "@tokamakdev/platform-ios-simulator-x64": "0.1.1-beta.58",
57
+ "@tokamakdev/platform-macos-arm64": "0.1.1-beta.58",
58
+ "@tokamakdev/platform-macos-x64": "0.1.1-beta.58",
59
+ "@tokamakdev/platform-windows-x64": "0.1.1-beta.58",
60
+ "@tokamakdev/tok-darwin-arm64": "0.1.1-beta.58",
61
+ "@tokamakdev/tok-darwin-x64": "0.1.1-beta.58",
62
+ "@tokamakdev/tok-linux-x64": "0.1.1-beta.58",
63
+ "@tokamakdev/tok-win32-x64": "0.1.1-beta.58"
33
64
  },
34
65
  "publishConfig": {
35
66
  "access": "public"