UNPKG

one

Version:

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

76 lines (75 loc) • 4.14 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var prebuild_exports = {}; __export(prebuild_exports, { run: () => run }); module.exports = __toCommonJS(prebuild_exports); var import_node_fs = require("node:fs"); var import_node_path = require("node:path"); var import_appManifest = require("../native/appManifest.cjs"); var import_loadConfig = require("../vite/loadConfig.cjs"); const REACT_NATIVE_CONFIG = `module.exports = require('one/react-native-config') `; const REACT_NATIVE_CONFIG_NAMES = [ "react-native.config.js", "react-native.config.cjs", "react-native.config.mjs", "react-native.config.ts" ]; async function run(args) { const root = process.cwd(); const packageJson = JSON.parse((0, import_node_fs.readFileSync)((0, import_node_path.join)(root, "package.json"), "utf8")); const hasExpo = Object.hasOwn(packageJson.dependencies ?? {}, "expo") || Object.hasOwn(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."); } const { oneOptions } = await (0, import_loadConfig.loadUserOneOptions)("build", true); const native = oneOptions?.native; const 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"); } (0, import_appManifest.validateNativeApp)(app, args.platform); if ((app.ios?.backgroundTasks || app.ios?.appIntents) && args.platform !== "android") { const configured = oneOptions?.setupFile; const setupFile = typeof configured === "string" ? configured : configured && "native" in configured ? configured.native : configured && "ios" in configured ? configured.ios : void 0; if (!setupFile || !(0, import_node_fs.existsSync)((0, import_node_path.resolve)(root, setupFile))) { throw new Error(app.ios?.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"); } } const present = REACT_NATIVE_CONFIG_NAMES.filter((name) => (0, import_node_fs.existsSync)((0, import_node_path.join)(root, name))); if (present.length === 0) { (0, import_node_fs.writeFileSync)((0, import_node_path.join)(root, "react-native.config.cjs"), REACT_NATIVE_CONFIG); } else if (!present.some((name) => (0, import_node_fs.readFileSync)((0, import_node_path.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.`); } const { prebuild } = await import("vxrn"); await prebuild({ root: process.cwd(), ...args, app }); }