Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"dependencies": {
"@babel/generator": "^7.20.7",
"@babel/types": "^7.20.7",
"@expo/package-manager": "^0.0.57",
"@expo/spawn-async": "^1.7.0",
"@expo/cli": "^0.7.3",
"dot-object": "^2.1.4",
"prettier": "^2.8.0"
},
Expand Down
78 changes: 31 additions & 47 deletions packages/generator/src/expo/generate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import path from "path";
import fs from "node:fs";
import { AppSchema } from "@batiq/core";
import * as ExpoPackageManager from "@expo/package-manager";
import spawnAsync from "@expo/spawn-async";
import { generatePage } from "../codegen";
import Dot from "dot-object";
import { toVariableName } from "../utils/naming";
import { transformIR } from "@batiq/ir";
import { generateNavigation } from "./navigation";
import { getCombinedKnownVersionsAsync } from "@expo/cli/build/src/start/doctor/dependencies/getVersionedPackages";

const dot = new Dot("__");

Expand All @@ -33,6 +32,35 @@ export const installExpo = async (schema: AppSchema) => {
).flat()
)
);
const dependencies = [
"expo",
"@babel/core",
"@batiq/cli",
"@types/react",
"@types/react-native",
"dotenv",
"typescript",
"react",
"react-dom",
"react-native",
"react-native-web",
"@react-navigation/native-stack",
"@react-navigation/bottom-tabs",
"@react-navigation/native",
"react-native-screens",
"react-native-safe-area-context",
"@expo/webpack-config",
...componentDependencies,
];
const packages = await getCombinedKnownVersionsAsync({
projectRoot: "./app",
sdkVersion: "48.0.0",
skipCache: false,
});
const resolvedDependencies = dependencies.reduce(
(acc, dep) => ({ ...acc, [dep]: packages[dep] ?? "*" }),
{} as Record<string, string>
);
fs.writeFileSync(
"package.json",
JSON.stringify(
Expand All @@ -47,56 +75,12 @@ export const installExpo = async (schema: AppSchema) => {
web: "expo start --web",
},
private: true,
dependencies: resolvedDependencies,
},
null,
2
)
);
const pm = new ExpoPackageManager.NpmPackageManager({
cwd: process.cwd(),
silent: false,
});
if (process.env["NODE_ENV"] === "development") {
// remove yarn injected env variables
Object.keys(process.env)
.filter((key) => key.startsWith("npm"))
.forEach((key) => {
delete process.env[key];
});
}
await pm.addAsync("expo");
await pm.addDevAsync(
"@babel/core",
"@batiq/cli",
"@types/react",
"@types/react-native",
"dotenv",
"typescript"
);
await pm.installAsync();
const expoInstall = spawnAsync("npx", [
"expo",
"install",
"react",
"react-dom",
"react-native",
"react-native-web",
"@react-navigation/native-stack",
"@react-navigation/bottom-tabs",
"@react-navigation/native",
"react-native-screens",
"react-native-safe-area-context",
"@expo/webpack-config",
...componentDependencies,
"--npm",
]);
expoInstall.child.stdout?.on("data", (data) => {
console.log(data?.toString?.());
});
expoInstall.child.stderr?.on("data", (data) => {
console.error(data?.toString?.());
});
await expoInstall;
};

export const generateExpo = async (schema: AppSchema) => {
Expand Down