create-lacspace-app 2.8.0 → 2.10.0

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/dist/lib.js CHANGED
@@ -1998,6 +1998,11 @@ function applyFeatures(files, ctx) {
1998
1998
  files[rel] = content;
1999
1999
  }
2000
2000
  }
2001
+ if (ctx.mode === "static") {
2002
+ for (const feat of features) {
2003
+ for (const [rel, content] of Object.entries(feat.rootFiles?.(ctx) ?? {})) files[rel] = content;
2004
+ }
2005
+ }
2001
2006
  const addDeps = {};
2002
2007
  const addScripts = {};
2003
2008
  for (const feat of features) {
@@ -2276,6 +2281,68 @@ var FEATURES = [
2276
2281
  "Reuse the helpers in backend/src/mail/mailer.ts: sendWelcome / sendVerify / sendReset."
2277
2282
  ],
2278
2283
  learn: "https://developer.lacspace.com/packages/mailer"
2284
+ },
2285
+ {
2286
+ key: "i18n",
2287
+ label: "i18n (multi-language)",
2288
+ description: "Multi-language UI: a tiny runtime translator (t() + a language switcher) with English + Nepali locales, plus an i18n:check lint script.",
2289
+ deps: {},
2290
+ scripts: { "i18n:check": "npx lacspace-i18n@0.2.0 check locales" },
2291
+ files: () => ({
2292
+ "lib/i18n.ts": i18nLib(),
2293
+ "components/language-provider.tsx": i18nProvider(),
2294
+ "app/i18n-demo/page.tsx": i18nDemoPage(),
2295
+ "locales/en.json": i18nEn(),
2296
+ "locales/ne.json": i18nNe()
2297
+ }),
2298
+ nextSteps: [
2299
+ "Wrap app/layout.tsx's <body> with <LanguageProvider> (from @/components/language-provider).",
2300
+ 'Use it in a client component: const { t } = useT(); then {t("hello", { name })}.',
2301
+ "Add keys in locales/*.json, then lint them with `npm run i18n:check`."
2302
+ ],
2303
+ learn: "https://developer.lacspace.com/tools/i18n"
2304
+ },
2305
+ {
2306
+ key: "quality",
2307
+ label: "Quality & CI",
2308
+ description: "One-command quality gates from the Lacspace dev-tools \u2014 bundle-size budget, dependency audit and fake fixtures \u2014 plus a ready GitHub Actions CI workflow.",
2309
+ deps: {},
2310
+ scripts: {
2311
+ "size:check": "npx lacspace-size@0.2.0 .next/static --metric gzip --max 500kb",
2312
+ "deps:audit": "npx lacspace-deps@0.2.0 . --fail-on duplicates",
2313
+ "fixtures:gen": 'npx lacspace-fake@0.2.0 --fields "id:autoincrement,name:fullName,email:unique(email)" -n 50 --pretty -o fixtures/users.json'
2314
+ },
2315
+ files: () => ({}),
2316
+ rootFiles: (ctx) => ({ ".github/workflows/ci.yml": qualityCiWorkflow(ctx) }),
2317
+ nextSteps: [
2318
+ "Run `npm run size:check` (bundle-size budget) and `npm run deps:audit` (dependency audit) \u2014 both fail loudly in CI.",
2319
+ "Generate sample data: `npm run fixtures:gen` \u2192 fixtures/users.json.",
2320
+ "The GitHub Actions workflow (.github/workflows/ci.yml) runs the checks on every push."
2321
+ ],
2322
+ learn: "https://developer.lacspace.com/tools/size"
2323
+ },
2324
+ {
2325
+ key: "uploads",
2326
+ label: "File uploads",
2327
+ description: "Authenticated file uploads stored in MongoDB, served via signed, expiring URLs (@lacspace/signed-url). No S3 required. Full-stack.",
2328
+ requiresBackend: true,
2329
+ deps: {},
2330
+ files: () => ({ "app/uploads/page.tsx": uploadsPage() }),
2331
+ backend: () => ({
2332
+ deps: { "@lacspace/signed-url": "^1.1.0" },
2333
+ files: {
2334
+ "src/models/upload.ts": uploadModel(),
2335
+ "src/routes/uploads.ts": uploadsRoutes()
2336
+ },
2337
+ routes: [{ path: "/uploads", handler: "uploadRoutes", auth: false, importLine: 'import uploadRoutes from "./uploads.js";' }],
2338
+ env: { UPLOAD_URL_SECRET: "Secret for signing file download URLs (blank = reuse JWT_SECRET)." }
2339
+ }),
2340
+ nextSteps: [
2341
+ "Sign in, then open http://localhost:3000/uploads and upload an image or file.",
2342
+ "Files are stored in MongoDB and served via signed, expiring links \u2014 no S3 required.",
2343
+ "For large files or production, swap the Mongo storage for disk or object storage."
2344
+ ],
2345
+ learn: "https://developer.lacspace.com/packages/signed-url"
2279
2346
  }
