write script to use env variables

This commit is contained in:
Andy Malkin 2024-02-06 15:42:41 -08:00
parent 35a94b4a75
commit ee085cbbb1
3 changed files with 30 additions and 2 deletions

View File

@ -7,8 +7,8 @@
"start:android": "expo start --android", "start:android": "expo start --android",
"start:ios": "expo start --ios", "start:ios": "expo start --ios",
"android": "expo run:android", "android": "expo run:android",
"android:dev": "NODE_ENV=development expo run:android", "android:dev": "node ./start.js development",
"android:prod": "NODE_ENV=production expo run:android", "android:test": "node ./start.js test",
"ios": "expo run:ios", "ios": "expo run:ios",
"ios:dev": "NODE_ENV=development expo run:ios", "ios:dev": "NODE_ENV=development expo run:ios",
"ios:prod": "NODE_ENV=production expo run:ios", "ios:prod": "NODE_ENV=production expo run:ios",

28
start.js Normal file
View File

@ -0,0 +1,28 @@
const { spawn } = require("child_process");
const envName = process.argv[2];
const expoStart = spawn("expo", ["start", "-c"]);
expoStart.stdout.on("data", (data) => {
console.log(`${data}`);
if (data.toString().includes("Logs for your project will appear below")) {
console.log("Shutting down the server...");
expoStart.kill("SIGINT");
}
});
expoStart.on("close", () => {
const env = { ...process.env, NODE_ENV: envName };
const expoRunAndroid = spawn("expo", ["run:android"], { env });
expoRunAndroid.stdout.on("data", (data) => {
console.log(`${data}`);
});
expoRunAndroid.stderr.on("data", (data) => {
console.error(`${data}`);
});
});