{"version":3,"sources":["init.js"],"names":["DEFAULT_DEPENDENCIES","expo","react","DEFAULT_DEV_DEPENDENCIES","module","exports","appPath","appName","verbose","cwd","ownPackageName","require","name","ownPath","join","useYarn","npmOrYarn","npmVersion","sync","stdout","toString","trim","match","console","log","yellow","process","exit","readmeExists","rename","appPackagePath","JSON","readFile","appPackage","parse","main","scripts","start","eject","android","ios","test","jest","preset","dependencies","devDependencies","writeFile","copy","code","data","appendFile","unlink","command","args","error","cdpath","resolve","cyan"],"mappings":";;;;;;;;;;;;;;;;;;AAEA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;;;AAEA;AACA,IAAMA,uBAAuB;AAC3BC,QAAM,SADqB;AAE3BC,SAAO,QAFoB;AAG3B,kBAAgB;AAHW,CAA7B;;AAMA;;;AACA,IAAMC,2BAA2B;AAC/B,eAAa,QADkB;AAE/B,yBAAuB;AAFQ,CAAjC;;AAKAC,OAAOC,OAAP;AAAA,sFAAiB,iBAAOC,OAAP,EAAwBC,OAAxB,EAAyCC,OAAzC;AAAA,QAA2DC,GAA3D,uEAAyE,EAAzE;;AAAA;;AAAA;AAAA;AAAA;AAAA;AACTC,0BADS,GACgBC,QAAQ,oBAAR,EAA8BC,IAD9C;AAETC,mBAFS,GAES,eAAKC,IAAL,CAAUR,OAAV,EAAmB,cAAnB,EAAmCI,cAAnC,CAFT;AAAA;AAAA,mBAGgB,0BAAW,eAAKI,IAAL,CAAUR,OAAV,EAAmB,WAAnB,CAAX,CAHhB;;AAAA;AAGTS,mBAHS;AAITC,qBAJS,GAIGD,UAAU,MAAV,GAAmB,KAJtB;;AAMf;;AACA,gBAAI,CAACA,OAAL,EAAc;AACRE,wBADQ,GACK,qBAAMC,IAAN,CAAW,KAAX,EAAkB,CAAC,WAAD,CAAlB,EAAiCC,MAAjC,CAAwCC,QAAxC,GAAmDC,IAAnD,EADL;;;AAGZ,kBAAIJ,WAAWK,KAAX,CAAiB,KAAjB,EAAwB,CAAxB,MA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gD,uBAASjD,OAAT;AACD;;AAED,yDAGiBC,OAHjB,YAG+BD,OAH/B,oEAME,gBAAMmD,IAAN,CAAWzC,YAAY,QAAvB,CANF,8GAUE,gBAAMyC,IAAN,CAAWzC,YAAY,UAAvB,CAVF,yHAcE,gBAAMyC,IAAN,CAAWzC,YAAY,cAAvB,CAdF,wJAmBE,gBAAMyC,IAAN,CAAWzC,YAAY,OAAvB,CAnBF,2CAsBE,gBAAMyC,IAAN,CAAWzC,YAAY,YAAvB,CAtBF,iNA4BE,gBAAMyC,IAAN,CAAW,QAAQF,MAAnB,CA5BF,YA6BE,gBAAME,IAAN,CAAWzC,YAAY,QAAvB,CA7BF;;AAgCA,gBAAIY,YAAJ,EAAkB;AAChB,wCAEF,gBAAMH,MAAN,CAAa,8DAAb,CAFE;AAID;;AAED;AACA,+BAAI,gBAAJ;;AAhJe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAAjB;;AAAA;AAAA;AAAA;AAAA","file":"init.js","sourcesContent":["// @flow\n\nimport chalk from 'chalk';\nimport fse from 'fs-extra';\nimport path from 'path';\nimport pathExists from 'path-exists';\nimport spawn from 'cross-spawn';\nimport log from '../util/log';\nimport install from '../util/install';\n\n// UPDATE DEPENDENCY VERSIONS HERE\nconst DEFAULT_DEPENDENCIES = {\n expo: '^25.0.0',\n react: '16.2.0',\n 'react-native': '0.52.0',\n};\n\n// TODO figure out how this interacts with ejection\nconst DEFAULT_DEV_DEPENDENCIES = {\n 'jest-expo': '25.0.0',\n 'react-test-renderer': '16.2.0',\n};\n\nmodule.exports = async (appPath: string, appName: string, verbose: boolean, cwd: string = '') => {\n const ownPackageName: string = require('../../package.json').name;\n const ownPath: string = path.join(appPath, 'node_modules', ownPackageName);\n const useYarn: boolean = await pathExists(path.join(appPath, 'yarn.lock'));\n const npmOrYarn = useYarn ? 'yarn' : 'npm';\n\n // FIXME(perry) remove when npm 5 is supported\n if (!useYarn) {\n let npmVersion = spawn.sync('npm', ['--version']).stdout.toString().trim();\n\n if (npmVersion.match(/\\d+/)[0] === '5') {\n console.log(\n chalk.yellow(\n `\n*******************************************************************************\nERROR: npm 5 is not supported yet\n*******************************************************************************\n\nIt looks like you're using npm 5 which was recently released.\n\nCreate React Native App doesn't work with npm 5 yet, unfortunately. We\nrecommend using npm 4 or yarn until some bugs are resolved.\n\nYou can follow the known issues with npm 5 at:\nhttps://github.com/npm/npm/issues/16991\n\n*******************************************************************************\n `\n )\n );\n process.exit(1);\n }\n }\n\n const readmeExists: boolean = await pathExists(path.join(appPath, 'README.md'));\n if (readmeExists) {\n await fse.rename(path.join(appPath, 'README.md'), path.join(appPath, 'README.old.md'));\n }\n\n const appPackagePath: string = path.join(appPath, 'package.json');\n const appPackage = JSON.parse(await fse.readFile(appPackagePath));\n\n // mutate the default package.json in any ways we need to\n appPackage.main = './node_modules/react-native-scripts/build/bin/crna-entry.js';\n appPackage.scripts = {\n start: 'react-native-scripts start',\n eject: 'react-native-scripts eject',\n android: 'react-native-scripts android',\n ios: 'react-native-scripts ios',\n test: 'node node_modules/jest/bin/jest.js',\n };\n\n appPackage.jest = {\n preset: 'jest-expo',\n };\n\n if (!appPackage.dependencies) {\n appPackage.dependencies = {};\n }\n\n if (!appPackage.devDependencies) {\n appPackage.devDependencies = {};\n }\n\n // react-native-scripts is already in the package.json devDependencies\n // so we need to merge instead of assigning\n Object.assign(appPackage.dependencies, DEFAULT_DEPENDENCIES);\n Object.assign(appPackage.devDependencies, DEFAULT_DEV_DEPENDENCIES);\n\n // Write the new appPackage after copying so that we can include any existing\n await fse.writeFile(appPackagePath, JSON.stringify(appPackage, null, 2));\n\n // Copy the files for the user\n await fse.copy(path.join(ownPath, 'template'), appPath);\n\n // Rename gitignore after the fact to prevent npm from renaming it to .npmignore\n try {\n await fse.rename(path.join(appPath, 'gitignore'), path.join(appPath, '.gitignore'));\n } catch (err) {\n // Append if there's already a `.gitignore` file there\n if (err.code === 'EEXIST') {\n const data = await fse.readFile(path.join(appPath, 'gitignore'));\n await fse.appendFile(path.join(appPath, '.gitignore'), data);\n await fse.unlink(path.join(appPath, 'gitignore'));\n } else {\n throw err;\n }\n }\n const { code, command, args } = await install(appPath);\n if (code !== 0) {\n console.error('Failed to install');\n // console.error(`\\`${command} ${args.join(' ')}\\` failed`);\n return;\n }\n\n // display the cleanest way to get to the app dir\n // if the cwd + appName is equal to the full path, then just cd into appName\n let cdpath;\n if (path.resolve(cwd, appName) === appPath) {\n cdpath = appName;\n } else {\n cdpath = appPath;\n }\n\n log(\n `\n\nSuccess! Created ${appName} at ${appPath}\nInside that directory, you can run several commands:\n\n ${chalk.cyan(npmOrYarn + ' start')}\n Starts the development server so you can open your app in the Expo\n app on your phone.\n\n ${chalk.cyan(npmOrYarn + ' run ios')}\n (Mac only, requires Xcode)\n Starts the development server and loads your app in an iOS simulator.\n\n ${chalk.cyan(npmOrYarn + ' run android')}\n (Requires Android build tools)\n Starts the development server and loads your app on a connected Android\n device or emulator.\n\n ${chalk.cyan(npmOrYarn + ' test')}\n Starts the test runner.\n\n ${chalk.cyan(npmOrYarn + ' run eject')}\n Removes this tool and copies build dependencies, configuration files\n and scripts into the app directory. If you do this, you can’t go back!\n\nWe suggest that you begin by typing:\n\n ${chalk.cyan('cd ' + cdpath)}\n ${chalk.cyan(npmOrYarn + ' start')}`\n );\n\n if (readmeExists) {\n log(\n `\n${chalk.yellow('You had a `README.md` file, we renamed it to `README.old.md`')}`\n );\n }\n\n log();\n log('Happy hacking!');\n};\n"]}