MCPcopy Create free account
hub / github.com/Create-Node-App/create-node-app / createApp

Function createApp

src/install.js:20–95  ·  view source on GitHub ↗
(name, verbose, useNpm, inplace, addons, alias, installDependencies)

Source from the content-addressed store, hash-verified

18const { loadFiles } = require('./loaders');
19
20async function createApp(name, verbose, useNpm, inplace, addons, alias, installDependencies) {
21 const root = path.resolve(name);
22 const appName = path.basename(root);
23
24 fs.ensureDirSync(name);
25
26 console.log(`Creating a new React app in ${chalk.green(root)}.`);
27 console.log();
28
29 const useYarn = useNpm ? false : shouldUseYarn();
30 const command = useYarn ? 'yarn' : 'npm run';
31
32 const { packageJson, dependencies, devDependencies } = await resolvePackage({
33 addons,
34 appName,
35 command,
36 });
37
38 fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(packageJson, null, 2) + os.EOL);
39
40 const originalDirectory = process.cwd();
41 process.chdir(root);
42 if (!useYarn && !checkThatNpmCanReadCwd()) {
43 process.exit(1);
44 }
45
46 if (!semver.satisfies(process.version, '>=6.0.0')) {
47 console.log(
48 chalk.yellow(
49 `You are using Node ${process.version} so the project will be bootstrapped with an old unsupported version of tools.\n\n` +
50 `Please update to Node 6 or higher for a better, fully supported experience.\n`
51 )
52 );
53 }
54
55 if (!useYarn) {
56 const npmInfo = checkNpmVersion();
57 if (!npmInfo.hasMinNpm) {
58 if (npmInfo.npmVersion) {
59 console.log(
60 chalk.yellow(
61 `You are using npm ${npmInfo.npmVersion} so the project will be bootstrapped with an old unsupported version of tools.\n\n` +
62 `Please update to npm 3 or higher for a better, fully supported experience.\n`
63 )
64 );
65 }
66 }
67 }
68
69 if (useYarn) {
70 let yarnUsesDefaultRegistry = true;
71 try {
72 yarnUsesDefaultRegistry =
73 execSync('yarnpkg config get registry').toString().trim() ===
74 'https://registry.yarnpkg.com';
75 } catch (e) {
76 // ignore
77 }

Callers 1

index.jsFile · 0.85

Calls 4

shouldUseYarnFunction · 0.85
checkThatNpmCanReadCwdFunction · 0.85
checkNpmVersionFunction · 0.85
runFunction · 0.85

Tested by

no test coverage detected