Ver código fonte

Add rnpm link script for #53

Ben Hsieh 8 anos atrás
pai
commit
749a5a528b
1 arquivos alterados com 8 adições e 3 exclusões
  1. 8
    3
      src/scripts/prelink.js

+ 8
- 3
src/scripts/prelink.js Ver arquivo

@@ -9,11 +9,11 @@ if (!hasNecessaryFile) {
9 9
   throw 'RNFetchBlob could not found link Android automatically, some files could not be found.'
10 10
 }
11 11
 
12
-var package = fs.readFileSync(PACKAGE_JSON);
12
+var package = JSON.parse(fs.readFileSync(PACKAGE_JSON));
13 13
 var APP_NAME = package.name;
14 14
 var APPLICATION_MAIN = process.cwd() + '/android/app/src/main/java/com/' + APP_NAME.toLocaleLowerCase() + '/MainApplication.java';
15 15
 
16
-if(!fs.existsSync('APPLICATION_MAIN')) {
16
+if(!fs.existsSync(APPLICATION_MAIN)) {
17 17
   throw 'RNFetchBlob could not found link Android automatically, MainApplication.java not found in path : ' + APPLICATION_MAIN
18 18
 }
19 19
 
@@ -23,7 +23,12 @@ console.log('RNFetchBlob detected app version .. ' + VERSION);
23 23
 if(VERSION >= 0.29) {
24 24
   console.log('RNFetchBlob patching MainApplication.java .. ');
25 25
   var main = fs.readFileSync(APPLICATION_MAIN);
26
-  main = main.replace('new MainReactPackage()', 'new RNFetchBlobPackage(),\n           new MainReactPackage()');
26
+  if(String(main).match('new RNFetchBlobPackage()') !== null) {
27
+    console.log('skipped');
28
+    return
29
+  }
30
+  main = String(main).replace('new MainReactPackage()', 'new RNFetchBlobPackage(),\n           new MainReactPackage()');
31
+  main = String(main).replace('import com.facebook.react.ReactApplication;', 'import com.facebook.react.ReactApplication;\nimport com.RNFetchBlob.RNFetchBlobPackage;')
27 32
   fs.writeFileSync(APPLICATION_MAIN, main);
28 33
   console.log('RNFetchBlob patching MainApplication.java .. ok')
29 34