From d22b98c20aaef6e6362fba301d33964114e3e58b Mon Sep 17 00:00:00 2001 From: Garrett Date: Wed, 27 Sep 2023 12:50:32 -0700 Subject: [PATCH] Update commands to run single services --- docs/introduction/cli.md | 14 ++++++++++---- packages/cli/index.ts | 32 +++++++++++++++++++++++--------- packages/core/build.ts | 6 +++--- packages/core/index.ts | 9 +++++++++ 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/docs/introduction/cli.md b/docs/introduction/cli.md index 3aec57f..c4b585f 100644 --- a/docs/introduction/cli.md +++ b/docs/introduction/cli.md @@ -1,17 +1,21 @@ # CLI Commands The CLI commands for `commoners` share the same options structure: -- `--web` - Default option +- `--web` - Default option (`boolean`) -- `--desktop` - For your current desktop platform +- `--desktop` - For your current desktop platform (`boolean`) - `--mac` - For Mac - `--windows` - For Windows - `--linux` - For Linux -- `--mobile` - For the mobile platform corresponding to your build enviroment +- `--mobile` - For the mobile platform corresponding to your build enviroment (`boolean`) - `--ios` - For iOS - `--android` - For Android +- `--frontend` - Frontend resources only (`boolean`) +- `--services` - All services defined in the configuration file (`boolean`) +- `--service [name]` - For specific service(s) (`string`) + ## commoners Start your project in development mode @@ -22,4 +26,6 @@ Build the project assets - `--pwa` - As a Progressive Web App ## commoners launch -Launch your built application \ No newline at end of file +Launch your built application + +> **Note:** No service-related options available for this command \ No newline at end of file diff --git a/packages/cli/index.ts b/packages/cli/index.ts index 684441b..83e56ad 100755 --- a/packages/cli/index.ts +++ b/packages/cli/index.ts @@ -3,7 +3,7 @@ import chalk from "chalk"; import { onExit as processOnExit } from "../core/utils/processes.js"; -import { command, COMMAND, PLATFORM, target, TARGET } from "../core/globals.js"; +import { cliArgs, command, COMMAND, PLATFORM, target, TARGET } from "../core/globals.js"; import { build, createServer, launch, loadConfigFromFile, configureForDesktop, resolveConfig, createServices } from "../core/index.js"; import { clearOutputDirectory, populateOutputDirectory } from "../core/common.js"; @@ -23,21 +23,35 @@ if (command.launch) launch(baseOptions) // Launch the specified build else if (command.build) build(baseOptions) // Build the application using the specified settings else if (command.dev || command.start || !command) { - const config = await loadConfigFromFile() // Load configuration file only once + const config = await loadConfigFromFile() // Load configuration file only once const resolvedConfig = await resolveConfig(config); - if (target.mobile) await build(baseOptions, resolvedConfig) // Create mobile build + const runServices = cliArgs.services || cliArgs.service + + const onlyRunServices = !cliArgs.frontend && runServices + + // Only run services + if (onlyRunServices) await createServices(resolvedConfig) + + // Run services alongside the frontend else { - await clearOutputDirectory() - await populateOutputDirectory(resolvedConfig) - } - if (target.desktop) configureForDesktop() // Configure the desktop instance - else await createServices(resolvedConfig) // Run services in parallel + const runFrontendWithServices = !cliArgs.frontend || runServices + + if (target.mobile) await build(baseOptions, resolvedConfig) // Create mobile build + else { + await clearOutputDirectory() + await populateOutputDirectory(resolvedConfig) + } + if (target.desktop) configureForDesktop() // Configure the desktop instance + else if (runFrontendWithServices) await createServices(resolvedConfig) // Run services in parallel - if (!target.mobile) await createServer(config, !target.desktop) // Create frontend server + + if (!target.mobile) await createServer(config, !target.desktop) // Create frontend server + + } } diff --git a/packages/core/build.ts b/packages/core/build.ts index 9064cd6..2d0fbca 100644 --- a/packages/core/build.ts +++ b/packages/core/build.ts @@ -26,8 +26,8 @@ export default async function build ({ target, platform }: BuildOptions, config? const { icon , services } = resolvedConfig const toBuild = { - frontend: cliArgs['frontend'] || !cliArgs['backend'], - backend: cliArgs['backend'] || !cliArgs['frontend'] + frontend: cliArgs['frontend'] || (!cliArgs['services'] && !cliArgs.service), + services: cliArgs['services'] || cliArgs.service || !cliArgs['frontend'] } if (toBuild.frontend) { @@ -36,7 +36,7 @@ export default async function build ({ target, platform }: BuildOptions, config? } // Build services if not specifically the frontend - if (toBuild.backend) { + if (toBuild.services) { for (let name in services) { const service = services[name] let build = (service && typeof service === 'object') ? service.build : null diff --git a/packages/core/index.ts b/packages/core/index.ts index 5f39883..ec8333a 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -56,6 +56,15 @@ export async function resolveConfig(o: UserConfig = {}) { copy.services = await resolveAll(copy.services) // Always resolve all backend services before going forward + // Remove services that are not specified + const selectedServices = cliArgs.service + if (selectedServices) { + const selected = !Array.isArray(selectedServices) ? [ selectedServices ] : selectedServices + for (let name in copy.services) { + if (!selected.includes(name)) delete copy.services[name] + } + } + // Run PWA prebuild to specify manifest file if (cliArgs.pwa) {