Permalink
Browse files

CLI errors if no package.json is found

Summary:
If you don't have a `package.json` in your project you can't do anything with the cli as it errors. This fixes that by wrapping the reading of the `package.json` file and returns `my-react-native-app` if an error is caught.
Closes #10207

Differential Revision: D4022113

Pulled By: javache

fbshipit-source-id: ffe940160f9d0b58e630adfab5e0dc9d34b859e5
  • Loading branch information...
1 parent b77b760 commit 41f4f1eaaf82ec0b1dd2951d761c47fb7cee9f50 @benhughes benhughes committed with Facebook Github Bot Oct 14, 2016
Showing with 9 additions and 3 deletions.
  1. +9 −3 local-cli/android/android.js
@@ -25,8 +25,14 @@ module.exports = {
func: android,
options: [{
command: '--project-name [name]',
- default: () => JSON.parse(
- fs.readFileSync('package.json', 'utf8')
- ).name,
+ default: () => {
+ try {
+ return JSON.parse(
+ fs.readFileSync('package.json', 'utf8')
+ ).name
+ } catch (e) {
+ return 'unknown-app-name'
+ }
+ },
}],
};

0 comments on commit 41f4f1e

Please sign in to comment.