Skip to content

Commit 7b81cb6

Browse files
authored
Add bootstrap scripts (#120)
* Add a "bootstrap" script to packages * Don't nuke the examples directory skip copying already copied dirs
1 parent d703f8d commit 7b81cb6

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"clean": "tsc --build --clean",
1414
"dev": "tsc --build --watch",
1515
"lint": "eslint .",
16-
"test": "npm run test --workspace react-native-node-api --workspace cmake-rn --workspace gyp-to-cmake --workspace node-addon-examples"
16+
"test": "npm run test --workspace react-native-node-api --workspace cmake-rn --workspace gyp-to-cmake --workspace node-addon-examples",
17+
"bootstrap": "npm run build && npm run bootstrap --workspaces --if-present"
1718
},
1819
"author": {
1920
"name": "Callstack",

packages/host/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"generate-weak-node-api": "tsx scripts/generate-weak-node-api.ts",
4545
"generate-weak-node-api-injector": "tsx scripts/generate-weak-node-api-injector.ts",
4646
"build-weak-node-api": "npm run generate-weak-node-api && cmake-rn --android --apple --no-auto-link --no-weak-node-api-linkage --xcframework-extension --source ./weak-node-api",
47-
"test": "tsx --test --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=spec --test-reporter-destination=stdout src/node/**/*.test.ts src/node/*.test.ts"
47+
"test": "tsx --test --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=spec --test-reporter-destination=stdout src/node/**/*.test.ts src/node/*.test.ts",
48+
"bootstrap": "npm run copy-node-api-headers && npm run generate-weak-node-api-injector && npm run build-weak-node-api"
4849
},
4950
"keywords": [
5051
"react-native",

packages/node-addon-examples/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"build": "tsx scripts/build-examples.mts",
1414
"copy-and-build": "npm run copy-examples && npm run gyp-to-cmake && npm run build",
1515
"verify": "tsx scripts/verify-prebuilds.mts",
16-
"test": "npm run copy-and-build && npm run verify"
16+
"test": "npm run copy-and-build && npm run verify",
17+
"bootstrap": "npm run copy-and-build"
1718
},
1819
"devDependencies": {
1920
"cmake-rn": "*",

packages/node-addon-examples/scripts/copy-examples.mts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ const ALLOW_LIST = [
5151
];
5252

5353
console.log("Copying files to", EXAMPLES_DIR);
54+
5455
// Clean up the destination directory before copying
55-
fs.rmSync(EXAMPLES_DIR, { recursive: true, force: true });
56+
// fs.rmSync(EXAMPLES_DIR, { recursive: true, force: true });
5657

5758
const require = createRequire(import.meta.url);
5859

@@ -67,17 +68,28 @@ let counter = 0;
6768
for (const src of ALLOW_LIST) {
6869
const srcPath = path.join(SRC_DIR, src);
6970
const destPath = path.join(EXAMPLES_DIR, src);
71+
72+
const uniquePackageName = `example-${counter++}`;
73+
74+
if (fs.existsSync(destPath)) {
75+
console.warn(
76+
`Destination path ${destPath} already exists - skipping copy of ${src}.`
77+
);
78+
continue;
79+
}
80+
7081
console.log("Copying from", srcPath, "to", destPath);
7182
fs.cpSync(srcPath, destPath, { recursive: true });
72-
// Delete all package.json files recursively, as they have duplicate names, causing collisions when hashing
83+
// Update package names in package.json files recursively,
84+
// as they have duplicate names, causing collisions when vendored into the host package.
7385
for (const entry of fs.readdirSync(destPath, {
7486
withFileTypes: true,
7587
recursive: true,
7688
})) {
7789
if (entry.name === "package.json") {
7890
const packageJson = readPackageSync({ cwd: entry.parentPath });
7991
// Ensure example package names are unique
80-
packageJson.name = `example-${counter++}`;
92+
packageJson.name = uniquePackageName;
8193
fs.writeFileSync(
8294
path.join(entry.parentPath, entry.name),
8395
JSON.stringify(packageJson, null, 2),

0 commit comments

Comments
 (0)