create-lacspace-app 2.1.1 → 2.2.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 CHANGED
@@ -120,9 +120,44 @@ npx create-lacspace-app my-app --theme "#0bb9d9,#7c3aed" # an exact fr
120
120
 
121
121
  **Presets:** `lacspace` · `violet` · `indigo` · `blue` · `cyan` · `sky` · `teal` · `emerald` · `green` · `lime` · `amber` · `orange` · `red` · `rose` · `pink` · `fuchsia` · `purple` · `slate` · `sunset` · `ocean` · `forest` · `aurora` · `gold`. Give a single hex and the CLI derives a matching second stop for you.
122
122
 
123
+ ## 📦 Use it as a library
124
+
125
+ The same generator is exported as a programmatic API, so you can scaffold Lacspace projects from your own code — build tools, custom CLIs, CI jobs, tests, a playground, or a server-side **"download as ZIP"** button. It ships dual **ESM + CJS** with full TypeScript types.
126
+
127
+ ```ts
128
+ import {
129
+ generateProject, // pure: returns an in-memory file map — no disk I/O
130
+ scaffold, // Node: writes a project to disk
131
+ listTemplates, // the 9 templates + their metadata
132
+ listSections, // the 15 prebuilt sections
133
+ } from "create-lacspace-app";
134
+
135
+ // 1. Pure — get the whole project as { "path": "contents" }. Runs anywhere.
136
+ const files = generateProject({ name: "acme", template: "saas", theme: "#ff6a00" });
137
+ files["app/page.tsx"]; // → the generated home page source
138
+ Object.keys(files).length; // → ~70 files
139
+
140
+ // 2. Write it to disk (Node).
141
+ const { dir, files: written } = await scaffold({ name: "acme", template: "saas" });
142
+ console.log(`Scaffolded ${written.length} files → ${dir}`);
143
+ ```
144
+
145
+ `generateProject` is **pure** (no I/O), so it's perfect for previews, snapshot tests, zipping in a server route, or post-processing files before you write them. `scaffold` is the thin Node wrapper that writes the map to disk.
146
+
147
+ | Export | What it does |
148
+ | --- | --- |
149
+ | `generateProject(options)` | Returns the project as an in-memory `{ path: contents }` map. Pure, isomorphic. |
150
+ | `scaffold(options)` | Generates **and writes** the project to disk (`options.dir`, or `<cwd>/<name>`). Node only. |
151
+ | `listTemplates()` / `templates` | The built-in templates with metadata (`key`, `label`, `description`, `accent`, defaults). |
152
+ | `getTemplate(key)` | One template's metadata, or `undefined`. |
153
+ | `listSections()` / `getSection(name)` | The prebuilt section names, and one section's source. |
154
+ | `templateKeys` | Every valid `template` key. |
155
+
156
+ `options`: `{ name?, template?, theme? }` — the same choices as the CLI flags above.
157
+
123
158
  ## Licensing
124
159
 
