1import { getDevServer } from '../getDevServer';
2
3/** Middleware for creating an entry file in the project. */
4export function createEntryFileAsync() {
5  if (process.env.NODE_ENV === 'production') {
6    // No dev server
7    console.warn('createEntryFile() cannot be used in production');
8    return;
9  }
10
11  // Pings middleware in the Expo CLI dev server.
12  return fetch(getDevServer().url + '_expo/touch', {
13    method: 'POST',
14    body: JSON.stringify({
15      contents: TEMPLATE,
16      // Legacy
17      path: './app/index.js',
18      // New
19      absolutePath: getAbsolutePath(),
20    }),
21  });
22}
23
24export function getAbsolutePath() {
25  return process.env.EXPO_ROUTER_ABS_APP_ROOT + '/index.js';
26}
27
28const TEMPLATE = `import { StyleSheet, Text, View } from "react-native";
29
30export default function Page() {
31  return (
32    <View style={styles.container}>
33      <View style={styles.main}>
34        <Text style={styles.title}>Hello World</Text>
35        <Text style={styles.subtitle}>This is the first page of your app.</Text>
36      </View>
37    </View>
38  );
39}
40
41const styles = StyleSheet.create({
42  container: {
43    flex: 1,
44    alignItems: "center",
45    padding: 24,
46  },
47  main: {
48    flex: 1,
49    justifyContent: "center",
50    maxWidth: 960,
51    marginHorizontal: "auto",
52  },
53  title: {
54    fontSize: 64,
55    fontWeight: "bold",
56  },
57  subtitle: {
58    fontSize: 36,
59    color: "#38434D",
60  },
61});
62`;
63