You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
4.8 KiB

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.deleteLinesInFileAsync = deleteLinesInFileAsync;
exports.getManifestAsync = getManifestAsync;
exports.getResolvedLocalesAsync = getResolvedLocalesAsync;
exports.isDirectory = isDirectory;
exports.regexFileAsync = regexFileAsync;
exports.saveUrlToPathAsync = saveUrlToPathAsync;
exports.spawnAsync = spawnAsync;
exports.spawnAsyncThrowError = spawnAsyncThrowError;
function _spawnAsync() {
const data = _interopRequireDefault(require("@expo/spawn-async"));
_spawnAsync = function () {
return data;
};
return data;
}
function _axios() {
const data = _interopRequireDefault(require("axios"));
_axios = 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 _internal() {
const data = require("../internal");
_internal = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
async function saveUrlToPathAsync(url, path, timeout = 20000) {
const response = await _axios().default.get(url, {
responseType: 'stream',
timeout
});
return new Promise(function (resolve, reject) {
const stream = _fsExtra().default.createWriteStream(path);
stream.on('close', resolve);
stream.on('error', reject);
response.data.on('error', reject).pipe(stream);
});
}
async function getManifestAsync(url, headers, options = {}) {
const buildPhaseLogger = options.logger || _internal().LoggerDetach.withFields({
buildPhase: 'reading manifest'
});
let response;
try {
response = await _retryPromise(() => _axios().default.get(url.replace('exp://', 'http://'), {
headers
}));
} catch (err) {
buildPhaseLogger.error(err);
throw new Error('Failed to fetch manifest from www');
}
buildPhaseLogger.info('Using manifest:', JSON.stringify(response.data, null, 2));
return response.data;
}
async function _retryPromise(fn, retries = 5) {
try {
return await fn();
} catch (err) {
if (retries-- > 0) {
return await _retryPromise(fn, retries);
} else {
throw err;
}
}
}
async function spawnAsyncThrowError(command, args, options = {
stdio: 'inherit',
cwd: process.cwd()
}) {
const {
pipeToLogger
} = options;
if (pipeToLogger) {
options.stdio = 'pipe';
options.cwd = options.cwd || process.cwd();
}
const promise = (0, _spawnAsync().default)(command, args, options);
if (pipeToLogger && promise.child) {
const streams = {};
if (pipeToLogger === true || pipeToLogger.stdout) {
streams.stdout = promise.child.stdout;
}
if (pipeToLogger === true || pipeToLogger.stderr) {
streams.stderr = promise.child.stderr;
}
(0, _internal().pipeOutputToLogger)(streams, options.loggerFields, options);
}
return promise;
}
async function spawnAsync(command, args, options) {
try {
return await spawnAsyncThrowError(command, args, options);
} catch (e) {
_internal().LoggerDetach.error(e.message);
}
}
function isDirectory(dir) {
try {
if (_fsExtra().default.statSync(dir).isDirectory()) {
return true;
}
return false;
} catch {
return false;
}
}
async function getResolvedLocalesAsync(projectRoot, exp) {
const locales = {};
if (exp.locales !== undefined) {
for (const [lang, localePath] of Object.entries(exp.locales)) {
const s = await _fsExtra().default.readFile(_path().default.resolve(projectRoot, localePath), 'utf8');
try {
locales[lang] = JSON.parse(s);
} catch (e) {
throw new (_internal().XDLError)('INVALID_JSON', JSON.stringify(e));
}
}
}
return locales;
}
async function regexFileAsync(regex, replace, filename) {
const file = await _fsExtra().default.readFile(filename);
const fileString = file.toString();
await _fsExtra().default.writeFile(filename, fileString.replace(regex, replace));
}
// Matches sed /d behavior
async function deleteLinesInFileAsync(startRegex, endRegex, filename) {
const file = await _fsExtra().default.readFile(filename);
const fileString = file.toString();
const lines = fileString.split(/\r?\n/);
const filteredLines = [];
let inDeleteRange = false;
for (let i = 0; i < lines.length; i++) {
if (lines[i].match(startRegex)) {
inDeleteRange = true;
}
if (!inDeleteRange) {
filteredLines.push(lines[i]);
}
if (inDeleteRange && lines[i].match(endRegex)) {
inDeleteRange = false;
}
}
await _fsExtra().default.writeFile(filename, filteredLines.join('\n'));
}
//# sourceMappingURL=ExponentTools.js.map