-
Notifications
You must be signed in to change notification settings - Fork 187
Add iOS build phase #90
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
Changes from 21 commits
b848161
f2d0e66
74c73e1
de84171
280d69a
20e047e
8db7f08
93653f4
77b4367
987b65d
c3cbfd4
3ed3080
7131935
d7514b8
e69ed9c
b4e411e
a168474
3d4b77c
bfa3e4d
62044a1
6e0c3e5
b6d7803
028ed1c
9dfff1f
afd93e1
5557254
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,6 +125,8 @@ async function init() { | |
| progress.warn(messages.gitNotFound()); | ||
| } | ||
|
|
||
| await addToXcodeBuild(cwd); | ||
|
|
||
| progress = ora(messages.generatingConfig()).start(); | ||
|
|
||
| await new Promise(resolve => setTimeout(resolve, 1000)); | ||
|
|
@@ -140,6 +142,122 @@ async function init() { | |
| progress.succeed(messages.generatedConfig()); | ||
| } | ||
|
|
||
| const sleep = (time: number = 1000) => | ||
| new Promise(resolve => setTimeout(resolve, time)); | ||
|
|
||
| /** | ||
| * Adds Haul to native iOS build pipeline | ||
| */ | ||
| const addToXcodeBuild = async (cwd: string) => { | ||
| let entry; | ||
|
|
||
| // Does `ios/*.xcodeproj` exist? | ||
| const iosPath = path.join(cwd, 'ios'); | ||
| if (fs.existsSync(iosPath)) { | ||
| const list = fs | ||
| .readdirSync(path.join(cwd, 'ios')) | ||
| .filter(file => file.includes('.xcodeproj')); | ||
|
|
||
| // Do nothing if multiple projects were found | ||
| if (list.length === 1) { | ||
| entry = path.join(iosPath, list[0]); | ||
| } | ||
| } | ||
|
|
||
| // Otherwise, ask for path to a file | ||
| if (!entry) { | ||
| const result = await inquirer.prompt([ | ||
| { | ||
| type: 'input', | ||
| name: 'entry', | ||
| message: 'Enter the name of the .xcodeproj file', | ||
| validate: pathToFile => | ||
| fs.existsSync(pathToFile) && pathToFile.includes('.xcodeproj') | ||
| ? true | ||
| : `${pathToFile} is not a valid .xcodeproj`, | ||
| }, | ||
| ]); | ||
|
|
||
| entry = path.join(cwd, result.entry); | ||
| } | ||
|
|
||
| const progress = ora('Adding haul to your native build pipeline'); | ||
|
Member
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.
Though I feel like we should ask before this change. Looks rather invasive and I might just want to try before integrating. |
||
|
|
||
| await sleep(); | ||
|
|
||
| let project = fs.readFileSync(path.join(entry, 'project.pbxproj')).toString(); | ||
|
|
||
| // Are we already integrated? | ||
| if (project.includes('AD0CE2C91E925489006FC317')) { | ||
|
Member
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. Let's store this in a constant |
||
| progress.info('Haul is already part of your build pipeline'); | ||
|
Member
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. nit: Mention XCode
Member
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.
|
||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * Define Haul integration script in the PBXShellScriptBuildPhase section. | ||
| * | ||
| * This is done by prepending our predefined script phase to the list | ||
| * of all phases. | ||
| */ | ||
| project = project.replace( | ||
| '/* Begin PBXShellScriptBuildPhase section */', | ||
| dedent` | ||
| /* Begin PBXShellScriptBuildPhase section */ | ||
| AD0CE2C91E925489006FC317 /* Integrate Haul with React Native */ = { | ||
| isa = PBXShellScriptBuildPhase; | ||
| buildActionMask = 2147483647; | ||
| name = "Integrate Haul with React Native"; | ||
| files = ( | ||
| ); | ||
| inputPaths = ( | ||
| ); | ||
| outputPaths = ( | ||
| ); | ||
| runOnlyForDeploymentPostprocessing = 0; | ||
| shellPath = /bin/sh; | ||
| shellScript = "bash ../node_modules/haul/src/utils/haul-integrate.sh"; | ||
| };`, | ||
| ); | ||
|
|
||
| /** | ||
| * Add Haul integration to build phases that already contain `react-native-xcode.sh` | ||
| * | ||
| * We are typically trying to match the following: | ||
| * | ||
| * ``` | ||
| * buildPhases = ( | ||
| * 13B07F871A680F5B00A75B9A \/* Sources *\/, | ||
| * 13B07F8C1A680F5B00A75B9A \/* Frameworks *\/, | ||
| * 13B07F8E1A680F5B00A75B9A \/* Resources *\/, | ||
| * 00DD1BFF1BD5951E006B06BC \/* Bundle React Native code and images *\/, | ||
| * ); | ||
| * ``` | ||
| * | ||
| * and prepend our build phase to the beginning. | ||
| */ | ||
| let sectionsCount = 0; | ||
| project = project.replace(/buildPhases = \(\n(?:.*,\n)*\s*\);/g, match => { | ||
| if (!match.includes('React Native')) return match; | ||
| sectionsCount++; | ||
| return match.replace( | ||
| 'buildPhases = (', | ||
| dedent` | ||
| buildPhases = ( | ||
| AD0CE2C91E925489006FC317 /* Integrate Haul with React Native */, | ||
| `, | ||
| ); | ||
| }); | ||
|
|
||
| if (sectionsCount > 0) { | ||
| fs.writeFileSync(path.join(entry, 'project.pbxproj'), project); | ||
| progress.succeed('Added haul to your native build pipeline'); | ||
|
Member
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. nit: Mention XCode |
||
| } else { | ||
| progress.fail( | ||
| 'Failed to add Haul to your build pipeline. See docs for manual instructions.', | ||
|
Member
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. nit: Mention XCode Link to docs? |
||
| ); | ||
| } | ||
| }; | ||
|
|
||
| module.exports = { | ||
| name: 'init', | ||
| description: 'Generates necessary configuration files', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| THIS_DIR=$(dirname $0) | ||
|
|
||
| SRC="$(cd "${THIS_DIR}/../../../react-native/packager" && pwd)" | ||
|
|
||
| # Replace local-cli with Haul in `react-native-xcode.sh` | ||
| sed -i -e 's|$REACT_NATIVE_DIR/local-cli/cli.js|./node_modules/.bin/haul|' ${SRC}/react-native-xcode.sh | ||
|
|
||
| # Replace `react-native start` in `packager.sh` | ||
| PACKAGER_CONTENT="cd ../../../ && node \"./node_modules/.bin/haul\" start --platform ios \"\$@\"" | ||
| echo "$PACKAGER_CONTENT" > ${SRC}/packager.sh |
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.
Isn't this the
pathand notname?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.
Yup, it's path