Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
runAsync: _asyncToGenerator(function* (env) {
var argv = env.argv;
var args = argv._;
// Here is what this will do
// 0. If there is a command line argument, make a new directory in the current directory and chdir to it
var dirName = args[1];
var originalCwd = process.cwd();
if (dirName) {
dirName = dirName.toString();
yield mkdirp.promise(dirName);
log('Setting up an Exponent project at', path.resolve(dirName));
process.chdir(dirName);
}
// 1. If there is no package.json in the current directory, run npm init
var pkgJsonFile = jsonFile('package.json');
var pkg;
try {
pkg = yield pkgJsonFile.readAsync();
} catch (e) {
//console.error(e);
// No package.json, so let's create it
log(crayon.cyan('No package.json file found. Using `npm init` to help you create one.'));
log(crayon.cyan('Answer the questions and a package.json will be created for you.'));
var _zero = yield spawnAsync('npm', ['init'], { stdio: 'inherit' });
description: "Hello Exponent!",
author,
//license: "MIT",
// scripts: {
// "test": "echo \"Error: no test specified\" && exit 1"
// },
}, info);
let pkgJson = jsonFile(path.join(root, 'package.json'));
let exists = await existsAsync(pkgJson.file);
if (exists && !opts.force) {
throw NewExpError('WONT_OVERWRITE_WITHOUT_FORCE', "Refusing to create new Exp because package.json already exists at root");
}
await mkdirp.promise(root);
let result = await pkgJson.writeAsync(data);
// Copy the template directory, which contains node_modules, without its
// package.json
await fsExtra.promise.copy(TEMPLATE_ROOT, root, {
filter: filePath => filePath !== path.join(TEMPLATE_ROOT, 'package.json')
});
// Custom code for replacing __NAME__ in main.js
let mainJs = await fs.readFile.promise(path.join(TEMPLATE_ROOT, 'main.js'), 'utf8');
let customMainJs = mainJs.replace(/__NAME__/g, data.name);
result = await fs.writeFile.promise(path.join(root, 'main.js'), customMainJs, 'utf8');
return data;
}
author: author,
dependencies: dependencies
}, //license: "MIT",
// scripts: {
// "test": "echo \"Error: no test specified\" && exit 1"
// },
info);
var pkgJson = jsonFile(path.join(root, 'package.json'));
var exists = yield existsAsync(pkgJson.file);
if (exists && !opts.force) {
throw NewExpError('WONT_OVERWRITE_WITHOUT_FORCE', "Refusing to create new Exp because package.json already exists at root");
}
yield mkdirp.promise(root);
var result = yield pkgJson.writeAsync(data);
yield fsExtra.promise.copy(TEMPLATE_ROOT, root);
// Custom code for replacing __NAME__ in main.js
var mainJs = yield fs.readFile.promise(path.join(TEMPLATE_ROOT, 'main.js'), 'utf8');
var customMainJs = mainJs.replace(/__NAME__/g, data.name);
result = yield fs.writeFile.promise(path.join(root, 'main.js'), customMainJs, 'utf8');
// Intall react-native
yield _installReactNativeInNewProjectWithRoot(root);
return data;
});
var _installReactNativeInNewProjectWithRoot = _asyncToGenerator(function* (root) {
var nodeModulesPath = path.join(root, 'node_modules');
yield mkdirp.promise(nodeModulesPath);
yield fsExtra.copy.promise(path.join(__dirname, '../../node_modules/react-native'), path.join(nodeModulesPath, 'react-native'));
});