Skip to content

Commit

Permalink
Rewrite copy shared script (#609)
Browse files Browse the repository at this point in the history
This PR rewrites `copy.sh` script that was used to copy shared
components to test-apps.
The rewrite is necessary to work on windows without resulting to using
tools that might not be present on user machine.
  • Loading branch information
filip131311 authored Oct 11, 2024
1 parent 7225cf4 commit f9fcdac
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 32 deletions.
2 changes: 1 addition & 1 deletion test-apps/expo-50-dev-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web",
"copy-shared": "../shared/copy.sh bare ./shared"
"copy-shared": "node ../shared/copy.js bare ./shared"
},
"dependencies": {
"@types/react": "~18.2.45",
Expand Down
2 changes: 1 addition & 1 deletion test-apps/expo-51-dev-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"web": "expo start --web",
"test": "jest --watchAll",
"lint": "expo lint",
"copy-shared": "../shared/copy.sh expo-router ./shared"
"copy-shared": "node ../shared/copy.js expo-router ./shared"
},
"jest": {
"preset": "jest-expo"
Expand Down
2 changes: 1 addition & 1 deletion test-apps/expo-51/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"web": "expo start --web",
"test": "jest --watchAll",
"lint": "expo lint",
"copy-shared": "../shared/copy.sh expo-router ./shared"
"copy-shared": "node ../shared/copy.js expo-router ./shared"
},
"jest": {
"preset": "jest-expo"
Expand Down
2 changes: 1 addition & 1 deletion test-apps/expo-go/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"copy-shared": "../shared/copy.sh bare ./shared"
"copy-shared": "node ../shared/copy.js bare ./shared"
},
"dependencies": {
"expo": "~50.0.14",
Expand Down
2 changes: 1 addition & 1 deletion test-apps/expo-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"web": "expo start --web",
"storybook-generate": "sb-rn-get-stories",
"storybook": "STORYBOOK_ENABLED='true' expo start",
"copy-shared": "../shared/copy.sh expo-router ./shared"
"copy-shared": "node ../shared/copy.js expo-router ./shared"
},
"dependencies": {
"@types/react": "~18.2.79",
Expand Down
2 changes: 1 addition & 1 deletion test-apps/react-native-73/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type-check": "tsc",
"test:report": "jest --collectCoverage --coverageDirectory=\"./coverage\" --ci --reporters=default --reporters=jest-junit --coverage",
"pod-install": "cd ios && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install && cd ..",
"copy-shared": "../shared/copy.sh bare ./shared"
"copy-shared": "node ../shared/copy.js bare ./shared"
},
"dependencies": {
"@react-native-masked-view/masked-view": "^0.3.0",
Expand Down
2 changes: 1 addition & 1 deletion test-apps/react-native-74/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "eslint .",
"start": "react-native start",
"test": "jest",
"copy-shared": "../shared/copy.sh bare ./shared"
"copy-shared": "node ../shared/copy.js bare ./shared"
},
"dependencies": {
"radon-ide": "^0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion test-apps/react-native-75/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "eslint .",
"start": "react-native start",
"test": "jest",
"copy-shared": "../shared/copy.sh bare ./shared"
"copy-shared": "node ../shared/copy.js bare ./shared"
},
"dependencies": {
"radon-ide": "^0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion test-apps/react-native-76/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "eslint .",
"start": "react-native start",
"test": "jest",
"copy-shared": "../shared/copy.sh bare ./shared"
"copy-shared": "node ../shared/copy.js bare ./shared"
},
"dependencies": {
"radon-ide": "^0.0.1",
Expand Down
35 changes: 35 additions & 0 deletions test-apps/shared/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

function showUsage() {
console.log("Copies shared code to a destination directory. Shared code has navigation directory, integrating with expo-router. To copy it, use 'expo-router' as the first argument. Otherwise, use 'bare'.");
console.log("Example: ./copy.js expo-router /src/shared");
console.log("");
console.log(`Usage: ${path.basename(process.argv[1])} {bare | expo-router} <destination>`);
process.exit(1);
}

if (process.argv.length !== 4 || !["bare", "expo-router"].includes(process.argv[2])) {
showUsage();
}

const mode = process.argv[2];
const destination = process.argv[3];
const scriptDir = path.dirname(__filename);

if (fs.existsSync(destination)) {
fs.rmSync(destination, { recursive: true, force: true });
}
fs.mkdirSync(destination, { recursive: true });

const sourceDir = path.join(scriptDir, 'src');
execSync(`cp -R ${sourceDir}/ ${destination}`);

// Remove the "navigation" directory is only testable in expo-router setups so we need to remove it
if (mode === "bare") {
const navigationDir = path.join(destination, 'navigation');
if (fs.existsSync(navigationDir)) {
fs.rmSync(navigationDir, { recursive: true, force: true });
}
}
23 changes: 0 additions & 23 deletions test-apps/shared/copy.sh

This file was deleted.

0 comments on commit f9fcdac

Please sign in to comment.