Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
13526f6
feat(cli): choose the engine of the backend at init
Decipher Nov 18, 2026
1566da4
chore: merge the release tooling from the branch below
Decipher Nov 18, 2026
1ba046d
chore: merge the pipeline triggers, the prose check and the slash tri…
Decipher Nov 18, 2026
8820aae
fix(cli): trim a step's directory in linear time
Decipher Nov 18, 2026
dbed0f2
chore: merge the fixes to init and the checks from the branch below
Decipher Nov 18, 2026
32df115
chore: merge the fixes to the release check from the branch below
Decipher Nov 18, 2026
af4455f
chore: merge the fixes to init's next steps and module info from the …
Decipher Nov 18, 2026
0d3efa7
fix(cli): say which engine the dev server starts the backend for
Decipher Nov 18, 2026
adffcba
chore: merge the test suite's git environment fix from the branch below
Decipher Nov 18, 2026
1cd8bd0
chore: merge the checks on a module registry's names from the branch …
Decipher Nov 18, 2026
bd73211
fix(cli): leave engine files in place when init writes into a directo…
Decipher Nov 18, 2026
f2b3503
chore: merge the attribution check's fixes from the branch below
Decipher Nov 19, 2026
a6c3a2a
chore: merge the cd line and config path fixes from the branch below
Decipher Nov 19, 2026
5f82124
chore: merge the branch below after its rebase onto the release line
Decipher Nov 19, 2026
8502aa8
chore: merge the Node version check from the branch below
Decipher Nov 19, 2026
a2644fa
chore: merge running on an older Node from the branch below
Decipher Nov 19, 2026
32c9f2d
chore: merge the test fix for the Node search from the branch below
Decipher Nov 19, 2026
45ec04d
chore: merge the launcher review fixes from the branch below
Decipher Nov 19, 2026
a90d949
chore: merge the release lookup and attribution fixes from the branch…
Decipher Nov 19, 2026
4a63989
chore: merge the release guide note from the branch below
Decipher Nov 19, 2026
2e14cba
chore: merge the icon and banner from the branch below
Decipher Nov 19, 2026
a9e9d71
chore: merge 0.x from the branch below
Decipher Nov 19, 2026
ef06061
chore: merge the registry revision from the branch below
Decipher Nov 19, 2026
8ce2c17
chore(cli): raise the revision of the starter registry
Decipher Nov 19, 2026
dad0791
chore: merge the registry test helper from the branch below
Decipher Nov 19, 2026
c0eb7ee
style: format the starter registry index
Decipher Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/first-release-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

First release of the Druxt command-line tool, with the binary `drx`.

- `drx init` creates a site from a starter in a registry, records its layout and parts in `drx.config.json` and prints what the site needs next. It warns when the commands the starter needs are not on `PATH`.
- `drx init` creates a site from a starter in a registry, records its layout and parts in `drx.config.json` and prints what the site needs next. `--engine` chooses how the backend runs, from the engines the starter lists or `none` for a backend that exists already. `init` keeps that engine's files only and warns when its commands are not on `PATH`.
- `drx module list`, `drx module search` and `drx module info` read the Druxt module registry, and in a project show what is installed and whether each module's range admits the Druxt there.
- `drx info` prints the versions of the CLI, Node and the packages of each part of a project.
- The registry holds one starter, `quickstart`, and the `monorepo` layout is the one available.
156 changes: 118 additions & 38 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/cli/src/commands-on-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function checkCommands(
}
}

