203 lines
6.2 KiB
JavaScript
203 lines
6.2 KiB
JavaScript
|
// Copyright 2015-present 650 Industries. All rights reserved.
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.manifestUsesSplashApi = exports.transformFileContentsAsync = exports.spawnAsync = exports.spawnAsyncThrowError = exports.rimrafDontThrow = exports.getManifestAsync = exports.saveImageToPathAsync = exports.saveUrlToPathAsync = exports.parseSdkMajorVersion = exports.isDirectory = undefined;
|
||
|
|
||
|
let getManifestAsync = (() => {
|
||
|
var _ref = _asyncToGenerator(function* (url, headers) {
|
||
|
let requestOptions = {
|
||
|
url: url.replace('exp://', 'http://') + '/index.exp',
|
||
|
headers
|
||
|
};
|
||
|
|
||
|
let response = yield request(requestOptions);
|
||
|
let responseBody = response.body;
|
||
|
console.log('Using manifest:', responseBody);
|
||
|
let manifest;
|
||
|
try {
|
||
|
manifest = JSON.parse(responseBody);
|
||
|
} catch (e) {
|
||
|
throw new Error(`Unable to parse manifest: ${e}`);
|
||
|
}
|
||
|
|
||
|
return manifest;
|
||
|
});
|
||
|
|
||
|
return function getManifestAsync(_x, _x2) {
|
||
|
return _ref.apply(this, arguments);
|
||
|
};
|
||
|
})();
|
||
|
|
||
|
let spawnAsyncThrowError = (() => {
|
||
|
var _ref2 = _asyncToGenerator(function* (...args) {
|
||
|
if (args.length === 2) {
|
||
|
return (0, (_spawnAsync || _load_spawnAsync()).default)(args[0], args[1], {
|
||
|
stdio: 'inherit',
|
||
|
cwd: process.cwd()
|
||
|
});
|
||
|
} else {
|
||
|
return (0, (_spawnAsync || _load_spawnAsync()).default)(...args);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return function spawnAsyncThrowError() {
|
||
|
return _ref2.apply(this, arguments);
|
||
|
};
|
||
|
})();
|
||
|
|
||
|
let spawnAsync = (() => {
|
||
|
var _ref3 = _asyncToGenerator(function* (...args) {
|
||
|
try {
|
||
|
return yield spawnAsyncThrowError(...args);
|
||
|
} catch (e) {
|
||
|
console.error(e.message);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return function spawnAsync() {
|
||
|
return _ref3.apply(this, arguments);
|
||
|
};
|
||
|
})();
|
||
|
|
||
|
let transformFileContentsAsync = (() => {
|
||
|
var _ref4 = _asyncToGenerator(function* (filename, transform) {
|
||
|
let fileString = yield (_fsExtra || _load_fsExtra()).default.readFile(filename, 'utf8');
|
||
|
let newFileString = transform(fileString);
|
||
|
if (newFileString !== null) {
|
||
|
yield (_fsExtra || _load_fsExtra()).default.writeFile(filename, newFileString);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return function transformFileContentsAsync(_x3, _x4) {
|
||
|
return _ref4.apply(this, arguments);
|
||
|
};
|
||
|
})();
|
||
|
|
||
|
var _fsExtra;
|
||
|
|
||
|
function _load_fsExtra() {
|
||
|
return _fsExtra = _interopRequireDefault(require('fs-extra'));
|
||
|
}
|
||
|
|
||
|
var _path = _interopRequireDefault(require('path'));
|
||
|
|
||
|
var _requestPromiseNative;
|
||
|
|
||
|
function _load_requestPromiseNative() {
|
||
|
return _requestPromiseNative = _interopRequireDefault(require('request-promise-native'));
|
||
|
}
|
||
|
|
||
|
var _rimraf;
|
||
|
|
||
|
function _load_rimraf() {
|
||
|
return _rimraf = _interopRequireDefault(require('rimraf'));
|
||
|
}
|
||
|
|
||
|
var _spawnAsync;
|
||
|
|
||
|
function _load_spawnAsync() {
|
||
|
return _spawnAsync = _interopRequireDefault(require('@expo/spawn-async'));
|
||
|
}
|
||
|
|
||
|
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"); }); }; }
|
||
|
|
||
|
const request = (_requestPromiseNative || _load_requestPromiseNative()).default.defaults({
|
||
|
resolveWithFullResponse: true
|
||
|
});
|
||
|
|
||
|
function _getFilesizeInBytes(path) {
|
||
|
let stats = (_fsExtra || _load_fsExtra()).default.statSync(path);
|
||
|
let fileSizeInBytes = stats['size'];
|
||
|
return fileSizeInBytes;
|
||
|
}
|
||
|
|
||
|
function parseSdkMajorVersion(expSdkVersion) {
|
||
|
let sdkMajorVersion = 0;
|
||
|
try {
|
||
|
let versionComponents = expSdkVersion.split('.').map(number => parseInt(number, 10));
|
||
|
sdkMajorVersion = versionComponents[0];
|
||
|
} catch (_) {}
|
||
|
return sdkMajorVersion;
|
||
|
}
|
||
|
|
||
|
function saveUrlToPathAsync(url, path) {
|
||
|
return new Promise(function (resolve, reject) {
|
||
|
let stream = (_fsExtra || _load_fsExtra()).default.createWriteStream(path);
|
||
|
stream.on('close', () => {
|
||
|
if (_getFilesizeInBytes(path) < 10) {
|
||
|
throw new Error(`{filename} is too small`);
|
||
|
}
|
||
|
resolve();
|
||
|
});
|
||
|
stream.on('error', reject);
|
||
|
request(url).pipe(stream);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function saveImageToPathAsync(projectRoot, pathOrURL, outPath) {
|
||
|
const localPath = _path.default.resolve(projectRoot, pathOrURL);
|
||
|
return new Promise(function (resolve, reject) {
|
||
|
let stream = (_fsExtra || _load_fsExtra()).default.createWriteStream(outPath);
|
||
|
stream.on('close', () => {
|
||
|
if (_getFilesizeInBytes(outPath) < 10) {
|
||
|
throw new Error(`{filename} is too small`);
|
||
|
}
|
||
|
resolve();
|
||
|
});
|
||
|
stream.on('error', reject);
|
||
|
if ((_fsExtra || _load_fsExtra()).default.existsSync(localPath)) {
|
||
|
(_fsExtra || _load_fsExtra()).default.createReadStream(localPath).pipe(stream);
|
||
|
} else {
|
||
|
request(pathOrURL).pipe(stream);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function manifestUsesSplashApi(manifest, platform) {
|
||
|
if (platform === 'ios') {
|
||
|
return manifest.splash || manifest.ios && manifest.ios.splash;
|
||
|
}
|
||
|
if (platform === 'android') {
|
||
|
return manifest.splash || manifest.android && manifest.android.splash;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
function rimrafDontThrow(directory) {
|
||
|
try {
|
||
|
(_rimraf || _load_rimraf()).default.sync(directory);
|
||
|
} catch (e) {
|
||
|
console.warn(`There was an issue cleaning up, but your project should still work. You may need to manually remove ${directory}. (${e})`);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function isDirectory(dir) {
|
||
|
try {
|
||
|
if ((_fsExtra || _load_fsExtra()).default.statSync(dir).isDirectory()) {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
} catch (e) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
exports.isDirectory = isDirectory;
|
||
|
exports.parseSdkMajorVersion = parseSdkMajorVersion;
|
||
|
exports.saveUrlToPathAsync = saveUrlToPathAsync;
|
||
|
exports.saveImageToPathAsync = saveImageToPathAsync;
|
||
|
exports.getManifestAsync = getManifestAsync;
|
||
|
exports.rimrafDontThrow = rimrafDontThrow;
|
||
|
exports.spawnAsyncThrowError = spawnAsyncThrowError;
|
||
|
exports.spawnAsync = spawnAsync;
|
||
|
exports.transformFileContentsAsync = transformFileContentsAsync;
|
||
|
exports.manifestUsesSplashApi = manifestUsesSplashApi;
|
||
|
//# sourceMappingURL=../__sourcemaps__/detach/ExponentTools.js.map
|