2280
2347
  ];
2281
2348
  var aiChatRoute = (_ctx) => `import { resolveConfig } from "@lacspace/providers";
@@ -6260,6 +6327,291 @@ export default function EmailTestPage() {
6260
6327
  );
6261
6328
  }
6262
6329
  `;
6330
+ var i18nLib = () => `import en from "@/locales/en.json";
6331
+ import ne from "@/locales/ne.json";
6332
+
6333
+ // how this works: a tiny, dependency-free translator. Locale files live in locales/,
6334
+ // keys are flat strings, and {vars} are interpolated. A missing key falls back to
6335
+ // English, then to the key itself. Lint the files with \`npm run i18n:check\`.
6336
+ export const locales = ["en", "ne"] as const;
6337
+ export type Locale = (typeof locales)[number];
6338
+ export const defaultLocale: Locale = "en";
6339
+
6340
+ const dicts: Record<Locale, Record<string, string>> = {
6341
+ en: en as Record<string, string>,
6342
+ ne: ne as Record<string, string>,
6343
+ };
6344
+
6345
+ export function translate(locale: Locale, key: string, vars?: Record<string, string | number>): string {
6346
+ const table = dicts[locale] ?? dicts[defaultLocale];
6347
+ let str = table[key] ?? dicts[defaultLocale][key] ?? key;
6348
+ if (vars) for (const [k, v] of Object.entries(vars)) str = str.split("{" + k + "}").join(String(v));
6349
+ return str;
6350
+ }
6351
+ `;
6352
+ var i18nProvider = () => `"use client";
6353
+ import { createContext, useContext, useEffect, useState } from "react";
6354
+ import { locales, defaultLocale, translate, type Locale } from "@/lib/i18n";
6355
+
6356
+ // how this works: holds the current locale (persisted in localStorage) and exposes
6357
+ // t() via the useT() hook. Wrap your app in <LanguageProvider> once (in layout.tsx).
6358
+ interface LocaleCtxValue { locale: Locale; setLocale: (l: Locale) => void; }
6359
+ const LocaleCtx = createContext<LocaleCtxValue>({ locale: defaultLocale, setLocale: () => {} });
6360
+
6361
+ export function LanguageProvider({ children }: { children: React.ReactNode }) {
6362
+ const [locale, setLocaleState] = useState<Locale>(defaultLocale);
6363
+ useEffect(() => {
6364
+ try {
6365
+ const saved = localStorage.getItem("locale");
6366
+ if (saved && (locales as readonly string[]).includes(saved)) setLocaleState(saved as Locale);
6367
+ } catch {}
6368
+ }, []);
6369
+ const setLocale = (l: Locale) => { setLocaleState(l); try { localStorage.setItem("locale", l); } catch {} };
6370
+ return <LocaleCtx.Provider value={{ locale, setLocale }}>{children}</LocaleCtx.Provider>;
6371
+ }
6372
+
6373
+ export function useT() {
6374
+ const { locale, setLocale } = useContext(LocaleCtx);
6375
+ return {
6376
+ t: (key: string, vars?: Record<string, string | number>) => translate(locale, key, vars),
6377
+ locale,
6378
+ setLocale,
6379
+ };
6380
+ }
6381
+
6382
+ export function LanguageSwitcher() {
6383
+ const { locale, setLocale } = useT();
6384
+ return (
6385
+ <div className="inline-flex gap-1 rounded-full border border-hairline p-1">
6386
+ {locales.map((l) => (
6387
+ <button
6388
+ key={l}
6389
+ onClick={() => setLocale(l)}
6390
+ className={"rounded-full px-3 py-1 text-sm transition " + (l === locale ? "gradient-bg on-accent" : "text-muted hover:text-fg")}
6391
+ >
6392
+ {l.toUpperCase()}
6393
+ </button>
6394
+ ))}
6395
+ </div>
6396
+ );
6397
+ }
6398
+ `;
6399
+ var i18nDemoPage = () => `"use client";
6400
+ import { LanguageProvider, LanguageSwitcher, useT } from "@/components/language-provider";
6401
+
6402
+ function Demo() {
6403
+ const { t } = useT();
6404
+ return (
6405
+ <div className="space-y-4">
6406
+ <h1 className="text-3xl font-bold">{t("hello", { name: "world" })}</h1>
6407
+ <p className="text-muted">{t("tagline")}</p>
6408
+ <LanguageSwitcher />
6409
+ </div>
6410
+ );
6411
+ }
6412
+
6413
+ export default function I18nDemoPage() {
6414
+ return (
6415
+ <main className="mx-auto max-w-md px-6 py-16">
6416
+ <LanguageProvider>
6417
+ <Demo />
6418
+ </LanguageProvider>
6419
+ </main>
6420
+ );
6421
+ }
6422
+ `;
6423
+ var i18nEn = () => JSON.stringify(
6424
+ { hello: "Hello, {name}!", tagline: "This text switches language instantly \u2014 no reload.", "nav.home": "Home", "nav.about": "About" },
6425
+ null,
6426
+ 2
6427
+ ) + "\n";
6428
+ var i18nNe = () => JSON.stringify(
6429
+ { hello: "\u0928\u092E\u0938\u094D\u0924\u0947, {name}!", tagline: "\u092F\u094B \u092A\u093E\u0920 \u0924\u0941\u0930\u0941\u0928\u094D\u0924\u0948 \u092D\u093E\u0937\u093E \u092B\u0947\u0930\u094D\u091B \u2014 \u0930\u093F\u0932\u094B\u0921 \u092C\u093F\u0928\u093E\u0964", "nav.home": "\u0917\u0943\u0939", "nav.about": "\u092C\u093E\u0930\u0947\u092E\u093E" },
6430
+ null,
6431
+ 2
6432
+ ) + "\n";
6433
+ var qualityCiWorkflow = (ctx) => {
6434
+ const sizePath = ctx.mode === "dynamic" ? "frontend/.next/static" : ".next/static";
6435
+ const depsGate = ctx.mode === "dynamic" ? "duplicates" : "missing,duplicates";
6436
+ return `name: CI
6437
+ on:
6438
+ push:
6439
+ branches: [main]
6440
+ pull_request:
6441
+ jobs:
6442
+ quality:
6443
+ runs-on: ubuntu-latest
6444
+ steps:
6445
+ - uses: actions/checkout@v4
6446
+ - uses: actions/setup-node@v4
6447
+ with:
6448
+ node-version: 20
6449
+ cache: npm
6450
+ - run: npm ci
6451
+ - run: npm run build
6452
+ - name: Bundle-size budget
6453
+ run: npx lacspace-size@0.2.0 ${sizePath} --metric gzip --max 500kb
6454
+ - name: Dependency audit
6455
+ run: npx lacspace-deps@0.2.0 . --fail-on ${depsGate}
6456
+ `;
6457
+ };
6458
+ var uploadModel = () => `import mongoose from "mongoose";
6459
+ import { uuidv7 } from "@lacspace/id";
6460
+
6461
+ // how this works: files are stored base64-in-Mongo so it works with NO S3/disk setup.
6462
+ // For large files or production, swap this for disk or object storage.
6463
+ export interface UploadDoc {
6464
+ _id: string;
6465
+ userId: string;
6466
+ filename: string;
6467
+ contentType: string;
6468
+ size: number;
6469
+ data: string; // base64
6470
+ createdAt: Date;
6471
+ }
6472
+
6473
+ const schema = new mongoose.Schema<UploadDoc>(
6474
+ {
6475
+ _id: { type: String, default: () => uuidv7() },
6476
+ userId: { type: String, required: true, index: true },
6477
+ filename: { type: String, required: true },
6478
+ contentType: { type: String, default: "application/octet-stream" },
6479
+ size: { type: Number, default: 0 },
6480
+ data: { type: String, required: true },
6481
+ },
6482
+ { timestamps: { createdAt: true, updatedAt: false } },
6483
+ );
6484
+
6485
+ export const Upload =
6486
+ (mongoose.models.Upload as mongoose.Model<UploadDoc>) ?? mongoose.model<UploadDoc>("Upload", schema);
6487
+ `;
6488
+ var uploadsRoutes = () => `import express from "express";
6489
+ import { signUrl, verifyUrl } from "@lacspace/signed-url";
6490
+ import { v } from "@lacspace/validate";
6491
+ import { asyncHandler, HttpError } from "../http.js";
6492
+ import { requireAuth } from "../middleware/auth.js";
6493
+ import { env } from "../env.js";
6494
+ import { Upload } from "../models/upload.js";
6495
+
6496
+ // how this works: uploads live in Mongo; each file is served from a PUBLIC route
6497
+ // protected by a signed, expiring URL (@lacspace/signed-url) \u2014 so <img src> works
6498
+ // without a bearer token, yet the link can't be forged or shared forever.
6499
+ const router = express.Router();
6500
+ const SECRET = process.env.UPLOAD_URL_SECRET ?? env.JWT_SECRET;
6501
+ const MAX_BYTES = 5 * 1024 * 1024; // 5 MB \u2014 base64-in-Mongo, keep it small
6502
+
6503
+ const UploadInput = v.object({ filename: v.string().min(1).max(200), dataUrl: v.string().min(1) });
6504
+
6505
+ // Sign a RELATIVE URL; the frontend prefixes it with the API base. Verified as-is.
6506
+ function signed(id: string): Promise<string> {
6507
+ return signUrl("/uploads/" + id + "/raw", { secret: SECRET, expiresIn: 3600 });
6508
+ }
6509
+
6510
+ // GET /uploads/:id/raw \u2014 PUBLIC, but the signed query params must verify.
6511
+ router.get("/:id/raw", asyncHandler(async (req, res) => {
6512
+ const check = await verifyUrl(req.originalUrl, { secret: SECRET, clockToleranceSec: 60 });
6513
+ if (!check.valid) throw new HttpError(check.reason === "expired" ? 410 : 403, "Link expired or invalid");
6514
+ const file = await Upload.findById(req.params.id);
6515
+ if (!file) throw new HttpError(404, "Not found");
6516
+ res.setHeader("Content-Type", file.contentType);
6517
+ res.send(Buffer.from(file.data, "base64"));
6518
+ }));
6519
+
6520
+ // POST /uploads \u2014 protected: store a base64 data URL.
6521
+ router.post("/", requireAuth, asyncHandler(async (req, res) => {
6522
+ const { filename, dataUrl } = UploadInput.parse(req.body);
6523
+ const m = /^data:(.+?);base64,(.*)$/.exec(dataUrl);
6524
+ if (!m) throw new HttpError(400, "Expected a base64 data URL");
6525
+ const contentType = m[1]!;
6526
+ const data = m[2]!;
6527
+ const size = Math.floor((data.length * 3) / 4);
6528
+ if (size > MAX_BYTES) throw new HttpError(413, "File too large (max 5 MB)");
6529
+ const file = await Upload.create({ userId: req.user!.sub, filename, contentType, size, data });
6530
+ res.status(201).json({ id: String(file._id), filename, contentType, size, url: await signed(String(file._id)) });
6531
+ }));
6532
+
6533
+ // GET /uploads \u2014 protected: this user's files (with fresh signed URLs).
6534
+ router.get("/", requireAuth, asyncHandler(async (req, res) => {
6535
+ const files = await Upload.find({ userId: req.user!.sub }).sort({ createdAt: -1 }).select("filename contentType size");
6536
+ const out = await Promise.all(
6537
+ files.map(async (f) => ({ id: String(f._id), filename: f.filename, contentType: f.contentType, size: f.size, url: await signed(String(f._id)) })),
6538
+ );
6539
+ res.json(out);
6540
+ }));
6541
+
6542
+ export default router;
6543
+ `;
6544
+ var uploadsPage = () => `"use client";
6545
+ import { useEffect, useState } from "react";
6546
+ import { useRouter } from "next/navigation";
6547
+ import { getToken } from "@/lib/api";
6548
+
6549
+ const API = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:4000";
6550
+ interface FileItem { id: string; filename: string; contentType: string; size: number; url: string; }
6551
+
6552
+ function readAsDataUrl(file: File): Promise<string> {
6553
+ return new Promise((resolve, reject) => {
6554
+ const r = new FileReader();
6555
+ r.onload = () => resolve(String(r.result));
6556
+ r.onerror = () => reject(new Error("read failed"));
6557
+ r.readAsDataURL(file);
6558
+ });
6559
+ }
6560
+
6561
+ export default function UploadsPage() {
6562
+ const router = useRouter();
6563
+ const [files, setFiles] = useState<FileItem[]>([]);
6564
+ const [busy, setBusy] = useState(false);
6565
+ const [error, setError] = useState<string | null>(null);
6566
+
6567
+ async function load() {
6568
+ const token = getToken();
6569
+ if (!token) { router.push("/login"); return; }
6570
+ const res = await fetch(API + "/uploads", { headers: { Authorization: "Bearer " + token } });
6571
+ if (res.ok) setFiles(await res.json());
6572
+ }
6573
+ useEffect(() => { void load(); }, []);
6574
+
6575
+ async function onPick(e: React.ChangeEvent<HTMLInputElement>) {
6576
+ const file = e.target.files?.[0];
6577
+ if (!file) return;
6578
+ setBusy(true); setError(null);
6579
+ try {
6580
+ const dataUrl = await readAsDataUrl(file);
6581
+ const token = getToken();
6582
+ const res = await fetch(API + "/uploads", {
6583
+ method: "POST",
6584
+ headers: { "Content-Type": "application/json", ...(token ? { Authorization: "Bearer " + token } : {}) },
6585
+ body: JSON.stringify({ filename: file.name, dataUrl }),
6586
+ });
6587
+ const data: unknown = await res.json().catch(() => ({}));
6588
+ if (!res.ok) throw new Error((data as { error?: string }).error ?? "Upload failed");
6589
+ await load();
6590
+ } catch (err) { setError(err instanceof Error ? err.message : "Upload failed"); }
6591
+ finally { setBusy(false); }
6592
+ }
6593
+
6594
+ return (
6595
+ <main className="mx-auto max-w-lg px-6 py-16">
6596
+ <h1 className="text-2xl font-bold">Uploads</h1>
6597
+ <p className="mt-1 text-muted">Stored in MongoDB, served via signed, expiring links.</p>
6598
+ <label className="mt-6 flex cursor-pointer items-center justify-center rounded-2xl border border-dashed border-hairline p-8 text-muted transition hover:bg-surface">
6599
+ <input type="file" className="hidden" onChange={onPick} disabled={busy} />
6600
+ {busy ? "Uploading\u2026" : "Choose a file (max 5 MB)"}
6601
+ </label>
6602
+ {error && <p className="mt-3 text-sm text-red-400">{error}</p>}
6603
+ <ul className="mt-6 space-y-2">
6604
+ {files.map((f) => (
6605
+ <li key={f.id} className="flex items-center justify-between rounded-xl border border-hairline p-3">
6606
+ <a href={API + f.url} target="_blank" rel="noreferrer" className="truncate underline">{f.filename}</a>
6607
+ <span className="ml-3 shrink-0 text-sm text-muted">{Math.max(1, Math.round(f.size / 1024))} KB</span>
6608
+ </li>
6609
+ ))}
6610
+ </ul>
6611
+ </main>
6612
+ );
6613
+ }
6614
+ `;
6263
6615
  var scope = (ctx) => `@${ctx.name}`;