/** The alternatives as a phrase: "php and composer, or ddev". */
/** The alternatives as a phrase: "one and two, or three". */
export function describeAlternatives(alternatives: string[][]): string {
return alternatives
.map((commands) =>
Expand Down
28 changes: 22 additions & 6 deletions packages/cli/src/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,39 @@ async function reportPart(root: string, part: Part): Promise<PartReport> {
}

function partLines(part: PartReport): string[] {
const heading = `${part.role} ${part.kind} ${part.path}/`
const heading = [
`${part.role} ${part.kind} ${part.path}/`,
...columns(
[
...(part.engine ? [['Engine', part.engine]] : []),
...(part.database ? [['Database', part.database]] : []),
...(part.baseUrl ? [['Backend URL', part.baseUrl]] : []),
],
' '
),
]
if (!adapterFor(part.kind)) {
return [heading, ` This version has no adapter for the ${part.kind} kind.`]
return [
...heading,
` This version has no adapter for the ${part.kind} kind.`,
]
}
if (!part.exists) return [heading, ' The directory does not exist.']
if (!part.exists) return [...heading, ' The directory does not exist.']
if (!part.detected) {
return [heading, ` The directory does not look like a ${part.kind} part.`]
return [
...heading,
` The directory does not look like a ${part.kind} part.`,
]
}
if (part.packages.length === 0) {
return [heading, ' No packages to report.']
return [...heading, ' No packages to report.']
}
const rows = part.packages.map((entry) => [
entry.name,
entry.range ?? '',
entry.installed ? `installed ${entry.installed}` : 'not installed',
])
return [heading, ...columns(rows, ' ')]
return [...heading, ...columns(rows, ' ')]
}

function text(report: InfoReport, cwd: string): string {
Expand Down
137 changes: 132 additions & 5 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import {
type CommandCheck,
} from '../commands-on-path.js'
import type { CliContext } from '../context.js'
import { writeBackendUrl } from '../engines/backend-url.js'
import {
assertBaseUrl,
chooseEngine,
missingCommandsWarning,
stepLines,
type EngineChoice,
} from '../engines/choose.js'
import { removeEngineFiles } from '../engines/files.js'
import { DrxError } from '../errors.js'
import {
assertLayoutAvailable,
Expand Down Expand Up @@ -64,6 +73,31 @@ const args = {
valueHint: 'name',
description: `Where the Druxt packages come from (default: ${DEFAULT_SOURCE})`,
},
engine: {
type: 'string',
valueHint: 'name',
description:
'How the backend runs: an engine of the starter, or none for a backend that exists already',
},
database: {
type: 'string',
valueHint: 'name',
description: 'The database, where the engine offers a choice',
},
'base-url': {
type: 'string',
valueHint: 'url',
description: 'With --engine none: the URL of the backend',
},
'keep-engines': {
type: 'boolean',
description: 'Keep the files of the engines that were not chosen',
},
setup: {
type: 'boolean',
description:
'Run the steps of the engine after creating the site (not available yet)',
},
install: {
type: 'boolean',
description: 'Install the dependencies of the site after creating it',
Expand All @@ -90,6 +124,11 @@ interface InitOptions {
layout?: Layout
registry?: string
source?: string
engine?: string
database?: string
baseUrl?: string
keepEngines: boolean
setup: boolean
install?: boolean
force: boolean
yes: boolean
Expand Down Expand Up @@ -190,6 +229,7 @@ function nodeSatisfies(running: string, needed: string): boolean {

function warnAboutStarter(
entry: StarterEntry,
engine: EngineChoice | undefined,
target: string,
context: CliContext,
output: Output
Expand All @@ -214,6 +254,19 @@ function warnAboutStarter(
}
}

if (engine) {
// The chosen engine's commands are the ones that matter. An engine with
// none, such as a backend that exists already, has nothing to check.
if (engine.commands.length === 0) return null
const check = checkCommands([engine.commands], context.findCommand)
if (!check.satisfied) {
output.warn(
missingCommandsWarning(engine.name, engine.commands, check.missing)
)
}
return check
}

if (!requires.commands) return null
const commands = checkCommands(requires.commands, context.findCommand)
if (!commands.satisfied) {
Expand Down Expand Up @@ -241,6 +294,14 @@ async function runInit(
)
}

if (options.setup) {
throw new DrxError(
'not-available',
'--setup is not available yet. init prints the steps for you to run.'
)
}
if (options.baseUrl) assertBaseUrl(options.baseUrl)

// Everything that can fail without the network is checked before it is used.
const userConfig = await loadUserConfig(context.env)
const source = resolveSource(options.source ?? DEFAULT_SOURCE, userConfig)
Expand All @@ -266,6 +327,7 @@ async function runInit(

const entry = await chooseStarter(registry, options, context, canAsk)
const layout = await chooseLayout(entry, options, context, canAsk)
const engine = await chooseEngine(entry, options, context, canAsk)

const defaultDir = entry.defaultDir ?? entry.name
const dir =
Expand All @@ -277,6 +339,8 @@ async function runInit(
})
: defaultDir)
const target = targetDirectory(context.cwd, dir, options.force)
// Looked at before the download, which fills the directory.
const held = existsSync(target) && readdirSync(target).length > 0

const install =
options.install ??
Expand Down Expand Up @@ -318,15 +382,61 @@ async function runInit(
)
}

let removed: string[] = []
if (engine && !options.keepEngines) {
// In a directory that held files, a path of another engine may be the
// user's own, and --force was a yes to writing, not to deleting.
const paths = await removeEngineFiles(
target,
engine.remove,
engine.keep,
held
)
if (held && paths.length > 0) {
output.warn(
`${target} was not empty, so the files of the engines not chosen were left in place: ${paths.join(', ')}. --force writes the files of the starter and deletes nothing.`
)
} else if (paths.length > 0) {
removed = paths
output.note(
`Removed the files of the engines not chosen: ${removed.join(', ')}.`
)
}
}
if (engine?.writeUrl) {
const where = entry.druxt.backendUrl
if (where) {
await writeBackendUrl(target, where, engine.writeUrl)
output.note(
`Wrote ${where.variable}=${engine.writeUrl} to ${where.file}.`
)
} else if (engine.baseUrl) {
output.warn(
`The ${entry.name} starter does not say where it reads its backend URL from. Point it at ${engine.baseUrl} yourself.`
)
}
}

const config: ProjectConfig = {
layout,
line: entry.druxt.line,
starter: entry.name,
source: source.name,
parts: entry.druxt.parts,
// The choice is recorded on every backend part, for the commands that
// will run tools in it.
parts: entry.druxt.parts.map((part) =>
engine && part.role === 'backend'
? {
...part,
engine: engine.name,
...(engine.database ? { database: engine.database } : {}),
...(engine.baseUrl ? { baseUrl: engine.baseUrl } : {}),
}
: part
),
}
await writeProjectConfig(target, config)
const commands = warnAboutStarter(entry, target, context, output)
const commands = warnAboutStarter(entry, engine, target, context, output)

if (install) {
output.note('Installing dependencies.')
Expand All @@ -351,10 +461,15 @@ async function runInit(
// A name that starts with a hyphen is written as a path: a shell reads
// "cd -" as the previous directory, and "cd -x" as an option.
`cd ${shellQuote(shown.startsWith('-') ? `./${shown}` : shown)}`,
...(entry.druxt.steps ?? []).filter((step) => !ran?.runs?.includes(step)),
...stepLines(
(engine ? engine.steps : (entry.druxt.steps ?? [])).filter(
(step) => !(typeof step === 'string' && ran?.runs?.includes(step))
)
),
]
const notes = ran?.notes ?? []
const { requires } = entry.druxt
const needs = engine ? [engine.label] : requires.tools
const notes = [...(engine?.notes ?? []), ...(ran?.notes ?? [])]

output.result(
{
Expand All @@ -364,6 +479,10 @@ async function runInit(
...config,
installed: install,
requires,
engine: engine?.name ?? null,
database: engine?.database ?? null,
baseUrl: engine?.baseUrl ?? null,
removed,
commands,
next,
notes,
Expand All @@ -373,7 +492,7 @@ async function runInit(
'',
'It needs:',
` Node ${requires.node}`,
...requires.tools.map((tool) => ` ${tool}`),
...needs.map((tool) => ` ${tool}`),
'',
'Next:',
...next.map((step) => ` ${step}`),
Expand All @@ -396,7 +515,15 @@ export function initCommand(context: CliContext) {
const options: InitOptions = {
force: parsed.force === true,
yes: parsed.yes === true,
keepEngines: parsed['keep-engines'] === true,
setup: parsed.setup === true,
}
const engine = valueOf('engine', parsed.engine)
const database = valueOf('database', parsed.database)
const baseUrl = valueOf('base-url', parsed['base-url'])
if (engine) options.engine = engine
if (database) options.database = database
if (baseUrl) options.baseUrl = baseUrl
const dir = valueOf('dir', parsed.dir)
const starter = valueOf('starter', parsed.starter)
const registry = valueOf('registry', parsed.registry)
Expand Down
37 changes: 37 additions & 0 deletions packages/cli/src/engines/backend-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { mkdir, readFile, writeFile } from 'node:fs/promises'
import { dirname, join } from 'node:path'
import type { BackendUrlTarget } from '../registry/entry.js'

async function read(file: string): Promise<string | undefined> {
try {
return await readFile(file, 'utf8')
} catch {
return undefined
}
}

/**
* Writes the URL of the backend where the starter reads it: one variable in
* a file of `NAME=value` lines. The file is started from the starter's
* template when it does not exist, and every other line is left as it is.
*/
export async function writeBackendUrl(
root: string,
target: BackendUrlTarget,
url: string
): Promise<void> {
const file = join(root, target.file)
const start =
(await read(file)) ??
(target.template ? await read(join(root, target.template)) : undefined) ??
''

const line = `${target.variable}=${url}`
const assignment = new RegExp(`^${target.variable}=.*$`, 'm')
const content = assignment.test(start)
? start.replace(assignment, line)
: `${start}${start === '' || start.endsWith('\n') ? '' : '\n'}${line}\n`

await mkdir(dirname(file), { recursive: true })
await writeFile(file, content)
}
Loading
Loading