1#!/usr/bin/env node
2
3// Basic node CLI script to resolve the native app entry file.
4//
5// Usage:
6//   node expo/scripts/resolveAppEntry.js path/to/project-root <platform> <format>
7//
8// Example:
9//   node expo/scripts/resolveAppEntry.js path/to/project-root/ android absolute
10//
11// Returns:
12//   The resolved entry file path.
13//
14// Limitations:
15//   Currently only supports android and ios.
16
17const { resolveEntryPoint } = require('@expo/config/paths');
18const fs = require('fs');
19const path = require('path');
20
21const projectRoot = process.argv[1];
22const platform = process.argv[2];
23const absolute = process.argv[3] === 'absolute';
24
25if (!platform || !projectRoot) {
26  console.error(
27    'Usage: node expo/scripts/resolveAppEntry.js <projectRoot> <platform> <relative|absolute>'
28  );
29  process.exit(1);
30}
31
32const entry = resolveEntryPoint(projectRoot, { platform });
33
34if (entry) {
35  // Prevent any logs from the app.config.js
36  // from being used in the output of this command.
37  console.clear();
38  // React Native's `PROJECT_ROOT` could be using a different root on MacOS (`/var` vs `/private/var`)
39  // We need to make sure to get the real path, `resolveEntryPoint` is using this too
40  console.log(
41    absolute
42      ? path.resolve(entry)
43      : path.relative(fs.realpathSync(projectRoot), fs.realpathSync(entry))
44  );
45} else {
46  console.error(`Error: Could not find entry file for project at: ${projectRoot}`);
47  process.exit(1);
48}
49