UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

58 lines (55 loc) • 3.42 kB
import { existsSync, readFileSync, writeFileSync } from "fs"; import { join, resolve } from "path"; import { validateNativeApp } from "../native/appManifest.native.js"; import { loadUserOneOptions } from "../vite/loadConfig.native.js"; var REACT_NATIVE_CONFIG = `module.exports = require('one/react-native-config') `; var REACT_NATIVE_CONFIG_NAMES = [ "react-native.config.js", "react-native.config.cjs", "react-native.config.mjs", "react-native.config.ts" ]; async function run(args) { var _packageJson_dependencies, _packageJson_devDependencies; var _app_ios, _app_ios1; var root = process.cwd(); var packageJson = JSON.parse(readFileSync(join(root, "package.json"), "utf8")); var hasExpo = Object.hasOwn((_packageJson_dependencies = packageJson.dependencies) !== null && _packageJson_dependencies !== void 0 ? _packageJson_dependencies : {}, "expo") || Object.hasOwn((_packageJson_devDependencies = packageJson.devDependencies) !== null && _packageJson_devDependencies !== void 0 ? _packageJson_devDependencies : {}, "expo"); if (hasExpo) { throw new Error("[one] one prebuild only generates Expo-free projects. This app declares expo; run Expo prebuild and list \"vxrn/expo-plugin\" in the Expo config."); } var { oneOptions } = await loadUserOneOptions("build", true); var native = oneOptions === null || oneOptions === void 0 ? void 0 : oneOptions.native; var app = typeof native === "object" ? native.app : void 0; if (!app) { throw new Error("[one] native.app is required: configure one({ native: { app } }) with name, ios.bundleId, and android.applicationId"); } validateNativeApp(app, args.platform); if ((((_app_ios = app.ios) === null || _app_ios === void 0 ? void 0 : _app_ios.backgroundTasks) || ((_app_ios1 = app.ios) === null || _app_ios1 === void 0 ? void 0 : _app_ios1.appIntents)) && args.platform !== "android") { var configured = oneOptions === null || oneOptions === void 0 ? void 0 : oneOptions.setupFile; var setupFile = typeof configured === "string" ? configured : configured && "native" in configured ? configured.native : configured && "ios" in configured ? configured.ios : void 0; if (!setupFile || !existsSync(resolve(root, setupFile))) { var _app_ios2; throw new Error(((_app_ios2 = app.ios) === null || _app_ios2 === void 0 ? void 0 : _app_ios2.backgroundTasks) ? "[one] native.app.ios.backgroundTasks requires an existing iOS native setupFile that defines every task handler before the app renders" : "[one] native.app.ios.appIntents requires an existing iOS native setupFile that defines every action handler before the app renders"); } } var present = REACT_NATIVE_CONFIG_NAMES.filter(function(name) { return existsSync(join(root, name)); }); if (present.length === 0) { writeFileSync(join(root, "react-native.config.cjs"), REACT_NATIVE_CONFIG); } else if (!present.some(function(name) { return readFileSync(join(root, name), "utf8").includes("one/react-native-config"); })) { throw new Error(`[one] ${present.join(", ")} does not load one/react-native-config, so Release builds would run the stock React Native bundler instead of One's. Set it to \`module.exports = require('one/react-native-config')\` or spread that into your config, then re-run one prebuild.`); } var { prebuild } = await import("vxrn"); await prebuild({ root: process.cwd(), ...args, app }); } export { run }; //# sourceMappingURL=prebuild.native.js.map