|
| 1 | +import { Android, Config, ProjectSettings, UrlUtils } from "xdl"; |
| 2 | + |
| 3 | +import chalk from "chalk"; |
| 4 | +import indent from "indent-string"; |
| 5 | +import path from "path"; |
| 6 | +import pathExists from "path-exists"; |
| 7 | +import qr from "qrcode-terminal"; |
| 8 | + |
| 9 | +import packager from "../util/packager"; |
| 10 | + |
| 11 | +Config.validation.reactNativeVersionWarnings = false; |
| 12 | +Config.developerTool = "crna"; |
| 13 | +Config.offline = true; |
| 14 | + |
| 15 | +const command: string = pathExists.sync(path.join(process.cwd(), "yarn.lock")) |
| 16 | + ? "yarnpkg" |
| 17 | + : "npm"; |
| 18 | + |
| 19 | +packager.run(startAndroidAndPrintInfo); |
| 20 | + |
| 21 | +// print a nicely formatted message with setup information |
| 22 | +async function startAndroidAndPrintInfo() { |
| 23 | + const address = await UrlUtils.constructManifestUrlAsync(process.cwd()); |
| 24 | + console.log(chalk.blue("Starting Android...")); |
| 25 | + |
| 26 | + const { success, error } = await Android.openProjectAsync(process.cwd()); |
| 27 | + |
| 28 | + qr.generate(address, qrCode => { |
| 29 | + console.log( |
| 30 | + `To view your app with live reloading, point the Exponent app to this QR code: |
| 31 | +
|
| 32 | +${indent(qrCode, 2)} |
| 33 | +
|
| 34 | +You'll find the QR scanner on the Projects tab of the app, under the '+' menu. |
| 35 | +
|
| 36 | +Or enter this address in the Exponent app's search bar: |
| 37 | +
|
| 38 | + ${chalk.underline(chalk.cyan(address))} |
| 39 | +
|
| 40 | +Your phone will need to be on the same local network as this computer. |
| 41 | +
|
| 42 | +For links to install the Exponent app, please visit ${chalk.underline(chalk.cyan("https://getexponent.com"))}. |
| 43 | +
|
| 44 | +Logs from serving your app will appear here. Press Ctrl+C at any time to stop. |
| 45 | +` |
| 46 | + ); |
| 47 | + }); |
| 48 | + |
| 49 | + if (!success) { |
| 50 | + console.log(chalk.red(error.message)); |
| 51 | + } |
| 52 | +} |
0 commit comments