Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions EJECTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
67 changes: 46 additions & 21 deletions react-native-scripts/src/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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';
Expand All @@ -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 => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO arrow function has a more simple form like

s => s.length > 0 && s.indexOf('-') === -1 && s.indexOf(' ') === -1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While valid, I think this is unrelated to this PR. I think your fix can come in as a separate PR.
(Thanks for the review)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for replying. So should I open a PR for the changes after this PR is merged?

Copy link

@amingilani amingilani May 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duchuyctlk or you could open a PR for bigosmallm/create-react-native-app:master, which when approved will be reflected here ;)
As part of this pull request

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
Expand Down