bleam 0.0.1 → 0.0.3

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.
Files changed (84) hide show
  1. package/dist/app.cjs +11 -0
  2. package/dist/app.d.cts +7 -0
  3. package/dist/app.d.cts.map +1 -0
  4. package/dist/app.d.ts +7 -0
  5. package/dist/app.d.ts.map +1 -0
  6. package/dist/app.js +10 -0
  7. package/dist/app.js.map +1 -0
  8. package/dist/bundler.cjs +0 -0
  9. package/dist/bundler.d.cts +28 -0
  10. package/dist/bundler.d.cts.map +1 -0
  11. package/dist/bundler.d.ts +28 -0
  12. package/dist/bundler.d.ts.map +1 -0
  13. package/dist/bundler.js +1 -0
  14. package/dist/chunk-CUT6urMc.cjs +30 -0
  15. package/dist/cli.cjs +477 -0
  16. package/dist/cli.d.cts +1 -0
  17. package/dist/cli.d.ts +1 -0
  18. package/dist/cli.js +470 -0
  19. package/dist/cli.js.map +1 -0
  20. package/dist/config.cjs +26 -0
  21. package/dist/config.d.cts +28 -0
  22. package/dist/config.d.cts.map +1 -0
  23. package/dist/config.d.ts +28 -0
  24. package/dist/config.d.ts.map +1 -0
  25. package/dist/config.js +25 -0
  26. package/dist/config.js.map +1 -0
  27. package/dist/crypto-BNhWeXMj.cjs +15 -0
  28. package/dist/crypto-Bg8cD8wX.d.cts +8 -0
  29. package/dist/crypto-Bg8cD8wX.d.cts.map +1 -0
  30. package/dist/crypto-CCA_hvao.js +11 -0
  31. package/dist/crypto-CCA_hvao.js.map +1 -0
  32. package/dist/crypto-IOzbNoJD.d.ts +8 -0
  33. package/dist/crypto-IOzbNoJD.d.ts.map +1 -0
  34. package/dist/crypto.cjs +4 -0
  35. package/dist/crypto.d.cts +2 -0
  36. package/dist/crypto.d.ts +2 -0
  37. package/dist/crypto.js +4 -0
  38. package/dist/dev-protocol.cjs +16 -0
  39. package/dist/dev-protocol.d.cts +16 -0
  40. package/dist/dev-protocol.d.cts.map +1 -0
  41. package/dist/dev-protocol.d.ts +16 -0
  42. package/dist/dev-protocol.d.ts.map +1 -0
  43. package/dist/dev-protocol.js +14 -0
  44. package/dist/dev-protocol.js.map +1 -0
  45. package/dist/fs-BK7joD1g.js +13 -0
  46. package/dist/fs-BK7joD1g.js.map +1 -0
  47. package/dist/fs-CEhcjuN6.d.ts +9 -0
  48. package/dist/fs-CEhcjuN6.d.ts.map +1 -0
  49. package/dist/fs-CfE8CHf_.d.cts +9 -0
  50. package/dist/fs-CfE8CHf_.d.cts.map +1 -0
  51. package/dist/fs-DKHYTPua.cjs +18 -0
  52. package/dist/fs.cjs +3 -0
  53. package/dist/fs.d.cts +2 -0
  54. package/dist/fs.d.ts +2 -0
  55. package/dist/fs.js +3 -0
  56. package/dist/index.cjs +6 -0
  57. package/dist/index.d.cts +3 -0
  58. package/dist/index.d.ts +3 -0
  59. package/dist/index.js +5 -0
  60. package/dist/native-runtime-BoqybBBf.js +18 -0
  61. package/dist/native-runtime-BoqybBBf.js.map +1 -0
  62. package/dist/native-runtime-CdeT0JyQ.cjs +30 -0
  63. package/dist/native.cjs +132 -0
  64. package/dist/native.d.cts +64 -0
  65. package/dist/native.d.cts.map +1 -0
  66. package/dist/native.d.ts +64 -0
  67. package/dist/native.d.ts.map +1 -0
  68. package/dist/native.js +133 -0
  69. package/dist/native.js.map +1 -0
  70. package/dist/runtime.cjs +0 -0
  71. package/dist/runtime.d.cts +14 -0
  72. package/dist/runtime.d.cts.map +1 -0
  73. package/dist/runtime.d.ts +14 -0
  74. package/dist/runtime.d.ts.map +1 -0
  75. package/dist/runtime.js +1 -0
  76. package/metro-config.cjs +75 -0
  77. package/package.json +81 -22
  78. package/templates/basic/app.config.ts +3 -0
  79. package/templates/basic/app.tsx +18 -0
  80. package/tsconfig.base.json +7 -0
  81. package/tsconfig.json +3 -0
  82. package/README.md +0 -1
  83. package/dist/index.d.mts +0 -9914
  84. package/dist/index.mjs +0 -1259