125
- Free under the **[Lacspace Free Licence](https://lacspace.com/licenses/lacspace-free-1.0)** — permissive freedoms. Use it in personal and commercial projects at no cost; the apps you generate are entirely yours.
160
+ Free under the **[Lacspace Free Licence](https://developer.lacspace.com/licenses/lacspace-free-1.0)** — permissive freedoms. Use it in personal and commercial projects at no cost; the apps you generate are entirely yours.
126
161
 
127
162
  <!-- LACSPACE-DEV-PLATFORM -->
128
163
 
@@ -130,13 +165,13 @@ Free under the **[Lacspace Free Licence](https://lacspace.com/licenses/lacspace-
130
165
 
131
166
  ## The Lacspace Developer Platform
132
167
 
133
- `create-lacspace-app` is part of **63 zero-dependency, isomorphic TypeScript packages** — one standard library for the modern web. Explore the ecosystem:
168
+ `create-lacspace-app` is part of **80+ zero-dependency, isomorphic TypeScript packages** — one standard library for the modern web. Explore the ecosystem:
134
169
 
135
- - 🗂️ **All 63 packages** — https://developer.lacspace.com/packages
170
+ - 🗂️ **All 80+ packages** — https://developer.lacspace.com/packages
136
171
  - 🧭 **Developer handbook** — guides & runnable recipes — https://developer.lacspace.com/handbook
137
172
  - 🧪 **Live playground** — run any package in your browser — https://developer.lacspace.com/playground
138
173
  - 🖥️ **Finished app templates** — https://templates.lacspace.com
139
174
  - 🚀 **Scaffold a full app** — `npm create lacspace-app@latest`
140
175
 
141
- Free under the **[Lacspace Free Licence](https://lacspace.com/licenses/lacspace-free-1.0)** — a permissive, free-to-use licence.
176
+ Free under the **[Lacspace Free Licence](https://developer.lacspace.com/licenses/lacspace-free-1.0)** — a permissive, free-to-use licence.
142
177
 
package/dist/index.js CHANGED
@@ -2,8 +2,9 @@
2
2
  import { existsSync, readdirSync, mkdirSync, writeFileSync } from 'fs';
3
3
  import { resolve, basename, join, dirname } from 'path';
4
4
  import { createInterface } from 'readline/promises';
5
- import { stdout, exit, argv, stdin, cwd } from 'process';
5
+ import { argv, stdout, exit, stdin, cwd } from 'process';
6
6
  import { spawnSync } from 'child_process';
7
+ import { pathToFileURL } from 'url';
7
8
 
8
9
  var C = {
9
10
  reset: "\x1B[0m",
@@ -27,6 +28,15 @@ var TEMPLATES = [
27
28
  { key: "restaurant", label: "Restaurant / cafe", description: "A warm restaurant home with menu highlights and reservations.", accent: ["#e11d48", "#f59e0b"], siteName: "LSResto", siteDescription: "Seasonal plates, natural wine and a warm room. Book a table." },
28
29
  { key: "marketplace", label: "Marketplace / commerce", description: "A real storefront wired to the Lacspace commerce packages \u2014 cart, checkout, tax, shipping, orders, invoices and Nepal payments.", accent: ["#0d9488", "#6366f1"], siteName: "LSBazaar", siteDescription: "A modern storefront \u2014 cart to checkout, wired end to end." }
29
30
  ];
31
+ function resolveContext(options = {}) {
32
+ const base = TEMPLATES.find((t) => t.key === options.template) ?? TEMPLATES[0];
33
+ const accent = resolveAccent(options.theme);
34
+ const template = accent ? { ...base, accent } : base;
35
+ const raw = options.name ?? "my-app";
36
+ const seg = raw.split(/[\\/]/).filter(Boolean).pop() ?? "my-app";
37
+ const name = seg.toLowerCase().replace(/[^a-z0-9-_]/g, "-").replace(/^-+|-+$/g, "") || "my-app";
38
+ return { name, template };
39
+ }
30
40
  var pkgJson = (ctx) => JSON.stringify({
31
41
  name: ctx.name,
32
42
  version: "0.1.0",
@@ -5068,10 +5078,15 @@ ${c("bold", "Done! Next steps")}
5068
5078
 
5069
5079
  `);
5070
5080
  }
5071
- main().catch((err) => {
5072
- stdout.write(c("red", `
5081
+ var invokedAsCli = argv[1] ? import.meta.url === pathToFileURL(argv[1]).href : false;
5082
+ if (invokedAsCli) {
5083
+ main().catch((err) => {
5084
+ stdout.write(c("red", `
5073
5085
  \u2717 ${err instanceof Error ? err.message : String(err)}
5074
5086
 
5075
5087
  `));
5076
- exit(1);
5077
- });
5088
+ exit(1);
5089
+ });
5090
+ }
5091
+
5092
+ export { SECTIONS, TEMPLATES, buildFiles, resolveContext };