zakieh 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Houzayfa Zakieh (حذيفة زكيه)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ # Zakieh
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Scaffold a Next.js or React project with the folder architecture you choose — by answering a few questions.**
4
+
5
+ [العربية](README.ar.md) · [Architectures](docs/ARCHITECTURES.md) · [Roadmap](ROADMAP.md) · [Contributing](CONTRIBUTING.md)
6
+
7
+ > **Status: v0.1.** The core is implemented and tested. Zakieh is now on npm. Follow the [roadmap](ROADMAP.md) for what comes next.
8
+
9
+ ## Why Zakieh exists
10
+
11
+ Every time I started a new project, I spent the first stretch of time on the same small things: creating folders, deciding where files should go, adding pages, wiring routes, and adjusting the setup until it felt right. None of it is hard, but all of it takes time, and I kept repeating it.
12
+
13
+ Zakieh is my answer to that. Instead of rebuilding the same structure by hand, you answer a few questions and get a project laid out the way you want, ready to work in.
14
+
15
+ ## What it does
16
+
17
+ When you create a project, Zakieh asks you for:
18
+
19
+ - the framework: Next.js (App Router) or React (Vite)
20
+ - the language: TypeScript or JavaScript
21
+ - the architecture: **TBA** (type-based), **FBA** (feature-based) or **Hybrid** (a mix of both)
22
+ - how many pages the site has, and their names
23
+ - which pages are dynamic (a detail route such as `/products/[id]`) and which have their own layout
24
+
25
+ It then shows you the folder tree for confirmation, generates the project, and optionally initializes git and installs the dependencies. The base project comes from the official tools (`create-next-app` and `create-vite`), so it stays up to date with the frameworks.
26
+
27
+ Later, you can keep growing the project with the same structure:
28
+
29
+ ```bash
30
+ zakieh add page about
31
+ zakieh add feature cart
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ Run it with npm:
37
+
38
+ ```bash
39
+ npm create zakieh@latest
40
+ ```
41
+
42
+ A non-interactive form for scripts and CI:
43
+
44
+ ```bash
45
+ npm create zakieh@latest my-app -- --framework next --arch hybrid --pages home,about,contact --yes
46
+ ```
47
+
48
+ Useful flags for `create`: `--framework next|react`, `--lang ts|js`, `--arch tba|fba|hybrid`, `--pages a,b,c`, `--dynamic a,b`, `--layout a,b`, `--pm npm|pnpm|yarn|bun`, `--no-install`, `--no-git`, `--no-credit` (leaves the credit line out of the generated README), `--dry-run` and `-y`.
49
+
50
+ ## Try it from source
51
+
52
+ Requirements: Node.js 20+ and pnpm.
53
+
54
+ ```bash
55
+ git clone https://github.com/Houzayfa-Zakieh/zakieh.git
56
+ cd zakieh
57
+ pnpm install
58
+ pnpm build
59
+ node packages/zakieh/dist/bin.js create
60
+ ```
61
+
62
+ ## Architectures
63
+
64
+ | | TBA | FBA | Hybrid |
65
+ | --- | --- | --- | --- |
66
+ | Organized by | File type | Feature / page | Features + shared layer |
67
+ | Good fit for | Small projects | Medium and large projects | Most projects |
68
+
69
+ See [docs/ARCHITECTURES.md](docs/ARCHITECTURES.md) for the full folder trees of each one, for both React and Next.js.
70
+
71
+ ## Contributing
72
+
73
+ Ideas, bug reports and pull requests are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) first.
74
+
75
+ ## License
76
+
77
+ [MIT](LICENSE) © 2026 Houzayfa Zakieh (حذيفة زكيه)
78
+
79
+ ## Author
80
+
81
+ Built by **Houzayfa Zakieh (حذيفة زكيه)**, frontend developer — [zakieh.dev](https://zakieh.dev)
package/dist/bin.js ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ main
4
+ } from "./chunk-3HVND4FT.js";
5
+
6
+ // src/bin.ts
7
+ void main();
@@ -0,0 +1,1114 @@
1
+ // src/router.ts
2
+ var IMPORTS_MARKER = "zakieh:imports";
3
+ var ROUTES_MARKER = "zakieh:routes";
4
+ function routerTemplate() {
5
+ return [
6
+ `import { Route, Routes } from 'react-router-dom'`,
7
+ `// ${IMPORTS_MARKER}`,
8
+ ``,
9
+ `export function AppRouter() {`,
10
+ ` return (`,
11
+ ` <Routes>`,
12
+ ` {/* ${ROUTES_MARKER} */}`,
13
+ ` </Routes>`,
14
+ ` )`,
15
+ `}`,
16
+ ``
17
+ ].join("\n");
18
+ }
19
+ function registerRoute(source, imports, routeLines) {
20
+ const lines = source.split("\n");
21
+ const importsAt = lines.findIndex((l) => l.includes(IMPORTS_MARKER));
22
+ const routesAt = lines.findIndex((l) => l.includes(ROUTES_MARKER));
23
+ if (importsAt === -1 || routesAt === -1) {
24
+ throw new Error(
25
+ `Could not find the "${IMPORTS_MARKER}" and "${ROUTES_MARKER}" markers in the router file. Add the route manually, or restore the markers.`
26
+ );
27
+ }
28
+ const present = new Set(lines.map((l) => l.trim()));
29
+ const newImports = imports.filter((i) => !present.has(i.trim()));
30
+ const indent2 = /^\s*/.exec(lines[routesAt] ?? "")?.[0] ?? "";
31
+ lines.splice(routesAt, 0, ...routeLines.map((l) => indent2 + l));
32
+ lines.splice(importsAt, 0, ...newImports);
33
+ return lines.join("\n");
34
+ }
35
+
36
+ // src/constants.ts
37
+ var AUTHOR_NAME = "Houzayfa Zakieh";
38
+ var AUTHOR_NAME_AR = "\u062D\u0630\u064A\u0641\u0629 \u0632\u0643\u064A\u0647";
39
+ var WEBSITE = "https://zakieh.dev";
40
+ var CONFIG_FILE = "zakieh.config.json";
41
+ var MAX_PAGES = 30;
42
+ var RESERVED_NAMES = ["api", "app", "index", "node-modules", "public", "src", "static"];
43
+ var REACT_ROUTER_VERSION = "^7.0.0";
44
+ var ADD_SELF_AS_DEV_DEPENDENCY = false;
45
+ var ARCHITECTURE_LABELS = {
46
+ tba: "TBA \u2014 Type-Based: files grouped by what they are",
47
+ fba: "FBA \u2014 Feature-Based: files grouped by the feature they belong to",
48
+ hybrid: "Hybrid \u2014 features + a shared layer (recommended)"
49
+ };
50
+
51
+ // src/names.ts
52
+ var cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
53
+ function toKebab(input) {
54
+ return input.trim().replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").replace(/[^a-zA-Z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "").toLowerCase();
55
+ }
56
+ function toPascal(kebab) {
57
+ return kebab.split("-").filter(Boolean).map(cap).join("");
58
+ }
59
+ function toCamel(kebab) {
60
+ const p3 = toPascal(kebab);
61
+ return p3.charAt(0).toLowerCase() + p3.slice(1);
62
+ }
63
+ function toTitle(kebab) {
64
+ return kebab.split("-").filter(Boolean).map(cap).join(" ");
65
+ }
66
+ function parseList(input) {
67
+ return input.split(/[,،\s]+/).map((s) => s.trim()).filter(Boolean);
68
+ }
69
+ function validateName(kebab, kind) {
70
+ if (!kebab) {
71
+ return `A ${kind} name must contain English letters or numbers (for example "about-us").`;
72
+ }
73
+ if (!/^[a-z]/.test(kebab)) {
74
+ return `"${kebab}" must start with a letter.`;
75
+ }
76
+ if (RESERVED_NAMES.includes(kebab)) {
77
+ return `"${kebab}" is a reserved name. Please choose another one.`;
78
+ }
79
+ return void 0;
80
+ }
81
+ function validateProjectName(raw) {
82
+ const kebab = toKebab(raw);
83
+ if (!kebab) return 'Use English letters or numbers, for example "my-app".';
84
+ if (!/^[a-z]/.test(kebab)) return "The project name must start with a letter.";
85
+ return void 0;
86
+ }
87
+ function validatePageCount(value) {
88
+ if (!Number.isInteger(value) || value < 1 || value > MAX_PAGES) {
89
+ return `Enter a whole number between 1 and ${MAX_PAGES}.`;
90
+ }
91
+ return void 0;
92
+ }
93
+ function normalizePageNames(raw) {
94
+ const seen = /* @__PURE__ */ new Set();
95
+ const result = [];
96
+ for (const item of raw) {
97
+ const kebab = toKebab(item);
98
+ const problem = validateName(kebab, "page");
99
+ if (problem) throw new Error(`Invalid page name "${item}": ${problem}`);
100
+ if (seen.has(kebab)) throw new Error(`The page "${kebab}" appears more than once.`);
101
+ seen.add(kebab);
102
+ result.push(kebab);
103
+ }
104
+ return result;
105
+ }
106
+
107
+ // src/plan.ts
108
+ function compExt(cfg) {
109
+ if (cfg.language === "ts") return "tsx";
110
+ return cfg.framework === "next" ? "js" : "jsx";
111
+ }
112
+ function codeExt(cfg) {
113
+ return cfg.language === "ts" ? "ts" : "js";
114
+ }
115
+ var indent = (text2, spaces) => text2.split("\n").map((l) => l ? " ".repeat(spaces) + l : l).join("\n");
116
+ function routeOf(page) {
117
+ if (page.name === "home") return "/";
118
+ return `/${page.name}${page.dynamic ? "/[id]" : ""}`;
119
+ }
120
+ function locate(cfg, page) {
121
+ const n = page.name;
122
+ const P = toPascal(n);
123
+ const x = compExt(cfg);
124
+ const arch = cfg.architecture;
125
+ if (cfg.framework === "react") {
126
+ if (arch === "tba") {
127
+ return {
128
+ pageFile: `src/pages/${P}Page.${x}`,
129
+ layoutFile: page.layout ? `src/components/layout/${P}Layout.${x}` : void 0
130
+ };
131
+ }
132
+ if (arch === "fba") {
133
+ return {
134
+ pageFile: `src/features/${n}/${P}Page.${x}`,
135
+ layoutFile: page.layout ? `src/features/${n}/${P}Layout.${x}` : void 0,
136
+ featureDir: `src/features/${n}`
137
+ };
138
+ }
139
+ return {
140
+ pageFile: `src/pages/${P}Page.${x}`,
141
+ layoutFile: page.layout ? `src/features/${n}/components/${P}Layout.${x}` : void 0,
142
+ featureDir: `src/features/${n}`
143
+ };
144
+ }
145
+ const base = n === "home" ? "src/app" : `src/app/${n}`;
146
+ const routeDir = page.dynamic ? `${base}/[id]` : base;
147
+ const loc = {
148
+ pageFile: `${routeDir}/page.${x}`,
149
+ layoutFile: page.layout && n !== "home" ? `src/app/${n}/layout.${x}` : void 0
150
+ };
151
+ if (arch === "fba") {
152
+ loc.componentFile = `src/features/${n}/${P}Page.${x}`;
153
+ loc.featureDir = `src/features/${n}`;
154
+ }
155
+ if (arch === "hybrid") loc.featureDir = `src/features/${n}`;
156
+ return loc;
157
+ }
158
+ function jsx(page, where, withId) {
159
+ const lines = [`<main>`, ` <h1>${toTitle(page.name)}</h1>`];
160
+ if (withId) lines.push(` <p>ID: {id}</p>`);
161
+ lines.push(` <p>Edit ${where} to change this page.</p>`, `</main>`);
162
+ return lines.join("\n");
163
+ }
164
+ function reactPageComponent(cfg, page, where) {
165
+ const P = toPascal(page.name);
166
+ const out = [];
167
+ if (page.dynamic) out.push(`import { useParams } from 'react-router-dom'`, "");
168
+ out.push(`export function ${P}Page() {`);
169
+ if (page.dynamic) out.push(` const { id } = useParams()`, "");
170
+ out.push(` return (`, indent(jsx(page, where, page.dynamic), 4), ` )`, `}`, "");
171
+ return out.join("\n");
172
+ }
173
+ function reactLayoutComponent(page) {
174
+ const P = toPascal(page.name);
175
+ return [
176
+ `import { Outlet } from 'react-router-dom'`,
177
+ ``,
178
+ `export function ${P}Layout() {`,
179
+ ` return (`,
180
+ ` <section>`,
181
+ ` <Outlet />`,
182
+ ` </section>`,
183
+ ` )`,
184
+ `}`,
185
+ ``
186
+ ].join("\n");
187
+ }
188
+ var paramsType = (cfg) => cfg.language === "ts" ? `{ params }: { params: Promise<{ id: string }> }` : `{ params }`;
189
+ function nextInlineRoute(cfg, page, where) {
190
+ const P = toPascal(page.name);
191
+ if (!page.dynamic) {
192
+ return [`export default function ${P}Page() {`, ` return (`, indent(jsx(page, where, false), 4), ` )`, `}`, ""].join("\n");
193
+ }
194
+ return [
195
+ `import { Suspense } from 'react'`,
196
+ ``,
197
+ `async function ${P}Content(${paramsType(cfg)}) {`,
198
+ ` const { id } = await params`,
199
+ ``,
200
+ ` return (`,
201
+ indent(jsx(page, where, true), 4),
202
+ ` )`,
203
+ `}`,
204
+ ``,
205
+ `export default function ${P}Page(${paramsType(cfg)}) {`,
206
+ ` return (`,
207
+ ` <Suspense fallback={null}>`,
208
+ ` <${P}Content params={params} />`,
209
+ ` </Suspense>`,
210
+ ` )`,
211
+ `}`,
212
+ ``
213
+ ].join("\n");
214
+ }
215
+ function nextFeatureComponent(cfg, page, where) {
216
+ const P = toPascal(page.name);
217
+ const args = page.dynamic ? cfg.language === "ts" ? `{ id }: { id: string }` : `{ id }` : "";
218
+ return [`export function ${P}Page(${args}) {`, ` return (`, indent(jsx(page, where, page.dynamic), 4), ` )`, `}`, ""].join("\n");
219
+ }
220
+ function nextThinRoute(cfg, page) {
221
+ const P = toPascal(page.name);
222
+ const imp = `import { ${P}Page } from '@/features/${page.name}'`;
223
+ if (!page.dynamic) {
224
+ return [imp, ``, `export default function Page() {`, ` return <${P}Page />`, `}`, ""].join("\n");
225
+ }
226
+ return [
227
+ `import { Suspense } from 'react'`,
228
+ imp,
229
+ ``,
230
+ `async function Content(${paramsType(cfg)}) {`,
231
+ ` const { id } = await params`,
232
+ ``,
233
+ ` return <${P}Page id={id} />`,
234
+ `}`,
235
+ ``,
236
+ `export default function Page(${paramsType(cfg)}) {`,
237
+ ` return (`,
238
+ ` <Suspense fallback={null}>`,
239
+ ` <Content params={params} />`,
240
+ ` </Suspense>`,
241
+ ` )`,
242
+ `}`,
243
+ ``
244
+ ].join("\n");
245
+ }
246
+ function nextLayout(cfg, page) {
247
+ const P = toPascal(page.name);
248
+ const args = cfg.language === "ts" ? `{ children }: { children: React.ReactNode }` : `{ children }`;
249
+ return [`export default function ${P}Layout(${args}) {`, ` return <section>{children}</section>`, `}`, ""].join("\n");
250
+ }
251
+ function routerFile(cfg) {
252
+ const x = compExt(cfg);
253
+ return cfg.architecture === "tba" ? `src/routes/index.${x}` : `src/app/router.${x}`;
254
+ }
255
+ function reactRegistration(cfg, page) {
256
+ const n = page.name;
257
+ const P = toPascal(n);
258
+ const arch = cfg.architecture;
259
+ const imports = [];
260
+ if (arch === "fba") {
261
+ const names = page.layout ? `${P}Page, ${P}Layout` : `${P}Page`;
262
+ imports.push(`import { ${names} } from '@/features/${n}'`);
263
+ } else {
264
+ imports.push(`import { ${P}Page } from '@/pages/${P}Page'`);
265
+ if (page.layout) {
266
+ imports.push(
267
+ arch === "tba" ? `import { ${P}Layout } from '@/components/layout/${P}Layout'` : `import { ${P}Layout } from '@/features/${n}/components/${P}Layout'`
268
+ );
269
+ }
270
+ }
271
+ const path5 = n === "home" ? "/" : `/${n}`;
272
+ let routeLines;
273
+ if (!page.layout) {
274
+ routeLines = [`<Route path="${page.dynamic ? `${path5}/:id` : path5}" element={<${P}Page />} />`];
275
+ } else if (page.dynamic) {
276
+ routeLines = [
277
+ `<Route path="${path5}" element={<${P}Layout />}>`,
278
+ ` <Route path=":id" element={<${P}Page />} />`,
279
+ `</Route>`
280
+ ];
281
+ } else {
282
+ routeLines = [
283
+ `<Route path="${path5}" element={<${P}Layout />}>`,
284
+ ` <Route index element={<${P}Page />} />`,
285
+ `</Route>`
286
+ ];
287
+ }
288
+ return { imports, routeLines };
289
+ }
290
+ function skeleton(cfg) {
291
+ const { framework: fw, architecture: arch } = cfg;
292
+ let dirs;
293
+ if (fw === "react") {
294
+ if (arch === "tba") {
295
+ dirs = ["assets", "components/common", "components/layout", "components/ui", "constants", "hooks", "pages", "routes", "services", "store", "types", "utils"];
296
+ } else if (arch === "fba") {
297
+ dirs = ["app/providers", "features"];
298
+ } else {
299
+ dirs = ["app/providers", "pages", "features", "shared/components/ui", "shared/components/layout", "shared/components/common", "shared/hooks", "shared/services", "shared/utils", "shared/types", "shared/constants", "store"];
300
+ }
301
+ } else if (arch === "tba") {
302
+ dirs = ["components/common", "components/layout", "components/ui", "constants", "hooks", "lib", "services", "store", "types", "utils"];
303
+ } else if (arch === "fba") {
304
+ dirs = ["features"];
305
+ } else {
306
+ dirs = ["features", "shared/components/ui", "shared/components/layout", "shared/components/common", "shared/hooks", "shared/lib", "shared/utils", "shared/types", "shared/constants", "store"];
307
+ }
308
+ if (cfg.language === "js") dirs = dirs.filter((d) => !d.endsWith("types"));
309
+ return dirs.map((d) => `src/${d}`);
310
+ }
311
+ function withGitkeep(files, dirs) {
312
+ const out = [...files];
313
+ for (const dir of dirs) {
314
+ if (!out.some((f) => f.path.startsWith(`${dir}/`))) out.push({ path: `${dir}/.gitkeep`, content: "" });
315
+ }
316
+ return out;
317
+ }
318
+ function featureSkeletonDirs(cfg, dir) {
319
+ const dirs = ["components", "hooks", "services", "types"].filter((d) => cfg.language === "ts" || d !== "types");
320
+ return dirs.map((d) => `${dir}/${d}`);
321
+ }
322
+ function planPage(cfg, page) {
323
+ const loc = locate(cfg, page);
324
+ const P = toPascal(page.name);
325
+ const ce = codeExt(cfg);
326
+ const files = [];
327
+ const dirs = [];
328
+ if (cfg.framework === "react") {
329
+ files.push({ path: loc.pageFile, content: reactPageComponent(cfg, page, loc.pageFile) });
330
+ if (loc.layoutFile) files.push({ path: loc.layoutFile, content: reactLayoutComponent(page) });
331
+ } else {
332
+ if (cfg.architecture === "fba" && loc.componentFile) {
333
+ files.push({ path: loc.componentFile, content: nextFeatureComponent(cfg, page, loc.componentFile) });
334
+ files.push({ path: loc.pageFile, content: nextThinRoute(cfg, page) });
335
+ } else {
336
+ files.push({ path: loc.pageFile, content: nextInlineRoute(cfg, page, loc.pageFile) });
337
+ }
338
+ if (loc.layoutFile) files.push({ path: loc.layoutFile, content: nextLayout(cfg, page) });
339
+ }
340
+ if (loc.featureDir) {
341
+ dirs.push(...featureSkeletonDirs(cfg, loc.featureDir));
342
+ const exports = [];
343
+ if (cfg.architecture === "fba") {
344
+ exports.push(`export { ${P}Page } from './${P}Page'`);
345
+ if (cfg.framework === "react" && page.layout) exports.push(`export { ${P}Layout } from './${P}Layout'`);
346
+ }
347
+ files.push({ path: `${loc.featureDir}/index.${ce}`, content: exports.length ? `${exports.join("\n")}
348
+ ` : `export {}
349
+ ` });
350
+ }
351
+ return withGitkeep(files, dirs);
352
+ }
353
+ function planFeature(cfg, name) {
354
+ const P = toPascal(name);
355
+ const C = toCamel(name);
356
+ const x = compExt(cfg);
357
+ const ce = codeExt(cfg);
358
+ const ts = cfg.language === "ts";
359
+ if (cfg.architecture === "tba") {
360
+ const files = [
361
+ {
362
+ path: `src/components/${name}/${P}.${x}`,
363
+ content: [`export function ${P}() {`, ` return <div>${toTitle(name)}</div>`, `}`, ""].join("\n")
364
+ },
365
+ { path: `src/components/${name}/index.${ce}`, content: `export { ${P} } from './${P}'
366
+ ` },
367
+ { path: `src/hooks/use${P}.${ce}`, content: [`export function use${P}() {`, ` return {}`, `}`, ""].join("\n") },
368
+ { path: `src/services/${C}.service.${ce}`, content: `export const ${C}Service = {}
369
+ ` }
370
+ ];
371
+ if (ts) files.push({ path: `src/types/${name}.types.ts`, content: `export interface ${P} {}
372
+ ` });
373
+ return files;
374
+ }
375
+ const dir = `src/features/${name}`;
376
+ return withGitkeep([{ path: `${dir}/index.${ce}`, content: `export {}
377
+ ` }], featureSkeletonDirs(cfg, dir));
378
+ }
379
+ function planProject(cfg, pages, options = {}) {
380
+ const files = [];
381
+ const x = compExt(cfg);
382
+ const ts = cfg.language === "ts";
383
+ if (cfg.framework === "react") {
384
+ const appDir = cfg.architecture === "tba" ? "src" : "src/app";
385
+ const appImport = cfg.architecture === "tba" ? "./App" : "./app/App";
386
+ const routerImport = cfg.architecture === "tba" ? "@/routes" : "./router";
387
+ files.push({
388
+ path: `src/main.${x}`,
389
+ content: [
390
+ `import { StrictMode } from 'react'`,
391
+ `import { createRoot } from 'react-dom/client'`,
392
+ `import './styles/index.css'`,
393
+ `import App from '${appImport}'`,
394
+ ``,
395
+ `createRoot(document.getElementById('root')${ts ? "!" : ""}).render(`,
396
+ ` <StrictMode>`,
397
+ ` <App />`,
398
+ ` </StrictMode>,`,
399
+ `)`,
400
+ ``
401
+ ].join("\n")
402
+ });
403
+ files.push({
404
+ path: `${appDir}/App.${x}`,
405
+ content: [
406
+ `import { BrowserRouter } from 'react-router-dom'`,
407
+ `import { AppRouter } from '${routerImport}'`,
408
+ ``,
409
+ `export default function App() {`,
410
+ ` return (`,
411
+ ` <BrowserRouter>`,
412
+ ` <AppRouter />`,
413
+ ` </BrowserRouter>`,
414
+ ` )`,
415
+ `}`,
416
+ ``
417
+ ].join("\n")
418
+ });
419
+ files.push({ path: "src/styles/index.css", content: options.indexCss ?? "/* Global styles */\n" });
420
+ let router = routerTemplate();
421
+ for (const page of pages) {
422
+ const reg = reactRegistration(cfg, page);
423
+ router = registerRoute(router, reg.imports, reg.routeLines);
424
+ }
425
+ files.push({ path: routerFile(cfg), content: router });
426
+ }
427
+ const dirs = skeleton(cfg);
428
+ for (const page of pages) {
429
+ const pageFiles = planPage(cfg, page);
430
+ files.push(...pageFiles.filter((f) => !f.path.endsWith("/.gitkeep")));
431
+ for (const f of pageFiles) {
432
+ if (f.path.endsWith("/.gitkeep")) dirs.push(f.path.slice(0, -"/.gitkeep".length));
433
+ }
434
+ }
435
+ return withGitkeep(files, dirs);
436
+ }
437
+
438
+ // src/tree.ts
439
+ function emptyNode() {
440
+ return { dirs: /* @__PURE__ */ new Map(), files: [] };
441
+ }
442
+ function renderTree(paths, rootLabel) {
443
+ const root = emptyNode();
444
+ for (const p3 of paths) {
445
+ const parts = p3.split("/").filter(Boolean);
446
+ const file = parts.pop();
447
+ if (!file) continue;
448
+ let node = root;
449
+ for (const part of parts) {
450
+ let next = node.dirs.get(part);
451
+ if (!next) {
452
+ next = emptyNode();
453
+ node.dirs.set(part, next);
454
+ }
455
+ node = next;
456
+ }
457
+ if (file !== ".gitkeep") node.files.push(file);
458
+ }
459
+ const out = [`${rootLabel}/`];
460
+ const walk = (node, prefix) => {
461
+ const entries = [
462
+ ...[...node.dirs.keys()].sort().map((name) => ({ name, dir: node.dirs.get(name) })),
463
+ ...[...node.files].sort().map((name) => ({ name }))
464
+ ];
465
+ entries.forEach((entry, i) => {
466
+ const last = i === entries.length - 1;
467
+ out.push(`${prefix}${last ? "\u2514\u2500 " : "\u251C\u2500 "}${entry.name}${entry.dir ? "/" : ""}`);
468
+ if (entry.dir) walk(entry.dir, prefix + (last ? " " : "\u2502 "));
469
+ });
470
+ };
471
+ walk(root, "");
472
+ return out.join("\n");
473
+ }
474
+
475
+ // src/cli.ts
476
+ import { Command } from "commander";
477
+ import pc4 from "picocolors";
478
+
479
+ // package.json
480
+ var package_default = {
481
+ name: "zakieh",
482
+ version: "0.1.0",
483
+ description: "Scaffold a Next.js or React project with the folder architecture you choose (TBA, FBA or Hybrid).",
484
+ keywords: [
485
+ "scaffold",
486
+ "cli",
487
+ "nextjs",
488
+ "react",
489
+ "vite",
490
+ "architecture",
491
+ "feature-based",
492
+ "create-app"
493
+ ],
494
+ author: "Houzayfa Zakieh (\u062D\u0630\u064A\u0641\u0629 \u0632\u0643\u064A\u0647) <https://zakieh.dev>",
495
+ homepage: "https://zakieh.dev",
496
+ license: "MIT",
497
+ type: "module",
498
+ bin: {
499
+ zakieh: "dist/bin.js"
500
+ },
501
+ main: "dist/index.js",
502
+ types: "dist/index.d.ts",
503
+ exports: {
504
+ ".": {
505
+ types: "./dist/index.d.ts",
506
+ import: "./dist/index.js"
507
+ }
508
+ },
509
+ files: [
510
+ "dist",
511
+ "README.md",
512
+ "LICENSE"
513
+ ],
514
+ engines: {
515
+ node: ">=20"
516
+ },
517
+ scripts: {
518
+ build: "tsup",
519
+ dev: "tsup --watch",
520
+ test: "vitest run",
521
+ typecheck: "tsc --noEmit"
522
+ },
523
+ dependencies: {
524
+ "@clack/prompts": "^1.9.0",
525
+ commander: "^15.1.0",
526
+ execa: "^10.2.1",
527
+ "jsonc-parser": "^3.3.1",
528
+ picocolors: "^1.1.1"
529
+ },
530
+ devDependencies: {
531
+ "@types/node": "^26.6.11",
532
+ tsup: "^9.0.0",
533
+ typescript: "^5.9.3",
534
+ vitest: "^5.1.2"
535
+ },
536
+ repository: {
537
+ type: "git",
538
+ url: "git+https://github.com/Houzayfa-Zakieh/zakieh.git",
539
+ directory: "packages/zakieh"
540
+ },
541
+ bugs: {
542
+ url: "https://github.com/Houzayfa-Zakieh/zakieh/issues"
543
+ }
544
+ };
545
+
546
+ // src/errors.ts
547
+ var UserError = class extends Error {
548
+ constructor(message) {
549
+ super(message);
550
+ this.name = "UserError";
551
+ }
552
+ };
553
+
554
+ // src/commands/add.ts
555
+ import { readFile as readFile2 } from "fs/promises";
556
+ import path2 from "path";
557
+ import * as p from "@clack/prompts";
558
+ import pc from "picocolors";
559
+
560
+ // src/fsx.ts
561
+ import { access, mkdir, readFile, writeFile } from "fs/promises";
562
+ import path from "path";
563
+ async function exists(p3) {
564
+ try {
565
+ await access(p3);
566
+ return true;
567
+ } catch {
568
+ return false;
569
+ }
570
+ }
571
+ async function writeFiles(root, files) {
572
+ for (const file of files) {
573
+ const target = path.join(root, ...file.path.split("/"));
574
+ await mkdir(path.dirname(target), { recursive: true });
575
+ await writeFile(target, file.content, "utf8");
576
+ }
577
+ }
578
+ async function findProjectRoot(start) {
579
+ let dir = path.resolve(start);
580
+ for (; ; ) {
581
+ if (await exists(path.join(dir, CONFIG_FILE))) return dir;
582
+ const parent = path.dirname(dir);
583
+ if (parent === dir) {
584
+ throw new UserError(
585
+ `No ${CONFIG_FILE} found in this folder or any parent folder. Run this command inside a project created with "zakieh create".`
586
+ );
587
+ }
588
+ dir = parent;
589
+ }
590
+ }
591
+ async function readConfig(root) {
592
+ const raw = await readFile(path.join(root, CONFIG_FILE), "utf8");
593
+ let data;
594
+ try {
595
+ data = JSON.parse(raw);
596
+ } catch {
597
+ throw new UserError(`${CONFIG_FILE} is not valid JSON.`);
598
+ }
599
+ const ok = (data.framework === "next" || data.framework === "react") && (data.language === "ts" || data.language === "js") && (data.architecture === "tba" || data.architecture === "fba" || data.architecture === "hybrid");
600
+ if (!ok) throw new UserError(`${CONFIG_FILE} is missing or has invalid "framework", "language" or "architecture".`);
601
+ return { framework: data.framework, language: data.language, architecture: data.architecture, srcDir: "src", alias: "@/" };
602
+ }
603
+ function configFile(cfg) {
604
+ return { path: CONFIG_FILE, content: `${JSON.stringify(cfg, null, 2)}
605
+ ` };
606
+ }
607
+
608
+ // src/commands/add.ts
609
+ function checkName(raw, kind) {
610
+ const name = toKebab(raw);
611
+ const problem = validateName(name, kind);
612
+ if (problem) throw new UserError(problem);
613
+ return name;
614
+ }
615
+ async function assertNoConflicts(root, files) {
616
+ const clashes = [];
617
+ for (const f of files) {
618
+ if (f.path.endsWith("/.gitkeep")) continue;
619
+ if (await exists(path2.join(root, ...f.path.split("/")))) clashes.push(f.path);
620
+ }
621
+ if (clashes.length > 0) {
622
+ throw new UserError(`These files already exist, so nothing was changed:
623
+ ${clashes.map((c) => ` ${c}`).join("\n")}`);
624
+ }
625
+ }
626
+ function report(created, updated, dryRun) {
627
+ const list = [
628
+ ...created.filter((f) => !f.path.endsWith("/.gitkeep")).map((f) => `${pc.green("+")} ${f.path}`),
629
+ ...updated.map((f) => `${pc.yellow("~")} ${f}`)
630
+ ];
631
+ p.note(list.join("\n"), dryRun ? "Files that would be created (dry run)" : "Files");
632
+ }
633
+ async function addPageCommand(rawName, opts) {
634
+ const name = checkName(rawName, "page");
635
+ if (name === "home" && (opts.dynamic || opts.layout)) throw new UserError('The "home" page cannot be dynamic or have its own layout.');
636
+ const root = await findProjectRoot(process.cwd());
637
+ const cfg = await readConfig(root);
638
+ const page = { name, dynamic: Boolean(opts.dynamic), layout: Boolean(opts.layout) };
639
+ const files = planPage(cfg, page);
640
+ await assertNoConflicts(root, files);
641
+ const updates = [];
642
+ if (cfg.framework === "react") {
643
+ const routerPath = routerFile(cfg);
644
+ const routerFull = path2.join(root, ...routerPath.split("/"));
645
+ if (!await exists(routerFull)) throw new UserError(`The router file ${routerPath} was not found.`);
646
+ const reg = reactRegistration(cfg, page);
647
+ updates.push({ path: routerPath, content: registerRoute(await readFile2(routerFull, "utf8"), reg.imports, reg.routeLines) });
648
+ }
649
+ p.intro(pc.bold(`Add page "${name}"`));
650
+ report(files, updates.map((u) => u.path), Boolean(opts.dryRun));
651
+ if (opts.dryRun) return;
652
+ await writeFiles(root, [...files, ...updates]);
653
+ p.outro(`Page "${name}" added.`);
654
+ }
655
+ async function addFeatureCommand(rawName, opts) {
656
+ const name = checkName(rawName, "feature");
657
+ const root = await findProjectRoot(process.cwd());
658
+ const cfg = await readConfig(root);
659
+ const files = planFeature(cfg, name);
660
+ await assertNoConflicts(root, files);
661
+ p.intro(pc.bold(`Add feature "${name}"`));
662
+ report(files, [], Boolean(opts.dryRun));
663
+ if (opts.dryRun) return;
664
+ await writeFiles(root, files);
665
+ p.outro(`Feature "${name}" added.`);
666
+ }
667
+
668
+ // src/commands/create.ts
669
+ import path4 from "path";
670
+ import { readdir as readdir2 } from "fs/promises";
671
+ import * as p2 from "@clack/prompts";
672
+ import pc3 from "picocolors";
673
+
674
+ // src/branding.ts
675
+ import pc2 from "picocolors";
676
+ function authorLabel() {
677
+ return process.env.ZAKIEH_ARABIC === "1" ? `${AUTHOR_NAME} (${AUTHOR_NAME_AR})` : AUTHOR_NAME;
678
+ }
679
+ function banner() {
680
+ return [
681
+ "",
682
+ ` ${pc2.bold(pc2.yellow("ZAKIEH"))} ${pc2.dim("\xB7")} by ${authorLabel()}`,
683
+ ` ${pc2.dim(WEBSITE)}`,
684
+ ""
685
+ ].join("\n");
686
+ }
687
+ function closingLine() {
688
+ return `${pc2.dim("Generated with Zakieh by")} ${authorLabel()} ${pc2.dim("\xB7")} ${pc2.dim(WEBSITE)}`;
689
+ }
690
+ function readmeCredit() {
691
+ return `---
692
+
693
+ Generated with [Zakieh](${WEBSITE}) by ${AUTHOR_NAME} (${AUTHOR_NAME_AR}).
694
+ `;
695
+ }
696
+
697
+ // src/frameworks.ts
698
+ import { readFile as readFile3, rm, writeFile as writeFile2, readdir } from "fs/promises";
699
+ import path3 from "path";
700
+ import { execa } from "execa";
701
+ import { applyEdits, modify } from "jsonc-parser";
702
+ function runner(pm) {
703
+ switch (pm) {
704
+ case "pnpm":
705
+ return ["pnpm", "dlx"];
706
+ case "yarn":
707
+ return ["yarn", "dlx"];
708
+ case "bun":
709
+ return ["bunx"];
710
+ default:
711
+ return ["npx", "--yes"];
712
+ }
713
+ }
714
+ async function run(cmd, args, cwd, inherit = false) {
715
+ try {
716
+ await execa(cmd, args, { cwd, stdio: inherit ? "inherit" : "pipe" });
717
+ } catch (error) {
718
+ const e = error;
719
+ const detail = (e.stderr || e.stdout || "").split("\n").slice(-12).join("\n").trim();
720
+ throw new UserError(`Command failed: ${cmd} ${args.join(" ")}
721
+ ${e.shortMessage ?? ""}${detail ? `
722
+ ${detail}` : ""}`);
723
+ }
724
+ }
725
+ async function scaffoldBase(parentDir, name, cfg, pm) {
726
+ const [cmd, ...pre] = runner(pm);
727
+ if (cfg.framework === "next") {
728
+ await run(
729
+ cmd,
730
+ [
731
+ ...pre,
732
+ "create-next-app@latest",
733
+ name,
734
+ cfg.language === "ts" ? "--ts" : "--js",
735
+ "--no-tailwind",
736
+ "--eslint",
737
+ "--app",
738
+ "--src-dir",
739
+ "--import-alias",
740
+ "@/*",
741
+ `--use-${pm}`,
742
+ "--skip-install",
743
+ "--disable-git",
744
+ "--yes"
745
+ ],
746
+ parentDir
747
+ );
748
+ } else {
749
+ await run(
750
+ cmd,
751
+ [...pre, "create-vite@latest", name, "--template", cfg.language === "ts" ? "react-ts" : "react", "--no-interactive"],
752
+ parentDir
753
+ );
754
+ }
755
+ }
756
+ async function removeIfExists(p3) {
757
+ await rm(p3, { recursive: true, force: true });
758
+ }
759
+ async function cleanBase(root, cfg) {
760
+ if (cfg.framework === "next") {
761
+ for (const f of ["page.tsx", "page.ts", "page.js", "page.jsx", "page.module.css"]) {
762
+ await removeIfExists(path3.join(root, "src", "app", f));
763
+ }
764
+ return {};
765
+ }
766
+ let indexCss;
767
+ const css = path3.join(root, "src", "index.css");
768
+ if (await exists(css)) indexCss = await readFile3(css, "utf8");
769
+ await removeIfExists(css);
770
+ for (const f of ["App.css", "App.tsx", "App.jsx"]) await removeIfExists(path3.join(root, "src", f));
771
+ const assets = path3.join(root, "src", "assets");
772
+ if (await exists(assets)) {
773
+ for (const entry of await readdir(assets)) await removeIfExists(path3.join(assets, entry));
774
+ if (cfg.architecture !== "tba") await removeIfExists(assets);
775
+ }
776
+ return { indexCss };
777
+ }
778
+ async function readJson(file) {
779
+ return JSON.parse(await readFile3(file, "utf8"));
780
+ }
781
+ var sortKeys = (obj) => Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)));
782
+ async function patchProject(root, cfg, selfVersion) {
783
+ const warnings = [];
784
+ const pkgPath = path3.join(root, "package.json");
785
+ const pkg = await readJson(pkgPath);
786
+ if (cfg.framework === "react") {
787
+ const deps = { ...pkg.dependencies ?? {}, "react-router-dom": REACT_ROUTER_VERSION };
788
+ pkg.dependencies = sortKeys(deps);
789
+ }
790
+ if (ADD_SELF_AS_DEV_DEPENDENCY) {
791
+ const dev = { ...pkg.devDependencies ?? {}, zakieh: `^${selfVersion}` };
792
+ pkg.devDependencies = sortKeys(dev);
793
+ }
794
+ await writeFile2(pkgPath, `${JSON.stringify(pkg, null, 2)}
795
+ `, "utf8");
796
+ if (cfg.framework === "react") warnings.push(...await patchViteAlias(root, cfg));
797
+ return warnings;
798
+ }
799
+ async function patchViteAlias(root, cfg) {
800
+ const warnings = [];
801
+ const viteFile = path3.join(root, cfg.language === "ts" ? "vite.config.ts" : "vite.config.js");
802
+ let vite = await readFile3(viteFile, "utf8");
803
+ const anchor = "plugins: [react()],";
804
+ if (vite.includes(anchor)) {
805
+ vite = vite.replace(
806
+ anchor,
807
+ `${anchor}
808
+ resolve: {
809
+ alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) },
810
+ },`
811
+ );
812
+ vite = `import { fileURLToPath, URL } from 'node:url'
813
+ ${vite}`;
814
+ await writeFile2(viteFile, vite, "utf8");
815
+ } else {
816
+ warnings.push(`Could not add the "@/" alias to ${path3.basename(viteFile)}. Add resolve.alias manually.`);
817
+ }
818
+ if (cfg.language === "ts") {
819
+ const tsconfig = path3.join(root, "tsconfig.app.json");
820
+ const text2 = await readFile3(tsconfig, "utf8");
821
+ const edits = modify(text2, ["compilerOptions", "paths"], { "@/*": ["./src/*"] }, { formattingOptions: { insertSpaces: true, tabSize: 2 } });
822
+ await writeFile2(tsconfig, applyEdits(text2, edits), "utf8");
823
+ } else {
824
+ const jsconfig = { compilerOptions: { baseUrl: ".", paths: { "@/*": ["src/*"] } }, include: ["src"] };
825
+ await writeFile2(path3.join(root, "jsconfig.json"), `${JSON.stringify(jsconfig, null, 2)}
826
+ `, "utf8");
827
+ }
828
+ return warnings;
829
+ }
830
+
831
+ // src/readme.ts
832
+ var ARCH_TEXT = {
833
+ tba: "Files are grouped by **type** (components, hooks, services, ...). Simple and quick to start with.",
834
+ fba: "Each page is a **feature** with its own folder holding everything it needs. Other features import it only through its `index`.",
835
+ hybrid: "Pages live in **feature** folders, and anything shared between pages lives in `shared/`, grouped by type."
836
+ };
837
+ var FRAMEWORK_TEXT = { next: "Next.js (App Router)", react: "React (Vite)" };
838
+ function projectReadme(opts) {
839
+ const { name, cfg, pages, tree, pm, credit } = opts;
840
+ const run2 = pm === "npm" ? "npm run" : pm;
841
+ const lines = [
842
+ `# ${name}`,
843
+ ``,
844
+ `Created with [Zakieh](https://zakieh.dev): ${FRAMEWORK_TEXT[cfg.framework]}, ${cfg.language === "ts" ? "TypeScript" : "JavaScript"}, **${cfg.architecture.toUpperCase()}** architecture.`,
845
+ ``,
846
+ `## Getting started`,
847
+ ``,
848
+ "```bash",
849
+ `${pm} install`,
850
+ `${run2} dev`,
851
+ "```",
852
+ ``,
853
+ `## Architecture`,
854
+ ``,
855
+ ARCH_TEXT[cfg.architecture],
856
+ ``,
857
+ `## Project structure`,
858
+ ``,
859
+ "```text",
860
+ tree,
861
+ "```",
862
+ ``,
863
+ `## Pages`,
864
+ ``,
865
+ `| Route | Name |`,
866
+ `| --- | --- |`,
867
+ ...pages.map((p3) => `| \`${routeOf(p3)}\` | ${toPascal(p3.name)} |`),
868
+ ``,
869
+ `## Adding pages and features`,
870
+ ``,
871
+ `The structure is recorded in \`zakieh.config.json\`. With the Zakieh CLI installed (\`npm install -g zakieh\`), run from the project root:`,
872
+ ``,
873
+ "```bash",
874
+ `zakieh add page <name>`,
875
+ `zakieh add feature <name>`,
876
+ "```",
877
+ ``
878
+ ];
879
+ if (credit) lines.push(readmeCredit());
880
+ return lines.join("\n");
881
+ }
882
+
883
+ // src/commands/create.ts
884
+ function detectPackageManager() {
885
+ const agent = process.env.npm_config_user_agent ?? "";
886
+ if (agent.startsWith("pnpm")) return "pnpm";
887
+ if (agent.startsWith("yarn")) return "yarn";
888
+ if (agent.startsWith("bun")) return "bun";
889
+ return "npm";
890
+ }
891
+ function pickOne(value, allowed, flag) {
892
+ if (value === void 0) return void 0;
893
+ const v = value.toLowerCase();
894
+ if (!allowed.includes(v)) throw new UserError(`Invalid value "${value}" for ${flag}. Use one of: ${allowed.join(", ")}.`);
895
+ return v;
896
+ }
897
+ function cancelled(value) {
898
+ if (p2.isCancel(value)) {
899
+ p2.cancel("Cancelled. Nothing was created.");
900
+ process.exit(0);
901
+ }
902
+ }
903
+ function pageNamesFromFlag(value, known, flag) {
904
+ if (!value) return [];
905
+ const names = parseList(value).map(toKebab);
906
+ for (const n of names) {
907
+ if (!known.includes(n)) throw new UserError(`${flag}: "${n}" is not one of the pages (${known.join(", ")}).`);
908
+ if (n === "home") throw new UserError(`${flag}: the "home" page cannot be dynamic or have its own layout.`);
909
+ }
910
+ return names;
911
+ }
912
+ async function gather(nameArg, opts, interactive) {
913
+ let rawName;
914
+ if (nameArg) {
915
+ rawName = nameArg;
916
+ } else {
917
+ if (!interactive) throw new UserError("Please provide a project name, for example: zakieh create my-app --yes");
918
+ const v = await p2.text({ message: "Project name", placeholder: "my-app", defaultValue: "my-app", validate: (x) => validateProjectName(x || "my-app") });
919
+ cancelled(v);
920
+ rawName = String(v);
921
+ }
922
+ const nameError = validateProjectName(rawName);
923
+ if (nameError) throw new UserError(`Invalid project name "${rawName}". ${nameError}`);
924
+ const name = toKebab(rawName);
925
+ let framework = pickOne(opts.framework, ["next", "react"], "--framework");
926
+ if (!framework) {
927
+ if (interactive) {
928
+ const v = await p2.select({
929
+ message: "Which framework?",
930
+ options: [
931
+ { value: "next", label: "Next.js", hint: "App Router" },
932
+ { value: "react", label: "React", hint: "Vite + React Router" }
933
+ ]
934
+ });
935
+ cancelled(v);
936
+ framework = v;
937
+ } else framework = "next";
938
+ }
939
+ let language = pickOne(opts.lang, ["ts", "js"], "--lang");
940
+ if (!language) {
941
+ if (interactive) {
942
+ const v = await p2.select({
943
+ message: "Which language?",
944
+ options: [
945
+ { value: "ts", label: "TypeScript" },
946
+ { value: "js", label: "JavaScript" }
947
+ ]
948
+ });
949
+ cancelled(v);
950
+ language = v;
951
+ } else language = "ts";
952
+ }
953
+ let architecture = pickOne(opts.arch, ["tba", "fba", "hybrid"], "--arch");
954
+ if (!architecture) {
955
+ if (interactive) {
956
+ const v = await p2.select({
957
+ message: "Which architecture?",
958
+ options: Object.keys(ARCHITECTURE_LABELS).map((k) => ({ value: k, label: ARCHITECTURE_LABELS[k] })),
959
+ initialValue: "hybrid"
960
+ });
961
+ cancelled(v);
962
+ architecture = v;
963
+ } else architecture = "hybrid";
964
+ }
965
+ let pageNames;
966
+ if (opts.pages) {
967
+ pageNames = normalizePageNames(parseList(opts.pages));
968
+ } else if (interactive) {
969
+ const countValue = await p2.text({
970
+ message: "How many pages does the site have?",
971
+ initialValue: "3",
972
+ validate: (x) => validatePageCount(Number(x))
973
+ });
974
+ cancelled(countValue);
975
+ const count = Number(countValue);
976
+ const names = await p2.text({
977
+ message: `Names of the ${count} page${count === 1 ? "" : "s"}, separated by commas`,
978
+ placeholder: "home, about, contact",
979
+ validate: (x) => {
980
+ try {
981
+ const list = normalizePageNames(parseList(x ?? ""));
982
+ if (list.length !== count) return `You entered ${list.length} name${list.length === 1 ? "" : "s"}, but you said ${count}.`;
983
+ } catch (e) {
984
+ return e.message;
985
+ }
986
+ return void 0;
987
+ }
988
+ });
989
+ cancelled(names);
990
+ pageNames = normalizePageNames(parseList(String(names)));
991
+ } else {
992
+ pageNames = ["home"];
993
+ }
994
+ let addedHome = false;
995
+ if (!pageNames.includes("home")) {
996
+ pageNames.unshift("home");
997
+ addedHome = true;
998
+ }
999
+ const candidates = pageNames.filter((n) => n !== "home");
1000
+ let dynamic = pageNamesFromFlag(opts.dynamic, pageNames, "--dynamic");
1001
+ let layout = pageNamesFromFlag(opts.layout, pageNames, "--layout");
1002
+ if (interactive && candidates.length > 0) {
1003
+ if (opts.dynamic === void 0) {
1004
+ const v = await p2.multiselect({
1005
+ message: "Which pages are dynamic? They get a /name/[id] route. (space to select, enter to continue)",
1006
+ options: candidates.map((n) => ({ value: n, label: n })),
1007
+ required: false
1008
+ });
1009
+ cancelled(v);
1010
+ dynamic = v;
1011
+ }
1012
+ if (opts.layout === void 0) {
1013
+ const v = await p2.multiselect({
1014
+ message: "Which pages need their own layout? (space to select, enter to continue)",
1015
+ options: candidates.map((n) => ({ value: n, label: n })),
1016
+ required: false
1017
+ });
1018
+ cancelled(v);
1019
+ layout = v;
1020
+ }
1021
+ }
1022
+ const pages = pageNames.map((n) => ({ name: n, dynamic: dynamic.includes(n), layout: layout.includes(n) }));
1023
+ return { name, cfg: { framework, language, architecture, srcDir: "src", alias: "@/" }, pages, addedHome };
1024
+ }
1025
+ async function createCommand(nameArg, opts, version) {
1026
+ const interactive = !opts.yes && Boolean(process.stdin.isTTY);
1027
+ console.log(banner());
1028
+ p2.intro(pc3.bold("Create a new project"));
1029
+ const pm = pickOne(opts.pm, ["npm", "pnpm", "yarn", "bun"], "--pm") ?? detectPackageManager();
1030
+ const { name, cfg, pages, addedHome } = await gather(nameArg, opts, interactive);
1031
+ const root = path4.resolve(process.cwd(), name);
1032
+ if (await exists(root)) {
1033
+ const entries = await readdir2(root).catch(() => []);
1034
+ if (entries.length > 0) throw new UserError(`The folder "${name}" already exists and is not empty.`);
1035
+ }
1036
+ if (addedHome) p2.log.info('Added a "home" page for the "/" route.');
1037
+ const previewFiles = planProject(cfg, pages);
1038
+ const treeOf = (files2) => renderTree(files2.map((f) => f.path), name);
1039
+ p2.note(treeOf(previewFiles), "Structure that will be generated");
1040
+ p2.log.message(pc3.dim(`Base files (package.json, config files) come from ${cfg.framework === "next" ? "create-next-app" : "create-vite"}.`));
1041
+ if (opts.dryRun) {
1042
+ p2.outro("Dry run: no files were written.");
1043
+ return;
1044
+ }
1045
+ if (interactive) {
1046
+ const ok = await p2.confirm({ message: "Create the project?", initialValue: true });
1047
+ cancelled(ok);
1048
+ if (!ok) {
1049
+ p2.cancel("Cancelled. Nothing was created.");
1050
+ return;
1051
+ }
1052
+ }
1053
+ const spin = p2.spinner();
1054
+ spin.start(`Creating the base project with ${cfg.framework === "next" ? "create-next-app" : "create-vite"}`);
1055
+ await scaffoldBase(process.cwd(), name, cfg, pm);
1056
+ spin.stop("Base project created");
1057
+ spin.start("Applying your architecture");
1058
+ const { indexCss } = await cleanBase(root, cfg);
1059
+ const files = planProject(cfg, pages, { indexCss });
1060
+ await writeFiles(root, files);
1061
+ await writeFiles(root, [
1062
+ configFile(cfg),
1063
+ { path: "README.md", content: projectReadme({ name, cfg, pages, tree: treeOf(files), pm, credit: opts.credit }) }
1064
+ ]);
1065
+ const warnings = await patchProject(root, cfg, version);
1066
+ spin.stop("Structure generated");
1067
+ for (const w of warnings) p2.log.warn(w);
1068
+ if (opts.git) {
1069
+ const inside = await run("git", ["rev-parse", "--is-inside-work-tree"], root).then(
1070
+ () => true,
1071
+ () => false
1072
+ );
1073
+ if (!inside) {
1074
+ await run("git", ["init"], root).then(
1075
+ () => p2.log.success("Initialized a git repository"),
1076
+ () => p2.log.warn("Could not initialize git (is git installed?)")
1077
+ );
1078
+ }
1079
+ }
1080
+ if (opts.install) {
1081
+ p2.log.step(`Installing dependencies with ${pm}...`);
1082
+ await run(pm, ["install"], root, true);
1083
+ }
1084
+ const dev = pm === "npm" ? "npm run dev" : `${pm} dev`;
1085
+ p2.note([`cd ${name}`, ...opts.install ? [] : [`${pm} install`], dev].join("\n"), "Next steps");
1086
+ p2.outro(closingLine());
1087
+ }
1088
+
1089
+ // src/cli.ts
1090
+ async function main(argv = process.argv.slice(2)) {
1091
+ const program = new Command();
1092
+ program.name("zakieh").description("Scaffold a Next.js or React project with the folder architecture you choose.").version(package_default.version);
1093
+ program.command("create [name]").description("Create a new project").option("--framework <framework>", "next or react").option("--lang <language>", "ts or js").option("--arch <architecture>", "tba, fba or hybrid").option("--pages <names>", 'page names separated by commas (a "home" page is always added)').option("--dynamic <names>", "pages that get a /name/[id] route").option("--layout <names>", "pages that get their own layout").option("--pm <manager>", "npm, pnpm, yarn or bun (default: the one running the command)").option("-y, --yes", "skip the questions and use defaults for anything not given").option("--no-install", "do not install dependencies").option("--no-git", "do not initialize a git repository").option("--no-credit", 'leave the "Generated with Zakieh" line out of the project README').option("--dry-run", "show the structure without writing any files").action((name, opts) => createCommand(name, opts, package_default.version));
1094
+ const add = program.command("add").description("Add a page or a feature to an existing project");
1095
+ add.command("page <name>").description("Add a page (run inside a project created with zakieh)").option("--dynamic", "create a /name/[id] route").option("--layout", "create a layout for the page").option("--dry-run", "show the files without writing them").action((name, opts) => addPageCommand(name, opts));
1096
+ add.command("feature <name>").description('Add a feature without a page, for example "auth" or "cart"').option("--dry-run", "show the files without writing them").action((name, opts) => addFeatureCommand(name, opts));
1097
+ try {
1098
+ await program.parseAsync(argv, { from: "user" });
1099
+ } catch (error) {
1100
+ if (error instanceof UserError) console.error(`
1101
+ ${pc4.red("Error:")} ${error.message}
1102
+ `);
1103
+ else console.error(error);
1104
+ process.exitCode = 1;
1105
+ }
1106
+ }
1107
+
1108
+ export {
1109
+ planPage,
1110
+ planFeature,
1111
+ planProject,
1112
+ renderTree,
1113
+ main
1114
+ };
@@ -0,0 +1,39 @@
1
+ declare function main(argv?: string[]): Promise<void>;
2
+
3
+ type Framework = 'next' | 'react';
4
+ type Language = 'ts' | 'js';
5
+ type Architecture = 'tba' | 'fba' | 'hybrid';
6
+ interface ProjectConfig {
7
+ framework: Framework;
8
+ language: Language;
9
+ architecture: Architecture;
10
+ srcDir: 'src';
11
+ alias: '@/';
12
+ }
13
+ interface PageSpec {
14
+ /** kebab-case name, e.g. "about-us". The page called "home" is the "/" route. */
15
+ name: string;
16
+ /** Generates a detail page at /<name>/[id] instead of /<name>. */
17
+ dynamic: boolean;
18
+ /** Generates a layout that wraps the page. */
19
+ layout: boolean;
20
+ }
21
+ interface FileOp {
22
+ /** Path relative to the project root, always with forward slashes. */
23
+ path: string;
24
+ content: string;
25
+ }
26
+
27
+ declare function planPage(cfg: ProjectConfig, page: PageSpec): FileOp[];
28
+ declare function planFeature(cfg: ProjectConfig, name: string): FileOp[];
29
+ interface ProjectPlanOptions {
30
+ /** Content of the global stylesheet that Vite generated (React only). */
31
+ indexCss?: string;
32
+ }
33
+ declare function planProject(cfg: ProjectConfig, pages: PageSpec[], options?: ProjectPlanOptions): FileOp[];
34
+
35
+ /** Renders paths as a folder tree. `.gitkeep` files are hidden but keep their folder visible. */
36
+ declare function renderTree(paths: string[], rootLabel: string): string;
37
+
38
+ export { main, planFeature, planPage, planProject, renderTree };
39
+ export type { Architecture, FileOp, Framework, Language, PageSpec, ProjectConfig };
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ import {
2
+ main,
3
+ planFeature,
4
+ planPage,
5
+ planProject,
6
+ renderTree
7
+ } from "./chunk-3HVND4FT.js";
8
+ export {
9
+ main,
10
+ planFeature,
11
+ planPage,
12
+ planProject,
13
+ renderTree
14
+ };
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "zakieh",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Scaffold a Next.js or React project with the folder architecture you choose (TBA, FBA or Hybrid).",
5
+ "keywords": [
6
+ "scaffold",
7
+ "cli",
8
+ "nextjs",
9
+ "react",
10
+ "vite",
11
+ "architecture",
12
+ "feature-based",
13
+ "create-app"
14
+ ],
15
+ "author": "Houzayfa Zakieh (حذيفة زكيه) <https://zakieh.dev>",
16
+ "homepage": "https://zakieh.dev",
17
+ "license": "MIT",
18
+ "type": "module",
19
+ "bin": {
20
+ "zakieh": "dist/bin.js"
21
+ },
22
+ "main": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "engines": {
36
+ "node": ">=20"
37
+ },
38
+ "dependencies": {
39
+ "@clack/prompts": "^1.9.0",
40
+ "commander": "^15.1.0",
41
+ "execa": "^10.2.1",
42
+ "jsonc-parser": "^3.3.1",
43
+ "picocolors": "^1.1.1"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^26.6.11",
47
+ "tsup": "^9.0.0",
48
+ "typescript": "^5.9.3",
49
+ "vitest": "^5.1.2"
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/Houzayfa-Zakieh/zakieh.git",
54
+ "directory": "packages/zakieh"
55
+ },
56
+ "bugs": {
57
+ "url": "https://github.com/Houzayfa-Zakieh/zakieh/issues"
58
+ },
59
+ "scripts": {
60
+ "build": "tsup",
61
+ "dev": "tsup --watch",
62
+ "test": "vitest run",
63
+ "typecheck": "tsc --noEmit"
64
+ }
6
65
  }