From f5a46c9224a93b8da1790d10d3264c4d20a83c5d Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Sun, 6 Apr 2025 00:59:26 -0700 Subject: [PATCH] chore(cli): make dev & deploy app path required --- packages/actor-core-cli/package.json | 1 - .../actor-core-cli/src/commands/deploy.tsx | 6 +-- packages/actor-core-cli/src/commands/dev.tsx | 9 ++--- packages/actor-core-cli/src/server-entry.ts | 2 +- packages/actor-core-cli/src/utils/config.ts | 40 ++++--------------- .../src/workflows/validate-config.ts | 2 +- 6 files changed, 16 insertions(+), 44 deletions(-) diff --git a/packages/actor-core-cli/package.json b/packages/actor-core-cli/package.json index 9cfc4551e..a205d3655 100644 --- a/packages/actor-core-cli/package.json +++ b/packages/actor-core-cli/package.json @@ -57,7 +57,6 @@ "ink-gradient": "^3.0.0", "ink-link": "^4.1.0", "ink-spinner": "^5.0.0", - "joycon": "^3.1.1", "micromatch": "^4.0.8", "pkg-types": "^2.0.0", "react": "^18.3", diff --git a/packages/actor-core-cli/src/commands/deploy.tsx b/packages/actor-core-cli/src/commands/deploy.tsx index 877daad60..4a99df852 100644 --- a/packages/actor-core-cli/src/commands/deploy.tsx +++ b/packages/actor-core-cli/src/commands/deploy.tsx @@ -24,6 +24,7 @@ export const deploy = new Command() .addArgument( new Argument("", "The platform to deploy to").choices(["rivet"]), ) + .addArgument(new Argument("", "Location of the app.ts file")) .addOption(new Option("-r, --root [path]", "Location of the project").default("./")) .addOption(new Option("-p, --path [path]", "Location of the app.ts file")) .addOption(new Option("--skip-manager", "Skip deploying ActorCore manager")) @@ -33,9 +34,8 @@ export const deploy = new Command() "afterAll", "\nMissing your favorite platform?\nLet us know! https://github.com/rivet-gg/actor-core/issues/new", ) - .action(async (platform, opts: { + .action(async (platform, appPath: string, opts: { root: string; - path?: string; port?: string; skipManager: boolean, env?: string, @@ -54,7 +54,7 @@ export const deploy = new Command() const { config, cli } = yield* ctx.task( "Prepare", async function* (ctx) { - const config = yield* validateConfigTask(ctx, cwd, opts.path); + const config = yield* validateConfigTask(ctx, cwd, appPath); const cli = yield* ctx.task( "Locale rivet-cli", diff --git a/packages/actor-core-cli/src/commands/dev.tsx b/packages/actor-core-cli/src/commands/dev.tsx index 49ed05ea3..7161f6e01 100644 --- a/packages/actor-core-cli/src/commands/dev.tsx +++ b/packages/actor-core-cli/src/commands/dev.tsx @@ -12,10 +12,10 @@ import { spawn } from "node:child_process"; export const dev = new Command() .name("dev") .description("Run locally your ActorCore project.") + .addArgument(new Argument("", "Location of the app.ts file")) .addOption( new Option("-r, --root [path]", "Location of the project").default("./"), ) - .addOption(new Option("-p, --path [path]", "Location of the app.ts file")) .addOption( new Option("--port [port]", "Specify which platform to use").default( "6420", @@ -29,9 +29,8 @@ export const dev = new Command() .option("--no-open", "Do not open the browser with ActorCore Studio") .action(action); -export async function action(opts: { +export async function action(appPath: string, opts: { root: string; - path?: string; port?: string; open: boolean; }) { @@ -61,7 +60,7 @@ export async function action(opts: { "server-entry.js", ), ], - { env: { ...process.env, PORT: opts.port, PATH: opts.path }, cwd }, + { env: { ...process.env, PORT: opts.port, APP_PATH: appPath }, cwd }, ); } @@ -82,7 +81,7 @@ export async function action(opts: { }); while (true) { - yield* validateConfigTask(ctx, cwd, opts.path); + yield* validateConfigTask(ctx, cwd, appPath); server = createServer(); createLock(); diff --git a/packages/actor-core-cli/src/server-entry.ts b/packages/actor-core-cli/src/server-entry.ts index 8af3361f0..e75a28f91 100644 --- a/packages/actor-core-cli/src/server-entry.ts +++ b/packages/actor-core-cli/src/server-entry.ts @@ -2,7 +2,7 @@ import { validateConfig } from "./utils/config"; import { serve } from "@actor-core/nodejs"; async function run() { - const config = await validateConfig(process.cwd(), process.env.PATH); + const config = await validateConfig(process.cwd(), process.env.APP_PATH!); config.app.config.inspector = { enabled: true, }; diff --git a/packages/actor-core-cli/src/utils/config.ts b/packages/actor-core-cli/src/utils/config.ts index 6aae873f4..a6a90254c 100644 --- a/packages/actor-core-cli/src/utils/config.ts +++ b/packages/actor-core-cli/src/utils/config.ts @@ -1,7 +1,5 @@ -import fs from "node:fs"; import path from "node:path"; import { bundleRequire } from "bundle-require"; -import JoyCon from "joycon"; import z from "zod"; import type { ActorCoreApp } from "actor-core"; @@ -12,47 +10,23 @@ const ActorCoreConfig = z.object({ }); export async function loadConfig( - cwd: string, - appPath?: string, + _cwd: string, + appPath: string, ): Promise<{ path: string; data: z.infer } | null> { - const configJoycon = new JoyCon(); - - // Attempt to auto-resolve app path - let resolvedAppPath: string; - if (appPath) { - resolvedAppPath = appPath; - } else { - // Auto-resolve app path - const resolved = await configJoycon.resolve({ - files: [ - "src/app.ts", - "src/app.tsx", - "src/app.mts", - "src/app.js", - "src/app.cjs", - "src/app.mjs", - ], - cwd, - stopDir: path.parse(cwd).root, - }); - if (!resolved) return null; - resolvedAppPath = resolved; - } - try { const config = await bundleRequire({ - filepath: resolvedAppPath, + filepath: appPath, }); return { - path: resolvedAppPath, + path: appPath, data: config.mod.default || config.mod, }; } catch (error) { - throw { isBundleError: true, path: resolvedAppPath, details: error }; + throw { isBundleError: true, path: appPath, details: error }; } } -export async function requireConfig(cwd: string, appPath?: string) { +export async function requireConfig(cwd: string, appPath: string) { const config = await loadConfig(cwd, appPath); if (!config || !config.data) { throw { isNotFoundError: true, cwd, appPath }; @@ -60,7 +34,7 @@ export async function requireConfig(cwd: string, appPath?: string) { return config; } -export async function validateConfig(cwd: string, appPath?: string) { +export async function validateConfig(cwd: string, appPath: string) { const config = await requireConfig(cwd, appPath); return await ActorCoreConfig.parseAsync({ ...config.data, diff --git a/packages/actor-core-cli/src/workflows/validate-config.ts b/packages/actor-core-cli/src/workflows/validate-config.ts index 88c5ab64f..4aeac3960 100644 --- a/packages/actor-core-cli/src/workflows/validate-config.ts +++ b/packages/actor-core-cli/src/workflows/validate-config.ts @@ -9,7 +9,7 @@ import type { Context } from "../workflow"; export function validateConfigTask( ctx: Context, cwd: string, - appPath?: string, + appPath: string, ) { return ctx.task("Build project", async () => { try {