From 1f2479fa6e64a81bf39484241e46c8070881ebb4 Mon Sep 17 00:00:00 2001 From: Duy Bao Nguyen Date: Sat, 15 Jul 2017 22:34:37 +0700 Subject: [PATCH 1/4] fix(objc): call emitMessageToRN method not property --- templates/modules/ios-objc/Template.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/modules/ios-objc/Template.m b/templates/modules/ios-objc/Template.m index 92c89ac..7e240e1 100644 --- a/templates/modules/ios-objc/Template.m +++ b/templates/modules/ios-objc/Template.m @@ -40,7 +40,7 @@ - (NSDictionary *)constantsToExport // https://facebook.github.io/react-native/docs/native-modules-ios.html RCT_EXPORT_METHOD(exampleMethod) { - [self.emitMessageToRN:@"EXAMPLE_EVENT" :nil] + [self emitMessageToRN:@"EXAMPLE_EVENT" :nil]; } // List all your events here From e0cae6b09918092e2dcc2a2001cac4a65dfffb9e Mon Sep 17 00:00:00 2001 From: Duy Bao Nguyen Date: Fri, 21 Jul 2017 20:48:31 +0700 Subject: [PATCH 2/4] support setting specify path for ios files --- src/index.js | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 0888a36..a4ee032 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,13 @@ const promptConfig = [ default: ["Android/Java", "iOS/Objective-C"], choices: ["Android/Java", "Android/Kotlin", "iOS/Swift", "iOS/Objective-C"] }, + { + type: "input", + name: "nativePath", + message: "What directory should we deliver your native files to?", + default: "ios|android", + validate: input => isValid(input) + }, { type: "input", name: "jsPath", @@ -53,6 +60,7 @@ async function init() { environment, bridgeType, templateName, + nativePath, jsPath } = await inquirer.prompt(promptConfig); @@ -61,7 +69,7 @@ async function init() { : bridgeType[0] === "Native Module" ? "modules" : "ui-components"; const promises = environment.map(env => - environmentMap[env](templateName, templateFolder) + environmentMap[env](templateName, templateFolder, nativePath) ); promises.push(createJSEnvironment(templateName, templateFolder, jsPath)); @@ -77,7 +85,7 @@ async function init() { } } -async function createJavaEnvironment(templateName, templateFolder) { +async function createJavaEnvironment(templateName, templateFolder, nativePath) { const appPath = path.join( process.cwd(), "android", @@ -119,7 +127,11 @@ async function createJavaEnvironment(templateName, templateFolder) { ); } -async function createKotlinEnvironment(templateName, templateFolder) { +async function createKotlinEnvironment( + templateName, + templateFolder, + nativePath +) { const appPath = path.join( process.cwd(), "android", @@ -161,7 +173,11 @@ async function createKotlinEnvironment(templateName, templateFolder) { ); } -async function createSwiftEnvironment(templateName, templateFolder) { +async function createSwiftEnvironment( + templateName, + templateFolder, + nativePath +) { const readDirPath = path.join( __dirname, "..", @@ -170,9 +186,16 @@ async function createSwiftEnvironment(templateName, templateFolder) { "ios-swift" ); + if (nativePath === "ios|android") { + nativePath = "ios"; + } else { + nativePath = path.join(process.cwd(), "ios", nativePath); + await mkdir(nativePath); + } + const paths = { readDirPath, - writeDirPath: path.join(process.cwd(), "ios") + writeDirPath: nativePath }; const files = await getFileNames(readDirPath); @@ -180,7 +203,7 @@ async function createSwiftEnvironment(templateName, templateFolder) { return readAndWriteFiles(files, paths, templateName); } -async function createObjCEnvironment(templateName, templateFolder) { +async function createObjCEnvironment(templateName, templateFolder, nativePath) { const readDirPath = path.join( __dirname, "..", @@ -189,9 +212,16 @@ async function createObjCEnvironment(templateName, templateFolder) { "ios-objc" ); + if (nativePath === "ios|android") { + nativePath = "ios"; + } else { + nativePath = path.join(process.cwd(), "ios", nativePath); + await mkdir(nativePath); + } + const paths = { readDirPath, - writeDirPath: path.join(process.cwd(), "ios") + writeDirPath: nativePath }; const files = await getFileNames(readDirPath); From 8f8ed44929e9ee582a082410603a3f282936cc19 Mon Sep 17 00:00:00 2001 From: Duy Bao Nguyen Date: Tue, 25 Jul 2017 14:47:28 +0700 Subject: [PATCH 3/4] add separate prompt for iOS and Android files depend on previous answers --- src/index.js | 63 +++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/src/index.js b/src/index.js index a4ee032..ecf0c50 100644 --- a/src/index.js +++ b/src/index.js @@ -30,20 +30,6 @@ const promptConfig = [ message: "What OS & languages would you like to support?", default: ["Android/Java", "iOS/Objective-C"], choices: ["Android/Java", "Android/Kotlin", "iOS/Swift", "iOS/Objective-C"] - }, - { - type: "input", - name: "nativePath", - message: "What directory should we deliver your native files to?", - default: "ios|android", - validate: input => isValid(input) - }, - { - type: "input", - name: "jsPath", - message: "What directory should we deliver your JS files to?", - default: ".", - validate: input => isValid(input) } ]; @@ -56,21 +42,42 @@ const environmentMap = { async function init() { try { - const { - environment, - bridgeType, - templateName, - nativePath, - jsPath - } = await inquirer.prompt(promptConfig); + const { environment, bridgeType, templateName } = await inquirer.prompt( + promptConfig + ); + + const fileTypes = ["JS"]; + const includediOS = environment.find( + answer => answer.indexOf("iOS") !== -1 + ); + if (includediOS) fileTypes.unshift("iOS"); + const includedAndroid = environment.find( + answer => answer.indexOf("Android") !== -1 + ); + if (includedAndroid) fileTypes.unshift("Android"); + + const extraPromptConfig = fileTypes.map(fileType => { + return { + type: "input", + name: `${fileType.toLowerCase()}Path`, + message: `What directory should we deliver your ${fileType} files to?`, + default: fileType === "JS" ? "." : fileType.toLowerCase(), + validate: input => isValid(input) + }; + }); + + const { iosPath, androidPath, jsPath } = await inquirer.prompt( + extraPromptConfig + ); const templateFolder = bridgeType.length > 1 ? "combined" : bridgeType[0] === "Native Module" ? "modules" : "ui-components"; - const promises = environment.map(env => - environmentMap[env](templateName, templateFolder, nativePath) - ); + const promises = environment.map(env => { + const nativePath = env.indexOf("iOS") !== -1 ? iosPath : androidPath; + return environmentMap[env](templateName, templateFolder, nativePath); + }); promises.push(createJSEnvironment(templateName, templateFolder, jsPath)); await Promise.all(promises); @@ -186,9 +193,7 @@ async function createSwiftEnvironment( "ios-swift" ); - if (nativePath === "ios|android") { - nativePath = "ios"; - } else { + if (nativePath !== "ios") { nativePath = path.join(process.cwd(), "ios", nativePath); await mkdir(nativePath); } @@ -212,9 +217,7 @@ async function createObjCEnvironment(templateName, templateFolder, nativePath) { "ios-objc" ); - if (nativePath === "ios|android") { - nativePath = "ios"; - } else { + if (nativePath !== "ios") { nativePath = path.join(process.cwd(), "ios", nativePath); await mkdir(nativePath); } From ecbf7fd266e30c349c9fba7df0c08a60bd560b82 Mon Sep 17 00:00:00 2001 From: Duy Bao Nguyen Date: Thu, 31 Aug 2017 20:04:27 +0700 Subject: [PATCH 4/4] refactor code --- src/index.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index ecf0c50..c23d1f7 100644 --- a/src/index.js +++ b/src/index.js @@ -40,6 +40,12 @@ const environmentMap = { "iOS/Objective-C": createObjCEnvironment }; +const defaultPathsMap = { + JS: ".", + iOS: "ios", + Android: "android" +}; + async function init() { try { const { environment, bridgeType, templateName } = await inquirer.prompt( @@ -61,7 +67,7 @@ async function init() { type: "input", name: `${fileType.toLowerCase()}Path`, message: `What directory should we deliver your ${fileType} files to?`, - default: fileType === "JS" ? "." : fileType.toLowerCase(), + default: defaultPathsMap[fileType], validate: input => isValid(input) }; }); @@ -193,10 +199,8 @@ async function createSwiftEnvironment( "ios-swift" ); - if (nativePath !== "ios") { - nativePath = path.join(process.cwd(), "ios", nativePath); - await mkdir(nativePath); - } + nativePath = path.join(process.cwd(), "ios", nativePath); + await mkdir(nativePath); const paths = { readDirPath, @@ -217,10 +221,8 @@ async function createObjCEnvironment(templateName, templateFolder, nativePath) { "ios-objc" ); - if (nativePath !== "ios") { - nativePath = path.join(process.cwd(), "ios", nativePath); - await mkdir(nativePath); - } + nativePath = path.join(process.cwd(), "ios", nativePath); + await mkdir(nativePath); const paths = { readDirPath,