Skip to content

Commit

Permalink
Fix launch when no explicit target
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Dec 1, 2024
1 parent 93980a5 commit 250f1e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
17 changes: 12 additions & 5 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,32 @@ 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

// Do not use configuration options for servers
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
Expand All @@ -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
Expand All @@ -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 })
})
Expand Down
29 changes: 15 additions & 14 deletions packages/core/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 250f1e2

Please sign in to comment.