-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(path ios files): [WIP] Support user to specify path for ios/android files #25
Open
bduyng
wants to merge
6
commits into
peggyrayzis:master
Choose a base branch
from
bduyng:feature/support-native-files-path
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f2479f
fix(objc): call emitMessageToRN method not property
bduyng e0cae6b
support setting specify path for ios files
bduyng c31ca27
Merge branch 'master' of https://github.com/peggyrayzis/react-native-…
bduyng 8f8ed44
add separate prompt for iOS and Android files depend on previous answers
bduyng 27fa594
Merge remote-tracking branch 'upstream/master' into feature/support-n…
bduyng ecbf7fd
refactor code
bduyng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,13 +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: "jsPath", | ||
message: "What directory should we deliver your JS files to?", | ||
default: ".", | ||
validate: input => isValid(input) | ||
} | ||
]; | ||
|
||
|
@@ -49,20 +42,42 @@ const environmentMap = { | |
|
||
async function init() { | ||
try { | ||
const { | ||
environment, | ||
bridgeType, | ||
templateName, | ||
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) | ||
); | ||
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); | ||
|
@@ -77,7 +92,7 @@ async function init() { | |
} | ||
} | ||
|
||
async function createJavaEnvironment(templateName, templateFolder) { | ||
async function createJavaEnvironment(templateName, templateFolder, nativePath) { | ||
const appPath = path.join( | ||
process.cwd(), | ||
"android", | ||
|
@@ -119,7 +134,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 +180,11 @@ async function createKotlinEnvironment(templateName, templateFolder) { | |
); | ||
} | ||
|
||
async function createSwiftEnvironment(templateName, templateFolder) { | ||
async function createSwiftEnvironment( | ||
templateName, | ||
templateFolder, | ||
nativePath | ||
) { | ||
const readDirPath = path.join( | ||
__dirname, | ||
"..", | ||
|
@@ -170,17 +193,22 @@ async function createSwiftEnvironment(templateName, templateFolder) { | |
"ios-swift" | ||
); | ||
|
||
if (nativePath !== "ios") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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); | ||
|
||
return readAndWriteFiles(files, paths, templateName); | ||
} | ||
|
||
async function createObjCEnvironment(templateName, templateFolder) { | ||
async function createObjCEnvironment(templateName, templateFolder, nativePath) { | ||
const readDirPath = path.join( | ||
__dirname, | ||
"..", | ||
|
@@ -189,9 +217,14 @@ async function createObjCEnvironment(templateName, templateFolder) { | |
"ios-objc" | ||
); | ||
|
||
if (nativePath !== "ios") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as the Swift function |
||
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); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the default, we should create an object above with the file types as the keys and the default paths as the values. Then, you can look them up.
You can use the paths that we're currently delivering the files to in RNCB as your defaults.