bleam 0.0.1 → 0.0.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/dist/app.cjs +11 -0
- package/dist/app.d.cts +7 -0
- package/dist/app.d.cts.map +1 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +10 -0
- package/dist/app.js.map +1 -0
- package/dist/bundler.cjs +0 -0
- package/dist/bundler.d.cts +28 -0
- package/dist/bundler.d.cts.map +1 -0
- package/dist/bundler.d.ts +28 -0
- package/dist/bundler.d.ts.map +1 -0
- package/dist/bundler.js +1 -0
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/cli.cjs +479 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +472 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.cjs +26 -0
- package/dist/config.d.cts +28 -0
- package/dist/config.d.cts.map +1 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +25 -0
- package/dist/config.js.map +1 -0
- package/dist/crypto-BNhWeXMj.cjs +15 -0
- package/dist/crypto-Bg8cD8wX.d.cts +8 -0
- package/dist/crypto-Bg8cD8wX.d.cts.map +1 -0
- package/dist/crypto-CCA_hvao.js +11 -0
- package/dist/crypto-CCA_hvao.js.map +1 -0
- package/dist/crypto-IOzbNoJD.d.ts +8 -0
- package/dist/crypto-IOzbNoJD.d.ts.map +1 -0
- package/dist/crypto.cjs +4 -0
- package/dist/crypto.d.cts +2 -0
- package/dist/crypto.d.ts +2 -0
- package/dist/crypto.js +4 -0
- package/dist/dev-protocol.cjs +16 -0
- package/dist/dev-protocol.d.cts +16 -0
- package/dist/dev-protocol.d.cts.map +1 -0
- package/dist/dev-protocol.d.ts +16 -0
- package/dist/dev-protocol.d.ts.map +1 -0
- package/dist/dev-protocol.js +14 -0
- package/dist/dev-protocol.js.map +1 -0
- package/dist/fs-BK7joD1g.js +13 -0
- package/dist/fs-BK7joD1g.js.map +1 -0
- package/dist/fs-CEhcjuN6.d.ts +9 -0
- package/dist/fs-CEhcjuN6.d.ts.map +1 -0
- package/dist/fs-CfE8CHf_.d.cts +9 -0
- package/dist/fs-CfE8CHf_.d.cts.map +1 -0
- package/dist/fs-DKHYTPua.cjs +18 -0
- package/dist/fs.cjs +3 -0
- package/dist/fs.d.cts +2 -0
- package/dist/fs.d.ts +2 -0
- package/dist/fs.js +3 -0
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/native-runtime-BoqybBBf.js +18 -0
- package/dist/native-runtime-BoqybBBf.js.map +1 -0
- package/dist/native-runtime-CdeT0JyQ.cjs +30 -0
- package/dist/native.cjs +132 -0
- package/dist/native.d.cts +64 -0
- package/dist/native.d.cts.map +1 -0
- package/dist/native.d.ts +64 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +133 -0
- package/dist/native.js.map +1 -0
- package/dist/runtime.cjs +0 -0
- package/dist/runtime.d.cts +14 -0
- package/dist/runtime.d.cts.map +1 -0
- package/dist/runtime.d.ts +14 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/metro-config.cjs +75 -0
- package/package.json +88 -22
- package/templates/basic/app.config.ts +3 -0
- package/templates/basic/app.tsx +18 -0
- package/tsconfig.base.json +7 -0
- package/tsconfig.json +3 -0
- package/README.md +0 -1
- package/dist/index.d.mts +0 -9914
- 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 @@
|
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","names":[],"sources":["../src/app.ts"],"sourcesContent":[],"mappings":";;;iBAGgB,WAAA,YAAuB"}
|
package/dist/app.js
ADDED
package/dist/app.js.map
ADDED
|
@@ -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"}
|
package/dist/bundler.cjs
ADDED
|
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"}
|
package/dist/bundler.js
ADDED
|
@@ -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,479 @@
|
|
|
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 = 8081;
|
|
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
|
+
typescript: packageJson.dependencies?.typescript
|
|
215
|
+
},
|
|
216
|
+
expo: { install: { exclude: ["typescript"] } }
|
|
217
|
+
}, null, 2)}\n`);
|
|
218
|
+
(0, node_fs.writeFileSync)(node_path.default.join(workspaceRoot, "tsconfig.json"), `${JSON.stringify({
|
|
219
|
+
extends: "bleam/tsconfig",
|
|
220
|
+
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"))]
|
|
221
|
+
}, null, 2)}\n`);
|
|
222
|
+
return workspaceRoot;
|
|
223
|
+
}
|
|
224
|
+
function writeProjectRuntimeConfig(projectRoot, config, origin) {
|
|
225
|
+
const projectConfigPath = node_path.default.join(projectRoot, ".bleam", "project.json");
|
|
226
|
+
(0, node_fs.mkdirSync)(node_path.default.dirname(projectConfigPath), { recursive: true });
|
|
227
|
+
(0, node_fs.writeFileSync)(projectConfigPath, `${JSON.stringify({
|
|
228
|
+
name: config.name,
|
|
229
|
+
version: config.version,
|
|
230
|
+
bundleIdentifier: config.bundleIdentifier,
|
|
231
|
+
teamId: config.teamId,
|
|
232
|
+
devServer: origin,
|
|
233
|
+
runtimeVersion: config.runtimeVersion,
|
|
234
|
+
sdkVersion: config.sdkVersion
|
|
235
|
+
}, null, 2)}\n`);
|
|
236
|
+
return projectConfigPath;
|
|
237
|
+
}
|
|
238
|
+
function runtimeCacheRoot() {
|
|
239
|
+
return node_path.default.join(node_os.default.homedir(), "Library", "Caches", "bleam", "runtimes", runtimeVersion, runtimePlatform);
|
|
240
|
+
}
|
|
241
|
+
function localDevelopmentRuntimeAppPath() {
|
|
242
|
+
return node_path.default.resolve(packageRoot, "..", "..", "app", "bleam", "build", "Build", "Products", "Debug-maccatalyst", "Bleam.app");
|
|
243
|
+
}
|
|
244
|
+
function runtimeReleaseBaseUrl() {
|
|
245
|
+
return process.env.BLEAM_RUNTIME_RELEASE_BASE_URL ?? "https://github.com/bajedev/bleam-app/releases/download";
|
|
246
|
+
}
|
|
247
|
+
function runtimeArchiveName() {
|
|
248
|
+
return `bleam-runtime-v${runtimeVersion}-${runtimePlatform}.zip`;
|
|
249
|
+
}
|
|
250
|
+
function runtimeArchiveUrl() {
|
|
251
|
+
const tag = encodeURIComponent(`bleam@${runtimeVersion}`);
|
|
252
|
+
return `${runtimeReleaseBaseUrl()}/${tag}/${runtimeArchiveName()}`;
|
|
253
|
+
}
|
|
254
|
+
function sha256(filePath) {
|
|
255
|
+
return (0, node_crypto.createHash)("sha256").update((0, node_fs.readFileSync)(filePath)).digest("hex");
|
|
256
|
+
}
|
|
257
|
+
async function downloadFile(url, destination) {
|
|
258
|
+
const response = await fetch(url);
|
|
259
|
+
if (!response.ok) throw new Error(`Failed to download ${url}: ${response.status} ${response.statusText}`);
|
|
260
|
+
(0, node_fs.writeFileSync)(destination, new Uint8Array(await response.arrayBuffer()));
|
|
261
|
+
}
|
|
262
|
+
async function downloadExpectedSha256(url) {
|
|
263
|
+
const response = await fetch(`${url}.sha256`);
|
|
264
|
+
if (!response.ok) return;
|
|
265
|
+
return (await response.text()).trim().split(/\s+/)[0];
|
|
266
|
+
}
|
|
267
|
+
async function downloadRuntimeArtifact() {
|
|
268
|
+
if (process.platform !== "darwin") throw new Error("Bleam runtime artifacts are currently only available on macOS.");
|
|
269
|
+
const cacheRoot = runtimeCacheRoot();
|
|
270
|
+
const cachedAppPath = node_path.default.join(cacheRoot, "Bleam.app");
|
|
271
|
+
if ((0, node_fs.existsSync)(cachedAppPath)) return {
|
|
272
|
+
appPath: cachedAppPath,
|
|
273
|
+
version: runtimeVersion,
|
|
274
|
+
platform: runtimePlatform
|
|
275
|
+
};
|
|
276
|
+
(0, node_fs.mkdirSync)(cacheRoot, { recursive: true });
|
|
277
|
+
const archiveUrl = runtimeArchiveUrl();
|
|
278
|
+
const archivePath = node_path.default.join(cacheRoot, runtimeArchiveName());
|
|
279
|
+
const extractRoot = node_path.default.join(cacheRoot, "extract");
|
|
280
|
+
await downloadFile(archiveUrl, archivePath);
|
|
281
|
+
const expectedSha256 = await downloadExpectedSha256(archiveUrl);
|
|
282
|
+
if (expectedSha256 && sha256(archivePath) !== expectedSha256) {
|
|
283
|
+
(0, node_fs.rmSync)(archivePath, { force: true });
|
|
284
|
+
throw new Error(`Runtime artifact checksum mismatch: ${archiveUrl}`);
|
|
285
|
+
}
|
|
286
|
+
(0, node_fs.rmSync)(extractRoot, {
|
|
287
|
+
recursive: true,
|
|
288
|
+
force: true
|
|
289
|
+
});
|
|
290
|
+
(0, node_fs.mkdirSync)(extractRoot, { recursive: true });
|
|
291
|
+
(0, node_child_process.execFileSync)("ditto", [
|
|
292
|
+
"-x",
|
|
293
|
+
"-k",
|
|
294
|
+
archivePath,
|
|
295
|
+
extractRoot
|
|
296
|
+
], { stdio: "ignore" });
|
|
297
|
+
const extractedAppPath = node_path.default.join(extractRoot, "Bleam.app");
|
|
298
|
+
if (!(0, node_fs.existsSync)(extractedAppPath)) throw new Error(`Runtime archive did not contain Bleam.app: ${archiveUrl}`);
|
|
299
|
+
(0, node_fs.rmSync)(cachedAppPath, {
|
|
300
|
+
recursive: true,
|
|
301
|
+
force: true
|
|
302
|
+
});
|
|
303
|
+
(0, node_fs.cpSync)(extractedAppPath, cachedAppPath, { recursive: true });
|
|
304
|
+
(0, node_fs.rmSync)(extractRoot, {
|
|
305
|
+
recursive: true,
|
|
306
|
+
force: true
|
|
307
|
+
});
|
|
308
|
+
return {
|
|
309
|
+
appPath: cachedAppPath,
|
|
310
|
+
version: runtimeVersion,
|
|
311
|
+
platform: runtimePlatform
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
async function resolveRuntimeArtifact() {
|
|
315
|
+
const overrideAppPath = process.env.BLEAM_RUNTIME_APP;
|
|
316
|
+
if (overrideAppPath) {
|
|
317
|
+
const appPath = node_path.default.resolve(overrideAppPath);
|
|
318
|
+
if (!(0, node_fs.existsSync)(appPath)) throw new Error(`BLEAM_RUNTIME_APP does not exist: ${appPath}`);
|
|
319
|
+
return {
|
|
320
|
+
appPath,
|
|
321
|
+
version: runtimeVersion,
|
|
322
|
+
platform: runtimePlatform
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
const localAppPath = localDevelopmentRuntimeAppPath();
|
|
326
|
+
if ((0, node_fs.existsSync)(localAppPath)) return {
|
|
327
|
+
appPath: localAppPath,
|
|
328
|
+
version: runtimeVersion,
|
|
329
|
+
platform: runtimePlatform
|
|
330
|
+
};
|
|
331
|
+
return downloadRuntimeArtifact();
|
|
332
|
+
}
|
|
333
|
+
function copyRuntimeClient(projectRoot, runtime) {
|
|
334
|
+
const clientAppPath = node_path.default.join(projectRoot, ".bleam", "client", "Bleam.app");
|
|
335
|
+
(0, node_fs.rmSync)(clientAppPath, {
|
|
336
|
+
recursive: true,
|
|
337
|
+
force: true
|
|
338
|
+
});
|
|
339
|
+
(0, node_fs.mkdirSync)(node_path.default.dirname(clientAppPath), { recursive: true });
|
|
340
|
+
(0, node_fs.cpSync)(runtime.appPath, clientAppPath, { recursive: true });
|
|
341
|
+
return clientAppPath;
|
|
342
|
+
}
|
|
343
|
+
function waitForDevServer(port, timeoutMs = 12e4) {
|
|
344
|
+
return new Promise((resolve, reject) => {
|
|
345
|
+
const startedAt = Date.now();
|
|
346
|
+
const poll = () => {
|
|
347
|
+
const req = node_http.default.get(`http://localhost:${port}/status`, (res) => {
|
|
348
|
+
let data = "";
|
|
349
|
+
res.on("data", (chunk) => {
|
|
350
|
+
data += chunk.toString();
|
|
351
|
+
});
|
|
352
|
+
res.on("end", () => {
|
|
353
|
+
if (data.includes("packager-status:running")) {
|
|
354
|
+
resolve();
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
retry();
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
req.on("error", retry);
|
|
361
|
+
req.setTimeout(2e3, () => {
|
|
362
|
+
req.destroy();
|
|
363
|
+
retry();
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
const retry = () => {
|
|
367
|
+
if (Date.now() - startedAt > timeoutMs) {
|
|
368
|
+
reject(/* @__PURE__ */ new Error(`Bleam dev server did not start within ${timeoutMs / 1e3}s`));
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
setTimeout(poll, 500);
|
|
372
|
+
};
|
|
373
|
+
poll();
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
function isBleamManifest(value) {
|
|
377
|
+
const manifest = value && typeof value === "object" ? value : {};
|
|
378
|
+
return typeof manifest.name === "string" && typeof manifest.bundleUrl === "string" && manifest.platform === "macos" && manifest.dev === true;
|
|
379
|
+
}
|
|
380
|
+
async function readDevManifest(origin, timeoutMs = 3e4) {
|
|
381
|
+
const manifestUrl = `${origin}/bleam/manifest.json`;
|
|
382
|
+
const startedAt = Date.now();
|
|
383
|
+
while (Date.now() - startedAt <= timeoutMs) {
|
|
384
|
+
try {
|
|
385
|
+
const response = await fetch(manifestUrl, { cache: "no-store" });
|
|
386
|
+
const value = await response.json();
|
|
387
|
+
if (response.ok && isBleamManifest(value)) return value;
|
|
388
|
+
} catch {}
|
|
389
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
390
|
+
}
|
|
391
|
+
throw new Error(`Bleam manifest did not become available: ${manifestUrl}`);
|
|
392
|
+
}
|
|
393
|
+
function openRuntimeClient(appPath, projectConfigPath, manifest) {
|
|
394
|
+
(0, node_child_process.spawn)("open", [
|
|
395
|
+
appPath,
|
|
396
|
+
"--args",
|
|
397
|
+
"--bleam-project-config",
|
|
398
|
+
projectConfigPath,
|
|
399
|
+
"--bleam-bundle-url",
|
|
400
|
+
manifest.bundleUrl,
|
|
401
|
+
"--bleam-title",
|
|
402
|
+
manifest.name
|
|
403
|
+
], {
|
|
404
|
+
detached: true,
|
|
405
|
+
stdio: "ignore"
|
|
406
|
+
}).unref();
|
|
407
|
+
}
|
|
408
|
+
async function startDevServer(options) {
|
|
409
|
+
const config = readProjectConfig(options);
|
|
410
|
+
const runtime = await resolveRuntimeArtifact();
|
|
411
|
+
const clientAppPath = copyRuntimeClient(options.projectRoot, runtime);
|
|
412
|
+
const workspaceRoot = createDevWorkspace(options.projectRoot, config);
|
|
413
|
+
const origin = `http://localhost:${options.port}`;
|
|
414
|
+
const projectConfigPath = writeProjectRuntimeConfig(options.projectRoot, config, origin);
|
|
415
|
+
const child = (0, node_child_process.spawn)(process.execPath, [
|
|
416
|
+
require$1.resolve("expo/bin/cli"),
|
|
417
|
+
"start",
|
|
418
|
+
workspaceRoot,
|
|
419
|
+
"--localhost",
|
|
420
|
+
"--port",
|
|
421
|
+
String(options.port)
|
|
422
|
+
], {
|
|
423
|
+
stdio: "inherit",
|
|
424
|
+
env: {
|
|
425
|
+
...process.env,
|
|
426
|
+
BLEAM_DEV: "1",
|
|
427
|
+
BLEAM_PROJECT_ROOT: options.projectRoot,
|
|
428
|
+
BLEAM_DEV_NAME: config.name,
|
|
429
|
+
BLEAM_DEV_ORIGIN: origin,
|
|
430
|
+
BLEAM_DEV_PORT: String(options.port),
|
|
431
|
+
BLEAM_DEV_RUNTIME_VERSION: config.runtimeVersion,
|
|
432
|
+
BLEAM_DEV_SDK_VERSION: config.sdkVersion,
|
|
433
|
+
NODE_PATH: [
|
|
434
|
+
node_path.default.join(options.projectRoot, "node_modules"),
|
|
435
|
+
node_path.default.join(packageRoot, "node_modules"),
|
|
436
|
+
node_path.default.dirname(node_path.default.dirname(require$1.resolve("expo/package.json"))),
|
|
437
|
+
node_path.default.dirname(node_path.default.dirname(require$1.resolve("react/package.json"))),
|
|
438
|
+
node_path.default.dirname(node_path.default.dirname(require$1.resolve("react-native/package.json"))),
|
|
439
|
+
process.env.NODE_PATH
|
|
440
|
+
].filter(Boolean).join(node_path.default.delimiter)
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
const stop = (signal) => {
|
|
444
|
+
child.kill(signal);
|
|
445
|
+
};
|
|
446
|
+
process.on("SIGINT", () => stop("SIGINT"));
|
|
447
|
+
process.on("SIGTERM", () => stop("SIGTERM"));
|
|
448
|
+
child.on("exit", (code) => process.exit(code ?? 0));
|
|
449
|
+
await waitForDevServer(options.port);
|
|
450
|
+
const manifest = await readDevManifest(origin);
|
|
451
|
+
if (process.env.BLEAM_NO_OPEN !== "1") openRuntimeClient(clientAppPath, projectConfigPath, manifest);
|
|
452
|
+
}
|
|
453
|
+
async function main(argv = process.argv.slice(2)) {
|
|
454
|
+
const [command, ...args] = argv;
|
|
455
|
+
if (!command || command === "--help" || command === "-h") {
|
|
456
|
+
printUsage();
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (command === "new") {
|
|
460
|
+
const options = parseNewOptions(args);
|
|
461
|
+
createNewProject(options);
|
|
462
|
+
if (options.run) await startDevServer({
|
|
463
|
+
projectRoot: options.projectRoot,
|
|
464
|
+
port: 8081
|
|
465
|
+
});
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (command === "dev") {
|
|
469
|
+
await startDevServer(parseDevOptions(args));
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
throw new Error(`Unknown command: ${command}`);
|
|
473
|
+
}
|
|
474
|
+
main().catch((error) => {
|
|
475
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
476
|
+
process.exit(1);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
//#endregion
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|