create-signet-app 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/package.json +1 -1
- package/src/compose.ts +21 -2
- package/src/index.ts +120 -50
- package/src/picker.ts +179 -0
package/README.md
CHANGED
|
@@ -68,7 +68,14 @@ bunx create-signet-app my-app --starter saas --with ai # a starter, plus a
|
|
|
68
68
|
is the default).
|
|
69
69
|
- **Starters** are named mixes of parts, by the shape of app. `--with` adds to
|
|
70
70
|
the starter, `--without` takes away; `--without` alone starts from `full`.
|
|
71
|
-
Run with no flags on a terminal
|
|
71
|
+
Run with no flags on a terminal and it asks in plain words: the name (if not
|
|
72
|
+
given), what you are building (web app, API only, command-line tool, browser
|
|
73
|
+
extension, desktop app), then for a web app or an API a mix to start from
|
|
74
|
+
(just the basics, a starter, or everything) and its features, ticked so you
|
|
75
|
+
can add or remove any. Ticks that equal a starter are `--starter`, anything
|
|
76
|
+
else is `--with`. Then the theme (where there is a web UI) and MCP (where
|
|
77
|
+
there is an API). Before creating it shows a summary and the one-line
|
|
78
|
+
command that builds the same app.
|
|
72
79
|
|
|
73
80
|
| starter | parts (plus what they need) |
|
|
74
81
|
| --- | --- |
|
package/package.json
CHANGED
package/src/compose.ts
CHANGED
|
@@ -99,51 +99,70 @@ export const PARTS: Record<PartName, Part> = {
|
|
|
99
99
|
* brings orgs, everything brings auth). `surface: "api"` is the API half only.
|
|
100
100
|
* MCP is not listed: it is asked for (or --mcp / --no-mcp), as it always was.
|
|
101
101
|
* Each description is one line, quoted, first: signet-mcp's index reads it.
|
|
102
|
+
* The label is the picker's row, in words for someone who knows none of the
|
|
103
|
+
* part names; at most 44 characters, or clack wraps the row at 60 columns.
|
|
102
104
|
*/
|
|
103
105
|
export const STARTERS = {
|
|
104
106
|
full: {
|
|
105
107
|
description: "every part, web + API",
|
|
108
|
+
label: "Everything — every feature",
|
|
106
109
|
parts: PART_NAMES.filter((p) => !["mcp", "dashboard", "pwa"].includes(p)),
|
|
107
110
|
},
|
|
108
|
-
blank: {
|
|
111
|
+
blank: {
|
|
112
|
+
description: "no parts: the shell, the API and the database",
|
|
113
|
+
label: "Empty shell — site, server and database",
|
|
114
|
+
parts: [],
|
|
115
|
+
},
|
|
109
116
|
saas: {
|
|
110
117
|
description: "a paid team product: orgs, admin, billing, inbox, account, privacy",
|
|
118
|
+
label: "SaaS — teams, billing, admin, notifications",
|
|
111
119
|
parts: ["account", "orgs", "admin", "notifications", "privacy", "payments"],
|
|
112
120
|
},
|
|
113
121
|
launch: {
|
|
114
122
|
description: "before launch: sign-in, waitlist, invites, referrals, feedback, privacy",
|
|
123
|
+
label: "Pre-launch — waitlist, invites, feedback",
|
|
115
124
|
parts: ["account", "privacy", "growth"],
|
|
116
125
|
},
|
|
117
126
|
"internal-tool": {
|
|
118
127
|
description: "for your own team: orgs and roles, the admin panel, approval workflows",
|
|
128
|
+
label: "Internal tool — roles, admin, approvals",
|
|
119
129
|
parts: ["account", "orgs", "admin", "workflows"],
|
|
120
130
|
},
|
|
121
131
|
"api-billing": {
|
|
122
132
|
description: "the API half only: sign-in, API keys, billing webhooks",
|
|
133
|
+
label: "Sign-in + billing — accounts, API keys",
|
|
123
134
|
parts: ["account", "payments"],
|
|
124
135
|
surface: "api",
|
|
125
136
|
},
|
|
126
137
|
"ai-app": {
|
|
127
138
|
description: "an AI product: spend caps per user, billing, account, privacy",
|
|
139
|
+
label: "AI product — per-user spend limits, billing",
|
|
128
140
|
parts: ["account", "privacy", "payments", "ai"],
|
|
129
141
|
},
|
|
130
142
|
paywall: {
|
|
131
143
|
description: "sell access: plans, entitlements, billing, remote paywalls",
|
|
144
|
+
label: "Paid access — plans, billing, paywalls",
|
|
132
145
|
parts: ["account", "payments", "paywalls"],
|
|
133
146
|
},
|
|
134
147
|
automation: {
|
|
135
148
|
description: "durable workflows with approvals, and an inbox to tell people",
|
|
149
|
+
label: "Automations — jobs, approvals, alerts",
|
|
136
150
|
parts: ["account", "notifications", "workflows"],
|
|
137
151
|
},
|
|
138
152
|
dashboard: {
|
|
139
153
|
description: "a sidebar shell and an overview: stat tiles, a chart, a table",
|
|
154
|
+
label: "Dashboard — sidebar, stats, a chart, a table",
|
|
140
155
|
parts: ["account", "dashboard"],
|
|
141
156
|
},
|
|
142
157
|
pwa: {
|
|
143
158
|
description: "installable and offline: web manifest, service worker, install prompt",
|
|
159
|
+
label: "Installable app — works offline",
|
|
144
160
|
parts: ["account", "pwa"],
|
|
145
161
|
},
|
|
146
|
-
} satisfies Record<
|
|
162
|
+
} satisfies Record<
|
|
163
|
+
string,
|
|
164
|
+
{ description: string; label: string; parts: PartName[]; surface?: "api" }
|
|
165
|
+
>
|
|
147
166
|
export type StarterName = keyof typeof STARTERS
|
|
148
167
|
|
|
149
168
|
/**
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,17 @@
|
|
|
13
13
|
import { existsSync } from "node:fs"
|
|
14
14
|
import { cp, mkdir, readdir, readFile, rename, writeFile } from "node:fs/promises"
|
|
15
15
|
import { basename, join, resolve } from "node:path"
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
cancel,
|
|
18
|
+
confirm,
|
|
19
|
+
intro,
|
|
20
|
+
isCancel,
|
|
21
|
+
multiselect,
|
|
22
|
+
note,
|
|
23
|
+
outro,
|
|
24
|
+
select,
|
|
25
|
+
text,
|
|
26
|
+
} from "@clack/prompts"
|
|
17
27
|
import {
|
|
18
28
|
applyBlocks,
|
|
19
29
|
type BaseDeps,
|
|
@@ -28,11 +38,23 @@ import {
|
|
|
28
38
|
type StarterName,
|
|
29
39
|
} from "./compose.js"
|
|
30
40
|
import { appId, DESKTOP_PKG } from "./desktop.js"
|
|
41
|
+
import {
|
|
42
|
+
choose,
|
|
43
|
+
command,
|
|
44
|
+
type Mix,
|
|
45
|
+
mixRows,
|
|
46
|
+
nameError,
|
|
47
|
+
PLATFORMS,
|
|
48
|
+
type Platform,
|
|
49
|
+
partRows,
|
|
50
|
+
summary,
|
|
51
|
+
THEME_LABELS,
|
|
52
|
+
ticked,
|
|
53
|
+
WHAT,
|
|
54
|
+
} from "./picker.js"
|
|
31
55
|
|
|
32
56
|
const THEMES = ["editorial", "cinematic", "finance"] as const
|
|
33
57
|
type Theme = (typeof THEMES)[number]
|
|
34
|
-
const PLATFORMS = ["web", "api", "cli", "extension", "desktop"] as const
|
|
35
|
-
type Platform = (typeof PLATFORMS)[number]
|
|
36
58
|
// --template is the old name for --platform, kept working; its `full` is now `--starter full`.
|
|
37
59
|
const TEMPLATES = [...PLATFORMS, "full"] as const
|
|
38
60
|
type Template = (typeof TEMPLATES)[number]
|
|
@@ -474,7 +496,9 @@ Examples:
|
|
|
474
496
|
}
|
|
475
497
|
}
|
|
476
498
|
|
|
477
|
-
|
|
499
|
+
// On a terminal a missing name is asked for (askName); elsewhere it is an error.
|
|
500
|
+
if (!name && !process.stdin.isTTY)
|
|
501
|
+
throw new Error("Missing target directory.\nUsage: create-signet-app <directory>")
|
|
478
502
|
const composing =
|
|
479
503
|
composeFlags.starter ||
|
|
480
504
|
composeFlags.ui ||
|
|
@@ -518,6 +542,7 @@ Examples:
|
|
|
518
542
|
mcp,
|
|
519
543
|
pm: pm ?? detectPm(),
|
|
520
544
|
composeFlags,
|
|
545
|
+
themeGiven,
|
|
521
546
|
// Nothing said what to build: asked on a terminal, else the web platform.
|
|
522
547
|
pick: !templateGiven && !composing,
|
|
523
548
|
}
|
|
@@ -574,56 +599,85 @@ async function substitute(dir: string, vars: Record<string, string>) {
|
|
|
574
599
|
}
|
|
575
600
|
}
|
|
576
601
|
|
|
577
|
-
/** One line each in the picker; cut to the terminal's width when shown. */
|
|
578
|
-
const PLATFORM_HINTS: Record<Platform, string> = {
|
|
579
|
-
web: "Vite + React + Signet UI",
|
|
580
|
-
api: "Hono Worker: error envelope, request ids, rate limiting",
|
|
581
|
-
cli: "Bun CLI compiled to one binary, device-code login",
|
|
582
|
-
extension: "Chrome MV3 extension: popup, options page, service worker",
|
|
583
|
-
desktop: "Tauri v2 desktop + menu-bar app, browser sign-in",
|
|
584
|
-
}
|
|
585
|
-
|
|
586
602
|
/** Ctrl+C at a prompt: say so and leave without scaffolding. */
|
|
587
603
|
function cancelled(): never {
|
|
588
604
|
cancel("Cancelled.")
|
|
589
605
|
process.exit(130)
|
|
590
606
|
}
|
|
591
607
|
|
|
592
|
-
/** A
|
|
593
|
-
function
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
// clack keeps when it wraps a row.
|
|
597
|
-
const room = width - label.length - 21
|
|
598
|
-
return {
|
|
599
|
-
value,
|
|
600
|
-
label,
|
|
601
|
-
hint: room < 2 ? undefined : hint.length > room ? `${hint.slice(0, room - 1)}…` : hint,
|
|
602
|
-
}
|
|
608
|
+
/** A prompt's answer, or Ctrl+C's exit. */
|
|
609
|
+
function ask<T>(answer: T): Exclude<T, symbol> {
|
|
610
|
+
if (isCancel(answer)) cancelled()
|
|
611
|
+
return answer as Exclude<T, symbol>
|
|
603
612
|
}
|
|
604
613
|
|
|
605
|
-
/**
|
|
606
|
-
async function
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
614
|
+
/** The directory name, when it was not given; only asked on a terminal. */
|
|
615
|
+
async function askName(): Promise<string> {
|
|
616
|
+
const name = ask(
|
|
617
|
+
await text({
|
|
618
|
+
message: "Project name?",
|
|
619
|
+
placeholder: "my-app",
|
|
620
|
+
defaultValue: "my-app",
|
|
621
|
+
validate: (v) => nameError(v, process.cwd()),
|
|
622
|
+
}),
|
|
623
|
+
)
|
|
624
|
+
return name.trim() || "my-app"
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* The picker: what you are building; for web and api, a ready-made mix and
|
|
629
|
+
* its features (ticked, to adjust); the theme where there is a web UI; MCP
|
|
630
|
+
* where there is an API. Rows and the mapping to flags are in src/picker.ts.
|
|
631
|
+
*/
|
|
632
|
+
async function askWhat(themeGiven?: Theme) {
|
|
633
|
+
const what = ask(
|
|
634
|
+
await select<Platform>({
|
|
635
|
+
message: "What are you building?",
|
|
636
|
+
initialValue: "web",
|
|
637
|
+
options: WHAT,
|
|
638
|
+
}),
|
|
639
|
+
)
|
|
640
|
+
let choice = choose(what)
|
|
641
|
+
let ticks: PartName[] = []
|
|
642
|
+
if (what === "web" || what === "api") {
|
|
643
|
+
const mix = ask(
|
|
644
|
+
await select<Mix>({ message: "Start from", initialValue: "basics", options: mixRows(what) }),
|
|
645
|
+
)
|
|
646
|
+
ticks = ask(
|
|
647
|
+
await multiselect<PartName>({
|
|
648
|
+
message: "Features (change any, Enter to accept)",
|
|
649
|
+
options: partRows(what),
|
|
650
|
+
initialValues: ticked(mix),
|
|
651
|
+
required: false,
|
|
652
|
+
}),
|
|
653
|
+
)
|
|
654
|
+
choice = choose(what, mix, ticks)
|
|
655
|
+
}
|
|
656
|
+
// A web app's every answer has a web UI; an API's and a CLI's none.
|
|
657
|
+
const ui = what !== "api" && what !== "cli"
|
|
658
|
+
const theme =
|
|
659
|
+
ui && !themeGiven
|
|
660
|
+
? ask(
|
|
661
|
+
await select<Theme>({
|
|
662
|
+
message: "Theme",
|
|
663
|
+
initialValue: "editorial",
|
|
664
|
+
options: THEMES.map((t) => ({ value: t, label: THEME_LABELS[t] ?? t })),
|
|
665
|
+
}),
|
|
666
|
+
)
|
|
667
|
+
: themeGiven
|
|
668
|
+
const mcp = choice.template === "api" || choice.template === "full" ? await askMcp() : undefined
|
|
669
|
+
return { what, choice, ticks, theme: ui ? theme : undefined, mcp }
|
|
619
670
|
}
|
|
620
671
|
|
|
621
|
-
/** "
|
|
672
|
+
/** "Let AI coding agents work with this app?", default yes; only asked on a terminal. */
|
|
622
673
|
async function askMcp(): Promise<boolean> {
|
|
623
674
|
if (!process.stdin.isTTY) return true
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
675
|
+
return ask(
|
|
676
|
+
await confirm({
|
|
677
|
+
message: "Let AI coding agents work with this app? (adds an MCP server)",
|
|
678
|
+
initialValue: true,
|
|
679
|
+
}),
|
|
680
|
+
)
|
|
627
681
|
}
|
|
628
682
|
|
|
629
683
|
/** A platform's template, its --target files and MCP's overlay, as they always were. */
|
|
@@ -714,8 +768,12 @@ function composedMessage(
|
|
|
714
768
|
|
|
715
769
|
async function main() {
|
|
716
770
|
const parsed = parseArgs(process.argv)
|
|
717
|
-
const {
|
|
771
|
+
const { target, pm, ...flags } = parsed
|
|
718
772
|
let { theme, template } = parsed
|
|
773
|
+
// On a terminal, a missing name or a missing platform is asked for, in one frame.
|
|
774
|
+
const asking = process.stdin.isTTY && (parsed.pick || !parsed.name)
|
|
775
|
+
if (asking) intro("create-signet-app")
|
|
776
|
+
const name = parsed.name ?? (await askName())
|
|
719
777
|
const dest = resolve(process.cwd(), name)
|
|
720
778
|
const appName = basename(dest)
|
|
721
779
|
|
|
@@ -732,12 +790,24 @@ async function main() {
|
|
|
732
790
|
}
|
|
733
791
|
const picking = parsed.pick && process.stdin.isTTY
|
|
734
792
|
if (picking) {
|
|
735
|
-
const what = await askWhat()
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
793
|
+
const { what, choice, ticks, theme: picked, mcp } = await askWhat(parsed.themeGiven)
|
|
794
|
+
template = choice.template
|
|
795
|
+
const c = parsed.composeFlags
|
|
796
|
+
c.starter = choice.starter
|
|
797
|
+
c.api = choice.api ?? false
|
|
798
|
+
c.with = choice.with ?? []
|
|
799
|
+
if (picked) theme = picked
|
|
800
|
+
flags.mcp = mcp
|
|
801
|
+
const runner = `${pm === "bun" ? "bunx" : "npx"} create-signet-app`
|
|
802
|
+
note(
|
|
803
|
+
[
|
|
804
|
+
...summary(what, choice, ticks, picked, mcp),
|
|
805
|
+
"",
|
|
806
|
+
"Same as:",
|
|
807
|
+
command(runner, name, choice, picked, mcp),
|
|
808
|
+
].join("\n"),
|
|
809
|
+
`Creating ${appName}`,
|
|
810
|
+
)
|
|
741
811
|
}
|
|
742
812
|
if (parsed.pm === "deno" && template === "cli")
|
|
743
813
|
throw new Error(
|
|
@@ -867,7 +937,7 @@ async function main() {
|
|
|
867
937
|
}
|
|
868
938
|
const steps = `cd ${name}\n ${install}\n ${run} dev`
|
|
869
939
|
// Closes the picker's frame; the next steps below are printed as they always were.
|
|
870
|
-
if (
|
|
940
|
+
if (asking) outro(`Scaffolded ${appName}.`)
|
|
871
941
|
console.log(
|
|
872
942
|
template === "cli"
|
|
873
943
|
? `
|
package/src/picker.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The picker's rows and what the answers scaffold, apart from the prompts so
|
|
3
|
+
* the mapping is tested without a terminal. Step 1 picks a platform; for web
|
|
4
|
+
* and api, "Start from" picks a ready-made mix and "Features" ticks its parts,
|
|
5
|
+
* which the user adjusts. Every row is one plain-language line, explanation
|
|
6
|
+
* included: clack shows a hint only on the highlighted row. Each label is at
|
|
7
|
+
* most 44 characters, or clack wraps the row at 60 columns.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { existsSync, readdirSync } from "node:fs"
|
|
11
|
+
import { resolve } from "node:path"
|
|
12
|
+
import {
|
|
13
|
+
PART_NAMES,
|
|
14
|
+
PARTS,
|
|
15
|
+
type PartName,
|
|
16
|
+
resolveParts,
|
|
17
|
+
STARTERS,
|
|
18
|
+
type StarterName,
|
|
19
|
+
} from "./compose.js"
|
|
20
|
+
|
|
21
|
+
export const PLATFORMS = ["web", "api", "cli", "extension", "desktop"] as const
|
|
22
|
+
export type Platform = (typeof PLATFORMS)[number]
|
|
23
|
+
|
|
24
|
+
export const WHAT: { value: Platform; label: string }[] = [
|
|
25
|
+
{ value: "web", label: "Web app — a site people open in a browser" },
|
|
26
|
+
{ value: "api", label: "API only — a server other apps talk to" },
|
|
27
|
+
{ value: "cli", label: "Command-line tool — runs in a terminal" },
|
|
28
|
+
{ value: "extension", label: "Browser extension — a Chrome add-on" },
|
|
29
|
+
{ value: "desktop", label: "Desktop app — Mac, Windows and Linux" },
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
/** "Start from": the platform alone, or a starter. */
|
|
33
|
+
export type Mix = "basics" | StarterName
|
|
34
|
+
|
|
35
|
+
const STARTER_NAMES = Object.keys(STARTERS) as StarterName[]
|
|
36
|
+
const apiStarter = (s: StarterName) => "surface" in STARTERS[s]
|
|
37
|
+
|
|
38
|
+
/** The starters offered on a path: the API ones for api, the rest for web; full on both, last. */
|
|
39
|
+
function startersFor(what: "web" | "api"): StarterName[] {
|
|
40
|
+
const ends: StarterName[] = what === "web" ? ["blank", "full"] : ["full"]
|
|
41
|
+
const rest = STARTER_NAMES.filter((s) => !ends.includes(s) && (what === "api") === apiStarter(s))
|
|
42
|
+
return [...rest, ...ends]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** "Start from" rows: the basics first, the starters, everything last. */
|
|
46
|
+
export function mixRows(what: "web" | "api"): { value: Mix; label: string }[] {
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
value: "basics",
|
|
50
|
+
label:
|
|
51
|
+
what === "api"
|
|
52
|
+
? "Just the basics — a plain API, no extras"
|
|
53
|
+
: "Just the basics — a themed site, no server",
|
|
54
|
+
},
|
|
55
|
+
...startersFor(what).map((s) => ({ value: s, label: STARTERS[s].label })),
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Every part but mcp, which is its own question. */
|
|
60
|
+
const PART_LABELS: Record<Exclude<PartName, "mcp">, string> = {
|
|
61
|
+
auth: "Sign-in — log in with a phone code",
|
|
62
|
+
account: "Account page — profile, devices, API keys",
|
|
63
|
+
orgs: "Teams & roles — members and invite links",
|
|
64
|
+
admin: "Admin panel",
|
|
65
|
+
notifications: "Notifications — inbox and preferences",
|
|
66
|
+
privacy: "Privacy — consent, data export and deletion",
|
|
67
|
+
payments: "Billing — plans and payments",
|
|
68
|
+
paywalls: "Paywalls — offers shown per audience",
|
|
69
|
+
growth: "Growth — waitlist, referrals, feedback",
|
|
70
|
+
ai: "AI with spend limits",
|
|
71
|
+
workflows: "Approvals — multi-step jobs people sign off",
|
|
72
|
+
dashboard: "Dashboard — sidebar, stats, a chart, a table",
|
|
73
|
+
pwa: "Installable — works offline",
|
|
74
|
+
}
|
|
75
|
+
const partLabel = (p: PartName) => PART_LABELS[p as Exclude<PartName, "mcp">]
|
|
76
|
+
|
|
77
|
+
/** "Features" rows; the API path leaves out the web-only parts. */
|
|
78
|
+
export function partRows(what: "web" | "api"): { value: PartName; label: string }[] {
|
|
79
|
+
return PART_NAMES.filter((p) => p !== "mcp" && !(what === "api" && PARTS[p].webOnly)).map(
|
|
80
|
+
(p) => ({ value: p, label: partLabel(p) }),
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Parts plus everything they need, as compose installs them. */
|
|
85
|
+
const installed = (parts: readonly PartName[]) => resolveParts([...parts], []).parts
|
|
86
|
+
|
|
87
|
+
/** The parts already ticked for a mix: the starter's own and what they need. */
|
|
88
|
+
export function ticked(mix: Mix): PartName[] {
|
|
89
|
+
return mix === "basics" ? [] : installed(STARTERS[mix].parts)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type Choice = {
|
|
93
|
+
template: Platform | "full"
|
|
94
|
+
starter?: StarterName
|
|
95
|
+
api?: true
|
|
96
|
+
with?: PartName[]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const same = (a: readonly string[], b: readonly string[]) =>
|
|
100
|
+
a.length === b.length && a.every((x) => b.includes(x))
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* What the answers scaffold, as flags say it. Ticks that install the same
|
|
104
|
+
* parts as a starter on this path (needs counted on both sides) are
|
|
105
|
+
* `--starter <name>`, the chosen mix first; any other ticks are
|
|
106
|
+
* `--with`, plus `--api` on the API path. Nothing ticked from the basics, or
|
|
107
|
+
* nothing that matches a starter, is the platform alone.
|
|
108
|
+
*/
|
|
109
|
+
export function choose(what: Platform, mix: Mix = "basics", ticks: PartName[] = []): Choice {
|
|
110
|
+
if (what !== "web" && what !== "api") return { template: what }
|
|
111
|
+
if (mix === "basics" && !ticks.length) return { template: what }
|
|
112
|
+
const api = what === "api" ? ({ api: true } as const) : {}
|
|
113
|
+
const order = mix === "basics" ? startersFor(what) : [mix, ...startersFor(what)]
|
|
114
|
+
const starter = order.find((s) => same(installed(STARTERS[s].parts), installed(ticks)))
|
|
115
|
+
if (starter) return { template: "full", starter, ...(apiStarter(starter) ? {} : api) }
|
|
116
|
+
if (!ticks.length) return { template: what }
|
|
117
|
+
return { template: "full", with: ticks, ...api }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The one-line command that scaffolds the same app, so the picker teaches the flags. */
|
|
121
|
+
export function command(
|
|
122
|
+
runner: string,
|
|
123
|
+
name: string,
|
|
124
|
+
c: Choice,
|
|
125
|
+
theme?: string,
|
|
126
|
+
mcp?: boolean,
|
|
127
|
+
): string {
|
|
128
|
+
return [
|
|
129
|
+
runner,
|
|
130
|
+
name,
|
|
131
|
+
...(c.template !== "web" && c.template !== "full" ? ["--platform", c.template] : []),
|
|
132
|
+
...(c.starter ? ["--starter", c.starter] : []),
|
|
133
|
+
...(c.with ? ["--with", c.with.join(",")] : []),
|
|
134
|
+
...(c.api ? ["--api"] : []),
|
|
135
|
+
...(theme && theme !== "editorial" ? ["--theme", theme] : []),
|
|
136
|
+
...(mcp === undefined ? [] : [mcp ? "--mcp" : "--no-mcp"]),
|
|
137
|
+
].join(" ")
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The summary shown before creating: what, which mix, the parts installed (needs too), theme, MCP. */
|
|
141
|
+
export function summary(
|
|
142
|
+
what: Platform,
|
|
143
|
+
c: Choice,
|
|
144
|
+
ticks: PartName[],
|
|
145
|
+
theme?: string,
|
|
146
|
+
mcp?: boolean,
|
|
147
|
+
): string[] {
|
|
148
|
+
const short = (label: string) => label.split(" — ")[0]
|
|
149
|
+
const parts = installed(ticks)
|
|
150
|
+
return [
|
|
151
|
+
what === "web"
|
|
152
|
+
? c.template === "full"
|
|
153
|
+
? "Web app (site + server)"
|
|
154
|
+
: "Web app"
|
|
155
|
+
: short(WHAT.find((w) => w.value === what)?.label ?? what),
|
|
156
|
+
...(c.starter ? [`Starter: ${STARTERS[c.starter].label}`] : []),
|
|
157
|
+
...(c.template === "full"
|
|
158
|
+
? [`Features: ${parts.length ? parts.map((p) => short(partLabel(p))).join(", ") : "none"}`]
|
|
159
|
+
: []),
|
|
160
|
+
...(theme ? [`Theme: ${theme}`] : []),
|
|
161
|
+
...(mcp === undefined ? [] : [`AI coding agents (MCP): ${mcp ? "yes" : "no"}`]),
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Why a typed project name can't be used, or undefined; empty is the default, my-app. */
|
|
166
|
+
export function nameError(typed: string | undefined, cwd: string): string | undefined {
|
|
167
|
+
const name = typed?.trim() || "my-app"
|
|
168
|
+
if (name.startsWith("-")) return "A name can't start with -."
|
|
169
|
+
const dest = resolve(cwd, name)
|
|
170
|
+
if (existsSync(dest) && readdirSync(dest).length > 0)
|
|
171
|
+
return `${name} already exists and is not empty.`
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The theme rows' explanations; a theme missing here shows its name alone. */
|
|
175
|
+
export const THEME_LABELS: Record<string, string> = {
|
|
176
|
+
editorial: "Editorial — warm paper, ink text, green",
|
|
177
|
+
cinematic: "Cinematic — cool neutrals, violet accent",
|
|
178
|
+
finance: "Finance — editorial plus money colours",
|
|
179
|
+
}
|