create-mohit-next 1.0.0 → 2.0.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/README.md +96 -65
- package/index.js +195 -195
- package/lib/features.js +358 -0
- package/lib/scaffold.js +471 -0
- package/package.json +10 -6
- package/templates/common/_editorconfig +12 -0
- package/templates/common/_gitattributes +5 -0
- package/templates/common/_github/dependabot.yml +14 -0
- package/templates/common/_github/workflows/ci.yml +66 -0
- package/templates/common/_husky/commit-msg +1 -0
- package/templates/common/_husky/pre-commit +1 -0
- package/templates/common/_nvmrc +1 -0
- package/{template → templates/common}/_prettierignore +4 -0
- package/templates/common/commitlint.config.mjs +10 -0
- package/templates/next/README.md +328 -0
- package/{template → templates/next}/_env.example +10 -1
- package/{template → templates/next}/_gitignore +8 -0
- package/templates/next/e2e/rbac.spec.ts +69 -0
- package/templates/next/e2e/server.mjs +35 -0
- package/{template → templates/next}/eslint.config.mjs +12 -0
- package/{template → templates/next}/next.config.ts +2 -0
- package/{template → templates/next}/package.json +18 -3
- package/templates/next/playwright.config.ts +30 -0
- package/templates/next/scripts/seed.ts +111 -0
- package/templates/next/src/app/(app)/admin/audit/page.tsx +99 -0
- package/templates/next/src/app/(app)/admin/page.tsx +92 -0
- package/{template → templates/next}/src/app/(app)/dashboard/page.tsx +22 -29
- package/{template → templates/next}/src/app/(app)/error.tsx +7 -7
- package/{template → templates/next}/src/app/(app)/layout.tsx +25 -2
- package/templates/next/src/app/(app)/reports/page.tsx +128 -0
- package/templates/next/src/app/(app)/settings/page.tsx +66 -0
- package/templates/next/src/app/(auth)/forgot-password/page.tsx +17 -0
- package/templates/next/src/app/(auth)/layout.tsx +18 -0
- package/{template → templates/next}/src/app/(auth)/register/page.tsx +2 -4
- package/templates/next/src/app/(auth)/reset-password/page.tsx +18 -0
- package/templates/next/src/app/api/account/password/route.ts +45 -0
- package/templates/next/src/app/api/account/route.ts +25 -0
- package/templates/next/src/app/api/account/sessions/route.ts +12 -0
- package/templates/next/src/app/api/admin/audit/route.ts +13 -0
- package/{template → templates/next}/src/app/api/admin/users/[id]/route.ts +25 -4
- package/templates/next/src/app/api/auth/forgot-password/route.ts +47 -0
- package/{template → templates/next}/src/app/api/auth/login/route.ts +19 -2
- package/{template → templates/next}/src/app/api/auth/me/route.ts +4 -2
- package/{template → templates/next}/src/app/api/auth/register/route.ts +38 -4
- package/templates/next/src/app/api/auth/resend-verification/route.ts +25 -0
- package/templates/next/src/app/api/auth/reset-password/route.ts +43 -0
- package/templates/next/src/app/api/auth/verify-email/route.ts +29 -0
- package/{template → templates/next}/src/app/forbidden/page.tsx +11 -13
- package/{template → templates/next}/src/app/layout.tsx +9 -6
- package/templates/next/src/app/not-found.tsx +20 -0
- package/templates/next/src/app/opengraph-image.tsx +49 -0
- package/templates/next/src/app/page.tsx +165 -0
- package/templates/next/src/app/robots.ts +15 -0
- package/templates/next/src/app/sitemap.ts +13 -0
- package/templates/next/src/app/verify-email/page.tsx +23 -0
- package/templates/next/src/components/admin/user-actions.tsx +124 -0
- package/templates/next/src/components/admin/users-data-table.tsx +221 -0
- package/templates/next/src/components/admin/users-table.tsx +67 -0
- package/{template → templates/next}/src/components/auth/auth-card.tsx +8 -8
- package/templates/next/src/components/auth/forgot-password-form.tsx +76 -0
- package/templates/next/src/components/auth/form-field.tsx +40 -0
- package/{template → templates/next}/src/components/auth/login-form.tsx +14 -9
- package/templates/next/src/components/auth/password-input.tsx +43 -0
- package/{template → templates/next}/src/components/auth/register-form.tsx +22 -19
- package/templates/next/src/components/auth/reset-password-form.tsx +80 -0
- package/{template → templates/next}/src/components/auth/session-refresher.tsx +1 -1
- package/templates/next/src/components/auth/verify-email-banner.tsx +43 -0
- package/templates/next/src/components/auth/verify-email-status.tsx +44 -0
- package/templates/next/src/components/layout/nav-links.tsx +37 -0
- package/templates/next/src/components/layout/navbar.tsx +27 -0
- package/templates/next/src/components/layout/page-header.tsx +21 -0
- package/templates/next/src/components/layout/sidebar.tsx +83 -0
- package/templates/next/src/components/layout/skeletons.tsx +57 -0
- package/templates/next/src/components/layout/user-menu.tsx +118 -0
- package/{template → templates/next}/src/components/logo.tsx +3 -6
- package/{template → templates/next}/src/components/reports/animated-bar.tsx +1 -5
- package/templates/next/src/components/reports/role-chart.tsx +61 -0
- package/templates/next/src/components/reports/signups-chart.tsx +64 -0
- package/templates/next/src/components/role-badge.tsx +11 -0
- package/templates/next/src/components/settings/password-form.tsx +80 -0
- package/templates/next/src/components/settings/profile-form.tsx +63 -0
- package/templates/next/src/components/settings/sessions-card.tsx +70 -0
- package/templates/next/src/components/theme-toggle.tsx +61 -0
- package/templates/next/src/config/rbac.test.ts +89 -0
- package/{template → templates/next}/src/config/rbac.ts +35 -5
- package/{template → templates/next}/src/lib/api.ts +40 -4
- package/templates/next/src/lib/audit.ts +66 -0
- package/{template → templates/next}/src/lib/auth.ts +10 -2
- package/{template → templates/next}/src/lib/dal.ts +8 -5
- package/templates/next/src/lib/email-templates.ts +55 -0
- package/templates/next/src/lib/email.ts +53 -0
- package/templates/next/src/lib/env.ts +90 -0
- package/templates/next/src/lib/password-strength.test.ts +20 -0
- package/templates/next/src/lib/password-strength.ts +24 -0
- package/templates/next/src/lib/rate-limit.test.ts +47 -0
- package/templates/next/src/lib/rate-limit.ts +70 -0
- package/templates/next/src/lib/redirect.test.ts +23 -0
- package/{template → templates/next}/src/lib/session.ts +5 -1
- package/templates/next/src/lib/theme.ts +32 -0
- package/templates/next/src/lib/tokens.ts +63 -0
- package/{template → templates/next}/src/lib/users.ts +49 -12
- package/templates/next/src/lib/validations/account.ts +20 -0
- package/templates/next/src/lib/validations/auth.test.ts +39 -0
- package/{template → templates/next}/src/lib/validations/auth.ts +24 -2
- package/templates/next/src/models/audit-log.ts +33 -0
- package/templates/next/src/models/auth-token.ts +26 -0
- package/{template → templates/next}/src/models/user.ts +5 -0
- package/{template → templates/next}/src/proxy.ts +1 -1
- package/templates/next/src/styles/app.css +1092 -0
- package/{template → templates/next}/src/types/user.ts +3 -0
- package/templates/next/vitest.config.mts +13 -0
- package/templates/styles/css.css +580 -0
- package/templates/styles/tailwind.css +140 -0
- package/templates/ui/css/components/alert-dialog.tsx +172 -0
- package/templates/ui/css/components/avatar.tsx +17 -0
- package/templates/ui/css/components/badge.tsx +18 -0
- package/templates/ui/css/components/button.tsx +41 -0
- package/templates/ui/css/components/card.tsx +33 -0
- package/templates/ui/css/components/dropdown-menu.tsx +230 -0
- package/templates/ui/css/components/input.tsx +7 -0
- package/templates/ui/css/components/label.tsx +7 -0
- package/templates/ui/css/components/native-select.tsx +23 -0
- package/templates/ui/css/components/skeleton.tsx +7 -0
- package/templates/ui/css/components/slot.tsx +30 -0
- package/templates/ui/css/components/table.tsx +31 -0
- package/templates/ui/css/utils.ts +16 -0
- package/templates/ui/shadcn/components/alert-dialog.tsx +199 -0
- package/templates/ui/shadcn/components/avatar.tsx +111 -0
- package/templates/ui/shadcn/components/dropdown-menu.tsx +268 -0
- package/templates/ui/shadcn/components/table.tsx +115 -0
- package/templates/ui/tailwind/components/alert-dialog.tsx +177 -0
- package/templates/ui/tailwind/components/avatar.tsx +36 -0
- package/templates/ui/tailwind/components/badge.tsx +29 -0
- package/templates/ui/tailwind/components/button.tsx +65 -0
- package/templates/ui/tailwind/components/card.tsx +70 -0
- package/templates/ui/tailwind/components/dropdown-menu.tsx +236 -0
- package/templates/ui/tailwind/components/input.tsx +17 -0
- package/templates/ui/tailwind/components/label.tsx +16 -0
- package/templates/ui/tailwind/components/native-select.tsx +32 -0
- package/templates/ui/tailwind/components/skeleton.tsx +13 -0
- package/templates/ui/tailwind/components/slot.tsx +34 -0
- package/templates/ui/tailwind/components/table.tsx +56 -0
- package/templates/ui/tailwind/utils.ts +1 -0
- package/templates/vite/Dockerfile +29 -0
- package/templates/vite/README.md +142 -0
- package/templates/vite/_dockerignore +14 -0
- package/templates/vite/_env.example +8 -0
- package/templates/vite/_gitignore +37 -0
- package/templates/vite/e2e/app.spec.ts +41 -0
- package/templates/vite/index.html +32 -0
- package/templates/vite/nginx.conf +26 -0
- package/templates/vite/package.json +61 -0
- package/templates/vite/playwright.config.ts +27 -0
- package/templates/vite/public/favicon.svg +1 -0
- package/templates/vite/src/App.test.tsx +28 -0
- package/templates/vite/src/App.tsx +26 -0
- package/templates/vite/src/components/home.tsx +121 -0
- package/templates/vite/src/components/layout/root-layout.tsx +18 -0
- package/templates/vite/src/components/layout/site-footer.tsx +10 -0
- package/templates/vite/src/components/layout/site-header.tsx +49 -0
- package/templates/vite/src/components/theme-toggle.tsx +90 -0
- package/templates/vite/src/env.ts +36 -0
- package/templates/vite/src/lib/theme.ts +26 -0
- package/templates/vite/src/main.tsx +13 -0
- package/templates/vite/src/pages/about.tsx +52 -0
- package/templates/vite/src/pages/not-found.tsx +33 -0
- package/templates/vite/src/router.ts +24 -0
- package/templates/vite/src/styles/app.css +281 -0
- package/templates/vite/src/test/setup.ts +21 -0
- package/templates/vite/tsconfig.app.json +31 -0
- package/templates/vite/tsconfig.json +7 -0
- package/templates/vite/tsconfig.node.json +23 -0
- package/templates/vite/vite.config.ts +30 -0
- package/template/README.md +0 -262
- package/template/_prettierrc +0 -9
- package/template/components.json +0 -25
- package/template/src/app/(app)/admin/page.tsx +0 -53
- package/template/src/app/(app)/reports/page.tsx +0 -109
- package/template/src/app/(auth)/layout.tsx +0 -22
- package/template/src/app/not-found.tsx +0 -18
- package/template/src/app/page.tsx +0 -187
- package/template/src/components/admin/users-table.tsx +0 -162
- package/template/src/components/auth/form-field.tsx +0 -32
- package/template/src/components/layout/logout-button.tsx +0 -34
- package/template/src/components/layout/navbar.tsx +0 -67
- package/template/src/components/layout/page-header.tsx +0 -21
- package/template/src/components/layout/skeletons.tsx +0 -35
- package/template/src/components/role-badge.tsx +0 -17
- package/template/src/components/theme-toggle.tsx +0 -25
- package/template/src/lib/env.ts +0 -36
- package/template/src/lib/theme.ts +0 -8
- /package/{template → templates/next}/AGENTS.md +0 -0
- /package/{template → templates/next}/Dockerfile +0 -0
- /package/{template → templates/next}/_dockerignore +0 -0
- /package/{template → templates/next}/docker-compose.yml +0 -0
- /package/{template → templates/next}/public/robots.txt +0 -0
- /package/{template → templates/next}/src/app/(app)/loading.tsx +0 -0
- /package/{template → templates/next}/src/app/(auth)/login/page.tsx +0 -0
- /package/{template → templates/next}/src/app/api/admin/users/route.ts +0 -0
- /package/{template → templates/next}/src/app/api/auth/logout/route.ts +0 -0
- /package/{template → templates/next}/src/app/api/health/route.ts +0 -0
- /package/{template → templates/next}/src/app/favicon.ico +0 -0
- /package/{template → templates/next}/src/components/auth/can.tsx +0 -0
- /package/{template → templates/next}/src/components/motion/fade-in.tsx +0 -0
- /package/{template → templates/next}/src/components/providers/user-provider.tsx +0 -0
- /package/{template → templates/next}/src/config/site.ts +0 -0
- /package/{template → templates/next}/src/lib/db.ts +0 -0
- /package/{template → templates/next}/src/lib/http.ts +0 -0
- /package/{template → templates/next}/src/lib/redirect.ts +0 -0
- /package/{template → templates/next}/src/lib/validations/user.ts +0 -0
- /package/{template → templates/next}/tsconfig.json +0 -0
- /package/{template/src/app/globals.css → templates/styles/shadcn.css} +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/badge.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/button.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/card.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/input.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/label.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/native-select.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/skeleton.tsx +0 -0
- /package/{template/src/lib → templates/ui/shadcn}/utils.ts +0 -0
package/index.js
CHANGED
|
@@ -1,97 +1,89 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawn, spawnSync } from "node:child_process";
|
|
3
|
-
import crypto from "node:crypto";
|
|
4
3
|
import fs from "node:fs";
|
|
5
4
|
import path from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
5
|
|
|
8
6
|
import * as p from "@clack/prompts";
|
|
9
7
|
import pc from "picocolors";
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const DEFAULT_NAME = "my-app";
|
|
14
|
-
|
|
15
|
-
// npm strips dotfiles (and renames .gitignore) when publishing, so the template
|
|
16
|
-
// stores them with a leading underscore and we restore the real names here.
|
|
17
|
-
const RENAME_FILES = {
|
|
18
|
-
_gitignore: ".gitignore",
|
|
19
|
-
_dockerignore: ".dockerignore",
|
|
20
|
-
"_env.example": ".env.example",
|
|
21
|
-
_prettierrc: ".prettierrc",
|
|
22
|
-
_prettierignore: ".prettierignore",
|
|
23
|
-
};
|
|
9
|
+
import { FRAMEWORKS, LANGUAGES, QUESTIONS, QUESTION_KEYS, STYLES } from "./lib/features.js";
|
|
10
|
+
import { scaffold } from "./lib/scaffold.js";
|
|
24
11
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
// Never copy local build/dependency artifacts, even if they exist in template/.
|
|
28
|
-
const COPY_IGNORE = new Set(["node_modules", ".next", "next-env.d.ts", "package-lock.json", ".env.local"]);
|
|
12
|
+
const DEFAULT_NAME = "my-app";
|
|
29
13
|
|
|
30
14
|
const HELP = `
|
|
31
|
-
${pc.bold("create-mohit-next")} - scaffold a
|
|
15
|
+
${pc.bold("create-mohit-next")} - scaffold a production-ready React app (Next.js or Vite)
|
|
32
16
|
|
|
33
17
|
${pc.bold("Usage")}
|
|
34
|
-
npm create mohit-next@latest ${pc.cyan("[project-name]")} ${pc.dim("[options]")}
|
|
18
|
+
npm create mohit-next@latest ${pc.cyan("[project-name]")} ${pc.dim("-- [options]")}
|
|
35
19
|
|
|
36
|
-
${pc.bold("
|
|
37
|
-
|
|
38
|
-
--
|
|
20
|
+
${pc.bold("Choices")}
|
|
21
|
+
--ts | --js Language (default: TypeScript)
|
|
22
|
+
--next | --vite Framework (default: Next.js full-stack)
|
|
23
|
+
--shadcn | --tailwind | --css Styling (default: Tailwind + shadcn/ui)
|
|
24
|
+
|
|
25
|
+
${pc.bold("Features")} ${pc.dim("(each can be turned on/off: --<name> / --no-<name>)")}
|
|
26
|
+
${QUESTION_KEYS.join(", ")}
|
|
27
|
+
|
|
28
|
+
${pc.bold("Other")}
|
|
29
|
+
-y, --yes Skip prompts: use the defaults above with every feature on
|
|
30
|
+
--minimal Skip prompts: every optional feature off
|
|
39
31
|
--no-install Don't install dependencies
|
|
40
32
|
--no-git Don't initialize a git repository
|
|
41
33
|
-h, --help Show this help
|
|
42
34
|
|
|
43
35
|
${pc.bold("Examples")}
|
|
44
36
|
npm create mohit-next@latest my-app
|
|
45
|
-
npm create mohit-next@latest my-app -- --yes --no-docker
|
|
46
|
-
pnpm create mohit-next my-app
|
|
37
|
+
npm create mohit-next@latest my-app -- --yes --vite --css --no-docker
|
|
47
38
|
`;
|
|
48
39
|
|
|
49
40
|
// ---------------------------------------------------------------------------
|
|
50
|
-
//
|
|
41
|
+
// Arguments
|
|
51
42
|
// ---------------------------------------------------------------------------
|
|
52
43
|
|
|
53
44
|
function parseArgs(argv) {
|
|
54
|
-
const opts = { name: undefined, yes: false,
|
|
45
|
+
const opts = { name: undefined, yes: false, minimal: false, help: false, features: {} };
|
|
46
|
+
const set = (k, v) => (opts[k] = v);
|
|
47
|
+
const aliases = {
|
|
48
|
+
"--ts": () => set("lang", "ts"),
|
|
49
|
+
"--typescript": () => set("lang", "ts"),
|
|
50
|
+
"--js": () => set("lang", "js"),
|
|
51
|
+
"--javascript": () => set("lang", "js"),
|
|
52
|
+
"--next": () => set("framework", "next"),
|
|
53
|
+
"--vite": () => set("framework", "vite"),
|
|
54
|
+
"--shadcn": () => set("style", "shadcn"),
|
|
55
|
+
"--tailwind": () => set("style", "tailwind"),
|
|
56
|
+
"--css": () => set("style", "css"),
|
|
57
|
+
"--install": () => set("install", true),
|
|
58
|
+
"--no-install": () => set("install", false),
|
|
59
|
+
"--git": () => set("git", true),
|
|
60
|
+
"--no-git": () => set("git", false),
|
|
61
|
+
"-y": () => set("yes", true),
|
|
62
|
+
"--yes": () => set("yes", true),
|
|
63
|
+
"--minimal": () => set("minimal", true),
|
|
64
|
+
"-h": () => set("help", true),
|
|
65
|
+
"--help": () => set("help", true),
|
|
66
|
+
};
|
|
55
67
|
for (const arg of argv) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
break;
|
|
74
|
-
case "--no-install":
|
|
75
|
-
opts.install = false;
|
|
76
|
-
break;
|
|
77
|
-
case "--git":
|
|
78
|
-
opts.git = true;
|
|
79
|
-
break;
|
|
80
|
-
case "--no-git":
|
|
81
|
-
opts.git = false;
|
|
82
|
-
break;
|
|
83
|
-
default:
|
|
84
|
-
if (arg.startsWith("-")) {
|
|
85
|
-
console.error(pc.red(`Unknown option: ${arg}`));
|
|
86
|
-
console.log(HELP);
|
|
87
|
-
process.exit(1);
|
|
88
|
-
}
|
|
89
|
-
if (opts.name) {
|
|
90
|
-
console.error(pc.red(`Unexpected argument: ${arg}`));
|
|
91
|
-
process.exit(1);
|
|
92
|
-
}
|
|
93
|
-
opts.name = arg;
|
|
68
|
+
if (aliases[arg]) {
|
|
69
|
+
aliases[arg]();
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const feature = /^--(no-)?([a-z-]+)$/.exec(arg);
|
|
73
|
+
if (feature && QUESTION_KEYS.includes(feature[2])) {
|
|
74
|
+
opts.features[feature[2]] = !feature[1];
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (arg.startsWith("-")) {
|
|
78
|
+
console.error(pc.red(`Unknown option: ${arg}`));
|
|
79
|
+
console.log(HELP);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
if (opts.name) {
|
|
83
|
+
console.error(pc.red(`Unexpected argument: ${arg}`));
|
|
84
|
+
process.exit(1);
|
|
94
85
|
}
|
|
86
|
+
opts.name = arg;
|
|
95
87
|
}
|
|
96
88
|
return opts;
|
|
97
89
|
}
|
|
@@ -106,11 +98,12 @@ function validateProjectName(input) {
|
|
|
106
98
|
if (!value) return "Project name is required.";
|
|
107
99
|
// "." scaffolds into the current directory, whose name becomes the package name.
|
|
108
100
|
const name = value === "." ? path.basename(process.cwd()) : path.basename(value);
|
|
109
|
-
if (value === "." && name !== name.toLowerCase()) {
|
|
110
|
-
return `The current directory name "${name}" is not a valid npm package name (must be lowercase).`;
|
|
111
|
-
}
|
|
112
101
|
if (name.length > 214) return "Name must be 214 characters or fewer.";
|
|
113
|
-
if (name !== name.toLowerCase())
|
|
102
|
+
if (name !== name.toLowerCase()) {
|
|
103
|
+
return value === "."
|
|
104
|
+
? `The current directory name "${name}" is not a valid npm package name (must be lowercase).`
|
|
105
|
+
: "Name must be lowercase.";
|
|
106
|
+
}
|
|
114
107
|
if (/^[._]/.test(name)) return "Name cannot start with a dot or underscore.";
|
|
115
108
|
if (!/^[a-z0-9][a-z0-9._~-]*$/.test(name)) {
|
|
116
109
|
return "Use only lowercase letters, digits, '-', '.', '_' or '~' (npm package name rules).";
|
|
@@ -165,8 +158,7 @@ function run(cmd, args, cwd, { shell = false } = {}) {
|
|
|
165
158
|
});
|
|
166
159
|
}
|
|
167
160
|
|
|
168
|
-
// Animated spinner in a terminal; plain log lines in CI / piped output
|
|
169
|
-
// (an animated spinner would flood non-TTY logs with frames).
|
|
161
|
+
// Animated spinner in a terminal; plain log lines in CI / piped output.
|
|
170
162
|
function spinner() {
|
|
171
163
|
if (process.stdout.isTTY) return p.spinner();
|
|
172
164
|
return {
|
|
@@ -186,77 +178,41 @@ function guard(value) {
|
|
|
186
178
|
return value;
|
|
187
179
|
}
|
|
188
180
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
// ---------------------------------------------------------------------------
|
|
192
|
-
|
|
193
|
-
function copyTemplate(targetDir) {
|
|
194
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
195
|
-
fs.cpSync(TEMPLATE_DIR, targetDir, {
|
|
196
|
-
recursive: true,
|
|
197
|
-
force: false,
|
|
198
|
-
errorOnExist: false,
|
|
199
|
-
filter: (src) => !COPY_IGNORE.has(path.basename(src)),
|
|
200
|
-
});
|
|
201
|
-
for (const [from, to] of Object.entries(RENAME_FILES)) {
|
|
202
|
-
const src = path.join(targetDir, from);
|
|
203
|
-
if (fs.existsSync(src)) fs.renameSync(src, path.join(targetDir, to));
|
|
204
|
-
}
|
|
181
|
+
function questionMessage(q, framework) {
|
|
182
|
+
return typeof q.message === "function" ? q.message(framework) : q.message;
|
|
205
183
|
}
|
|
206
184
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
pkg.name = packageName;
|
|
211
|
-
if (!includeDocker) {
|
|
212
|
-
for (const script of Object.keys(pkg.scripts ?? {})) {
|
|
213
|
-
if (script.startsWith("docker:")) delete pkg.scripts[script];
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + "\n");
|
|
217
|
-
}
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
// Post-scaffold steps
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
218
188
|
|
|
219
|
-
function
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
189
|
+
function hasGit() {
|
|
190
|
+
const git = spawnSync("git", ["--version"], { stdio: "ignore" });
|
|
191
|
+
return !git.error && git.status === 0;
|
|
223
192
|
}
|
|
224
193
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
function processReadme(targetDir, { projectTitle, includeDocker, pm }) {
|
|
229
|
-
const file = path.join(targetDir, "README.md");
|
|
230
|
-
if (!fs.existsSync(file)) return;
|
|
231
|
-
let readme = fs.readFileSync(file, "utf8");
|
|
232
|
-
readme = includeDocker
|
|
233
|
-
? readme.replace(/^<!-- docker:(start|end) -->\r?\n(\r?\n)?/gm, "")
|
|
234
|
-
: readme.replace(/^<!-- docker:start -->[\s\S]*?<!-- docker:end -->\r?\n(\r?\n)?/gm, "");
|
|
235
|
-
readme = readme
|
|
236
|
-
.replaceAll("{{PROJECT_TITLE}}", projectTitle)
|
|
237
|
-
.replaceAll("npm run ", pm === "npm" ? "npm run " : runScriptCmd(pm, ""))
|
|
238
|
-
.replaceAll("npm install", `${pm} install`);
|
|
239
|
-
fs.writeFileSync(file, readme);
|
|
194
|
+
function insideGitRepo(dir) {
|
|
195
|
+
const res = spawnSync("git", ["rev-parse", "--is-inside-work-tree"], { cwd: dir, stdio: "pipe" });
|
|
196
|
+
return res.status === 0 && String(res.stdout).trim() === "true";
|
|
240
197
|
}
|
|
241
198
|
|
|
242
|
-
function
|
|
243
|
-
|
|
244
|
-
if (!
|
|
245
|
-
|
|
246
|
-
fs.writeFileSync(file, content);
|
|
199
|
+
async function gitInit(targetDir) {
|
|
200
|
+
let init = await run("git", ["init", "-b", "main"], targetDir);
|
|
201
|
+
if (!init.ok) init = await run("git", ["init"], targetDir); // git < 2.28
|
|
202
|
+
return init.ok;
|
|
247
203
|
}
|
|
248
204
|
|
|
249
|
-
function
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
205
|
+
async function gitCommit(targetDir) {
|
|
206
|
+
const s = spinner();
|
|
207
|
+
s.start("Creating the initial commit");
|
|
208
|
+
await run("git", ["add", "-A"], targetDir);
|
|
209
|
+
const commit = await run(
|
|
210
|
+
"git",
|
|
211
|
+
["commit", "-m", "chore: initial commit from create-mohit-next"],
|
|
212
|
+
targetDir,
|
|
213
|
+
);
|
|
214
|
+
if (commit.ok) s.stop("Git repository initialized with an initial commit");
|
|
215
|
+
else s.stop("Git repository initialized (commit skipped - configure git user.name/user.email)");
|
|
260
216
|
}
|
|
261
217
|
|
|
262
218
|
async function installDependencies(targetDir, pm) {
|
|
@@ -272,35 +228,6 @@ async function installDependencies(targetDir, pm) {
|
|
|
272
228
|
return false;
|
|
273
229
|
}
|
|
274
230
|
|
|
275
|
-
async function initGit(targetDir) {
|
|
276
|
-
const git = spawnSync("git", ["--version"], { stdio: "ignore" });
|
|
277
|
-
if (git.error || git.status !== 0) {
|
|
278
|
-
p.log.warn("git not found - skipping repository initialization.");
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
const inside = spawnSync("git", ["rev-parse", "--is-inside-work-tree"], { cwd: targetDir, stdio: "pipe" });
|
|
282
|
-
if (inside.status === 0 && String(inside.stdout).trim() === "true") {
|
|
283
|
-
p.log.info("Already inside a git repository - skipping git init.");
|
|
284
|
-
return false;
|
|
285
|
-
}
|
|
286
|
-
const s = spinner();
|
|
287
|
-
s.start("Initializing git repository");
|
|
288
|
-
let init = await run("git", ["init", "-b", "main"], targetDir);
|
|
289
|
-
if (!init.ok) init = await run("git", ["init"], targetDir); // git < 2.28
|
|
290
|
-
if (!init.ok) {
|
|
291
|
-
s.error("git init failed - skipping.");
|
|
292
|
-
return false;
|
|
293
|
-
}
|
|
294
|
-
await run("git", ["add", "-A"], targetDir);
|
|
295
|
-
const commit = await run("git", ["commit", "-m", "Initial commit from create-mohit-next"], targetDir);
|
|
296
|
-
if (!commit.ok) {
|
|
297
|
-
s.stop("Git repository initialized (initial commit skipped - configure git user.name/user.email)");
|
|
298
|
-
return true;
|
|
299
|
-
}
|
|
300
|
-
s.stop("Git repository initialized with an initial commit");
|
|
301
|
-
return true;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
231
|
// ---------------------------------------------------------------------------
|
|
305
232
|
// Main
|
|
306
233
|
// ---------------------------------------------------------------------------
|
|
@@ -312,16 +239,15 @@ async function main() {
|
|
|
312
239
|
return;
|
|
313
240
|
}
|
|
314
241
|
|
|
315
|
-
if (!fs.existsSync(TEMPLATE_DIR)) bail(`Template directory not found at ${TEMPLATE_DIR}`);
|
|
316
|
-
|
|
317
242
|
const pm = detectPackageManager();
|
|
318
|
-
// Without a TTY (CI, piped input) prompts can't be answered, so
|
|
319
|
-
const interactive =
|
|
243
|
+
// Without a TTY (CI, piped input) prompts can't be answered, so use defaults.
|
|
244
|
+
const interactive =
|
|
245
|
+
!args.yes && !args.minimal && Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
320
246
|
|
|
321
247
|
console.log();
|
|
322
248
|
p.intro(pc.bgCyan(pc.black(" create-mohit-next ")));
|
|
323
249
|
|
|
324
|
-
//
|
|
250
|
+
// 1. Project name ----------------------------------------------------------
|
|
325
251
|
let projectName = args.name;
|
|
326
252
|
if (projectName) {
|
|
327
253
|
const error = validateTarget(projectName);
|
|
@@ -346,50 +272,124 @@ async function main() {
|
|
|
346
272
|
const packageName = path.basename(targetDir).toLowerCase();
|
|
347
273
|
const projectTitle = toTitle(packageName) || "My App";
|
|
348
274
|
|
|
349
|
-
//
|
|
275
|
+
// 2-4. Language, framework, styling ---------------------------------------
|
|
276
|
+
const choose = async (value, message, options, fallback) => {
|
|
277
|
+
if (value) return value;
|
|
278
|
+
if (!interactive) return fallback;
|
|
279
|
+
return guard(await p.select({ message, options, initialValue: fallback }));
|
|
280
|
+
};
|
|
281
|
+
const lang = await choose(args.lang, "Which language?", LANGUAGES, "ts");
|
|
282
|
+
const framework = await choose(args.framework, "Which framework?", FRAMEWORKS, "next");
|
|
283
|
+
const style = await choose(args.style, "How do you want to style it?", STYLES, "shadcn");
|
|
284
|
+
|
|
285
|
+
const keys = new Set([framework, style]);
|
|
286
|
+
if (lang === "ts") keys.add("ts");
|
|
287
|
+
if (style !== "css") keys.add("tailwind");
|
|
288
|
+
if (framework === "next") keys.add("ui"); // the Next.js pages are built from the UI kit
|
|
289
|
+
|
|
290
|
+
// 5. Yes / no questions -----------------------------------------------------
|
|
291
|
+
const on = (key) => keys.has(key);
|
|
292
|
+
let lastGroup;
|
|
293
|
+
for (const q of QUESTIONS) {
|
|
294
|
+
if (!q.frameworks.includes(framework)) continue;
|
|
295
|
+
if (q.when && !q.when(on)) continue;
|
|
296
|
+
let answer = args.features[q.key];
|
|
297
|
+
if (answer === undefined) {
|
|
298
|
+
if (interactive) {
|
|
299
|
+
if (q.group !== lastGroup) {
|
|
300
|
+
p.log.step(pc.bold(q.group));
|
|
301
|
+
lastGroup = q.group;
|
|
302
|
+
}
|
|
303
|
+
answer = guard(
|
|
304
|
+
await p.confirm({ message: questionMessage(q, framework), initialValue: true }),
|
|
305
|
+
);
|
|
306
|
+
} else {
|
|
307
|
+
answer = !args.minimal;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (answer) keys.add(q.key);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// 6. Install / git ------------------------------------------------------------
|
|
350
314
|
const ask = async (flag, message) => {
|
|
351
315
|
if (flag !== undefined) return flag;
|
|
352
316
|
if (!interactive) return true;
|
|
353
317
|
return guard(await p.confirm({ message, initialValue: true }));
|
|
354
318
|
};
|
|
355
|
-
|
|
319
|
+
if (interactive) p.log.step(pc.bold("Setup"));
|
|
356
320
|
const install = await ask(args.install, `Install dependencies with ${pm}?`);
|
|
357
|
-
const
|
|
321
|
+
const git = await ask(args.git, "Initialize a git repository?");
|
|
322
|
+
|
|
323
|
+
// Summary + confirmation ------------------------------------------------------
|
|
324
|
+
const label = (list, value) => list.find((o) => o.value === value)?.label ?? value;
|
|
325
|
+
const features = QUESTIONS.filter((q) => keys.has(q.key)).map((q) => q.key);
|
|
326
|
+
const summary = [
|
|
327
|
+
`${pc.dim("Name")} ${packageName}`,
|
|
328
|
+
`${pc.dim("Language")} ${label(LANGUAGES, lang)}`,
|
|
329
|
+
`${pc.dim("Framework")} ${label(FRAMEWORKS, framework)}`,
|
|
330
|
+
`${pc.dim("Styling")} ${label(STYLES, style)}`,
|
|
331
|
+
`${pc.dim("Features")} ${features.length ? features.join(", ") : "none"}`,
|
|
332
|
+
].join("\n");
|
|
333
|
+
p.note(summary, "Your project");
|
|
334
|
+
if (interactive) {
|
|
335
|
+
const go = guard(await p.confirm({ message: "Create the project?", initialValue: true }));
|
|
336
|
+
if (!go) bail("Nothing was created.");
|
|
337
|
+
}
|
|
358
338
|
|
|
359
|
-
//
|
|
339
|
+
// Scaffold ----------------------------------------------------------------------
|
|
360
340
|
const s = spinner();
|
|
361
341
|
s.start(`Scaffolding project in ${pc.cyan(targetDir)}`);
|
|
342
|
+
let warnings = [];
|
|
362
343
|
try {
|
|
363
|
-
|
|
364
|
-
updatePackageJson(targetDir, packageName, includeDocker);
|
|
365
|
-
if (!includeDocker) removeDocker(targetDir);
|
|
366
|
-
processReadme(targetDir, { projectTitle, includeDocker, pm });
|
|
367
|
-
setSiteName(targetDir, projectTitle);
|
|
368
|
-
createEnvLocal(targetDir, packageName);
|
|
344
|
+
warnings = await scaffold(targetDir, { framework, lang, style, keys, packageName, projectTitle, pm });
|
|
369
345
|
} catch (err) {
|
|
370
346
|
s.error("Scaffolding failed");
|
|
371
347
|
bail(err instanceof Error ? err.message : String(err));
|
|
372
348
|
}
|
|
373
|
-
s.stop(
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
349
|
+
s.stop(
|
|
350
|
+
framework === "next"
|
|
351
|
+
? "Project files created (.env.local generated with a random JWT_SECRET)"
|
|
352
|
+
: "Project files created (.env.local generated)",
|
|
353
|
+
);
|
|
354
|
+
for (const w of warnings) p.log.warn(w);
|
|
355
|
+
|
|
356
|
+
// git init before install, so Husky can install its hooks during `install`.
|
|
357
|
+
let gitReady = false;
|
|
358
|
+
if (git) {
|
|
359
|
+
if (!hasGit()) p.log.warn("git not found - skipping repository initialization.");
|
|
360
|
+
else if (insideGitRepo(targetDir)) p.log.info("Already inside a git repository - skipping git init.");
|
|
361
|
+
else gitReady = await gitInit(targetDir);
|
|
362
|
+
}
|
|
363
|
+
const installed = install ? await installDependencies(targetDir, pm) : false;
|
|
364
|
+
// The project's own Prettier also sorts Tailwind classes (its plugin isn't bundled here).
|
|
365
|
+
if (installed && keys.has("prettier")) {
|
|
366
|
+
const exec = { npm: ["npx"], pnpm: ["pnpm", "exec"], yarn: ["yarn"], bun: ["bunx"] }[pm];
|
|
367
|
+
await run(exec[0], [...exec.slice(1), "prettier", "--write", "."], targetDir, {
|
|
368
|
+
shell: process.platform === "win32",
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
if (gitReady) await gitCommit(targetDir);
|
|
378
372
|
|
|
379
|
-
//
|
|
373
|
+
// Next steps -----------------------------------------------------------------------
|
|
380
374
|
const rel = path.relative(process.cwd(), targetDir) || ".";
|
|
381
|
-
const steps = [
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
375
|
+
const steps = [rel !== "." && `cd ${rel}`, !installed && `${pm} install`];
|
|
376
|
+
if (framework === "next") {
|
|
377
|
+
steps.push(
|
|
378
|
+
keys.has("docker")
|
|
379
|
+
? `${runScriptCmd(pm, "docker:db")} ${pc.dim("# MongoDB in Docker (or set MONGODB_URI)")}`
|
|
380
|
+
: pc.dim("# set MONGODB_URI in .env.local"),
|
|
381
|
+
);
|
|
382
|
+
if (keys.has("seed")) steps.push(`${runScriptCmd(pm, "seed")} ${pc.dim("# optional demo users")}`);
|
|
383
|
+
}
|
|
384
|
+
steps.push(runScriptCmd(pm, "dev"));
|
|
385
|
+
if (keys.has("playwright")) {
|
|
386
|
+
steps.push(pc.dim(`# before e2e tests: ${pm === "npm" ? "npx" : pm} playwright install chromium`));
|
|
387
|
+
}
|
|
388
|
+
p.note(steps.filter(Boolean).join("\n"), "Next steps");
|
|
391
389
|
p.outro(
|
|
392
|
-
|
|
390
|
+
framework === "next"
|
|
391
|
+
? `Open ${pc.cyan("http://localhost:3000")} and register - ${pc.bold("the first account becomes admin")}.`
|
|
392
|
+
: `Open ${pc.cyan("http://localhost:5173")}. Happy hacking!`,
|
|
393
393
|
);
|
|
394
394
|
}
|
|
395
395
|
|