Ben Hughes 41f4f1eaaf 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 https://github.com/facebook/react-native/pull/10207

Differential Revision: D4022113

Pulled By: javache

fbshipit-source-id: ffe940160f9d0b58e630adfab5e0dc9d34b859e5
2016-10-14 10:58:43 -07:00

39 lines
940 B
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var generate = require('../generate/generate');
var fs = require('fs');
function android(argv, config, args) {
return generate([
'--platform', 'android',
'--project-path', process.cwd(),
'--project-name', args.projectName,
], config);
}
module.exports = {
name: 'android',
description: 'creates an empty android project',
func: android,
options: [{
command: '--project-name [name]',
default: () => {
try {
return JSON.parse(
fs.readFileSync('package.json', 'utf8')
).name
} catch (e) {
return 'unknown-app-name'
}
},
}],
};