@@ -20,6 +20,9 @@ const questions = [
2020
2121inquirer . prompt ( questions ) . then ( answers => {
2222 const { appKey, moduleName } = answers
23+ if ( moduleName == undefined ) {
24+ moduleName = "app"
25+ }
2326
2427 // 深度遍历所有文件,
2528 getAllFiles ( './ios' , function ( f , s ) {
@@ -43,7 +46,7 @@ inquirer.prompt(questions).then(answers => {
4346 var isSettingGradle = f . match ( / s e t t i n g s \. g r a d l e / )
4447 if ( isSettingGradle != null ) {
4548 console . log ( 'find settings.gradle in android project ' + f )
46- configureSetting ( f )
49+ configureSetting ( f , moduleName )
4750 }
4851
4952 // 找到project下的build.gradle
@@ -305,12 +308,12 @@ function configureAppKey(file, appKey) {
305308 var rf = fs . readFileSync ( file , 'utf-8' )
306309 var isAlreadyWrite = rf . match ( / .* J P U S H _ A P P K E Y .* / )
307310 if ( isAlreadyWrite == null ) {
308- var insertKey = rf . match ( / \n . * n d k \{ \n . * \} \n / )
311+ var insertKey = rf . match ( / . * v e r s i o n N a m e . * \n / )
309312 if ( insertKey != null ) {
310313 rf = rf . replace (
311314 insertKey [ 0 ] ,
312315 insertKey [ 0 ] +
313- 'manifestPlaceholders = [\n JPUSH_APPKEY: "' +
316+ ' manifestPlaceholders = [\n JPUSH_APPKEY: "' +
314317 appKey +
315318 '",\n APP_CHANNEL: "developer-default"\n ]\n'
316319 )
@@ -321,7 +324,7 @@ function configureAppKey(file, appKey) {
321324 }
322325}
323326
324- function configureSetting ( file ) {
327+ function configureSetting ( file , moduleName ) {
325328 if ( ! isFile ( file ) ) {
326329 console . log ( 'configuration JPush error!!' )
327330 return
@@ -333,11 +336,7 @@ function configureSetting(file) {
333336 var re = new RegExp ( "\n.*include.*':" + moduleName + "'" , 'gi' )
334337 var searchKey = rf . match ( re )
335338 if ( searchKey != null ) {
336- rf = rf . replace (
337- searchKey [ 0 ] ,
338- searchKey [ 0 ] +
339- ", ':jpush-react-native', ':jcore-react-native'\nproject(':jpush-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jpush-react-native/android')\nproject(':jcore-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jcore-react-native/android')\n"
340- )
339+ rf = rf . replace ( "\n" , "\ninclude ':jpush-react-native' \nproject(':jpush-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jpush-react-native/android')\ninclude ':jcore-react-native' \nproject(':jcore-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jcore-react-native/android')\n" )
341340 fs . writeFileSync ( file , rf , 'utf-8' )
342341 } else {
343342 console . log ( 'Did not find include in settings.gradle: ' + file )
0 commit comments