From afb5bffb49b9e8c670419aaacedf10f65cf82fd2 Mon Sep 17 00:00:00 2001 From: Maycon Mesquita <46308804+mayconmesquita@users.noreply.github.com> Date: Wed, 11 Mar 2020 06:13:47 -0300 Subject: [PATCH] Add Windows compatibility in 4 node scripts. (#6015) Added windows compatibility to build scripts. To run the packager on windows, use: `npm run start-windows` Co-authored-by: Guy Carmeli --- docs/docs/WorkingLocally.md | 1 + package.json | 6 +++--- scripts/build.js | 14 ++++++++++++++ scripts/clean.js | 15 ++++++++++++++- scripts/install-android.js | 8 +++++++- scripts/watch.js | 14 ++++++++++++++ 6 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 scripts/build.js create mode 100644 scripts/watch.js diff --git a/docs/docs/WorkingLocally.md b/docs/docs/WorkingLocally.md index 612500c7be7..ae3ffdc7e7f 100644 --- a/docs/docs/WorkingLocally.md +++ b/docs/docs/WorkingLocally.md @@ -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.
**Options:** `-- --release` | | `npm run uninstall-android` | uninstalls playground from running android devices/simulators | diff --git a/package.json b/package.json index 5b9eb59570a..e7718856e4a 100644 --- a/package.json +++ b/package.json @@ -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", @@ -159,4 +159,4 @@ } } } -} \ No newline at end of file +} diff --git a/scripts/build.js b/scripts/build.js new file mode 100644 index 00000000000..c4da0275d25 --- /dev/null +++ b/scripts/build.js @@ -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`); + } +} \ No newline at end of file diff --git a/scripts/clean.js b/scripts/clean.js index 758a914816f..d1495169227 100644 --- a/scripts/clean.js +++ b/scripts/clean.js @@ -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); @@ -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'); +} diff --git a/scripts/install-android.js b/scripts/install-android.js index 86c8a7265a4..234a51427b5 100644 --- a/scripts/install-android.js +++ b/scripts/install-android.js @@ -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'}`); + } } diff --git a/scripts/watch.js b/scripts/watch.js new file mode 100644 index 00000000000..c7787ecdd4e --- /dev/null +++ b/scripts/watch.js @@ -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`); + } +} \ No newline at end of file