1 line
21 KiB
Plaintext
1 line
21 KiB
Plaintext
{"version":3,"sources":["Exp.js"],"names":["async","root","let","exp","pkg","await","ProjectUtils","readConfigJsonAsync","entryPoint","main","determineEntryPointAsync","templateId","progressFunction","retryFunction","versions","Api","versionsAsync","templateApp","i","templatesv2","length","id","ErrorCode","INVALID_OPTIONS","starterAppVersion","version","starterAppName","filename","starterAppPath","path","join","_starterAppCacheDirectory","existsAsync","url","downloadAsync","_downloadStarterAppAsync","selectedDir","opts","schema","joi","object","keys","name","string","required","validateAsync","e","toString","Analytics","logEvent","fileExists","fs","statSync","readdirSync","DIRECTORY_ALREADY_EXISTS","mkdirpAsync","Logger","notifications","info","code","NotificationCode","PROGRESS","MessageCode","DOWNLOADING","downloadTemplateApp","EXTRACTING","Extract","extractAsync","CUSTOMIZING","appJson","readFileAsync","customAppJson","replace","writeFileAsync","initGitRepo","extractTemplateApp","process","platform","Binaries","isXcodeInstalled","global","warn","insideGit","spawnAsync","cwd","debug","resolve","recentExpsJsonFile","UserSettings","recentExps","readAsync","filter","x","unshift","writeAsync","slice","saveRecentExpRootAsync","description","icon","iconUrl","pathOrUrl","resolvedPath","existsSync","readableRoot","makePathReadable","expInfoSafeAsync","user","UserManager","ensureLoggedInAsync","Error","username","slug","configName","configFilenameAsync","sdkVersion","remotePackageName","remoteUsername","remoteFullPackageName","bundleIdentifierIOS","ios","bundleIdentifier","packageNameAndroid","android","package","args","getPublishInfoAsync","results","Promise","all","map","filteredResults","result","recentValidExpsAsync","recipient","url_","callMethodAsync","sendAsync","projectRoot","ps","ProjectSettings","randomness","urlRandomness","resetProjectRandomnessAsync","getProjectRandomnessAsync","UrlUtils","someRandomness","setAsync","dotExpoHomeDirectory","rimraf","sync","clearXDLCacheAsync","default","ENTRY_POINT_PLATFORM_TEMPLATE_STRING","promisify","readFile","writeFile","validate","dir","mkdirp","getHomeDir","env","pth","homedir","substr"],"mappings":";;;;;;;;+BAuCOA,WAAwCC,IAAxCD,EAAsD;AAC3DE,QAA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AACA;AAAA;AAAA;;;;AACA;AAAA;AAAA;;;;AACA;AAAA;AAAA;;;;AACA;AAAA;AAAA;;;;AACA;AAAA;AAAA;;;;AACA;AAAA;AAAA;;;;AACA;AAAA;AAAA;;;;;;;;AAEA;AACO,MAAMC,sFAAuC,oBAA7C;;AAIP,MAAMlF,gBAAgBmF,qCAAUtG,YAAGuG,QAAbD,CAAtB;AACA,MAAMhF,iBAAiBgF,qCAAUtG,YAAGwG,SAAbF,CAAvB;AACA,MAAM5G,gBAAgB4G,qCAAUlH,8BAAIqH,QAAdH,CAAtB;AACA,MAAMlG,cAAckG,yEAApB;;AAiBA,SAAS1H,yBAAT,GAAqC;AACnC7B,MAAIiJ,uBAAuB3D,gDAAa2D,oBAAb3D,EAA3BtF;AACAA,MAAI2J,MAAMhI,cAAKC,IAALD,CAAUsH,oBAAVtH,EAAgC,mBAAhCA,CAAV3B;AACA4J,sCAAOT,IAAPS,CAAYD,GAAZC;AACA,SAAOD,GAAP;AACF;;AAsJA,SAASE,UAAT,GAA8B;AAC5B,SAAOnF,QAAQoF,GAARpF,CAAYA,QAAQC,QAARD,KAAqB,OAArBA,GAA+B,aAA/BA,GAA+C,MAA3DA,KAAsE,EAA7E;AACF;;AAEA,SAAS4B,gBAAT,CAA0ByD,GAA1B,EAA+B;AAC7B/J,MAAIgK,UAAUH,YAAd7J;AACA,MAAI+J,IAAIE,MAAJF,CAAW,CAAXA,EAAcC,QAAQ9I,MAAtB6I,MAAkCC,OAAtC,EAA+C;AAC7C,WAAQ,IAAGD,IAAIE,MAAJF,CAAWC,QAAQ9I,MAAnB6I,CAA2B,EAAtC;AACF,GAFA,MAEO;AACL,WAAOA,GAAP;AACF;AACF","file":"../Exp.js","sourcesContent":["/**\n * @flow\n */\n\nimport promisify from 'util.promisify';\nimport existsAsync from 'exists-async';\nimport fs from 'fs';\nimport mkdirp from 'mkdirp';\nimport path from 'path';\nimport spawnAsync from '@expo/spawn-async';\nimport JsonFile from '@expo/json-file';\nimport joi from 'joi';\nimport rimraf from 'rimraf';\n\nimport * as Analytics from './Analytics';\nimport Api from './Api';\nimport * as Binaries from './Binaries';\nimport ErrorCode from './ErrorCode';\nimport * as Extract from './Extract';\nimport Logger from './Logger';\nimport NotificationCode from './NotificationCode';\nimport * as ProjectUtils from './project/ProjectUtils';\nimport UserManager from './User';\nimport * as UrlUtils from './UrlUtils';\nimport UserSettings from './UserSettings';\nimport XDLError from './XDLError';\nimport * as ProjectSettings from './ProjectSettings';\nimport MessageCode from './MessageCode';\n\n// FIXME(perry) eliminate usage of this template\nexport const ENTRY_POINT_PLATFORM_TEMPLATE_STRING = 'PLATFORM_GOES_HERE';\n\nexport { default as convertProjectAsync } from './project/Convert';\n\nconst readFileAsync = promisify(fs.readFile);\nconst writeFileAsync = promisify(fs.writeFile);\nconst validateAsync = promisify(joi.validate);\nconst mkdirpAsync = promisify(mkdirp);\n\nexport async function determineEntryPointAsync(root: string) {\n let { exp, pkg } = await ProjectUtils.readConfigJsonAsync(root);\n\n // entryPoint is relative to the packager root and main is relative\n // to the project root. So if your rn-cli.config.js points to a different\n // root than the project root, these can be different. Most of the time\n // you should use main.\n let entryPoint = pkg.main || 'index.js';\n if (exp && exp.entryPoint) {\n entryPoint = exp.entryPoint;\n }\n\n return entryPoint;\n}\n\nfunction _starterAppCacheDirectory() {\n let dotExpoHomeDirectory = UserSettings.dotExpoHomeDirectory();\n let dir = path.join(dotExpoHomeDirectory, 'starter-app-cache');\n mkdirp.sync(dir);\n return dir;\n}\n\nasync function _downloadStarterAppAsync(templateId, progressFunction, retryFunction) {\n let versions = await Api.versionsAsync();\n let templateApp = null;\n for (let i = 0; i < versions.templatesv2.length; i++) {\n if (templateId === versions.templatesv2[i].id) {\n templateApp = versions.templatesv2[i];\n }\n }\n\n if (!templateApp) {\n throw new XDLError(ErrorCode.INVALID_OPTIONS, `No template app with id ${templateId}.`);\n }\n\n let starterAppVersion = templateApp.version;\n let starterAppName = `${templateId}-${starterAppVersion}`;\n let filename = `${starterAppName}.tar.gz`;\n let starterAppPath = path.join(_starterAppCacheDirectory(), filename);\n\n if (await existsAsync(starterAppPath)) {\n return {\n starterAppPath,\n starterAppName,\n };\n }\n\n let url = `https://s3.amazonaws.com/exp-starter-apps/${filename}`;\n await Api.downloadAsync(\n url,\n path.join(_starterAppCacheDirectory(), filename),\n {},\n progressFunction,\n retryFunction\n );\n return {\n starterAppPath,\n starterAppName,\n };\n}\n\nexport async function downloadTemplateApp(templateId: string, selectedDir: string, opts: any) {\n // Validate\n let schema = joi.object().keys({\n name: joi.string().required(),\n });\n\n // Should we validate that name is a valid name here?\n try {\n await validateAsync({ name: opts.name }, schema);\n } catch (e) {\n throw new XDLError(ErrorCode.INVALID_OPTIONS, e.toString());\n }\n let name = opts.name;\n let root = path.join(selectedDir, name);\n\n Analytics.logEvent('New Project', {\n selectedDir,\n name,\n });\n\n let fileExists = true;\n try {\n // If file doesn't exist it will throw an error.\n // Don't want to continue unless there is nothing there.\n fs.statSync(root);\n } catch (e) {\n fileExists = false;\n }\n // This check is required because without it, the retry button would throw an error because the directory already exists,\n // even though it is empty.\n if (fileExists && fs.readdirSync(root).length !== 0) {\n throw new XDLError(\n ErrorCode.DIRECTORY_ALREADY_EXISTS,\n `That directory already exists. Please choose a different parent directory or project name.`\n );\n }\n\n // Download files\n await mkdirpAsync(root);\n Logger.notifications.info({ code: NotificationCode.PROGRESS }, MessageCode.DOWNLOADING);\n let { starterAppPath } = await _downloadStarterAppAsync(\n templateId,\n opts.progressFunction,\n opts.retryFunction\n );\n return { starterAppPath, name, root };\n}\n\nexport async function extractTemplateApp(starterAppPath: string, name: string, root: string) {\n Logger.notifications.info({ code: NotificationCode.PROGRESS }, MessageCode.EXTRACTING);\n await Extract.extractAsync(starterAppPath, root);\n\n // Update files\n Logger.notifications.info({ code: NotificationCode.PROGRESS }, MessageCode.CUSTOMIZING);\n\n // Update app.json\n let appJson = await readFileAsync(path.join(root, 'app.json'), 'utf8');\n let customAppJson = appJson\n .replace(/\\\"My New Project\\\"/, `\"${name}\"`)\n .replace(/\\\"my-new-project\\\"/, `\"${name}\"`);\n await writeFileAsync(path.join(root, 'app.json'), customAppJson, 'utf8');\n\n await initGitRepo(root);\n\n Logger.notifications.info({ code: NotificationCode.PROGRESS }, 'Starting project...');\n\n return root;\n}\n\nasync function initGitRepo(root: string) {\n if (process.platform === 'darwin' && !Binaries.isXcodeInstalled()) {\n Logger.global.warn(`Unable to initialize git repo. \\`git\\` not installed.`);\n return;\n }\n\n // let's see if we're in a git tree\n let insideGit = true;\n try {\n await spawnAsync('git', ['rev-parse', '--is-inside-work-tree'], {\n cwd: root,\n });\n Logger.global.debug('New project is already inside of a git repo, skipping git init.');\n } catch (e) {\n insideGit = false;\n }\n\n if (!insideGit) {\n try {\n await spawnAsync('git', ['init'], { cwd: root });\n } catch (e) {\n // no-op -- this is just a convenience and we don't care if it fails\n }\n }\n}\n\nexport async function saveRecentExpRootAsync(root: string) {\n root = path.resolve(root);\n\n // Write the recent Exps JSON file\n let recentExpsJsonFile = UserSettings.recentExpsJsonFile();\n let recentExps = await recentExpsJsonFile.readAsync();\n // Filter out copies of this so we don't get dupes in this list\n recentExps = recentExps.filter(function(x) {\n return x !== root;\n });\n recentExps.unshift(root);\n return await recentExpsJsonFile.writeAsync(recentExps.slice(0, 100));\n}\n\nfunction getHomeDir(): string {\n return process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME'] || '';\n}\n\nfunction makePathReadable(pth) {\n let homedir = getHomeDir();\n if (pth.substr(0, homedir.length) === homedir) {\n return `~${pth.substr(homedir.length)}`;\n } else {\n return pth;\n }\n}\n\nexport async function expInfoSafeAsync(root: string) {\n try {\n let { exp: { name, description, icon, iconUrl } } = await ProjectUtils.readConfigJsonAsync(\n root\n );\n let pathOrUrl =\n icon || iconUrl || 'https://d3lwq5rlu14cro.cloudfront.net/ExponentEmptyManifest_192.png';\n let resolvedPath = path.resolve(root, pathOrUrl);\n if (fs.existsSync(resolvedPath)) {\n icon = `file://${resolvedPath}`;\n } else {\n icon = pathOrUrl; // Assume already a URL\n }\n\n return {\n readableRoot: makePathReadable(root),\n root,\n name,\n description,\n icon,\n };\n } catch (e) {\n return null;\n }\n}\n\ntype PublishInfo = {\n args: {\n username: string,\n remoteUsername: string,\n remotePackageName: string,\n remoteFullPackageName: string,\n bundleIdentifierIOS: ?string,\n packageNameAndroid: ?string,\n },\n};\n\n// TODO: remove / change, no longer publishInfo, this is just used for signing\nexport async function getPublishInfoAsync(root: string): Promise<PublishInfo> {\n const user = await UserManager.ensureLoggedInAsync();\n\n if (!user) {\n throw new Error('Attempted to login in offline mode. This is a bug.');\n }\n\n const { username } = user;\n\n const { exp } = await ProjectUtils.readConfigJsonAsync(root);\n\n const name = exp.slug;\n const version = exp.version;\n\n const configName = await ProjectUtils.configFilenameAsync(root);\n\n if (!exp || !exp.sdkVersion) {\n throw new Error(`sdkVersion is missing from ${configName}`);\n }\n\n if (!name) {\n // slug is made programmatically for app.json\n throw new Error(`slug field is missing from exp.json.`);\n }\n\n if (!version) {\n throw new Error(`Can't get version of package.`);\n }\n\n let remotePackageName = name;\n let remoteUsername = username;\n let remoteFullPackageName = `@${remoteUsername}/${remotePackageName}`;\n let bundleIdentifierIOS = exp.ios ? exp.ios.bundleIdentifier : null;\n let packageNameAndroid = exp.android ? exp.android.package : null;\n\n return {\n args: {\n username,\n remoteUsername,\n remotePackageName,\n remoteFullPackageName,\n bundleIdentifierIOS,\n packageNameAndroid, // TODO: this isn't used anywhere\n },\n };\n}\n\nexport async function recentValidExpsAsync() {\n let recentExpsJsonFile = UserSettings.recentExpsJsonFile();\n let recentExps = await recentExpsJsonFile.readAsync();\n\n let results = await Promise.all(recentExps.map(expInfoSafeAsync));\n let filteredResults = results.filter(result => result);\n return filteredResults;\n}\n\nexport async function sendAsync(recipient: string, url_: string) {\n let result = await Api.callMethodAsync('send', [recipient, url_]);\n return result;\n}\n\n// TODO: figure out where these functions should live\nexport async function getProjectRandomnessAsync(projectRoot: string) {\n let ps = await ProjectSettings.readAsync(projectRoot);\n let randomness = ps.urlRandomness;\n if (randomness) {\n return randomness;\n } else {\n return resetProjectRandomnessAsync(projectRoot);\n }\n}\n\nexport async function resetProjectRandomnessAsync(projectRoot: string) {\n let randomness = UrlUtils.someRandomness();\n ProjectSettings.setAsync(projectRoot, { urlRandomness: randomness });\n return randomness;\n}\n\nexport async function clearXDLCacheAsync() {\n let dotExpoHomeDirectory = UserSettings.dotExpoHomeDirectory();\n rimraf.sync(path.join(dotExpoHomeDirectory, 'ios-simulator-app-cache'));\n rimraf.sync(path.join(dotExpoHomeDirectory, 'android-apk-cache'));\n rimraf.sync(path.join(dotExpoHomeDirectory, 'starter-app-cache'));\n Logger.notifications.info(`Cleared cache`);\n}\n"],"sourceRoot":"/xdl/src"} |