UNPKG

@expo/xdl

Version:
207 lines (161 loc) 5.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readAsync = readAsync; exports.setAsync = setAsync; exports.readPackagerInfoAsync = readPackagerInfoAsync; exports.getCurrentStatusAsync = getCurrentStatusAsync; exports.setPackagerInfoAsync = setPackagerInfoAsync; exports.dotExpoProjectDirectory = dotExpoProjectDirectory; exports.dotExpoProjectDirectoryExists = dotExpoProjectDirectoryExists; exports.getPackagerOptsAsync = getPackagerOptsAsync; function _jsonFile() { const data = _interopRequireDefault(require("@expo/json-file")); _jsonFile = function () { return data; }; return data; } function _fsExtra() { const data = _interopRequireDefault(require("fs-extra")); _fsExtra = function () { return data; }; return data; } function _path() { const data = _interopRequireDefault(require("path")); _path = function () { return data; }; return data; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const projectSettingsFile = 'settings.json'; const projectSettingsDefaults = { scheme: null, hostType: 'lan', lanType: 'ip', devClient: false, dev: true, minify: false, urlRandomness: null, https: false }; const packagerInfoFile = 'packager-info.json'; function projectSettingsJsonFile(projectRoot) { return new (_jsonFile().default)(_path().default.join(dotExpoProjectDirectory(projectRoot), projectSettingsFile)); } function packagerInfoJsonFile(projectRoot) { return new (_jsonFile().default)(_path().default.join(dotExpoProjectDirectory(projectRoot), packagerInfoFile)); } async function readAsync(projectRoot) { let projectSettings; try { projectSettings = await projectSettingsJsonFile(projectRoot).readAsync(); } catch (e) { projectSettings = await projectSettingsJsonFile(projectRoot).writeAsync(projectSettingsDefaults); } migrateDeprecatedSettings(projectSettings); // Set defaults for any missing fields return { ...projectSettingsDefaults, ...projectSettings }; } function migrateDeprecatedSettings(projectSettings) { if (projectSettings.hostType === 'ngrok') { // 'ngrok' is deprecated projectSettings.hostType = 'tunnel'; } if (projectSettings.urlType) { // urlType is deprecated as a project setting delete projectSettings.urlType; } if ('strict' in projectSettings) { // strict mode is not supported at the moment delete projectSettings.strict; } } async function setAsync(projectRoot, json) { try { return await projectSettingsJsonFile(projectRoot).mergeAsync(json, { cantReadFileDefault: projectSettingsDefaults }); } catch (e) { return await projectSettingsJsonFile(projectRoot).writeAsync({ ...projectSettingsDefaults, ...json }); } } async function readPackagerInfoAsync(projectRoot) { try { return await packagerInfoJsonFile(projectRoot).readAsync({ cantReadFileDefault: {} }); } catch (e) { return await packagerInfoJsonFile(projectRoot).writeAsync({}); } } async function getCurrentStatusAsync(projectRoot) { const { packagerPort, expoServerPort } = await readPackagerInfoAsync(projectRoot); if (packagerPort && expoServerPort) { return 'running'; } else if (packagerPort || expoServerPort) { return 'ill'; } else { return 'exited'; } } async function setPackagerInfoAsync(projectRoot, json) { try { return await packagerInfoJsonFile(projectRoot).mergeAsync(json, { cantReadFileDefault: {} }); } catch (e) { return await packagerInfoJsonFile(projectRoot).writeAsync(json); } } function dotExpoProjectDirectory(projectRoot) { const dirPath = _path().default.join(projectRoot, '.expo'); try { // move .exponent to .expo const oldDirPath = _path().default.join(projectRoot, '.exponent'); if (_fsExtra().default.statSync(oldDirPath).isDirectory()) { _fsExtra().default.renameSync(oldDirPath, dirPath); } } catch (e) {// no old directory, continue } _fsExtra().default.mkdirpSync(dirPath); const readmeFilePath = _path().default.resolve(dirPath, 'README.md'); if (!_fsExtra().default.existsSync(readmeFilePath)) { _fsExtra().default.writeFileSync(readmeFilePath, `> Why do I have a folder named ".expo" in my project? The ".expo" folder is created when an Expo project is started using "expo start" command. > What does the "packager-info.json" file contain? The "packager-info.json" file contains port numbers and process PIDs that are used to serve the application to the mobile device/simulator. > What does the "settings.json" file contain? The "settings.json" file contains the server configuration that is used to serve the application manifest. > Should I commit the ".expo" folder? No, you should not share the ".expo" folder. It does not contain any information that is relevant for other developers working on the project, it is specific to your machine. Upon project creation, the ".expo" folder is already added to your ".gitignore" file. `); } return dirPath; } function dotExpoProjectDirectoryExists(projectRoot) { const dirPath = _path().default.join(projectRoot, '.expo'); try { if (_fsExtra().default.statSync(dirPath).isDirectory()) { return true; } } catch (e) {// file doesn't exist } return false; } async function getPackagerOptsAsync(projectRoot) { const projectSettings = await readAsync(projectRoot); return projectSettings; } //# sourceMappingURL=__sourcemaps__/ProjectSettings.js.map