one
Version:
One is a React framework for web, iOS, and Android apps.
497 lines (494 loc) • 12.9 kB
JavaScript
;
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 __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 import_citty = require("citty");
var import_fs = require("fs");
var import_path = __toESM(require("path"), 1);
var import_url = require("url");
var import_picocolors = __toESM(require("picocolors"), 1);
const import_meta = {};
function getPackageVersion() {
var dirname;
if (typeof __dirname !== "undefined") {
dirname = __dirname;
} else {
dirname = import_path.default.dirname((0, import_url.fileURLToPath)(import_meta.url));
}
var packagePath = import_path.default.join(dirname, "..", "..", "package.json");
var packageJson = JSON.parse((0, import_fs.readFileSync)(packagePath, "utf-8"));
return packageJson.version;
}
var version = getPackageVersion();
var DOCS_BASE = "https://onestack.dev/docs";
var docsLinks = {
dev: `${DOCS_BASE}/one-dev`,
build: `${DOCS_BASE}/one-build`,
serve: `${DOCS_BASE}/one-serve`,
prebuild: `${DOCS_BASE}/guides-ios-native`,
"run:ios": `${DOCS_BASE}/guides-ios-native`,
"run:android": `${DOCS_BASE}/guides-ios-native`,
clean: `${DOCS_BASE}/configuration`,
patch: `${DOCS_BASE}/configuration`,
"generate-routes": `${DOCS_BASE}/routing-typed-routes`,
typegen: `${DOCS_BASE}/routing-typed-routes`,
"metro-eject": `${DOCS_BASE}/guides-ota-updates`,
"updates-publish": "https://onestack.dev/native/updates"
};
function withDocsLink(description, command) {
return `${description}
Docs: ${docsLinks[command]}`;
}
if (import_path.default.sep !== "/") {
console.warn(import_picocolors.default.bgYellow("WARNING: UNSUPPORTED OS") + import_picocolors.default.yellow(" - It appears you’re using Windows, which is currently not supported. You may experience unexpected issues."));
}
var modes = {
development: "development",
production: "production"
};
function lastValue(arg) {
if (Array.isArray(arg)) {
return arg[arg.length - 1];
}
return arg;
}
var dev = (0, import_citty.defineCommand)({
meta: {
name: "dev",
version,
description: withDocsLink("Start the dev server", "dev")
},
args: {
clean: { type: "boolean" },
host: { type: "string" },
port: { type: "string" },
mode: {
type: "string",
description: "If set to \"production\" you can run the development server but serve the production bundle"
},
"debug-bundle": {
type: "string",
description: `Will output the bundle to a temp file and then serve it from there afterwards allowing you to easily edit the bundle to debug problems.`
},
debug: {
type: "string",
description: `Pass debug args to Vite`
},
"extra-config": {
type: "string",
description: `Path to an extra vite config file to merge on top of the project config`
}
},
async run(param) {
var { args } = param;
var { dev: dev2 } = await import("./cli/dev.native.js");
await dev2({
...args,
port: lastValue(args.port),
host: lastValue(args.host),
debugBundle: lastValue(args["debug-bundle"]),
mode: modes[lastValue(args.mode)],
extraConfig: lastValue(args["extra-config"])
});
}
});
var buildCommand = (0, import_citty.defineCommand)({
meta: {
name: "build",
version,
description: withDocsLink("Build your app", "build")
},
args: {
step: {
type: "string",
required: false
},
only: {
type: "string",
required: false
},
platform: {
type: "string",
description: `One of: web, ios, android`,
default: "web",
required: false
},
"skip-env": {
type: "boolean",
description: `Skip loading .env files during build`,
required: false
}
},
async run(param) {
var { args } = param;
var { build } = await import("./cli/build.native.js");
var platforms = {
ios: "ios",
web: "web",
android: "android"
};
if (args.platform && !platforms[args.platform]) {
throw new Error(`Invalid platform: ${args.platform}`);
}
var platform = platforms[args.platform] || "web";
await build({
only: args.only,
platform,
step: args.step,
skipEnv: args["skip-env"]
});
process.exit(0);
}
});
var serveCommand = (0, import_citty.defineCommand)({
meta: {
name: "serve",
version,
description: withDocsLink("Serve a built app for production", "serve")
},
args: {
host: { type: "string" },
port: { type: "string" },
compress: { type: "boolean" },
loadEnv: { type: "boolean" },
outDir: {
type: "string",
description: "Build output directory (default: dist)"
},
cluster: {
type: "string",
description: "Enable cluster mode with N workers (default: cpu count)"
}
},
async run(param) {
var { args } = param;
var { serve } = await import("./serve.native.js");
var port = lastValue(args.port);
var host = lastValue(args.host);
var clusterArg = lastValue(args.cluster);
await serve({
port: port ? +port : void 0,
host,
compress: args.compress,
loadEnv: !!args.loadEnv,
outDir: lastValue(args.outDir),
cluster: clusterArg !== void 0 ? clusterArg ? +clusterArg : true : void 0
});
}
});
var prebuild = (0, import_citty.defineCommand)({
meta: {
name: "prebuild",
version,
description: withDocsLink("Prebuild native project", "prebuild")
},
args: {
platform: {
type: "string",
description: "ios or android"
},
"no-install": {
type: "boolean",
description: "skip installing native dependencies",
default: false
}
},
async run(param) {
var { args } = param;
if (args.install === false) args["no-install"] = true;
var { run } = await import("./cli/prebuild.native.js");
await run(args);
}
});
var runIos = (0, import_citty.defineCommand)({
meta: {
name: "run:ios",
version,
description: withDocsLink("Run the iOS app", "run:ios")
},
args: {
simulator: {
type: "string",
description: "explicitly set the simulator to use, e.g. \"iPhone 16\""
},
udid: {
type: "string",
description: "explicitly set the simulator to use by UDID"
}
},
async run(param) {
var { args } = param;
var { run } = await import("./cli/runIos.native.js");
await run(args);
}
});
var runAndroid = (0, import_citty.defineCommand)({
meta: {
name: "run:android",
version,
description: withDocsLink("Run the Android app", "run:android")
},
args: {},
async run(param) {
var { args } = param;
var { run } = await import("./cli/runAndroid.native.js");
await run(args);
}
});
var clean = (0, import_citty.defineCommand)({
meta: {
name: "clean",
version: "0.0.0",
description: withDocsLink("Clean build folders", "clean")
},
args: {},
async run() {
var { clean: vxrnClean } = await import("vxrn");
await vxrnClean({ root: process.cwd() });
}
});
var patch = (0, import_citty.defineCommand)({
meta: {
name: "patch",
version: "0.0.0",
description: withDocsLink("Apply package patches", "patch")
},
args: { force: {
type: "boolean",
description: "Force re-apply all patches"
} },
async run(param) {
var { args } = param;
var { run } = await import("./cli/patch.native.js");
await run(args);
}
});
var generateRoutes = (0, import_citty.defineCommand)({
meta: {
name: "generate-routes",
version,
description: withDocsLink("Generate route type definitions (routes.d.ts)", "generate-routes")
},
args: {
appDir: {
type: "string",
description: "Path to app directory (default: \"app\")"
},
typed: {
type: "string",
description: "Auto-generate route helpers. Options: \"type\" (type-only helpers) or \"runtime\" (runtime helpers)"
}
},
async run(param) {
var { args } = param;
var { run } = await import("./cli/generateRoutes.native.js");
await run(args);
}
});
var typegen = (0, import_citty.defineCommand)({
meta: {
name: "typegen",
version,
description: withDocsLink("Generate routes.d.ts (alias for generate-routes)", "typegen")
},
args: {
appDir: {
type: "string",
description: "Path to app directory (default: \"app\")"
},
typed: {
type: "string",
description: "Auto-generate route helpers. Options: \"type\" (type-only helpers) or \"runtime\" (runtime helpers)"
}
},
async run(param) {
var { args } = param;
var { run } = await import("./cli/generateRoutes.native.js");
await run(args);
}
});
var metroEject = (0, import_citty.defineCommand)({
meta: {
name: "metro-eject",
version,
description: withDocsLink("Write babel.config.cjs + metro.config.cjs so you can own them and customize freely", "metro-eject")
},
args: { force: {
type: "boolean",
description: "Overwrite existing files"
} },
async run(param) {
var { args } = param;
var { generateBundlerConfig } = await import("./cli/generateBundlerConfig.native.js");
var { loadUserOneOptions } = await import("./vite/loadConfig.native.js");
process.env.IS_VXRN_CLI = "true";
var { oneOptions } = await loadUserOneOptions("build");
var { ok } = generateBundlerConfig({
force: !!args.force,
eject: true,
oneOptions
});
if (!ok) process.exit(1);
}
});
var daemonCommand = (0, import_citty.defineCommand)({
meta: {
name: "daemon",
version,
description: "Multi-app development server proxy"
},
args: {
subcommand: {
type: "positional",
description: "Subcommand: start, stop, status, route (default: start)",
required: false
},
port: {
type: "string",
description: "Port to listen on (default: 8081)"
},
host: {
type: "string",
description: "Host to bind to (default: 0.0.0.0)"
},
app: {
type: "string",
description: "Bundle ID for route command"
},
slot: {
type: "string",
description: "Slot number for route command"
},
project: {
type: "string",
description: "Project path for route command"
},
tui: {
type: "boolean",
description: "Show TUI (default: true if TTY)"
}
},
async run(param) {
var { args } = param;
var { daemon } = await import("./cli/daemon.native.js");
await daemon({
...args,
port: lastValue(args.port),
host: lastValue(args.host)
});
}
});
var updatesPublish = (0, import_citty.defineCommand)({
meta: {
name: "updates publish",
version,
description: withDocsLink("Bundle and publish an over-the-air update", "updates-publish")
},
args: {
platform: {
type: "string",
description: "ios or android"
},
out: {
type: "string",
description: "Directory to write manifest.json and assets into"
},
metadata: {
type: "string",
description: "Manifest metadata as key=value (repeatable)"
},
intermediatesOut: {
type: "string",
description: "Separate directory for local debug bundle and composed source map; never upload it"
},
runtimeVersion: {
type: "string",
description: "Runtime version for an app built with expo prebuild, which has no native.app"
}
},
async run(param) {
var { args } = param;
var { runUpdatesPublish } = await import("./cli/updatesPublish.native.js");
await runUpdatesPublish(args);
}
});
var updates = (0, import_citty.defineCommand)({
meta: {
name: "updates",
version,
description: "Over-the-air updates"
},
subCommands: { publish: updatesPublish }
});
var subCommands = {
dev,
clean,
build: buildCommand,
prebuild,
"run:ios": runIos,
"run:android": runAndroid,
patch,
serve: serveCommand,
"generate-routes": generateRoutes,
typegen,
daemon: daemonCommand,
"metro-eject": metroEject,
updates
};
var subMain = (0, import_citty.defineCommand)({
meta: {
name: "one",
version,
description: "Welcome to One"
},
subCommands
});
var main = (0, import_citty.defineCommand)({
meta: {
name: "one",
version,
description: "Welcome to One"
},
args: { name: {
type: "positional",
description: "Folder name to place the app into",
required: false
} },
async run(param) {
var { args } = param;
if (subCommands[args.name]) {
(0, import_citty.runMain)(subMain);
return;
}
var { cliMain } = await import("./cli/main.native.js");
await cliMain(args);
}
});
var helpIndex = process.argv.indexOf("--help");
if (helpIndex > 0) {
var subCommandName = process.argv[helpIndex - 1];
var subCommand = subCommands[subCommandName];
if (subCommand) {
(0, import_citty.showUsage)(subCommand);
} else {
(0, import_citty.showUsage)(subMain);
}
} else {
(0, import_citty.runMain)(main);
}