Browse Source

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 <guyca@users.noreply.github.com>
Maycon Mesquita 4 years ago
parent
commit
afb5bffb49
No account linked to committer's email address
6 changed files with 53 additions and 5 deletions
  1. 1
    0
      docs/docs/WorkingLocally.md
  2. 3
    3
      package.json
  3. 14
    0
      scripts/build.js
  4. 14
    1
      scripts/clean.js
  5. 7
    1
      scripts/install-android.js
  6. 14
    0
      scripts/watch.js

+ 1
- 0
docs/docs/WorkingLocally.md View File

55
 | `npm run build` | compiles TypeScript sources `./lib/src` into javascript `./lib/dist` |
55
 | `npm run build` | compiles TypeScript sources `./lib/src` into javascript `./lib/dist` |
56
 | `npm run clean` | cleans all build directories, stops packager, fixes flakiness by removing watchman cache, etc. |
56
 | `npm run clean` | cleans all build directories, stops packager, fixes flakiness by removing watchman cache, etc. |
57
 | `npm run start` | starts the react-native packager for local debugging |
57
 | `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] |
58
 | `npm run xcode` | for convenience, opens xcode in this project |
59
 | `npm run xcode` | for convenience, opens xcode in this project |
59
 | `npm run install-android`  |  builds playground debug/release version and installs on running android devices/emulators. <br> **Options:** `-- --release` |
60
 | `npm run install-android`  |  builds playground debug/release version and installs on running android devices/emulators. <br> **Options:** `-- --release` |
60
 | `npm run uninstall-android` | uninstalls playground from running android devices/simulators |
61
 | `npm run uninstall-android` | uninstalls playground from running android devices/simulators |

+ 3
- 3
package.json View File

19
   "main": "lib/dist/index.js",
19
   "main": "lib/dist/index.js",
20
   "typings": "lib/dist/index.d.ts",
20
   "typings": "lib/dist/index.d.ts",
21
   "scripts": {
21
   "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",
24
     "xcode": "open playground/ios/playground.xcworkspace",
24
     "xcode": "open playground/ios/playground.xcworkspace",
25
     "install-android": "node ./scripts/install-android",
25
     "install-android": "node ./scripts/install-android",
26
     "uninstall-android": "cd playground/android && ./gradlew uninstallAll",
26
     "uninstall-android": "cd playground/android && ./gradlew uninstallAll",
159
       }
159
       }
160
     }
160
     }
161
   }
161
   }
162
-}
162
+}

+ 14
- 0
scripts/build.js View File

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
+}

+ 14
- 1
scripts/clean.js View File

1
 const exec = require('shell-utils').exec;
1
 const exec = require('shell-utils').exec;
2
 
2
 
3
-run();
3
+const isWindows = process.platform === 'win32' ? true : false;
4
+
5
+if (isWindows) runWin32();
6
+else run();
4
 
7
 
5
 function run() {
8
 function run() {
6
   exec.killPort(8081);
9
   exec.killPort(8081);
14
   exec.execSync(`rm -rf playground/android/app/build`);
17
   exec.execSync(`rm -rf playground/android/app/build`);
15
   exec.execSync(`rm -rf lib/dist`);
18
   exec.execSync(`rm -rf lib/dist`);
16
 }
19
 }
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
+}

+ 7
- 1
scripts/install-android.js View File

3
 
3
 
4
 const release = includes(process.argv, '--release');
4
 const release = includes(process.argv, '--release');
5
 
5
 
6
+const isWindows = process.platform === 'win32' ? true : false;
7
+
6
 run();
8
 run();
7
 
9
 
8
 function run() {
10
 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
+  }
10
 }
16
 }

+ 14
- 0
scripts/watch.js View File

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
+}