Skip to content

Commit afb5bff

Browse files
Add Windows compatibility in 4 node scripts. (wix#6015)
Added windows compatibility to build scripts. To run the packager on windows, use: `npm run start-windows` Co-authored-by: Guy Carmeli <guyca@users.noreply.github.com>
1 parent 7d6029f commit afb5bff

File tree

6 files changed

+53
-5
lines changed

6 files changed

+53
-5
lines changed

docs/docs/WorkingLocally.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ No PR will be accepted without adequate test coverage.
5555
| `npm run build` | compiles TypeScript sources `./lib/src` into javascript `./lib/dist` |
5656
| `npm run clean` | cleans all build directories, stops packager, fixes flakiness by removing watchman cache, etc. |
5757
| `npm run start` | starts the react-native packager for local debugging |
58+
| `npm run start-windows` | starts the react-native packager for local debugging [Windows only] |
5859
| `npm run xcode` | for convenience, opens xcode in this project |
5960
| `npm run install-android` | builds playground debug/release version and installs on running android devices/emulators. <br> **Options:** `-- --release` |
6061
| `npm run uninstall-android` | uninstalls playground from running android devices/simulators |

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"main": "lib/dist/index.js",
2020
"typings": "lib/dist/index.d.ts",
2121
"scripts": {
22-
"build": "rm -rf ./lib/dist && tsc",
23-
"watch": "rm -rf ./lib/dist && tsc --watch",
22+
"build": "node ./scripts/build",
23+
"watch": "node ./scripts/watch",
2424
"xcode": "open playground/ios/playground.xcworkspace",
2525
"install-android": "node ./scripts/install-android",
2626
"uninstall-android": "cd playground/android && ./gradlew uninstallAll",
@@ -159,4 +159,4 @@
159159
}
160160
}
161161
}
162-
}
162+
}

scripts/build.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const exec = require('shell-utils').exec;
2+
3+
const isWindows = process.platform === 'win32' ? true : false;
4+
5+
run();
6+
7+
function run() {
8+
if (isWindows) {
9+
exec.execSync(`del /F /S /Q lib\\dist`);
10+
exec.execSync(`tsc`);
11+
} else {
12+
exec.execSync(`rm -rf ./lib/dist && tsc`);
13+
}
14+
}

scripts/clean.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const exec = require('shell-utils').exec;
22

3-
run();
3+
const isWindows = process.platform === 'win32' ? true : false;
4+
5+
if (isWindows) runWin32();
6+
else run();
47

58
function run() {
69
exec.killPort(8081);
@@ -14,3 +17,13 @@ function run() {
1417
exec.execSync(`rm -rf playground/android/app/build`);
1518
exec.execSync(`rm -rf lib/dist`);
1619
}
20+
21+
function runWin32() {
22+
exec.execSync(`adb reverse tcp:8081 tcp:8081 || true`);
23+
24+
exec.execSync('del /F /S /Q lib\\android\\build');
25+
exec.execSync('del /F /S /Q lib\\android\\app\\build');
26+
exec.execSync('del /F /S /Q playground\\android\\build');
27+
exec.execSync('del /F /S /Q playground\\android\\app\\build');
28+
exec.execSync('del /F /S /Q lib\\dist');
29+
}

scripts/install-android.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ const exec = require('shell-utils').exec;
33

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

6+
const isWindows = process.platform === 'win32' ? true : false;
7+
68
run();
79

810
function run() {
9-
exec.execSync(`cd playground/android && ./gradlew ${release ? 'installRelease' : 'installDebug'}`);
11+
if (isWindows) {
12+
exec.execSync(`cd playground/android && gradlew ${release ? 'installRelease' : 'installDebug'}`);
13+
} else {
14+
exec.execSync(`cd playground/android && ./gradlew ${release ? 'installRelease' : 'installDebug'}`);
15+
}
1016
}

scripts/watch.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const exec = require('shell-utils').exec;
2+
3+
const isWindows = process.platform === 'win32' ? true : false;
4+
5+
run();
6+
7+
function run() {
8+
if (isWindows) {
9+
exec.execSync(`del /F /S /Q lib\\dist`);
10+
exec.execSync(`tsc --watch`);
11+
} else {
12+
exec.execSync(`rm -rf ./lib/dist && tsc --watch`);
13+
}
14+
}

0 commit comments

Comments
 (0)