Skip to content

Commit

Permalink
Add Windows compatibility in 4 node scripts. (#6015)
Browse files Browse the repository at this point in the history
Added windows compatibility to build scripts. To run the packager on windows, use: `npm run start-windows`

Co-authored-by: Guy Carmeli <[email protected]>
  • Loading branch information
mayconmesquita and guyca authored Mar 11, 2020
1 parent 7d6029f commit afb5bff
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/docs/WorkingLocally.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ No PR will be accepted without adequate test coverage.
| `npm run build` | compiles TypeScript sources `./lib/src` into javascript `./lib/dist` |
| `npm run clean` | cleans all build directories, stops packager, fixes flakiness by removing watchman cache, etc. |
| `npm run start` | starts the react-native packager for local debugging |
| `npm run start-windows` | starts the react-native packager for local debugging [Windows only] |
| `npm run xcode` | for convenience, opens xcode in this project |
| `npm run install-android` | builds playground debug/release version and installs on running android devices/emulators. <br> **Options:** `-- --release` |
| `npm run uninstall-android` | uninstalls playground from running android devices/simulators |
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"main": "lib/dist/index.js",
"typings": "lib/dist/index.d.ts",
"scripts": {
"build": "rm -rf ./lib/dist && tsc",
"watch": "rm -rf ./lib/dist && tsc --watch",
"build": "node ./scripts/build",
"watch": "node ./scripts/watch",
"xcode": "open playground/ios/playground.xcworkspace",
"install-android": "node ./scripts/install-android",
"uninstall-android": "cd playground/android && ./gradlew uninstallAll",
Expand Down Expand Up @@ -159,4 +159,4 @@
}
}
}
}
}
14 changes: 14 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const exec = require('shell-utils').exec;

const isWindows = process.platform === 'win32' ? true : false;

run();

function run() {
if (isWindows) {
exec.execSync(`del /F /S /Q lib\\dist`);
exec.execSync(`tsc`);
} else {
exec.execSync(`rm -rf ./lib/dist && tsc`);
}
}
15 changes: 14 additions & 1 deletion scripts/clean.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const exec = require('shell-utils').exec;

run();
const isWindows = process.platform === 'win32' ? true : false;

if (isWindows) runWin32();
else run();

function run() {
exec.killPort(8081);
Expand All @@ -14,3 +17,13 @@ function run() {
exec.execSync(`rm -rf playground/android/app/build`);
exec.execSync(`rm -rf lib/dist`);
}

function runWin32() {
exec.execSync(`adb reverse tcp:8081 tcp:8081 || true`);

exec.execSync('del /F /S /Q lib\\android\\build');
exec.execSync('del /F /S /Q lib\\android\\app\\build');
exec.execSync('del /F /S /Q playground\\android\\build');
exec.execSync('del /F /S /Q playground\\android\\app\\build');
exec.execSync('del /F /S /Q lib\\dist');
}
8 changes: 7 additions & 1 deletion scripts/install-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ const exec = require('shell-utils').exec;

const release = includes(process.argv, '--release');

const isWindows = process.platform === 'win32' ? true : false;

run();

function run() {
exec.execSync(`cd playground/android && ./gradlew ${release ? 'installRelease' : 'installDebug'}`);
if (isWindows) {
exec.execSync(`cd playground/android && gradlew ${release ? 'installRelease' : 'installDebug'}`);
} else {
exec.execSync(`cd playground/android && ./gradlew ${release ? 'installRelease' : 'installDebug'}`);
}
}
14 changes: 14 additions & 0 deletions scripts/watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const exec = require('shell-utils').exec;

const isWindows = process.platform === 'win32' ? true : false;

run();

function run() {
if (isWindows) {
exec.execSync(`del /F /S /Q lib\\dist`);
exec.execSync(`tsc --watch`);
} else {
exec.execSync(`rm -rf ./lib/dist && tsc --watch`);
}
}

0 comments on commit afb5bff

Please sign in to comment.