6264
6616
  var typesPkgJson = (ctx) => JSON.stringify({
6265
6617
  name: `${scope(ctx)}/types`,
@@ -6659,6 +7011,9 @@ function buildFullStack(ctx) {
6659
7011
  out[".gitignore"] = rootGitignore();
6660
7012
  out[".env.example"] = rootEnvExample(ctx);
6661
7013
  out["README.md"] = rootReadme(ctx);
7014
+ for (const f of ctx.features) {
7015
+ for (const [rel, content] of Object.entries(f.rootFiles?.(ctx) ?? {})) out[rel] = content;
7016
+ }
6662
7017
  const envBase = out[".env.example"];
6663
7018
  const seen = new Set(
6664
7019
  (envBase.match(/^#?\s*([A-Z0-9_]+)=/gm) ?? []).map((l) => l.replace(/^#?\s*/, "").replace(/=.*/, ""))
@@ -7218,7 +7573,7 @@ function backendFiles(ctx) {
7218
7573
  }
7219
7574
  var splitList = (s) => s.split(",").map((x) => x.trim()).filter(Boolean);
7220
7575
  function parseArgs(list) {
7221
- const a = { features: [], yes: false, install: true, git: true, pm: "npm", help: false };
7576
+ const a = { features: [], yes: false, install: true, git: true, pm: "npm", help: false, dryRun: false };
7222
7577
  for (let i = 0; i < list.length; i++) {
7223
7578
  const arg = list[i];
7224
7579
  const next = () => list[++i] ?? "";
@@ -7226,8 +7581,9 @@ function parseArgs(list) {
7226
7581
  else if (arg === "-y" || arg === "--yes") a.yes = true;
7227
7582
  else if (arg === "--no-install") a.install = false;
7228
7583
  else if (arg === "--no-git") a.git = false;
7584
+ else if (arg === "--dry-run" || arg === "--dry") a.dryRun = true;
7229
7585
  else if (arg === "--pm") a.pm = next();
7230
- else if (arg === "--theme" || arg === "--accent") a.theme = next();
7586
+ else if (arg === "--theme" || arg === "--accent" || arg === "--brand") a.theme = next();
7231
7587
  else if (arg === "--with" || arg === "--features") a.features.push(...splitList(next()));
7232
7588
  else if (arg === "--fullstack" || arg === "--full-stack" || arg === "--dynamic") a.mode = "dynamic";
7233
7589
  else if (arg === "--static") a.mode = "static";
@@ -7243,6 +7599,7 @@ function parseArgs(list) {
7243
7599
  else if (arg.startsWith("--template=")) a.template = arg.slice(11);
7244
7600
  else if (arg.startsWith("--theme=")) a.theme = arg.slice(8);
7245
7601
  else if (arg.startsWith("--accent=")) a.theme = arg.slice(9);
7602
+ else if (arg.startsWith("--brand=")) a.theme = arg.slice(8);
7246
7603
  else if (arg.startsWith("--with=")) a.features.push(...splitList(arg.slice(7)));
7247
7604
  else if (arg.startsWith("--features=")) a.features.push(...splitList(arg.slice(11)));
7248
7605
  else if (!arg.startsWith("-") && !a.name) a.name = arg;
@@ -7333,6 +7690,8 @@ ${c("bold", "Usage")}
7333
7690
  npm create lacspace-app@latest <name> [options]
7334
7691
  npx create-lacspace-app <name> --template <key>
7335
7692
  npx create-lacspace-app add <section...> ${c("dim", "# grow an existing app")}
7693
+ npx create-lacspace-app list ${c("dim", "# templates, add-ons & recipes")}
7694
+ npx create-lacspace-app explain <name> ${c("dim", "# what an add-on/recipe gives you")}
7336
7695
 
7337
7696
  ${c("bold", "Templates")}
7338
7697
  ${TEMPLATES.map((t) => ` ${t.key.padEnd(10)} ${t.description}`).join("\n")}
@@ -7344,8 +7703,9 @@ ${c("bold", "Options")}
7344
7703
  ${c("dim", "(alias --dynamic; default is --static, a single Next.js app)")}
7345
7704
  --with <a,b> Feature add-ons, comma-separated (alias --features)
7346
7705
  --recipe <key> Start from a curated stack (${RECIPES.map((r) => r.key).join(" | ")})
7347
- --theme <name|hex> Accent: a preset, a "#hex", or "from,to" (e.g. --theme lacspace)
7706
+ --theme <name|hex> Accent: a preset, a "#hex", or "from,to" (alias --brand)
7348
7707
  --pm <npm|pnpm|yarn|bun> Package manager (default npm)
7708
+ --dry-run Print the files that would be created; write nothing
7349
7709
  --no-install Skip installing dependencies
7350
7710
  --no-git Skip git init
7351
7711
  -y, --yes Accept defaults (needs <name>)
@@ -7721,12 +8081,103 @@ ${c("bold", "Use them")} \u2014 import into any page:
7721
8081
  return;
7722
8082
  }
7723
8083
  }
8084
+ function runList() {
8085
+ stdout.write(`
8086
+ ${c("bold", c("magenta", "\u25C6 create-lacspace-app"))} ${c("dim", "\u2014 what you can build")}
8087
+ `);
8088
+ stdout.write(`
8089
+ ${c("bold", "Templates")} ${c("dim", "(-t / --template)")}
8090
+ `);
8091
+ for (const t of TEMPLATES) stdout.write(` ${c("cyan", t.key.padEnd(12))} ${c("dim", t.description)}
8092
+ `);
8093
+ stdout.write(`
8094
+ ${c("bold", "Add-ons")} ${c("dim", "(--with) \u2014 free & keyless")}
8095
+ `);
8096
+ for (const f of FEATURES) stdout.write(` ${c("cyan", f.key.padEnd(12))} ${c("dim", f.description)}${f.requiresBackend ? c("green", " [full-stack]") : ""}
8097
+ `);
8098
+ stdout.write(`
8099
+ ${c("bold", "Recipes")} ${c("dim", "(--recipe) \u2014 a whole product in one command")}
8100
+ `);
8101
+ for (const r of RECIPES) stdout.write(` ${c("cyan", r.key.padEnd(14))} ${c("dim", r.description)}
8102
+ `);
8103
+ stdout.write(`
8104
+ ${c("dim", "Learn one:")} ${c("cyan", "npx create-lacspace-app explain <name>")}
8105
+
8106
+ `);
8107
+ }
8108
+ function runExplain(rawNames) {
8109
+ const name = rawNames.find((n) => !n.startsWith("-"))?.toLowerCase();
8110
+ if (!name) {
8111
+ stdout.write(`Usage: ${c("cyan", "npx create-lacspace-app explain <template|add-on|recipe>")}
8112
+
8113
+ `);
8114
+ runList();
8115
+ return;
8116
+ }
8117
+ const feat = FEATURES.find((f) => f.key === name);
8118
+ const recipe = RECIPES.find((r) => r.key === name);
8119
+ const tmpl = TEMPLATES.find((t) => t.key === name);
8120
+ stdout.write("\n");
8121
+ if (feat) {
8122
+ stdout.write(`${c("bold", c("magenta", "add-on: " + feat.key))} ${feat.requiresBackend ? c("green", "[full-stack]") : c("dim", "[frontend]")}
8123
+
8124
+ ${feat.description}
8125
+ `);
8126
+ const deps = { ...feat.deps, ...feat.backend?.({ name: "app", template: TEMPLATES[0], features: [], mode: "dynamic" })?.deps ?? {} };
8127
+ if (Object.keys(deps).length) stdout.write(`
8128
+ ${c("bold", "Packages")}: ${Object.keys(deps).map((d) => c("cyan", d)).join(", ")}
8129
+ `);
8130
+ stdout.write(`
8131
+ ${c("bold", "Next steps")}:
8132
+ `);
8133
+ for (const s of feat.nextSteps) stdout.write(` ${c("dim", "\u2022")} ${s}
8134
+ `);
8135
+ if (feat.learn) stdout.write(`
8136
+ Learn more \u2192 ${c("cyan", feat.learn)}
8137
+ `);
8138
+ stdout.write(`
8139
+ Add it: ${c("cyan", "npx create-lacspace-app my-app --with " + feat.key)}
8140
+
8141
+ `);
8142
+ } else if (recipe) {
8143
+ stdout.write(`${c("bold", c("magenta", "recipe: " + recipe.key))}
8144
+
8145
+ ${recipe.description}
8146
+
8147
+ ${c("bold", "Template")}: ${c("cyan", recipe.template)}${recipe.mode ? c("dim", " \xB7 " + recipe.mode) : ""}
8148
+ ${c("bold", "Add-ons")}: ${recipe.features.map((f) => c("cyan", f)).join(", ")}
8149
+
8150
+ Use it: ${c("cyan", "npx create-lacspace-app my-app --recipe " + recipe.key)}
8151
+
8152
+ `);
8153
+ } else if (tmpl) {
8154
+ stdout.write(`${c("bold", c("magenta", "template: " + tmpl.key))}
8155
+
8156
+ ${tmpl.description}
8157
+
8158
+ Use it: ${c("cyan", "npx create-lacspace-app my-app --template " + tmpl.key)}
8159
+
8160
+ `);
8161
+ } else {
8162
+ stdout.write(c("yellow", `Unknown "${name}".
8163
+ `));
8164
+ runList();
8165
+ }
8166
+ }
7724
8167
  async function main() {
7725
8168
  const raw = argv.slice(2);
7726
8169
  if (raw[0] === "add") {
7727
8170
  runAdd(raw.slice(1));
7728
8171
  return;
7729
8172
  }
8173
+ if (raw[0] === "list" || raw[0] === "ls") {
8174
+ runList();
8175
+ return;
8176
+ }
8177
+ if (raw[0] === "explain" || raw[0] === "info") {
8178
+ runExplain(raw.slice(1));
8179
+ return;
8180
+ }
7730
8181
  const args = parseArgs(raw);
7731
8182
  if (args.help) {
7732
8183
  stdout.write(HELP + "\n");
@@ -7745,10 +8196,32 @@ ${c("bold", c("magenta", "\u25C6 create-lacspace-app"))} ${c("dim", "\u2014 a go
7745
8196
  let templateKey = args.template ?? recipe?.template;
7746
8197
  let mode = args.mode ?? recipe?.mode ?? "static";
7747
8198
  const featureKeys = [...recipe?.features ?? [], ...args.features];
8199
+ let usedRecipe = Boolean(recipe);
7748
8200
  if (!args.yes && stdin.isTTY) {
7749
8201
  const rl = createInterface({ input: stdin, output: stdout });
7750
8202
  try {
7751
8203
  if (!name) name = (await rl.question(`${c("green", "?")} Project name ${c("dim", "(my-app)")}: `)).trim() || "my-app";
8204
+ if (!usedRecipe && !templateKey && featureKeys.length === 0) {
8205
+ stdout.write(`
8206
+ Start from a recipe? ${c("dim", "(a template + add-ons, ready to go)")}
8207
+ `);
8208
+ RECIPES.forEach((r, i) => stdout.write(` ${c("cyan", String(i + 1))}. ${c("bold", r.label)} ${c("dim", "\u2014 " + r.description)}
8209
+ `));
8210
+ stdout.write(` ${c("cyan", "0")}. ${c("dim", "No recipe \u2014 I'll choose a template myself")}
8211
+ `);
8212
+ const ans = (await rl.question(`
8213
+ ${c("green", "?")} Recipe ${c("dim", "(0)")}: `)).trim() || "0";
8214
+ const idx = /^\d+$/.test(ans) ? parseInt(ans, 10) - 1 : RECIPES.findIndex((r) => r.key === ans);
8215
+ const chosen = ans === "0" ? void 0 : RECIPES[idx];
8216
+ if (chosen) {
8217
+ usedRecipe = true;
8218
+ templateKey = chosen.template;
8219
+ mode = chosen.mode ?? mode;
8220
+ for (const k of chosen.features) if (!featureKeys.includes(k)) featureKeys.push(k);
8221
+ stdout.write(` ${c("green", "\u2714")} Recipe ${c("cyan", chosen.key)}
8222
+ `);
8223
+ }
8224
+ }
7752
8225
  if (!templateKey) {
7753
8226
  stdout.write(`
7754
8227
  Choose a template:
@@ -7760,7 +8233,7 @@ ${c("green", "?")} Template ${c("dim", "(1)")}: `)).trim() || "1";
7760
8233
  const idx = /^\d+$/.test(ans) ? parseInt(ans, 10) - 1 : TEMPLATES.findIndex((t) => t.key === ans);
7761
8234
  templateKey = TEMPLATES[idx]?.key ?? "personal";
7762
8235
  }
7763
- if (args.mode === void 0 && !recipe) {
8236
+ if (args.mode === void 0 && !usedRecipe) {
7764
8237
  stdout.write(`
7765
8238
  What kind of app?
7766
8239
  `);
@@ -7819,6 +8292,19 @@ ${c("green", "?")} Add features? ${c("dim", "(comma-separated numbers, or Enter
7819
8292
  `);
7820
8293
  }
7821
8294
  const files = buildFiles({ name: projectName, template, features, mode });
8295
+ if (args.dryRun) {
8296
+ const keys = Object.keys(files).sort();
8297
+ stdout.write(`
8298
+ ${c("bold", "Dry run")} ${c("dim", `\u2014 ${keys.length} files (${mode}${features.length ? ", +" + features.map((f) => f.key).join(",") : ""}), nothing written`)}
8299
+ `);
8300
+ for (const rel of keys) stdout.write(` ${c("dim", "+ " + rel)}
8301
+ `);
8302
+ stdout.write(`
8303
+ ${c("dim", "Remove --dry-run to create the project.")}
8304
+
8305
+ `);
8306
+ return;
8307
+ }
7822
8308
  for (const [rel, content] of Object.entries(files)) {
7823
8309
  const full = join(dir, rel);
7824
8310
  mkdirSync(dirname(full), { recursive: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-lacspace-app",
3
- "version": "2.8.0",
3
+ "version": "2.10.0",
4
4
  "description": "Scaffold a beautiful, production-ready Next.js app from a Lacspace template — portfolio, business, e-commerce, SaaS, blog, docs, dashboard, restaurant or marketplace — pre-wired with SEO, security headers, sitemap and robots. Use it as a CLI (like create-next-app, but you start gorgeous) or import it as a library to generate projects programmatically.",
5
5
  "type": "module",
6
6
  "bin": {