diff --git a/packages/cli/index.ts b/packages/cli/index.ts index 7f30cdd..b43ccc6 100755 --- a/packages/cli/index.ts +++ b/packages/cli/index.ts @@ -58,15 +58,19 @@ cli.command('launch [root]', 'Launch your build application in the specified dir .action(async (root, options) => { const { config: configPath, service, ...overrides } = options + const services = service - const onlyService = !!(!overrides.target && service) + const isOnlyServices = (!overrides.target && services) await preprocessTarget(overrides.target) + const config = await loadConfigFromFile(getConfigPathFromOpts({ root, config: configPath })) if (!config) return - if (onlyService) { + + // Services take priority if specified + if (isOnlyServices) { delete config.target @@ -74,10 +78,12 @@ cli.command('launch [root]', 'Launch your build application in the specified dir delete config.port delete config.host + // NOTE: If passed, this simply wouldn't take effect if (options.outDir) return await failed(`Cannot specify an output directory when launching services`) const resolvedServices = typeof services === 'string' ? [services] : services + // If specified, this simply wouldn't take effect if (Object.keys(resolvedServices).length > 1 && (options.port || options.host)) return await failed(`Cannot specify port or host when launching multiple services`) // Flag invalid services @@ -91,9 +97,11 @@ cli.command('launch [root]', 'Launch your build application in the specified dir }) } + // Ensure services are not specified with a target + else if (services) return await failed(`Cannot specify services without a target`) const launchConfig = reconcile(config, overrides) as LaunchConfig - launch(launchConfig) + launch(launchConfig, isOnlyServices) }) // Build the application using the specified settings @@ -120,8 +128,7 @@ cli.command('build [root]', 'Build the application in the specified directory', if (!config) return - // Ensure services are built only - if (buildOnlyServices) delete config.target + if (buildOnlyServices) delete config.target // Ensure services are built only build(reconcile(config, overrides), { servicesToBuild: service }) }) diff --git a/packages/core/launch.ts b/packages/core/launch.ts index 5c33471..1828e45 100644 --- a/packages/core/launch.ts +++ b/packages/core/launch.ts @@ -58,28 +58,17 @@ const getDesktopPath = (outDir) => { } export default async function ( - config: LaunchConfig + config: LaunchConfig, + isOnlyServices = false ) { const _chalk = await chalk let target = config.target; - if (config.outDir) { - const desktopPath = getDesktopPath(config.outDir) - - // Autodetect target build type from path - if (config.outDir){ - if (desktopPath) target = 'electron' - } - } - - - const { root, services = {}, port, host = 'localhost' } = config + const { root, services, port, host = 'localhost' } = config // ---------------- Service-Only Launch ---------------- - const isOnlyServices = !!(services && !target) - if (isOnlyServices) { const serviceNames = Object.keys(services) @@ -104,8 +93,20 @@ export default async function ( return { services: active } // Ensure users can access the createdservices } + // ---------------------- Auto-Detect Target ---------------------- + if (config.outDir) { + const desktopPath = getDesktopPath(config.outDir) + + // Autodetect target build type from path + if (config.outDir){ + if (desktopPath) target = 'electron' + } + } + target = await ensureTargetConsistent(target) + // ---------------------- Launch based on Target ---------------------- + const { outDir = join((root ?? ''), globalWorkspacePath, target) // Default location } = config