Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 9935139

Browse files
Fix unnecessary asking of android deployment key with link command (#1538)
1 parent a55a0be commit 9935139

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

package.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,13 @@
4141
},
4242
"rnpm": {
4343
"android": {
44-
"packageInstance": "new CodePush(${androidDeploymentKey}, getApplicationContext(), BuildConfig.DEBUG)"
44+
"packageInstance": "new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG)"
4545
},
4646
"ios": {
4747
"sharedLibraries": [
4848
"libz"
4949
]
5050
},
51-
"params": [
52-
{
53-
"type": "input",
54-
"name": "androidDeploymentKey",
55-
"message": "What is your CodePush deployment key for Android (hit <ENTER> to ignore)"
56-
}
57-
],
5851
"commands": {
5952
"postlink": "node node_modules/react-native-code-push/scripts/postlink/run"
6053
}

scripts/postlink/android/postlink.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var fs = require("fs");
22
var glob = require("glob");
33
var path = require("path");
4+
var inquirer = require('inquirer');
45

56
module.exports = () => {
67

@@ -91,5 +92,29 @@ module.exports = () => {
9192
fs.writeFileSync(buildGradlePath, buildGradleContents);
9293
}
9394

95+
//3. Add deployment key
96+
var stringsResourcesPath = glob.sync("**/strings.xml", ignoreFolders)[0];
97+
if (!stringsResourcesPath) {
98+
return Promise.reject(new Error(`Couldn't find strings.xml. You might need to update it manually.`));
99+
} else {
100+
var stringsResourcesContent = fs.readFileSync(stringsResourcesPath, "utf8");
101+
var deploymentKeyName = "reactNativeCodePush_androidDeploymentKey";
102+
if (~stringsResourcesContent.indexOf(deploymentKeyName)) {
103+
console.log(`${deploymentKeyName} already specified in the strings.xml`);
104+
} else {
105+
return inquirer.prompt({
106+
"type": "input",
107+
"name": "androidDeploymentKey",
108+
"message": "What is your CodePush deployment key for Android (hit <ENTER> to ignore)"
109+
}).then(function(answer) {
110+
var insertAfterString = "<resources>";
111+
var deploymentKeyString = `\t<string moduleConfig="true" name="${deploymentKeyName}">${answer.androidDeploymentKey || "deployment-key-here"}</string>`;
112+
stringsResourcesContent = stringsResourcesContent.replace(insertAfterString,`${insertAfterString}\n${deploymentKeyString}`);
113+
fs.writeFileSync(stringsResourcesPath, stringsResourcesContent);
114+
return Promise.resolve();
115+
});
116+
}
117+
}
118+
94119
return Promise.resolve();
95-
}
120+
}

scripts/postlink/run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var postlinks = [
2-
require("./ios/postlink"),
3-
require("./android/postlink")
2+
require("./android/postlink"),
3+
require("./ios/postlink")
44
];
55

66
//run them sequentially

0 commit comments

Comments
 (0)