Skip to content

Commit 723f7b9

Browse files
committed
Patch macos app with scripts and source files
1 parent 18c9857 commit 723f7b9

2 files changed

Lines changed: 91 additions & 19 deletions

File tree

package-lock.json

Lines changed: 14 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/init-macos-test-app.ts

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import assert from "node:assert/strict";
22
import cp from "node:child_process";
33
import fs from "node:fs";
44
import path from "node:path";
5+
import { readPackage } from "read-pkg";
56

67
const REACT_NATIVE_VERSION = "0.79.6";
78
const ROOT_PATH = path.join(import.meta.dirname, "..");
89
const APP_PATH = path.join(ROOT_PATH, "apps", "macos-test-app");
9-
const HOST_PACKAGE_PATH = path.join(ROOT_PATH, "packages", "host");
10+
const OTHER_APP_PATH = path.join(ROOT_PATH, "apps", "test-app");
1011

1112
function exec(command: string, args: string[], options: cp.SpawnOptions = {}) {
1213
const { status } = cp.spawnSync(command, args, {
@@ -50,6 +51,63 @@ async function initializeReactNativeTemplate() {
5051
}
5152
}
5253

54+
async function patchPackageJson() {
55+
console.log("Patching package.json scripts");
56+
const packageJson = await readPackage({ cwd: APP_PATH });
57+
const otherPackageJson = await readPackage({ cwd: OTHER_APP_PATH });
58+
59+
packageJson.scripts = {
60+
...packageJson.scripts,
61+
metro: "react-native start --reset-cache --no-interactive",
62+
"mocha-and-metro": "mocha-remote --exit-on-error -- node --run metro",
63+
premacos: "killall 'MacOSTestApp' || true",
64+
macos: "react-native run-macos --no-packager",
65+
test: "mocha-remote --exit-on-error -- concurrently --passthrough-arguments --kill-others-on-fail npm:metro 'npm:macos -- {@}' --",
66+
"test:allTests": "MOCHA_REMOTE_CONTEXT=allTests node --run test:ios -- ",
67+
"test:nodeAddonExamples":
68+
"MOCHA_REMOTE_CONTEXT=nodeAddonExamples node --run test -- ",
69+
"test:nodeTests": "MOCHA_REMOTE_CONTEXT=nodeTests node --run test -- ",
70+
"test:ferricExample":
71+
"MOCHA_REMOTE_CONTEXT=ferricExample node --run test -- ",
72+
};
73+
74+
const {
75+
"mocha-remote-cli": mochaRemoteCliSpec,
76+
"mocha-remote-react-native": mochaRemoteReactNativeSpec,
77+
} = otherPackageJson.dependencies || {};
78+
79+
assert(typeof mochaRemoteCliSpec === "string");
80+
assert(typeof mochaRemoteReactNativeSpec === "string");
81+
82+
packageJson.dependencies = {
83+
"@react-native-node-api/node-addon-examples": path.relative(
84+
APP_PATH,
85+
path.join(ROOT_PATH, "packages", "node-addon-examples"),
86+
),
87+
"@react-native-node-api/node-tests": path.relative(
88+
APP_PATH,
89+
path.join(ROOT_PATH, "packages", "node-tests"),
90+
),
91+
"@react-native-node-api/ferric-example": path.relative(
92+
APP_PATH,
93+
path.join(ROOT_PATH, "packages", "ferric-example"),
94+
),
95+
"react-native-node-api": path.relative(
96+
APP_PATH,
97+
path.join(ROOT_PATH, "packages", "host"),
98+
),
99+
["mocha-remote-cli"]: mochaRemoteCliSpec,
100+
["mocha-remote-react-native"]: mochaRemoteReactNativeSpec,
101+
...packageJson.dependencies,
102+
};
103+
104+
await fs.promises.writeFile(
105+
path.join(APP_PATH, "package.json"),
106+
JSON.stringify(packageJson, null, 2),
107+
"utf8",
108+
);
109+
}
110+
53111
function installDependencies() {
54112
console.log("Installing dependencies");
55113
exec(
@@ -60,7 +118,6 @@ function installDependencies() {
60118
"--prefer-offline",
61119
"--install-links",
62120
"react-native-macos-init",
63-
path.relative(APP_PATH, HOST_PACKAGE_PATH),
64121
],
65122
{
66123
cwd: APP_PATH,
@@ -102,8 +159,22 @@ async function patchPodfile() {
102159
await fs.promises.writeFile(podfilePath, podfileContents, "utf8");
103160
}
104161

105-
await deletePreviousApp();
106-
await initializeReactNativeTemplate();
162+
async function copySourceFiles() {
163+
console.log("Copying source files from test-app into macos-test-app:");
164+
const FILE_NAMES = ["App.tsx", "babel.config.js"];
165+
for (const fileName of FILE_NAMES) {
166+
console.log(`↳ ${fileName}`);
167+
await fs.promises.copyFile(
168+
path.join(OTHER_APP_PATH, fileName),
169+
path.join(APP_PATH, fileName),
170+
);
171+
}
172+
}
173+
174+
// await deletePreviousApp();
175+
// await initializeReactNativeTemplate();
176+
await patchPackageJson();
107177
installDependencies();
108-
initializeReactNativeMacOSTemplate();
109-
await patchPodfile();
178+
// initializeReactNativeMacOSTemplate();
179+
// await patchPodfile();
180+
await copySourceFiles();

0 commit comments

Comments
 (0)