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.
148 lines
5.0 KiB
148 lines
5.0 KiB
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.startExpoServerAsync = startExpoServerAsync;
|
|
exports.stopExpoServerAsync = stopExpoServerAsync;
|
|
function _config() {
|
|
const data = require("@expo/config");
|
|
_config = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _axios() {
|
|
const data = _interopRequireDefault(require("axios"));
|
|
_axios = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _express() {
|
|
const data = _interopRequireDefault(require("express"));
|
|
_express = 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 }; }
|
|
function _isIgnorableBugReportingExtraData(body) {
|
|
return body.length === 2 && body[0] === 'BugReporting extraData:';
|
|
}
|
|
function _isAppRegistryStartupMessage(body) {
|
|
return body.length === 1 && (/^Running application "main" with appParams:/.test(body[0]) || /^Running "main" with \{/.test(body[0]));
|
|
}
|
|
function _handleDeviceLogs(projectRoot, deviceId, deviceName, logs) {
|
|
for (let i = 0; i < logs.length; i++) {
|
|
const log = logs[i];
|
|
let body = typeof log.body === 'string' ? [log.body] : log.body;
|
|
let {
|
|
level
|
|
} = log;
|
|
if (_isIgnorableBugReportingExtraData(body)) {
|
|
level = 'debug';
|
|
}
|
|
if (_isAppRegistryStartupMessage(body)) {
|
|
body = [`Running application on ${deviceName}.`];
|
|
}
|
|
const args = body.map(obj => {
|
|
if (typeof obj === 'undefined') {
|
|
return 'undefined';
|
|
}
|
|
if (obj === 'null') {
|
|
return 'null';
|
|
}
|
|
if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean') {
|
|
return obj;
|
|
}
|
|
try {
|
|
return JSON.stringify(obj);
|
|
} catch {
|
|
return obj.toString();
|
|
}
|
|
});
|
|
const logLevel = level === 'info' || level === 'warn' || level === 'error' || level === 'debug' ? level : 'info';
|
|
_internal().ProjectUtils.getLogger(projectRoot)[logLevel]({
|
|
tag: 'device',
|
|
deviceId,
|
|
deviceName,
|
|
groupDepth: log.groupDepth,
|
|
shouldHide: log.shouldHide,
|
|
includesStack: log.includesStack
|
|
}, ...args);
|
|
}
|
|
}
|
|
async function startExpoServerAsync(projectRoot) {
|
|
(0, _internal().assertValidProjectRoot)(projectRoot);
|
|
await stopExpoServerAsync(projectRoot);
|
|
const app = (0, _express().default)();
|
|
app.use(_express().default.json({
|
|
limit: '10mb'
|
|
}));
|
|
app.use(_express().default.urlencoded({
|
|
limit: '10mb',
|
|
extended: true
|
|
}));
|
|
if ((_internal().ConnectionStatus.isOffline() ? await _internal().Doctor.validateWithoutNetworkAsync(projectRoot) : await _internal().Doctor.validateWithNetworkAsync(projectRoot)) === _internal().Doctor.FATAL) {
|
|
throw new Error(`Couldn't start project. Please fix the errors and restart the project.`);
|
|
}
|
|
// Serve the manifest.
|
|
const manifestHandler = _internal().ManifestHandler.getManifestHandler(projectRoot);
|
|
const loadingHandler = _internal().LoadingPageHandler.getLoadingPageHandler(projectRoot);
|
|
app.get('/', manifestHandler);
|
|
app.get('/manifest', manifestHandler);
|
|
app.get('/index.exp', manifestHandler);
|
|
app.get(_internal().LoadingPageHandler.LoadingEndpoint, loadingHandler);
|
|
app.get(_internal().LoadingPageHandler.DeepLinkEndpoint, loadingHandler);
|
|
app.post('/logs', async (req, res) => {
|
|
try {
|
|
const deviceId = req.get('Device-Id');
|
|
const deviceName = req.get('Device-Name');
|
|
if (deviceId && deviceName && req.body) {
|
|
_handleDeviceLogs(projectRoot, deviceId, deviceName, req.body);
|
|
}
|
|
} catch (e) {
|
|
_internal().ProjectUtils.logError(projectRoot, 'expo', `Error getting device logs: ${e} ${e.stack}`);
|
|
}
|
|
res.send('Success');
|
|
});
|
|
app.post('/shutdown', async (req, res) => {
|
|
server.close();
|
|
res.send('Success');
|
|
});
|
|
const expRc = await (0, _config().readExpRcAsync)(projectRoot);
|
|
const expoServerPort = expRc.manifestPort ? expRc.manifestPort : await (0, _internal().getFreePortAsync)(19000);
|
|
await _internal().ProjectSettings.setPackagerInfoAsync(projectRoot, {
|
|
expoServerPort
|
|
});
|
|
let server = app.listen(expoServerPort, () => {
|
|
const info = server.address();
|
|
const host = info.address;
|
|
const port = info.port;
|
|
_internal().ProjectUtils.logDebug(projectRoot, 'expo', `Local server listening at http://${host}:${port}`);
|
|
});
|
|
}
|
|
async function stopExpoServerAsync(projectRoot) {
|
|
(0, _internal().assertValidProjectRoot)(projectRoot);
|
|
const packagerInfo = await _internal().ProjectSettings.readPackagerInfoAsync(projectRoot);
|
|
if (packagerInfo && packagerInfo.expoServerPort) {
|
|
try {
|
|
await _axios().default.request({
|
|
method: 'post',
|
|
url: `http://127.0.0.1:${packagerInfo.expoServerPort}/shutdown`
|
|
});
|
|
} catch {}
|
|
}
|
|
await _internal().ProjectSettings.setPackagerInfoAsync(projectRoot, {
|
|
expoServerPort: null
|
|
});
|
|
}
|
|
//# sourceMappingURL=startLegacyExpoServerAsync.js.map
|