Browse Source

start scripts

Daniel Zlotin 7 years ago
parent
commit
12a134e19e
5 changed files with 42 additions and 11 deletions
  1. 1
    1
      .travis.yml
  2. 2
    2
      package.json
  3. 2
    8
      playground/ios/playground/AppDelegate.m
  4. 29
    0
      scripts/start.js
  5. 8
    0
      scripts/test-js.js

+ 1
- 1
.travis.yml View File

@@ -30,7 +30,7 @@ before_cache:
30 30
   - rm -rf $HOME/.gradle/caches/*/plugin-resolution/
31 31
 
32 32
 install:
33
-  - lsof -i :8081
33
+  - netstat -vanp tcp | grep 8081
34 34
   # node
35 35
   - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
36 36
   - export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

+ 2
- 2
package.json View File

@@ -29,8 +29,8 @@
29 29
     "xcode": "open playground/ios/playground.xcodeproj",
30 30
     "install-android": "cd playground/android && ./gradlew installDebug",
31 31
     "uninstall-android": "cd playground/android && ./gradlew uninstallAll",
32
-    "start": "adb reverse tcp:8081 tcp:8081; watchman watch-del-all; node ./node_modules/react-native/local-cli/cli.js start --root=./playground",
33
-    "test-js": "eslint lib/src integration e2e scripts playground/src && BABEL_ENV=test jest --coverage",
32
+    "start": "node ./scripts/start.js",
33
+    "test-js": "node ./scripts/test-js.js",
34 34
     "test-unit-android": "node ./scripts/test.unit.android.js",
35 35
     "test-unit-ios": "node ./scripts/test.unit.ios.js",
36 36
     "test-e2e-android": "node ./scripts/test.e2e.android.js",

+ 2
- 8
playground/ios/playground/AppDelegate.m View File

@@ -3,6 +3,7 @@
3 3
 // **********************************************
4 4
 // *** DON'T MISS: THE NEXT LINE IS IMPORTANT ***
5 5
 // **********************************************
6
+#import <React/RCTBundleURLProvider.h>
6 7
 #import <ReactNativeNavigation/ReactNativeNavigation.h>
7 8
 
8 9
 // IMPORTANT: if you're getting an Xcode error that RCCManager.h isn't found, you've probably ran "npm install"
@@ -14,17 +15,10 @@
14 15
 
15 16
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
16 17
 {
17
-	NSURL *jsCodeLocation;
18
-#ifdef DEBUG
19
-	jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
20
-#else
21
-	jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
22
-#endif
23
-	
24
-	
25 18
 	// **********************************************
26 19
 	// *** DON'T MISS: THIS IS HOW WE BOOTSTRAP *****
27 20
 	// **********************************************
21
+	NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
28 22
 	[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
29 23
 	
30 24
 	/*

+ 29
- 0
scripts/start.js View File

@@ -0,0 +1,29 @@
1
+const exec = require('shell-utils').exec;
2
+
3
+run();
4
+
5
+function run() {
6
+  const port = findPort();
7
+  exec.execSync(`watchman watch-del-all || true`);
8
+  exec.execSync(`adb reverse tcp:${port} tcp:${port} || true`);
9
+  exec.execSync(`node ./node_modules/react-native/local-cli/cli.js start --port=${port} --root=./playground`);
10
+}
11
+
12
+function findPort() {
13
+  let port = 8081;
14
+  if (!process.env.CI) {
15
+    return port;
16
+  }
17
+  while (!isPortOpen(port)) {
18
+    port = Number((Math.random() * 1000).toFixed(0)) + 35000;
19
+  }
20
+  return port;
21
+}
22
+
23
+function isPortOpen(port) {
24
+  try {
25
+    return !exec.execSyncRead(`netstat -vanp tcp | grep ${port}`);
26
+  } catch (e) {
27
+    return true;
28
+  }
29
+}

+ 8
- 0
scripts/test-js.js View File

@@ -0,0 +1,8 @@
1
+const exec = require('shell-utils').exec;
2
+
3
+run();
4
+
5
+function run() {
6
+  exec.execSync(`BABEL_ENV=test eslint lib/src integration e2e scripts playground/src`);
7
+  exec.execSync(`BABEL_ENV=test jest --coverage`);
8
+}