package/dist/app.cjs ADDED
@@ -0,0 +1,11 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ let expo = require("expo");
3
+ expo = require_chunk.__toESM(expo);
4
+
5
+ //#region src/app.ts
6
+ function registerApp(component) {
7
+ (0, expo.registerRootComponent)(component);
8
+ }
9
+
10
+ //#endregion
11
+ exports.registerApp = registerApp;
package/dist/app.d.cts ADDED
@@ -0,0 +1,7 @@
1
+ import { ComponentType } from "react";
2
+
3
+ //#region src/app.d.ts
4
+ declare function registerApp(component: ComponentType): void;
5
+ //#endregion
6
+ export { registerApp };
7
+ //# sourceMappingURL=app.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.cts","names":[],"sources":["../src/app.ts"],"sourcesContent":[],"mappings":";;;iBAGgB,WAAA,YAAuB"}
package/dist/app.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { ComponentType } from "react";
2
+
3
+ //#region src/app.d.ts
4
+ declare function registerApp(component: ComponentType): void;
5
+ //#endregion
6
+ export { registerApp };
7
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","names":[],"sources":["../src/app.ts"],"sourcesContent":[],"mappings":";;;iBAGgB,WAAA,YAAuB"}
package/dist/app.js ADDED
@@ -0,0 +1,10 @@
1
+ import { registerRootComponent } from "expo";
2
+
3
+ //#region src/app.ts
4
+ function registerApp(component) {
5
+ registerRootComponent(component);
6
+ }
7
+
8
+ //#endregion
9
+ export { registerApp };
10
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","names":[],"sources":["../src/app.ts"],"sourcesContent":["import { registerRootComponent } from 'expo'\nimport type { ComponentType } from 'react'\n\nexport function registerApp(component: ComponentType) {\n registerRootComponent(component)\n}\n"],"mappings":";;;AAGA,SAAgB,YAAY,WAA0B;AACpD,uBAAsB,UAAU"}
File without changes
@@ -0,0 +1,28 @@
1
+ //#region src/bundler.d.ts
2
+ interface DevServerOptions {
3
+ projectRoot: string;
4
+ port?: number;
5
+ }
6
+ interface DevServerHandle {
7
+ url: string;
8
+ close(): Promise<void>;
9
+ }
10
+ interface BundleOptions {
11
+ projectRoot: string;
12
+ entry: string;
13
+ platform: 'macos';
14
+ dev: boolean;
15
+ }
16
+ interface BundleResult {
17
+ entry: string;
18
+ assets: string[];
19
+ }
20
+ interface DevServer {
21
+ start(options: DevServerOptions): Promise<DevServerHandle>;
22
+ }
23
+ interface Bundler {
24
+ bundle(options: BundleOptions): Promise<BundleResult>;
25
+ }
26
+ //#endregion
27
+ export { BundleOptions, BundleResult, Bundler, DevServer, DevServerHandle, DevServerOptions };
28
+ //# sourceMappingURL=bundler.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundler.d.cts","names":[],"sources":["../src/bundler.ts"],"sourcesContent":[],"mappings":";UAAiB,gBAAA;EAAA,WAAA,EAAA,MAAgB;EAKhB,IAAA,CAAA,EAAA,MAAA;AAKjB;AAOiB,UAZA,eAAA,CAYY;EAKZ,GAAA,EAAA,MAAA;EACA,KAAA,EAAA,EAhBN,OAgBM,CAAA,IAAA,CAAA;;AAAmB,UAbnB,aAAA,CAamB;EAAO,WAAA,EAAA,MAAA;EAG1B,KAAA,EAAA,MAAO;EACN,QAAA,EAAA,OAAA;EAAwB,GAAA,EAAA,OAAA;;AAAD,UAVxB,YAAA,CAUwB;;;;UALxB,SAAA;iBACA,mBAAmB,QAAQ;;UAG3B,OAAA;kBACC,gBAAgB,QAAQ"}
@@ -0,0 +1,28 @@
1
+ //#region src/bundler.d.ts
2
+ interface DevServerOptions {
3
+ projectRoot: string;
4
+ port?: number;
5
+ }
6
+ interface DevServerHandle {
7
+ url: string;
8
+ close(): Promise<void>;
9
+ }
10
+ interface BundleOptions {
11
+ projectRoot: string;
12
+ entry: string;
13
+ platform: 'macos';
14
+ dev: boolean;
15
+ }
16
+ interface BundleResult {
17
+ entry: string;
18
+ assets: string[];
19
+ }
20
+ interface DevServer {
21
+ start(options: DevServerOptions): Promise<DevServerHandle>;
22
+ }
23
+ interface Bundler {
24
+ bundle(options: BundleOptions): Promise<BundleResult>;
25
+ }
26
+ //#endregion
27
+ export { BundleOptions, BundleResult, Bundler, DevServer, DevServerHandle, DevServerOptions };
28
+ //# sourceMappingURL=bundler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundler.d.ts","names":[],"sources":["../src/bundler.ts"],"sourcesContent":[],"mappings":";UAAiB,gBAAA;EAAA,WAAA,EAAA,MAAgB;EAKhB,IAAA,CAAA,EAAA,MAAA;AAKjB;AAOiB,UAZA,eAAA,CAYY;EAKZ,GAAA,EAAA,MAAA;EACA,KAAA,EAAA,EAhBN,OAgBM,CAAA,IAAA,CAAA;;AAAmB,UAbnB,aAAA,CAamB;EAAO,WAAA,EAAA,MAAA;EAG1B,KAAA,EAAA,MAAO;EACN,QAAA,EAAA,OAAA;EAAwB,GAAA,EAAA,OAAA;;AAAD,UAVxB,YAAA,CAUwB;;;;UALxB,SAAA;iBACA,mBAAmB,QAAQ;;UAG3B,OAAA;kBACC,gBAAgB,QAAQ"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,30 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ Object.defineProperty(exports, '__toESM', {
26
+ enumerable: true,
27
+ get: function () {
28
+ return __toESM;
29
+ }
30
+ });
package/dist/cli.cjs ADDED
@@ -0,0 +1,477 @@
1
+ #!/usr/bin/env node
2
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
3
+ let node_child_process = require("node:child_process");
4
+ node_child_process = require_chunk.__toESM(node_child_process);
5
+ let node_crypto = require("node:crypto");
6
+ node_crypto = require_chunk.__toESM(node_crypto);
7
+ let node_fs = require("node:fs");
8
+ node_fs = require_chunk.__toESM(node_fs);
9
+ let node_http = require("node:http");
10
+ node_http = require_chunk.__toESM(node_http);
11
+ let node_module = require("node:module");
12
+ node_module = require_chunk.__toESM(node_module);
13
+ let node_os = require("node:os");
14
+ node_os = require_chunk.__toESM(node_os);
15
+ let node_path = require("node:path");
16
+ node_path = require_chunk.__toESM(node_path);
17
+ let node_url = require("node:url");
18
+ node_url = require_chunk.__toESM(node_url);
19
+
20
+ //#region src/cli.ts
21
+ const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
22
+ const packageRoot = node_path.default.dirname((0, node_url.fileURLToPath)(new URL("../package.json", require("url").pathToFileURL(__filename).href)));
23
+ const packageJson = require$1("../package.json");
24
+ const runtimeVersion = packageJson.version;
25
+ const runtimePlatform = `macos-${process.arch}`;
26
+ function printUsage() {
27
+ console.log(`Usage: bleam <command>
28
+
29
+ Commands:
30
+ new [dir] [--run] Create a new Bleam project
31
+ dev [dir] [--port <port>] Start a Bleam dev server`);
32
+ }
33
+ function invocationRoot() {
34
+ return node_path.default.isAbsolute(process.env.PWD ?? "") ? process.env.PWD : process.cwd();
35
+ }
36
+ function parseDevOptions(argv) {
37
+ const root = invocationRoot();
38
+ let projectRoot = root;
39
+ let port = 8082;
40
+ let hasProjectRootArg = false;
41
+ for (let index = 0; index < argv.length; index += 1) {
42
+ const arg = argv[index];
43
+ if (arg === "--port" || arg === "-p") {
44
+ const value = argv[++index];
45
+ port = Number(value);
46
+ continue;
47
+ }
48
+ if (arg.startsWith("--port=")) {
49
+ port = Number(arg.slice(7));
50
+ continue;
51
+ }
52
+ if (arg === "--help" || arg === "-h") {
53
+ printUsage();
54
+ process.exit(0);
55
+ }
56
+ if (arg.startsWith("-")) throw new Error(`Unknown option: ${arg}`);
57
+ projectRoot = node_path.default.resolve(root, arg);
58
+ hasProjectRootArg = true;
59
+ }
60
+ if (!Number.isInteger(port) || port <= 0) throw new Error(`Invalid port: ${port}`);
61
+ if (!hasProjectRootArg && !isBleamProjectRoot(projectRoot)) projectRoot = discoverBleamProjectRoot(projectRoot) ?? projectRoot;
62
+ return {
63
+ projectRoot: node_path.default.resolve(projectRoot),
64
+ port
65
+ };
66
+ }
67
+ function parseNewOptions(argv) {
68
+ const root = invocationRoot();
69
+ let projectRoot = root;
70
+ let run = false;
71
+ for (const arg of argv) {
72
+ if (arg === "--run") {
73
+ run = true;
74
+ continue;
75
+ }
76
+ if (arg === "--help" || arg === "-h") {
77
+ printUsage();
78
+ process.exit(0);
79
+ }
80
+ if (arg.startsWith("-")) throw new Error(`Unknown option: ${arg}`);
81
+ projectRoot = node_path.default.resolve(root, arg);
82
+ }
83
+ return {
84
+ projectRoot,
85
+ run
86
+ };
87
+ }
88
+ function isBleamProjectRoot(projectRoot) {
89
+ return (0, node_fs.existsSync)(node_path.default.join(projectRoot, "app.config.ts")) && (0, node_fs.existsSync)(node_path.default.join(projectRoot, "app.tsx"));
90
+ }
91
+ function discoverBleamProjectRoot(searchRoot) {
92
+ const ignoredNames = new Set([
93
+ ".bleam",
94
+ ".expo",
95
+ ".git",
96
+ ".yarn",
97
+ "build",
98
+ "dist",
99
+ "node_modules",
100
+ "templates"
101
+ ]);
102
+ const matches = [];
103
+ function visit(directory) {
104
+ if (matches.length > 1) return;
105
+ if (isBleamProjectRoot(directory)) {
106
+ matches.push(directory);
107
+ return;
108
+ }
109
+ for (const entry of (0, node_fs.readdirSync)(directory, { withFileTypes: true })) {
110
+ if (!entry.isDirectory() || ignoredNames.has(entry.name)) continue;
111
+ visit(node_path.default.join(directory, entry.name));
112
+ }
113
+ }
114
+ visit(searchRoot);
115
+ if (matches.length > 1) throw new Error("Multiple Bleam projects found. Run bleam dev <dir>.");
116
+ return matches[0];
117
+ }
118
+ function assertStringField(value, field) {
119
+ if (typeof value !== "string" || value.trim() === "") throw new Error(`app.config.ts must define ${field}`);
120
+ return value;
121
+ }
122
+ function loadAppConfig(projectRoot) {
123
+ const configPath = node_path.default.join(projectRoot, "app.config.ts");
124
+ const loader = `
125
+ const mod = await import(${JSON.stringify((0, node_url.pathToFileURL)(configPath).href)});
126
+ const config = mod.default?.default ?? mod.default ?? mod;
127
+ process.stdout.write(JSON.stringify(config));
128
+ `;
129
+ const result = (0, node_child_process.spawnSync)(process.execPath, [
130
+ "--import",
131
+ require$1.resolve("tsx"),
132
+ "--eval",
133
+ loader
134
+ ], {
135
+ cwd: projectRoot,
136
+ encoding: "utf8",
137
+ env: {
138
+ ...process.env,
139
+ NODE_PATH: [
140
+ node_path.default.join(projectRoot, "node_modules"),
141
+ node_path.default.join(packageRoot, "node_modules"),
142
+ process.env.NODE_PATH
143
+ ].filter(Boolean).join(node_path.default.delimiter)
144
+ }
145
+ });
146
+ if (result.status !== 0) throw new Error(result.stderr.trim() || "Failed to load app.config.ts");
147
+ const value = JSON.parse(result.stdout);
148
+ return {
149
+ name: assertStringField(value.name, "name"),
150
+ version: typeof value.version === "string" ? value.version : void 0,
151
+ bundleIdentifier: typeof value.bundleIdentifier === "string" ? value.bundleIdentifier : void 0,
152
+ teamId: typeof value.teamId === "string" ? value.teamId : void 0
153
+ };
154
+ }
155
+ function assertBleamConfigFiles(projectRoot) {
156
+ if ((0, node_fs.existsSync)(node_path.default.join(projectRoot, "app.json"))) throw new Error("Bleam projects use app.config.ts; app.json is not supported.");
157
+ if (!(0, node_fs.existsSync)(node_path.default.join(projectRoot, "app.config.ts"))) throw new Error("Missing app.config.ts. Bleam projects must define app.config.ts.");
158
+ if (!(0, node_fs.existsSync)(node_path.default.join(projectRoot, "app.tsx"))) throw new Error("Missing app.tsx. Bleam projects must define app.tsx.");
159
+ }
160
+ function readProjectConfig(options) {
161
+ assertBleamConfigFiles(options.projectRoot);
162
+ const config = loadAppConfig(options.projectRoot);
163
+ return {
164
+ name: config.name,
165
+ version: config.version,
166
+ bundleIdentifier: config.bundleIdentifier,
167
+ teamId: config.teamId,
168
+ runtimeVersion,
169
+ sdkVersion: runtimeVersion
170
+ };
171
+ }
172
+ function slugFromName(name) {
173
+ return name.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "bleam-app";
174
+ }
175
+ function nameFromDirectory(projectRoot) {
176
+ const name = node_path.default.basename(projectRoot).replace(/[-_]+/g, " ").trim();
177
+ if (!name) return "Bleam App";
178
+ return name.replace(/\b\w/g, (letter) => letter.toUpperCase());
179
+ }
180
+ function createNewProject(options) {
181
+ const templateRoot = node_path.default.join(packageRoot, "templates", "basic");
182
+ if (!(0, node_fs.existsSync)(templateRoot)) throw new Error(`Missing basic template: ${templateRoot}`);
183
+ if ((0, node_fs.existsSync)(options.projectRoot) && (0, node_fs.readdirSync)(options.projectRoot).length > 0) throw new Error(`Directory is not empty: ${options.projectRoot}`);
184
+ (0, node_fs.mkdirSync)(options.projectRoot, { recursive: true });
185
+ (0, node_fs.cpSync)(templateRoot, options.projectRoot, { recursive: true });
186
+ (0, node_fs.writeFileSync)(node_path.default.join(options.projectRoot, "app.config.ts"), `export default {\n name: ${JSON.stringify(nameFromDirectory(options.projectRoot))},\n}\n`);
187
+ console.log(`Created Bleam project at ${options.projectRoot}`);
188
+ }
189
+ function createDevWorkspace(projectRoot, config) {
190
+ const workspaceRoot = node_path.default.join(projectRoot, ".bleam", "dev");
191
+ (0, node_fs.mkdirSync)(workspaceRoot, { recursive: true });
192
+ const workspaceNodeModules = node_path.default.join(workspaceRoot, "node_modules");
193
+ if (!(0, node_fs.existsSync)(workspaceNodeModules)) (0, node_fs.symlinkSync)(node_path.default.join(packageRoot, "node_modules"), workspaceNodeModules);
194
+ (0, node_fs.writeFileSync)(node_path.default.join(workspaceRoot, "app.config.js"), `module.exports = ${JSON.stringify({ expo: {
195
+ name: config.name,
196
+ slug: slugFromName(config.name),
197
+ version: config.version ?? "0.0.0",
198
+ orientation: "default",
199
+ platforms: ["ios"],
200
+ newArchEnabled: true
201
+ } }, null, 2)}\n`);
202
+ (0, node_fs.writeFileSync)(node_path.default.join(workspaceRoot, "index.js"), `import { registerApp } from 'bleam/app'\nimport App from ${JSON.stringify(node_path.default.join(projectRoot, "app"))}\n\nregisterApp(App)\n`);
203
+ (0, node_fs.writeFileSync)(node_path.default.join(workspaceRoot, "metro.config.js"), `const { getDefaultConfig } = require(${JSON.stringify(node_path.default.join(packageRoot, "metro-config.cjs"))})\n\nmodule.exports = getDefaultConfig(__dirname)\n`);
204
+ (0, node_fs.writeFileSync)(node_path.default.join(workspaceRoot, "package.json"), `${JSON.stringify({
205
+ name: `${slugFromName(config.name)}-bleam-dev`,
206
+ version: config.version ?? "0.0.0",
207
+ private: true,
208
+ main: "index.js",
209
+ dependencies: {
210
+ "@types/react": packageJson.dependencies?.["@types/react"],
211
+ expo: packageJson.dependencies?.expo,
212
+ react: packageJson.dependencies?.react,
213
+ "react-native": packageJson.dependencies?.["react-native"]
214
+ }
215
+ }, null, 2)}\n`);
216
+ (0, node_fs.writeFileSync)(node_path.default.join(workspaceRoot, "tsconfig.json"), `${JSON.stringify({
217
+ extends: "bleam/tsconfig",
218
+ include: [node_path.default.relative(workspaceRoot, node_path.default.join(projectRoot, "app.tsx")), node_path.default.relative(workspaceRoot, node_path.default.join(projectRoot, "app.config.ts"))]
219
+ }, null, 2)}\n`);
220
+ return workspaceRoot;
221
+ }
222
+ function writeProjectRuntimeConfig(projectRoot, config, origin) {
223
+ const projectConfigPath = node_path.default.join(projectRoot, ".bleam", "project.json");
224
+ (0, node_fs.mkdirSync)(node_path.default.dirname(projectConfigPath), { recursive: true });
225
+ (0, node_fs.writeFileSync)(projectConfigPath, `${JSON.stringify({
226
+ name: config.name,
227
+ version: config.version,
228
+ bundleIdentifier: config.bundleIdentifier,
229
+ teamId: config.teamId,
230
+ devServer: origin,
231
+ runtimeVersion: config.runtimeVersion,
232
+ sdkVersion: config.sdkVersion
233
+ }, null, 2)}\n`);
234
+ return projectConfigPath;
235
+ }
236
+ function runtimeCacheRoot() {
237
+ return node_path.default.join(node_os.default.homedir(), "Library", "Caches", "bleam", "runtimes", runtimeVersion, runtimePlatform);
238
+ }
239
+ function localDevelopmentRuntimeAppPath() {
240
+ return node_path.default.resolve(packageRoot, "..", "..", "app", "bleam", "build", "Build", "Products", "Debug-maccatalyst", "Bleam.app");
241
+ }
242
+ function runtimeReleaseBaseUrl() {
243
+ return process.env.BLEAM_RUNTIME_RELEASE_BASE_URL ?? "https://github.com/bajedev/bleam-app/releases/download";
244
+ }
245
+ function runtimeArchiveName() {
246
+ return `bleam-runtime-v${runtimeVersion}-${runtimePlatform}.zip`;
247
+ }
248
+ function runtimeArchiveUrl() {
249
+ const tag = encodeURIComponent(`bleam@${runtimeVersion}`);
250
+ return `${runtimeReleaseBaseUrl()}/${tag}/${runtimeArchiveName()}`;
251
+ }
252
+ function sha256(filePath) {
253
+ return (0, node_crypto.createHash)("sha256").update((0, node_fs.readFileSync)(filePath)).digest("hex");
254
+ }
255
+ async function downloadFile(url, destination) {
256
+ const response = await fetch(url);
257
+ if (!response.ok) throw new Error(`Failed to download ${url}: ${response.status} ${response.statusText}`);
258
+ (0, node_fs.writeFileSync)(destination, new Uint8Array(await response.arrayBuffer()));
259
+ }
260
+ async function downloadExpectedSha256(url) {
261
+ const response = await fetch(`${url}.sha256`);
262
+ if (!response.ok) return;
263
+ return (await response.text()).trim().split(/\s+/)[0];
264
+ }
265
+ async function downloadRuntimeArtifact() {
266
+ if (process.platform !== "darwin") throw new Error("Bleam runtime artifacts are currently only available on macOS.");
267
+ const cacheRoot = runtimeCacheRoot();
268
+ const cachedAppPath = node_path.default.join(cacheRoot, "Bleam.app");
269
+ if ((0, node_fs.existsSync)(cachedAppPath)) return {
270
+ appPath: cachedAppPath,
271
+ version: runtimeVersion,
272
+ platform: runtimePlatform
273
+ };
274
+ (0, node_fs.mkdirSync)(cacheRoot, { recursive: true });
275
+ const archiveUrl = runtimeArchiveUrl();
276
+ const archivePath = node_path.default.join(cacheRoot, runtimeArchiveName());
277
+ const extractRoot = node_path.default.join(cacheRoot, "extract");
278
+ await downloadFile(archiveUrl, archivePath);
279
+ const expectedSha256 = await downloadExpectedSha256(archiveUrl);
280
+ if (expectedSha256 && sha256(archivePath) !== expectedSha256) {
281
+ (0, node_fs.rmSync)(archivePath, { force: true });
282
+ throw new Error(`Runtime artifact checksum mismatch: ${archiveUrl}`);
283
+ }
284
+ (0, node_fs.rmSync)(extractRoot, {
285
+ recursive: true,
286
+ force: true
287
+ });
288
+ (0, node_fs.mkdirSync)(extractRoot, { recursive: true });
289
+ (0, node_child_process.execFileSync)("ditto", [
290
+ "-x",
291
+ "-k",
292
+ archivePath,
293
+ extractRoot
294
+ ], { stdio: "ignore" });
295
+ const extractedAppPath = node_path.default.join(extractRoot, "Bleam.app");
296
+ if (!(0, node_fs.existsSync)(extractedAppPath)) throw new Error(`Runtime archive did not contain Bleam.app: ${archiveUrl}`);
297
+ (0, node_fs.rmSync)(cachedAppPath, {
298
+ recursive: true,
299
+ force: true
300
+ });
301
+ (0, node_fs.cpSync)(extractedAppPath, cachedAppPath, { recursive: true });
302
+ (0, node_fs.rmSync)(extractRoot, {
303
+ recursive: true,
304
+ force: true
305
+ });
306
+ return {
307
+ appPath: cachedAppPath,
308
+ version: runtimeVersion,
309
+ platform: runtimePlatform
310
+ };
311
+ }
312
+ async function resolveRuntimeArtifact() {
313
+ const overrideAppPath = process.env.BLEAM_RUNTIME_APP;
314
+ if (overrideAppPath) {
315
+ const appPath = node_path.default.resolve(overrideAppPath);
316
+ if (!(0, node_fs.existsSync)(appPath)) throw new Error(`BLEAM_RUNTIME_APP does not exist: ${appPath}`);
317
+ return {
318
+ appPath,
319
+ version: runtimeVersion,
320
+ platform: runtimePlatform
321
+ };
322
+ }
323
+ const localAppPath = localDevelopmentRuntimeAppPath();
324
+ if ((0, node_fs.existsSync)(localAppPath)) return {
325
+ appPath: localAppPath,
326
+ version: runtimeVersion,
327
+ platform: runtimePlatform
328
+ };
329
+ return downloadRuntimeArtifact();
330
+ }
331
+ function copyRuntimeClient(projectRoot, runtime) {
332
+ const clientAppPath = node_path.default.join(projectRoot, ".bleam", "client", "Bleam.app");
333
+ (0, node_fs.rmSync)(clientAppPath, {
334
+ recursive: true,
335
+ force: true
336
+ });
337
+ (0, node_fs.mkdirSync)(node_path.default.dirname(clientAppPath), { recursive: true });
338
+ (0, node_fs.cpSync)(runtime.appPath, clientAppPath, { recursive: true });
339
+ return clientAppPath;
340
+ }
341
+ function waitForDevServer(port, timeoutMs = 12e4) {
342
+ return new Promise((resolve, reject) => {
343
+ const startedAt = Date.now();
344
+ const poll = () => {
345
+ const req = node_http.default.get(`http://localhost:${port}/status`, (res) => {
346
+ let data = "";
347
+ res.on("data", (chunk) => {
348
+ data += chunk.toString();
349
+ });
350
+ res.on("end", () => {
351
+ if (data.includes("packager-status:running")) {
352
+ resolve();
353
+ return;
354
+ }
355
+ retry();
356
+ });
357
+ });
358
+ req.on("error", retry);
359
+ req.setTimeout(2e3, () => {
360
+ req.destroy();
361
+ retry();
362
+ });
363
+ };
364
+ const retry = () => {
365
+ if (Date.now() - startedAt > timeoutMs) {
366
+ reject(/* @__PURE__ */ new Error(`Bleam dev server did not start within ${timeoutMs / 1e3}s`));
367
+ return;
368
+ }
369
+ setTimeout(poll, 500);
370
+ };
371
+ poll();
372
+ });
373
+ }
374
+ function isBleamManifest(value) {
375
+ const manifest = value && typeof value === "object" ? value : {};
376
+ return typeof manifest.name === "string" && typeof manifest.bundleUrl === "string" && manifest.platform === "macos" && manifest.dev === true;
377
+ }
378
+ async function readDevManifest(origin, timeoutMs = 3e4) {
379
+ const manifestUrl = `${origin}/bleam/manifest.json`;
380
+ const startedAt = Date.now();
381
+ while (Date.now() - startedAt <= timeoutMs) {
382
+ try {
383
+ const response = await fetch(manifestUrl, { cache: "no-store" });
384
+ const value = await response.json();
385
+ if (response.ok && isBleamManifest(value)) return value;
386
+ } catch {}
387
+ await new Promise((resolve) => setTimeout(resolve, 500));
388
+ }
389
+ throw new Error(`Bleam manifest did not become available: ${manifestUrl}`);
390
+ }
391
+ function openRuntimeClient(appPath, projectConfigPath, manifest) {
392
+ (0, node_child_process.spawn)("open", [
393
+ appPath,
394
+ "--args",
395
+ "--bleam-project-config",
396
+ projectConfigPath,
397
+ "--bleam-bundle-url",
398
+ manifest.bundleUrl,
399
+ "--bleam-title",
400
+ manifest.name
401
+ ], {
402
+ detached: true,
403
+ stdio: "ignore"
404
+ }).unref();
405
+ }
406
+ async function startDevServer(options) {
407
+ const config = readProjectConfig(options);
408
+ const runtime = await resolveRuntimeArtifact();
409
+ const clientAppPath = copyRuntimeClient(options.projectRoot, runtime);
410
+ const workspaceRoot = createDevWorkspace(options.projectRoot, config);
411
+ const origin = `http://localhost:${options.port}`;
412
+ const projectConfigPath = writeProjectRuntimeConfig(options.projectRoot, config, origin);
413
+ const child = (0, node_child_process.spawn)(process.execPath, [
414
+ require$1.resolve("expo/bin/cli"),
415
+ "start",
416
+ workspaceRoot,
417
+ "--localhost",
418
+ "--port",
419
+ String(options.port)
420
+ ], {
421
+ stdio: "inherit",
422
+ env: {
423
+ ...process.env,
424
+ BLEAM_DEV: "1",
425
+ BLEAM_PROJECT_ROOT: options.projectRoot,
426
+ BLEAM_DEV_NAME: config.name,
427
+ BLEAM_DEV_ORIGIN: origin,
428
+ BLEAM_DEV_PORT: String(options.port),
429
+ BLEAM_DEV_RUNTIME_VERSION: config.runtimeVersion,
430
+ BLEAM_DEV_SDK_VERSION: config.sdkVersion,
431
+ NODE_PATH: [
432
+ node_path.default.join(options.projectRoot, "node_modules"),
433
+ node_path.default.join(packageRoot, "node_modules"),
434
+ node_path.default.dirname(node_path.default.dirname(require$1.resolve("expo/package.json"))),
435
+ node_path.default.dirname(node_path.default.dirname(require$1.resolve("react/package.json"))),
436
+ node_path.default.dirname(node_path.default.dirname(require$1.resolve("react-native/package.json"))),
437
+ process.env.NODE_PATH
438
+ ].filter(Boolean).join(node_path.default.delimiter)
439
+ }
440
+ });
441
+ const stop = (signal) => {
442
+ child.kill(signal);
443
+ };
444
+ process.on("SIGINT", () => stop("SIGINT"));
445
+ process.on("SIGTERM", () => stop("SIGTERM"));
446
+ child.on("exit", (code) => process.exit(code ?? 0));
447
+ await waitForDevServer(options.port);
448
+ const manifest = await readDevManifest(origin);
449
+ if (process.env.BLEAM_NO_OPEN !== "1") openRuntimeClient(clientAppPath, projectConfigPath, manifest);
450
+ }
451
+ async function main(argv = process.argv.slice(2)) {
452
+ const [command, ...args] = argv;
453
+ if (!command || command === "--help" || command === "-h") {
454
+ printUsage();
455
+ return;
456
+ }
457
+ if (command === "new") {
458
+ const options = parseNewOptions(args);
459
+ createNewProject(options);
460
+ if (options.run) await startDevServer({
461
+ projectRoot: options.projectRoot,
462
+ port: 8082
463
+ });
464
+ return;
465
+ }
466
+ if (command === "dev") {
467
+ await startDevServer(parseDevOptions(args));
468
+ return;
469
+ }
470
+ throw new Error(`Unknown command: ${command}`);
471
+ }
472
+ main().catch((error) => {
473
+ console.error(error instanceof Error ? error.message : String(error));
474
+ process.exit(1);
475
+ });
476
+
477
+ //#endregion
package/dist/cli.d.cts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { };