Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- A release build of a GUI app run from a terminal prints its `--help`, `--version`, usage errors
and headless output: it attaches to the parent console just before printing
(`src/win/console.rs`). Opening the window never attaches, so closing the terminal doesn't close
the app, and Explorer launches are unchanged.
- The review panel and the next-steps box fit narrow terminals: below about 60 columns their right
edges used to wrap onto the next line. Title facts that don't fit move into the panel, and the
box drops its notes, then its frame, rather than overflow.
Expand Down Expand Up @@ -49,6 +53,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `--with subcommands` on desktop apps: `app <job>` runs a headless job (`themes`, `paths` to start
with) and exits, a bare run opens the window as before, and `tests/cli.rs` covers both paths.
- `--base <theme>`: lay the signature theme's accent on any shipped theme's surfaces, e.g.
`--base graphite` for neutral greys behind media. The default (`midnight`) is unchanged, and the
readability tests check the result in the generated project.
- `--without demo`: a GUI project starts from one empty page wired through the same page, shortcut
and command-palette machinery, instead of the overview cards, palette and about pages. Pages are
now additive: `Ctrl+1…9` and the palette follow `Page::ALL`, and `docs/ARCHITECTURE.md` explains
adding one.
- `--with subcommands`: a `cli` built on a clap `Subcommand` enum (no wildcard dispatch) with
matching integration tests, instead of the greeting demo.
- `--bin <name>`: an executable named differently from its crate. Writes `[[bin]]` and follows
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ create-rust-app [dir] [options]
| `--preset <p>` | `rustaman` `strobe` `cli` `tui` `lib` `minimal`, or `custom` for no preset (the defaults) |
| `--kind <k>` | `cli` `gui` `tui` `lib` `workspace` |
| `--gui <stack>` | `eframe` (wgpu) or `winit-glow` (winit + glutin + egui_glow) |
| `--base <theme>` | Surfaces the signature theme lays your accent on: any shipped theme id, e.g. `graphite` for neutral greys (default `midnight`) |
| `--edition <e>` | `2024` or `2021` |
| `--msrv <v>` | `rust-version` in Cargo.toml (default `1.98`) |
| `--toolchain <v>` | Exact channel pinned in `rust-toolchain.toml` and CI (default `1.99.1`) |
| `--license <l>` | `MIT`, `MIT+CommonsClause`, `Apache-2.0`, `MIT OR Apache-2.0` |
| `--author <name>` | Author for Cargo.toml, LICENSE, headers |
| `--github <user>` | GitHub handle for CODEOWNERS and repository links |
| `--accent <#hex>` | Accent colour for GUI themes (default `#00e5ff`) |
| `--with a,b` | Turn on features / tooling, e.g. `--with tray,commandPalette`, or `--with subcommands` for a CLI built on a clap `Subcommand` enum |
| `--with a,b` | Turn on features / tooling, e.g. `--with tray,commandPalette`, or `--with subcommands` for a CLI built on a clap `Subcommand` enum (on a desktop app: headless jobs beside the window) |
| `--without demo` | Start a desktop app from one empty page instead of the overview / palette / about showcase |
| `--without a,b` | Turn them off, e.g. `--without release,dependabot` |
| `--set <key.path=value>` | Set any answer directly (repeatable), e.g. `--set tagline="Fast grep"`, `--set crates.async=tokio`. The only way to set `tagline` / `displayName` without prompts. `true`/`false` become booleans |
| `-y`, `--yes` | Accept defaults for anything not given; no prompts |
Expand Down
8 changes: 6 additions & 2 deletions docs/CONTRACTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ test/*.test.ts node --test
edition: '2024' | '2021', msrv: '1.98', toolchain: '1.99.1', accent: '#00e5ff',
kind: 'cli' | 'gui' | 'tui' | 'lib' | 'workspace',
guiStack: 'eframe' | 'winit-glow',
themeBase: string, // a shipped theme id from templates/gui/files/assets/themes.toml ('' without a GUI)
crates: { errors: 'anyhow', thiserror: bool, logging: 'log'|'env_logger'|'tracing',
serde: bool, async: 'none'|'tokio', http: 'none'|'ureq'|'reqwest',
sqlite: bool, clap: bool },
features: { themes, brand, motion, icons, config, winres, tray, singleInstance,
commandPalette, screenshotExample, subcommands }, // all bool; subcommands: cli + clap only
commandPalette, screenshotExample, demo, subcommands }, // all bool; subcommands: cli or GUI kinds, with clap
tooling: { ci, release, cargoDeny, dependabot, toolchainPin, agentDocs, headerCheck,
unsafeCheck, changelogGen, issueTemplates, codeowners, securityMd }, // all bool
post: { git: bool, cargoCheck: bool, open: 'none'|'code'|'cursor' },
Expand All @@ -66,13 +67,16 @@ It then adds: `crate` (snake), `Name` (Pascal), `NAME` (SCREAMING),
- every true boolean in crates/features/tooling by its key: `thiserror`, `serde`, `sqlite`, `clap`,
`themes`, `tray`, `ci`, `release`, …
- `has_gui` (kind gui, or workspace — the workspace app crate is a GUI), `has_bin` (kind ≠ lib),
`base_dark` / `base_light` (the `--base` theme's mode; GUI kinds only),
`custom_bin` (`--bin` names the executable differently from its crate; a `[[bin]]` table is written),
`workspace` (kind workspace), `single` (not workspace)

### Tokens (`@@x@@`)

`name bin crate Name NAME appCrate appCrateSnake displayName tagline author github email year license edition msrv
toolchain accent module`. `@@module@@` is computed per file by `moduleFor(dest, ctx)`. `@@bin@@` is the
toolchain accent module`, plus `baseName baseMode baseApp basePanel baseRaised baseHover baseBorder
baseText baseTextMuted baseDanger baseWarning baseSuccess baseSpan baseAccentRgb`: the `--base` theme's
fields as read from `themes.toml` by `src/gen/themes.ts`, filled into the signature theme. `@@module@@` is computed per file by `moduleFor(dest, ctx)`. `@@bin@@` is the
command users type (`--bin`, else the project name); where the executable's file name matters (release
packaging) templates use `@@bin@@` under `custom_bin` and `@@appCrate@@` otherwise.
Unknown tokens throw (so a typo fails tests loudly).
Expand Down
7 changes: 4 additions & 3 deletions docs/PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ debug = "line-tables-only"
| identity | name (kebab `^[a-z][a-z0-9-]*$`), displayName, tagline, author ★`Lawrence Norton`, github ★`lnorton89`, email, license ★`MIT` / `MIT+CommonsClause` / `Apache-2.0` / `MIT OR Apache-2.0`, edition ★`2024`/`2021`, msrv ★`1.98`, toolchain ★`1.99.1` |
| kind | `cli` / `gui` ★ / `tui` / `lib` / `workspace` |
| gui stack | `eframe` ★ (rustaman: eframe + wgpu) / `winit-glow` (strobe) |
| theme base | any shipped theme id: `midnight` ★ / `graphite` / … (the surfaces the signature theme lays the accent on) |
| crates | errors: anyhow ★ (+ thiserror ★ for lib/workspace); logging: `log` ★gui / `env_logger` ★cli / `tracing`; serde+toml ★; async: none ★ / tokio; http: none ★ / ureq / reqwest; sqlite: off ★ / rusqlite bundled; clap ★ (everything but lib) |
| features (gui) | themes ★, brand ★, motion ★, icons ★, config ★, winres ★ (icon+manifest+version), tray, singleInstance, commandPalette, screenshotExample |
| features (cli) | subcommands (clap `Subcommand` enum, `tool <command> …`, replaces the greeting demo; needs clap) |
| features (gui) | themes ★, brand ★, motion ★, icons ★, config ★, winres ★ (icon+manifest+version), tray, singleInstance, commandPalette, screenshotExample, demo ★ (off: one empty page instead of the overview / palette / about showcase) |
| features (cli, gui) | subcommands (needs clap). cli: a clap `Subcommand` enum replaces the greeting demo. gui: optional headless jobs (`app themes`, `app paths`); a bare run opens the window |
| tooling | ci ★, release ★, cargoDeny ★, dependabot ★, toolchainPin ★, agentDocs ★ (AGENTS.md + CLAUDE.md), headerCheck ★, unsafeCheck ★ (gui), changelogGen ★, issueTemplates ★, codeowners ★, securityMd ★ |
| theme | accent ★`#00e5ff` |
| post | git ★ (init + initial commit `feat: scaffold <name> with create-rust-app`), cargoCheck ★ if cargo is on PATH, open: none ★ / code / cursor |
Expand All @@ -188,7 +189,7 @@ all tooling), `tui` (ratatui + crossterm), `lib` (thiserror, no bin, docs.rs met
- Runtime deps: `@clack/core` (prompt state machines and key handling) and `picocolors`. Everything
else is hand-rolled: arg parsing with `node:util` `parseArgs`, gradients in `src/ui/rainbow.ts`, the
banner in `src/ui/banner.ts`, rendering in `src/ui/{rail,choose,motion}.ts`.
- Flags: `create-rust-app [dir] --name --bin --preset <p> --kind --gui <eframe|winit-glow> --edition --msrv
- Flags: `create-rust-app [dir] --name --bin --preset <p> --kind --gui <eframe|winit-glow> --base --edition --msrv
--toolchain --license --author --github --accent --with a,b --without a,b --set key.path=value
--yes/-y --no-git --no-fetch --cargo-check --no-cargo-check --open <code|cursor> --dry-run --json
--no-color --quiet --force --help --version`. Non-TTY implies `--yes`.
Expand Down
8 changes: 6 additions & 2 deletions src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { existsSync } from 'node:fs';
import { DEFAULTS, PRESETS } from './presets.ts';
import { validateBin, validateName } from './context.ts';
import type { PartialAnswers } from './types.ts';
import { shippedThemes } from './gen/themes.ts';

/** @type {Record<string, import('node:util').ParseArgsOptionConfig>} */
const OPTIONS: NonNullable<import('node:util').ParseArgsConfig['options']> = {};
for (const name of ['name', 'bin', 'preset', 'kind', 'gui', 'edition', 'msrv', 'toolchain', 'license', 'author', 'github', 'accent', 'open']) {
for (const name of ['name', 'bin', 'preset', 'kind', 'gui', 'base', 'edition', 'msrv', 'toolchain', 'license', 'author', 'github', 'accent', 'open']) {
OPTIONS[name] = { type: 'string' };
}
for (const name of ['with', 'without', 'set']) OPTIONS[name] = { type: 'string', multiple: true };
Expand Down Expand Up @@ -44,6 +45,7 @@ Object.assign(SHORT_NAMES, {
const CHOICES: Record<string, string[]> = {
preset: [...Object.keys(PRESETS), 'custom'],
kind: ['cli', 'gui', 'tui', 'lib', 'workspace'], guiStack: ['eframe', 'winit-glow'],
themeBase: shippedThemes().map((theme) => theme.id),
license: ['MIT', 'MIT+CommonsClause', 'Apache-2.0', 'MIT OR Apache-2.0'],
edition: ['2024', '2021'], 'crates.errors': ['anyhow'],
'crates.logging': ['log', 'env_logger', 'tracing'], 'crates.async': ['none', 'tokio'],
Expand Down Expand Up @@ -146,6 +148,7 @@ export function parseArgv(argv: string[]) {
else if (name === 'no-fetch') setAnswer(overrides, 'post.fetch', false);
else if (name === 'open') setAnswer(overrides, 'post.open', String(value));
else if (name === 'gui') setAnswer(overrides, 'guiStack', String(value));
else if (name === 'base') setAnswer(overrides, 'themeBase', String(value));
else if (Object.hasOwn(DEFAULTS, name)) setAnswer(overrides, name, String(value));
}
return { dir: parsed.positionals[0], flags, overrides: overrides as PartialAnswers };
Expand All @@ -169,7 +172,7 @@ async function choiceHelp(caps: unknown): Promise<string[]> {
const tint = (c: string, t: string) => rainbow.hex?.(caps, c, t) ?? t;
const sections: [string, string, Record<string, { label: string; hint: string }>][] = [
['crates', '#ff6ec7', { ...labels.CRATE_TOGGLES, tokio: { label: 'tokio', hint: labels.ASYNC.tokio.hint }, ureq: { label: 'ureq', hint: labels.HTTP.ureq.hint }, reqwest: { label: 'reqwest', hint: labels.HTTP.reqwest.hint }, tracing: { label: 'tracing', hint: labels.LOGGING.tracing.hint }, env_logger: { label: 'env_logger', hint: labels.LOGGING.env_logger.hint } }],
['command line (cli kind, with clap)', '#b6ff6e', { subcommands: labels.FEATURES.subcommands }],
['command line (cli and desktop kinds, with clap)', '#b6ff6e', { subcommands: labels.FEATURES.subcommands }],
['app features (desktop kinds)', '#ff9f6e', labels.DESKTOP],
['tooling', '#ffd36e', labels.TOOLING],
];
Expand All @@ -195,6 +198,7 @@ export async function renderHelp(caps: unknown) {
' --preset <preset> ' + Object.keys(PRESETS).join(' | ') + ' | custom',
' --kind <kind> cli | gui | tui | lib | workspace',
' --gui <stack> eframe | winit-glow',
' --base <theme> Surfaces for the signature theme: ' + shippedThemes().map((theme) => theme.id).join(' | '),
' --author <name> Author name --github <user> GitHub owner',
' --license <license> MIT | MIT+CommonsClause | Apache-2.0 | "MIT OR Apache-2.0"',
' --edition <edition> 2024 | 2021 --msrv <version> Minimum Rust version',
Expand Down
27 changes: 24 additions & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Answers, Ctx, TokenKey } from './types.ts';
import { DEFAULT_BASE, shippedTheme } from './gen/themes.ts';
/** Answers → Ctx (see docs/CONTRACTS.md). */

export const NAME_RE = /^[a-z][a-z0-9-]*$/;
Expand Down Expand Up @@ -39,7 +40,7 @@ const LICENSE_FLAG = {

/** App features only a desktop GUI generates (kind `gui`, or the `workspace` app crate). */
export const GUI_ONLY_FEATURES = ['themes', 'brand', 'motion', 'icons', 'winres', 'tray', 'singleInstance',
'commandPalette', 'screenshotExample'] as const satisfies readonly (keyof Answers['features'])[];
'commandPalette', 'screenshotExample', 'demo'] as const satisfies readonly (keyof Answers['features'])[];

/**
* The answers as they apply to this kind of project: options the kind never generates read
Expand All @@ -52,12 +53,14 @@ export function effectiveAnswers(a: Answers): Answers {
if (!hasGui) {
for (const f of GUI_ONLY_FEATURES) out.features[f] = false;
out.tooling.unsafeCheck = false;
out.themeBase = '';
}
// The GUI kinds always ship a config file; the CLI only when serde is on to read it. A library
// leaves config to the app embedding it, and the TUI template has none.
if (!hasGui && !(a.kind === 'cli' && a.crates.serde)) out.features.config = false;
// Subcommands shape a clap command line, so they need the cli kind with clap.
if (a.kind !== 'cli' || !a.crates.clap) out.features.subcommands = false;
// Subcommands shape a clap command line: the cli kind's commands, or a desktop app's headless
// jobs. A TUI or a library has no place for them, and without clap there is no parser.
if (!a.crates.clap || !(a.kind === 'cli' || hasGui)) out.features.subcommands = false;
// A library has no binary, and a binary named like its crate needs no [[bin]] table.
if (a.kind === 'lib' || a.bin === (a.kind === 'workspace' ? `${a.name}-app` : a.name)) out.bin = '';
return out;
Expand All @@ -72,6 +75,8 @@ export function buildContext(raw: Answers): Ctx {
if (err) throw new Error(`invalid project name "${a.name}": ${err}`);
const binErr = a.bin ? validateBin(a.bin) : null;
if (binErr) throw new Error(`invalid binary name "${a.bin}": ${binErr}`);
const base = shippedTheme(a.themeBase || DEFAULT_BASE);
if (!base) throw new Error(`unknown theme base "${a.themeBase}"`);
const workspace = a.kind === 'workspace';
const hasGui = a.kind === 'gui' || workspace;

Expand All @@ -86,6 +91,7 @@ export function buildContext(raw: Answers): Ctx {
}
if (a.kind !== 'lib') flags.add('has_bin');
if (a.bin) flags.add('custom_bin');
if (hasGui) flags.add(`base_${base.mode}`);
const lf = LICENSE_FLAG[/** @type {keyof typeof LICENSE_FLAG} */ (a.license as keyof typeof LICENSE_FLAG)];
if (!lf) throw new Error(`unknown license ${a.license}`);
flags.add(lf);
Expand Down Expand Up @@ -122,6 +128,21 @@ export function buildContext(raw: Answers): Ctx {
msrv: a.msrv,
toolchain: a.toolchain,
accent: a.accent,
// The --base theme's stated colours, for the signature theme (theme/mod.rs).
baseName: base.name,
baseMode: base.mode === 'light' ? 'Light' : 'Dark',
baseApp: base.app,
basePanel: base.panel,
baseRaised: base.raised,
baseHover: base.hover,
baseBorder: base.border,
baseText: base.text,
baseTextMuted: base.text_muted,
baseDanger: base.danger,
baseWarning: base.warning,
baseSuccess: base.success,
baseSpan: Number.isInteger(base.rainbow_span) ? `${base.rainbow_span}.0` : String(base.rainbow_span),
baseAccentRgb: [1, 3, 5].map((i) => `0x${base.accent.slice(i, i + 2).toLowerCase()}`).join(', '),
};

return {
Expand Down
64 changes: 64 additions & 0 deletions src/gen/themes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* The built-in theme catalog (templates/gui/files/assets/themes.toml), read by the generator so
* `--base` can lay the signature theme's accent on any shipped theme's surfaces. The file the
* generated app compiles in is the single source: a theme added there is a valid `--base` at once.
*/
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { TEMPLATES } from '../engine/plan.ts';

/** One `[[theme]]` from the catalog: the eleven stated colours plus identity and band. */
export interface ShippedTheme {
id: string; name: string; mode: 'dark' | 'light';
app: string; panel: string; raised: string; hover: string; border: string;
accent: string; text: string; text_muted: string;
danger: string; warning: string; success: string;
rainbow_span: number;
}

/** The base the signature theme uses unless `--base` says otherwise. */
export const DEFAULT_BASE = 'midnight';

const COLOURS = ['app', 'panel', 'raised', 'hover', 'border', 'accent', 'text', 'text_muted', 'danger', 'warning', 'success'] as const;

let cache: ShippedTheme[] | undefined;

/** Every shipped theme, in catalog order. Throws if the catalog is malformed (a template bug). */
export function shippedThemes(): ShippedTheme[] {
if (cache) return cache;
const text = readFileSync(join(TEMPLATES, 'gui', 'files', 'assets', 'themes.toml'), 'utf8');
const blocks = text.split(/^\[\[theme\]\]\s*$/m).slice(1);
cache = blocks.map((block, index) => {
const fields: Record<string, string> = {};
for (const line of block.split('\n')) {
const m = /^([a-z_]+)\s*=\s*(?:"([^"]*)"|([\d.]+))\s*$/.exec(line.trim());
if (m?.[1]) fields[m[1]] = m[2] ?? m[3] ?? '';
}
const where = `themes.toml theme #${index + 1}`;
const need = (key: string) => {
const value = fields[key];
if (value === undefined) throw new Error(`${where}: missing ${key}`);
return value;
};
const mode = need('mode');
if (mode !== 'dark' && mode !== 'light') throw new Error(`${where}: mode must be dark or light`);
for (const key of COLOURS) {
if (!/^#[\da-f]{6}$/i.test(need(key))) throw new Error(`${where}: ${key} is not a #rrggbb colour`);
}
const span = Number(need('rainbow_span'));
if (!Number.isFinite(span)) throw new Error(`${where}: rainbow_span is not a number`);
return {
id: need('id'), name: need('name'), mode,
app: need('app'), panel: need('panel'), raised: need('raised'), hover: need('hover'), border: need('border'),
accent: need('accent'), text: need('text'), text_muted: need('text_muted'),
danger: need('danger'), warning: need('warning'), success: need('success'),
rainbow_span: span,
};
});
return cache;
}

/** The shipped theme with this id, or undefined. */
export function shippedTheme(id: string): ShippedTheme | undefined {
return shippedThemes().find((theme) => theme.id === id);
}
3 changes: 2 additions & 1 deletion src/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export const DEFAULTS: Answers = Object.freeze<Answers>({
accent: '#00e5ff',
kind: 'gui',
guiStack: 'eframe',
themeBase: 'midnight',
crates: { errors: 'anyhow', thiserror: false, logging: 'log', serde: true, async: 'none', http: 'none', sqlite: false, clap: true },
features: { themes: true, brand: true, motion: true, icons: true, config: true, winres: true, tray: false, singleInstance: false, commandPalette: false, screenshotExample: false, subcommands: false },
features: { themes: true, brand: true, motion: true, icons: true, config: true, winres: true, tray: false, singleInstance: false, commandPalette: false, screenshotExample: false, demo: true, subcommands: false },
tooling: { ci: true, release: true, cargoDeny: true, dependabot: true, toolchainPin: true, agentDocs: true, headerCheck: true, unsafeCheck: true, changelogGen: true, issueTemplates: true, codeowners: true, securityMd: true },
// fetch (seconds) by default; a full check of a GUI project compiles eframe/wgpu (minutes).
post: { git: true, fetch: true, cargoCheck: false, open: 'none' },
Expand Down
Loading