diff --git a/EJECTING.md b/EJECTING.md index 79e8656e..d7859ef9 100644 --- a/EJECTING.md +++ b/EJECTING.md @@ -20,6 +20,17 @@ If you do need to eject to build your own distribution package or to include you `npm run eject` will start the process of ejecting from Create React Native App's build scripts. You'll be asked a couple of questions about how you'd like to build your project. Once this command has successfully run, you should also follow any steps below that are applicable to your environment. +##### Non-interactive Ejection Process + +If you want to run the ejection process in an automated or CI environment, you can use: +```sh +npm run eject -- -eject-params raw,MyAppName,MyProjectName +``` +All params are required: +1. Eject method: Allowed values are: `raw` or `expoKit` +2. App name +3. Project name + ### Ejecting to Regular React Native This will give you a project very similar to one created by `react-native init`. Make sure to install the `react-native-cli` tool: diff --git a/react-native-scripts/src/scripts/eject.js b/react-native-scripts/src/scripts/eject.js index c197d293..2e67f2e0 100644 --- a/react-native-scripts/src/scripts/eject.js +++ b/react-native-scripts/src/scripts/eject.js @@ -12,6 +12,20 @@ import { detach } from '../util/expo'; async function eject() { try { + const isInteractive = process.argv.indexOf('-eject-params') == -1; + const ejectParams = isInteractive ? [] : process.argv[process.argv.indexOf("-eject-params") + 1].split(','); + if(!isInteractive) { + if(ejectParams.length < 3) { + log(chalk.red('You must provide the values for Eject method, App name and Project name in the -eject-params arg')); + log(chalk.red('Example usage: npm run eject -- -eject-params raw,MyAppName,MyProjectName')); + process.exit(1); + } + if(!(ejectParams[0] == 'raw' || ejectParams[0] == 'expoKit')) { + log(chalk.red('Eject method must be either raw or expoKit')); + process.exit(1); + } + + } const filesWithExpo = await filesUsingExpoSdk(); const usingExpo = filesWithExpo.length > 0; @@ -74,7 +88,13 @@ Ejecting is permanent! Please be careful with your selection. }, ]; - const { ejectMethod } = await inquirer.prompt(questions); + let ejectMethod; + if(isInteractive) { + ejectMethod = await inquirer.prompt(questions).ejectMethod; + } + else { + ejectMethod = ejectParams[0]; + } if (ejectMethod === 'raw') { const npmOrYarn = (await fsp.exists(path.resolve('yarn.lock'))) ? 'yarnpkg' : 'npm'; @@ -96,28 +116,33 @@ Ejecting is permanent! Please be careful with your selection. newDisplayName = expName; } - log("We have a couple of questions to ask you about how you'd like to name your app:"); - const { enteredName, enteredDisplayname } = await inquirer.prompt([ - { - name: 'enteredDisplayname', - message: "What should your app appear as on a user's home screen?", - default: newDisplayName, - validate: s => { - return s.length > 0; + if(isInteractive) { + log("We have a couple of questions to ask you about how you'd like to name your app:"); + const { enteredName, enteredDisplayname } = await inquirer.prompt([ + { + name: 'enteredDisplayname', + message: "What should your app appear as on a user's home screen?", + default: newDisplayName, + validate: s => { + return s.length > 0; + }, }, - }, - { - name: 'enteredName', - message: 'What should your Android Studio and Xcode projects be called?', - default: newName, - validate: s => { - return s.length > 0 && s.indexOf('-') === -1 && s.indexOf(' ') === -1; + { + name: 'enteredName', + message: 'What should your Android Studio and Xcode projects be called?', + default: newName, + validate: s => { + return s.length > 0 && s.indexOf('-') === -1 && s.indexOf(' ') === -1; + }, }, - }, - ]); - - appJson.name = enteredName; - appJson.displayName = enteredDisplayname; + ]); + appJson.name = enteredName; + appJson.displayName = enteredDisplayname; + } + else { + appJson.name = ejectParams[1]; + appJson.displayName = ejectParams[2]; + } log('Writing your selections to app.json...'); // write the updated app.json file