@macify/catalyst 0.0.1

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.
@@ -0,0 +1,14 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let expo = require("expo");
3
+
4
+ //#region src/MacifyModule.ts
5
+ var MacifyModule_default = (0, expo.requireNativeModule)("Macify");
6
+
7
+ //#endregion
8
+ //#region src/index.ts
9
+ function hello() {
10
+ return MacifyModule_default.hello();
11
+ }
12
+
13
+ //#endregion
14
+ exports.hello = hello;
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env node
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+
28
+ //#endregion
29
+ let child_process = require("child_process");
30
+ let fs = require("fs");
31
+ let http = require("http");
32
+ http = __toESM(http);
33
+ let path = require("path");
34
+ path = __toESM(path);
35
+
36
+ //#region cli/main.ts
37
+ function getProjectName() {
38
+ const name = findXcodeProj(path.default.resolve(process.cwd(), "ios"));
39
+ if (!name) {
40
+ console.error("Error: Could not find .xcodeproj in ios/");
41
+ process.exit(1);
42
+ }
43
+ return name;
44
+ }
45
+ function findXcodeProj(dir) {
46
+ try {
47
+ const xcodeproj = (0, fs.readdirSync)(dir).find((file) => file.endsWith(".xcodeproj"));
48
+ return xcodeproj ? xcodeproj.replace(".xcodeproj", "") : null;
49
+ } catch {
50
+ return null;
51
+ }
52
+ }
53
+ function parseArgs(argv) {
54
+ const clean = argv.includes("--clean") || argv.includes("-c");
55
+ return {
56
+ command: argv.find((arg) => !arg.startsWith("-")),
57
+ clean
58
+ };
59
+ }
60
+ /**
61
+ * Poll Metro's health endpoint until it responds.
62
+ * Resolves once Metro is ready, rejects on timeout.
63
+ */
64
+ function waitForMetro(port = 8081, timeoutMs = 12e4, intervalMs = 500) {
65
+ return new Promise((resolve, reject) => {
66
+ const start = Date.now();
67
+ const poll = () => {
68
+ const req = http.default.get(`http://localhost:${port}/status`, (res) => {
69
+ let data = "";
70
+ res.on("data", (chunk) => data += chunk);
71
+ res.on("end", () => {
72
+ if (data.includes("packager-status:running")) resolve();
73
+ else scheduleRetry();
74
+ });
75
+ });
76
+ req.on("error", () => {
77
+ scheduleRetry();
78
+ });
79
+ req.setTimeout(2e3, () => {
80
+ req.destroy();
81
+ scheduleRetry();
82
+ });
83
+ };
84
+ const scheduleRetry = () => {
85
+ if (Date.now() - start > timeoutMs) {
86
+ reject(/* @__PURE__ */ new Error(`Metro did not start within ${timeoutMs / 1e3}s`));
87
+ return;
88
+ }
89
+ setTimeout(poll, intervalMs);
90
+ };
91
+ poll();
92
+ });
93
+ }
94
+ /**
95
+ * Run xcodebuild for Mac Catalyst. Blocks until complete.
96
+ */
97
+ function buildApp(projectName) {
98
+ const resolveCmd = [
99
+ "xcodebuild",
100
+ `-workspace ios/${projectName}.xcworkspace`,
101
+ `-scheme ${projectName}`,
102
+ "-resolvePackageDependencies",
103
+ "-clonedSourcePackagesDirPath ios/build/SourcePackages"
104
+ ].join(" ");
105
+ console.log("\n\x1B[36m▸ Resolving package dependencies...\x1B[0m\n");
106
+ (0, child_process.execSync)(resolveCmd, { stdio: "inherit" });
107
+ const cmd = [
108
+ "xcodebuild",
109
+ `-workspace ios/${projectName}.xcworkspace`,
110
+ `-scheme ${projectName}`,
111
+ "-configuration Debug",
112
+ "'-destination platform=macOS,arch=arm64,variant=Mac Catalyst'",
113
+ "-derivedDataPath ios/build",
114
+ "-clonedSourcePackagesDirPath ios/build/SourcePackages",
115
+ "build"
116
+ ].join(" ");
117
+ console.log("\n\x1B[36m▸ Building for Mac Catalyst...\x1B[0m\n");
118
+ (0, child_process.execSync)(cmd, { stdio: "inherit" });
119
+ console.log("\n\x1B[32m✔ Build complete\x1B[0m\n");
120
+ }
121
+ /**
122
+ * Spawn Metro (expo start) with full TTY passthrough.
123
+ * Returns the child process handle.
124
+ */
125
+ function startMetro() {
126
+ console.log("\x1B[36m▸ Starting Metro...\x1B[0m\n");
127
+ return (0, child_process.spawn)("npx", ["expo", "start"], {
128
+ stdio: "inherit",
129
+ shell: true
130
+ });
131
+ }
132
+ /**
133
+ * Cleanup handler: kill Metro and exit.
134
+ */
135
+ function setupCleanup(metro) {
136
+ const cleanup = (signal) => {
137
+ metro.kill(signal);
138
+ process.exit(0);
139
+ };
140
+ process.on("SIGINT", () => cleanup("SIGINT"));
141
+ process.on("SIGTERM", () => cleanup("SIGTERM"));
142
+ metro.on("exit", (code) => {
143
+ process.exit(code ?? 0);
144
+ });
145
+ }
146
+ async function runMac(clean) {
147
+ const projectName = getProjectName();
148
+ const appPath = `./ios/build/Build/Products/Debug-maccatalyst/${projectName}.app`;
149
+ if (clean && (0, fs.existsSync)("./ios/build")) {
150
+ console.log("\x1B[33m▸ Cleaning build directory...\x1B[0m");
151
+ (0, fs.rmSync)("./ios/build", {
152
+ recursive: true,
153
+ force: true
154
+ });
155
+ }
156
+ if (clean || !(0, fs.existsSync)(appPath)) buildApp(projectName);
157
+ else console.log("\x1B[32m▸ Using existing build\x1B[0m");
158
+ setupCleanup(startMetro());
159
+ try {
160
+ await waitForMetro();
161
+ console.log("\n\x1B[36m▸ Opening app...\x1B[0m\n");
162
+ (0, child_process.execSync)(`open "${appPath}"`, { stdio: "inherit" });
163
+ } catch (err) {
164
+ console.error(`\n\x1b[31m✖ ${err instanceof Error ? err.message : err}\x1b[0m`);
165
+ }
166
+ }
167
+ async function main() {
168
+ const { command, clean } = parseArgs(process.argv.slice(2));
169
+ switch (command) {
170
+ case "run:mac":
171
+ await runMac(clean);
172
+ break;
173
+ default:
174
+ console.log("Usage: macify run:mac [--clean | -c]");
175
+ console.log("");
176
+ console.log("Commands:");
177
+ console.log(" run:mac Build and run the app as Mac Catalyst");
178
+ console.log("");
179
+ console.log("Options:");
180
+ console.log(" --clean, -c Clean build directory before building");
181
+ process.exit(command ? 1 : 0);
182
+ }
183
+ }
184
+ main().catch((error) => {
185
+ console.error(`\x1b[31m✖ ${error instanceof Error ? error.message : error}\x1b[0m`);
186
+ process.exit(1);
187
+ });
188
+
189
+ //#endregion
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@macify/catalyst",
3
+ "version": "0.0.1",
4
+ "description": "Mac Catalyst support for Expo and React Native",
5
+ "main": "build/index.cjs",
6
+ "types": "build/index.d.cts",
7
+ "bin": {
8
+ "macify": "./cli/build/main.cjs"
9
+ },
10
+ "license": "MIT",
11
+ "scripts": {
12
+ "build": "tsdown"
13
+ },
14
+ "devDependencies": {
15
+ "@expo/config-plugins": "*",
16
+ "@macify/xcode-types": "workspace:*",
17
+ "tsdown": "*"
18
+ }
19
+ }