Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function startExpoProject(config, platform) {
try {
const projectRoot = path.join(path.resolve('.'), '.expo', platform);
setupExpoDir(projectRoot, platform);
await startExpoServer(projectRoot, config.devServer.port);
const address = await UrlUtils.constructManifestUrlAsync(projectRoot);
console.log(`Expo address for ${platform}:`, address);
console.log("To open this app on your phone scan this QR code in Expo Client (if it doesn't get started automatically)");
qr.generate(address, code => {
console.log(code);
});
if (platform === 'android') {
const { success, error } = await Android.openProjectAsync(projectRoot);
if (!success) {
console.error(error.message);
}
} else if (platform === 'ios') {
const { success, msg } = await Simulator.openUrlInSimulatorSafeAsync(address);
if (!success) {
console.error("Failed to start Simulator: ", msg);
}
}
} catch (e) {
console.error(e.stack);
}
}
async function handleKeypress(key) {
switch (key) {
case CTRL_C:
case CTRL_D:
process.emit('SIGINT');
return;
case 'a': {
clearConsole();
log.withTimestamp('Starting Android...');
const { success, error } = await Android.openProjectAsync(process.cwd());
if (!success) {
log(chalk.red(error.message));
}
printUsage();
return;
}
case 'i': {
clearConsole();
log.withTimestamp('Starting iOS...');
const localAddress = await UrlUtils.constructManifestUrlAsync(process.cwd(), {
hostType: 'localhost',
});
const { success, msg } = await Simulator.openUrlInSimulatorSafeAsync(localAddress);
if (!success) {
log(chalk.red(msg));
}
async function handleKeypress (key) {
switch (key) {
case CTRL_C:
case CTRL_D:
process.emit('SIGINT')
return
case 'a': {
clearConsole()
log.withTimestamp('Starting Android...')
const { success, error } = await Android.openProjectAsync(projectDir)
if (!success) {
log(chalk.red(error.message))
}
printUsage()
return
}
case 'i': {
clearConsole()
log.withTimestamp('Starting iOS...')
const localAddress = await UrlUtils.constructManifestUrlAsync(projectDir, {
hostType: 'localhost'
})
const { success, msg } = await Simulator.openUrlInSimulatorSafeAsync(localAddress)
if (!success) {
log(chalk.red(msg))
}
async function startAndroidAndPrintInfo() {
const address = await UrlUtils.constructManifestUrlAsync(process.cwd());
log.withTimestamp('Starting Android...');
const { success, error } = await Android.openProjectAsync(process.cwd());
qr.generate(address, qrCode => {
log.withTimestamp(`${chalk.green('Packager started!')}`);
log(
`
To view your app with live reloading, point the Expo app to this QR code.
You'll find the QR scanner on the Projects tab of the app.
${indent(qrCode, 2)}
Or enter this address in the Expo app's search bar:
${chalk.underline(chalk.cyan(address))}
Your phone will need to be on the same local network as this computer.
For links to install the Expo app, please visit ${chalk.underline(chalk.cyan('https://expo.io'))}.
_simulatorAndroidAsync = async () => {
return await Android.openProjectAsync(this.props.projectRoot);
};
}
async function handleMobileOptsAsync(projectDir, options) {
if (options.android) {
await Android.openProjectAsync(projectDir);
}
if (options.ios) {
await Simulator.openProjectAsync(projectDir);
}
return !!options.android || !!options.ios;
}