Skip to content

Commit

Permalink
Update commands to run single services
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Sep 27, 2023
1 parent dae715f commit d22b98c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
14 changes: 10 additions & 4 deletions docs/introduction/cli.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -22,4 +26,6 @@ Build the project assets
- `--pwa` - As a Progressive Web App

## commoners launch
Launch your built application
Launch your built application

> **Note:** No service-related options available for this command
32 changes: 23 additions & 9 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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

}

}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down

0 comments on commit d22b98c

Please sign in to comment.