GT2/GT2-iOS/node_modules/xdl/build/ProjectSettings.js

173 lines
5.3 KiB
JavaScript

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getPackagerOptsAsync = exports.setPackagerInfoAsync = exports.readPackagerInfoAsync = exports.setAsync = exports.readAsync = undefined;
let readAsync = exports.readAsync = (() => {
var _ref = _asyncToGenerator(function* (projectRoot) {
let projectSettings;
try {
projectSettings = yield projectSettingsJsonFile(projectRoot, projectSettingsFile).readAsync();
} catch (e) {
projectSettings = yield projectSettingsJsonFile(projectRoot, projectSettingsFile).writeAsync(projectSettingsDefaults);
}
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;
}
// Set defaults for any missing fields
(_lodash || _load_lodash()).default.defaults(projectSettings, projectSettingsDefaults);
return projectSettings;
});
return function readAsync(_x) {
return _ref.apply(this, arguments);
};
})();
let setAsync = exports.setAsync = (() => {
var _ref2 = _asyncToGenerator(function* (projectRoot, json) {
try {
return yield projectSettingsJsonFile(projectRoot, projectSettingsFile).mergeAsync(json, {
cantReadFileDefault: projectSettingsDefaults
});
} catch (e) {
return yield projectSettingsJsonFile(projectRoot, projectSettingsFile).writeAsync((_lodash || _load_lodash()).default.defaults(json, projectSettingsDefaults));
}
});
return function setAsync(_x2, _x3) {
return _ref2.apply(this, arguments);
};
})();
let readPackagerInfoAsync = exports.readPackagerInfoAsync = (() => {
var _ref3 = _asyncToGenerator(function* (projectRoot) {
try {
return yield projectSettingsJsonFile(projectRoot, packagerInfoFile).readAsync({
cantReadFileDefault: {}
});
} catch (e) {
return yield projectSettingsJsonFile(projectRoot, packagerInfoFile).writeAsync({});
}
});
return function readPackagerInfoAsync(_x4) {
return _ref3.apply(this, arguments);
};
})();
let setPackagerInfoAsync = exports.setPackagerInfoAsync = (() => {
var _ref4 = _asyncToGenerator(function* (projectRoot, json) {
try {
return yield projectSettingsJsonFile(projectRoot, packagerInfoFile).mergeAsync(json, {
cantReadFileDefault: {}
});
} catch (e) {
return yield projectSettingsJsonFile(projectRoot, packagerInfoFile).writeAsync(json);
}
});
return function setPackagerInfoAsync(_x5, _x6) {
return _ref4.apply(this, arguments);
};
})();
let getPackagerOptsAsync = exports.getPackagerOptsAsync = (() => {
var _ref5 = _asyncToGenerator(function* (projectRoot) {
let projectSettings = yield readAsync(projectRoot);
return projectSettings;
});
return function getPackagerOptsAsync(_x7) {
return _ref5.apply(this, arguments);
};
})();
exports.dotExpoProjectDirectory = dotExpoProjectDirectory;
exports.dotExpoProjectDirectoryExists = dotExpoProjectDirectoryExists;
var _lodash;
function _load_lodash() {
return _lodash = _interopRequireDefault(require('lodash'));
}
var _jsonFile;
function _load_jsonFile() {
return _jsonFile = _interopRequireDefault(require('@expo/json-file'));
}
var _fs = _interopRequireDefault(require('fs'));
var _mkdirp;
function _load_mkdirp() {
return _mkdirp = _interopRequireDefault(require('mkdirp'));
}
var _path = _interopRequireDefault(require('path'));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
let projectSettingsFile = 'settings.json';
let projectSettingsDefaults = {
hostType: 'tunnel',
lanType: 'ip',
dev: true,
minify: false,
urlRandomness: null
};
let packagerInfoFile = 'packager-info.json';
function projectSettingsJsonFile(projectRoot, filename) {
return new (_jsonFile || _load_jsonFile()).default(_path.default.join(dotExpoProjectDirectory(projectRoot), filename));
}
function dotExpoProjectDirectory(projectRoot) {
let dirPath = _path.default.join(projectRoot, '.expo');
try {
// move .exponent to .expo
let oldDirPath = _path.default.join(projectRoot, '.exponent');
if (_fs.default.statSync(oldDirPath).isDirectory()) {
_fs.default.renameSync(oldDirPath, dirPath);
}
} catch (e) {
// no old directory, continue
}
(_mkdirp || _load_mkdirp()).default.sync(dirPath);
return dirPath;
}
function dotExpoProjectDirectoryExists(projectRoot) {
let dirPath = _path.default.join(projectRoot, '.expo');
try {
if (_fs.default.statSync(dirPath).isDirectory()) {
return true;
}
} catch (e) {
// file doesn't exist
}
return false;
}
//# sourceMappingURL=__sourcemaps__/ProjectSettings.js.map