@shakil-dev/shakil-stack 2.2.3 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +164 -33
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as
|
|
2
|
+
import{Command as le}from"commander";import te from"fs-extra";import T from"path";import{fileURLToPath as ue}from"url";import s from"fs-extra";import o from"path";import n from"chalk";import ae from"ora";import _ from"inquirer";import{execSync as oe}from"child_process";import xe from"fs-extra";var i=(e,r=process.cwd())=>{try{return oe(e,{stdio:"inherit",cwd:r}),!0}catch{return!1}},h=()=>{let e=process.env.npm_config_user_agent||"";return e.includes("pnpm")?"pnpm":e.includes("yarn")?"yarn":"npm"};var k=e=>`import { Server } from 'http';
|
|
3
3
|
import app from './app.js';
|
|
4
4
|
import config from './app/config/index.js';
|
|
5
5
|
|
|
@@ -14,7 +14,7 @@ async function bootstrap() {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
bootstrap();
|
|
17
|
-
`,
|
|
17
|
+
`,j=e=>`import cors from 'cors';
|
|
18
18
|
import express, { Application, Request, Response } from 'express';
|
|
19
19
|
import httpStatus from 'http-status';
|
|
20
20
|
import globalErrorHandler from './app/middleware/globalErrorHandler.js';
|
|
@@ -65,10 +65,10 @@ app.use(globalErrorHandler);
|
|
|
65
65
|
app.use(notFound);
|
|
66
66
|
|
|
67
67
|
export default app;
|
|
68
|
-
`,
|
|
68
|
+
`,v=`import dotenv from 'dotenv';
|
|
69
69
|
import path from 'path';
|
|
70
70
|
|
|
71
|
-
dotenv.config({ path: path.join(process.cwd(),
|
|
71
|
+
dotenv.config({ path: path.join(process.cwd(), "..", ".env") });
|
|
72
72
|
|
|
73
73
|
export default {
|
|
74
74
|
env: process.env.NODE_ENV,
|
|
@@ -90,7 +90,7 @@ const prisma = new PrismaClient({ adapter });
|
|
|
90
90
|
|
|
91
91
|
export default prisma;
|
|
92
92
|
export { prisma };
|
|
93
|
-
`,
|
|
93
|
+
`,S=`import { betterAuth } from "better-auth";
|
|
94
94
|
import { prismaAdapter } from "better-auth/adapters/prisma";
|
|
95
95
|
import config from "../config/index.js";
|
|
96
96
|
import { prisma } from "./prisma.js";
|
|
@@ -106,7 +106,7 @@ export const auth = betterAuth({
|
|
|
106
106
|
enabled: true,
|
|
107
107
|
},
|
|
108
108
|
});
|
|
109
|
-
`,
|
|
109
|
+
`,E=`import { Router } from 'express';
|
|
110
110
|
const router = Router();
|
|
111
111
|
export default router;
|
|
112
112
|
`,A=`import { ErrorRequestHandler } from 'express';
|
|
@@ -121,7 +121,7 @@ const globalErrorHandler: ErrorRequestHandler = (error, req, res, next) => {
|
|
|
121
121
|
};
|
|
122
122
|
|
|
123
123
|
export default globalErrorHandler;
|
|
124
|
-
`,
|
|
124
|
+
`,C=`import { Request, Response, NextFunction } from 'express';
|
|
125
125
|
import httpStatus from 'http-status';
|
|
126
126
|
|
|
127
127
|
const notFound = (req: Request, res: Response, next: NextFunction) => {
|
|
@@ -132,7 +132,7 @@ const notFound = (req: Request, res: Response, next: NextFunction) => {
|
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
export default notFound;
|
|
135
|
-
`,
|
|
135
|
+
`,D=`import { NextFunction, Request, RequestHandler, Response } from 'express';
|
|
136
136
|
|
|
137
137
|
const catchAsync = (fn: RequestHandler) => {
|
|
138
138
|
return async (req: Request, res: Response, next: NextFunction) => {
|
|
@@ -145,7 +145,7 @@ const catchAsync = (fn: RequestHandler) => {
|
|
|
145
145
|
};
|
|
146
146
|
|
|
147
147
|
export default catchAsync;
|
|
148
|
-
|
|
148
|
+
`,F=`class ApiError extends Error {
|
|
149
149
|
statusCode: number;
|
|
150
150
|
constructor(statusCode: number, message: string | undefined, stack = '') {
|
|
151
151
|
super(message);
|
|
@@ -155,7 +155,7 @@ export default catchAsync;
|
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
export default ApiError;
|
|
158
|
-
`,
|
|
158
|
+
`,O=`import { JSDOM } from 'jsdom';
|
|
159
159
|
import createDOMPurify from 'dompurify';
|
|
160
160
|
|
|
161
161
|
const window = new JSDOM('').window;
|
|
@@ -170,7 +170,7 @@ export const sanitize = (data: any): any => {
|
|
|
170
170
|
}
|
|
171
171
|
return data;
|
|
172
172
|
};
|
|
173
|
-
`,
|
|
173
|
+
`,P=`import { Request, Response, NextFunction } from 'express';
|
|
174
174
|
import { sanitize } from '../utils/sanitizer.js';
|
|
175
175
|
|
|
176
176
|
export const sanitizeRequest = (req: Request, res: Response, next: NextFunction) => {
|
|
@@ -179,7 +179,7 @@ export const sanitizeRequest = (req: Request, res: Response, next: NextFunction)
|
|
|
179
179
|
if (req.params) sanitize(req.params);
|
|
180
180
|
next();
|
|
181
181
|
};
|
|
182
|
-
`,
|
|
182
|
+
`,I=`import { Response } from 'express';
|
|
183
183
|
|
|
184
184
|
type IResponse<T> = {
|
|
185
185
|
statusCode: number;
|
|
@@ -203,15 +203,16 @@ const sendResponse = <T>(res: Response, data: IResponse<T>) => {
|
|
|
203
203
|
};
|
|
204
204
|
|
|
205
205
|
export default sendResponse;
|
|
206
|
-
|
|
206
|
+
`,$=`generator client {
|
|
207
207
|
provider = "prisma-client-js"
|
|
208
208
|
previewFeatures = ["prismaSchemaFolder"]
|
|
209
|
+
output = "../../generated/prisma"
|
|
209
210
|
}
|
|
210
211
|
|
|
211
212
|
datasource db {
|
|
212
213
|
provider = "postgresql"
|
|
213
214
|
}
|
|
214
|
-
`,
|
|
215
|
+
`,N=`model User {
|
|
215
216
|
id String @id @default(uuid())
|
|
216
217
|
email String @unique
|
|
217
218
|
name String
|
|
@@ -247,7 +248,7 @@ model Account {
|
|
|
247
248
|
updatedAt DateTime @updatedAt
|
|
248
249
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
249
250
|
}
|
|
250
|
-
`,
|
|
251
|
+
`,q=`import "dotenv/config";
|
|
251
252
|
import { defineConfig } from "prisma/config";
|
|
252
253
|
import process from "process";
|
|
253
254
|
|
|
@@ -257,7 +258,7 @@ export default defineConfig({
|
|
|
257
258
|
url: process.env.DATABASE_URL,
|
|
258
259
|
},
|
|
259
260
|
});
|
|
260
|
-
`,
|
|
261
|
+
`,H=`{
|
|
261
262
|
"compilerOptions": {
|
|
262
263
|
"target": "ES2022",
|
|
263
264
|
"module": "NodeNext",
|
|
@@ -276,19 +277,149 @@ export default defineConfig({
|
|
|
276
277
|
"include": ["src/**/*"],
|
|
277
278
|
"exclude": ["node_modules", "dist"]
|
|
278
279
|
}
|
|
279
|
-
`;var
|
|
280
|
+
`;var L=`MIT License
|
|
281
|
+
|
|
282
|
+
Copyright (c) 2026 Shakil Ahmed Billal
|
|
283
|
+
|
|
284
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
285
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
286
|
+
in the Software without restriction, including without limitation the rights
|
|
287
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
288
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
289
|
+
furnished to do so, subject to the following conditions:
|
|
290
|
+
|
|
291
|
+
The above copyright notice and this permission notice shall be included in all
|
|
292
|
+
copies or substantial portions of the Software.
|
|
293
|
+
|
|
294
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
295
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
296
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
297
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
298
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
299
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
300
|
+
SOFTWARE.
|
|
301
|
+
`,z=`# Contributor Covenant Code of Conduct
|
|
302
|
+
|
|
303
|
+
## Our Pledge
|
|
304
|
+
|
|
305
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
306
|
+
contributors and maintainers pledge to making participation in our project and
|
|
307
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
308
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
309
|
+
education, socio-economic status, nationality, personal appearance, race,
|
|
310
|
+
religion, or sexual identity and orientation.
|
|
311
|
+
|
|
312
|
+
## Our Standards
|
|
313
|
+
|
|
314
|
+
Examples of behavior that contributes to creating a positive environment
|
|
315
|
+
include:
|
|
316
|
+
|
|
317
|
+
* Using welcoming and inclusive language
|
|
318
|
+
* Being respectful of differing viewpoints and experiences
|
|
319
|
+
* Gracefully accepting constructive criticism
|
|
320
|
+
* Focusing on what is best for the community
|
|
321
|
+
* Showing empathy towards other community members
|
|
322
|
+
|
|
323
|
+
Examples of unacceptable behavior by participants include:
|
|
324
|
+
|
|
325
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
326
|
+
advances
|
|
327
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
328
|
+
* Public or private harassment
|
|
329
|
+
* Publishing others' private information, such as a physical or electronic
|
|
330
|
+
address, without explicit permission
|
|
331
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
332
|
+
professional setting
|
|
333
|
+
|
|
334
|
+
## Our Responsibilities
|
|
335
|
+
|
|
336
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
337
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
338
|
+
response to any instances of unacceptable behavior.
|
|
339
|
+
|
|
340
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
341
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
342
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
343
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
344
|
+
threatening, offensive, or harmful.
|
|
345
|
+
|
|
346
|
+
## Scope
|
|
347
|
+
|
|
348
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
349
|
+
when an individual is representing the project or its community. Examples of
|
|
350
|
+
representing a project or community include using an official project e-mail
|
|
351
|
+
address, posting via an official social media account, or acting as an
|
|
352
|
+
appointed representative at an online or offline event. Representation of a
|
|
353
|
+
project may be further defined and clarified by project maintainers.
|
|
354
|
+
|
|
355
|
+
## Enforcement
|
|
356
|
+
|
|
357
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
358
|
+
reported by contacting the project team. All complaints will be reviewed and
|
|
359
|
+
investigated and will result in a response that is deemed necessary and
|
|
360
|
+
appropriate to the circumstances. The project team will maintain confidentiality
|
|
361
|
+
with regard to the reporter of an incident. Further details of specific
|
|
362
|
+
enforcement policies may be posted separately.
|
|
363
|
+
|
|
364
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
365
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
366
|
+
members of the project's leadership.
|
|
367
|
+
|
|
368
|
+
## Attribution
|
|
369
|
+
|
|
370
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
371
|
+
version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
|
372
|
+
|
|
373
|
+
[homepage]: http://contributor-covenant.org
|
|
374
|
+
[version]: http://contributor-covenant.org/version/1/4
|
|
375
|
+
`,M=`node_modules/
|
|
376
|
+
.env
|
|
377
|
+
dist/
|
|
378
|
+
*.log
|
|
379
|
+
.DS_Store
|
|
380
|
+
`,U=e=>`# \u{1F680} ${e}
|
|
381
|
+
|
|
382
|
+
This project was generated using [Shakil-Stack](https://github.com/shakil-ahmed-billal/shakil-stack-cli).
|
|
383
|
+
|
|
384
|
+
## \u{1F4C2} Project Structure
|
|
385
|
+
|
|
386
|
+
\`\`\`text
|
|
387
|
+
${e}/
|
|
388
|
+
\u251C\u2500\u2500 backend/ # Express.js + Prisma
|
|
389
|
+
\u251C\u2500\u2500 frontend/ # Next.js + Tailwind
|
|
390
|
+
\u251C\u2500\u2500 .env # Root environment variables
|
|
391
|
+
\u251C\u2500\u2500 .gitignore # Root gitignore
|
|
392
|
+
\u251C\u2500\u2500 LICENSE # Project license
|
|
393
|
+
\u2514\u2500\u2500 README.md # This file
|
|
394
|
+
\`\`\`
|
|
395
|
+
|
|
396
|
+
## \u{1F680} Getting Started
|
|
397
|
+
|
|
398
|
+
1. **Environment**: Update the root \`.env\` file with your credentials.
|
|
399
|
+
2. **Database**: Migrate your database:
|
|
400
|
+
\`\`\`bash
|
|
401
|
+
cd backend
|
|
402
|
+
pnpm prisma migrate dev
|
|
403
|
+
\`\`\`
|
|
404
|
+
3. **Launch**: Run the development servers:
|
|
405
|
+
- Backend: \`cd backend && pnpm dev\`
|
|
406
|
+
- Frontend: \`cd frontend && pnpm dev\`
|
|
407
|
+
|
|
408
|
+
---
|
|
409
|
+
Built with \u26A1 by **Shakil Ahmed Billal**
|
|
410
|
+
`;var x=async e=>{let r=e;r||(r=(await _.prompt([{type:"input",name:"projectName",message:"What is your project name?",default:"shakil-stack-app"}])).projectName),r||(console.log(n.red("\u274C Error: Project name is required.")),process.exit(1));let{packageManager:a,useShadcn:g,installDeps:c}=await _.prompt([{type:"list",name:"packageManager",message:"Which package manager do you want to use?",choices:["pnpm","npm","yarn"],default:h()},{type:"confirm",name:"useShadcn",message:"Would you like to use shadcn/ui?",default:!0},{type:"confirm",name:"installDeps",message:"Do you want to install dependencies automatically?",default:!0}]),t=o.join(process.cwd(),r);s.existsSync(t)&&(console.log(n.red(`\u274C Error: Directory ${r} already exists.`)),process.exit(1)),console.log(n.cyan(`
|
|
280
411
|
\u{1F680} Initializing ${n.bold(r)}...
|
|
281
|
-
`));let
|
|
282
|
-
\u{1F5BC}\uFE0F Scaffolding Next.js frontend...`)),i(`npx create-next-app@latest frontend --ts --tailwind --eslint --app --src-dir --import-alias "@/*" --use-${a}`,t);let
|
|
283
|
-
\u{1F3A8} Setting up shadcn/ui...`));try{i("npx shadcn@latest init -d",
|
|
284
|
-
\u26A0\uFE0F Warning: Failed to automate shadcn/ui init. You can run "npx shadcn@latest init" in the frontend folder.`))}}await
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
412
|
+
`));let d=ae("\u{1F6E0}\uFE0F Creating project structure...").start();try{await s.ensureDir(t),await s.ensureDir(o.join(t,"backend","src","app","config")),await s.ensureDir(o.join(t,"backend","src","app","lib")),await s.ensureDir(o.join(t,"backend","src","app","module")),await s.ensureDir(o.join(t,"backend","src","app","routes")),await s.ensureDir(o.join(t,"backend","src","app","middleware")),await s.ensureDir(o.join(t,"backend","src","app","utils")),await s.ensureDir(o.join(t,"backend","src","app","errorHelpers")),await s.ensureDir(o.join(t,"backend","prisma","schema")),console.log(n.cyan(`
|
|
413
|
+
\u{1F5BC}\uFE0F Scaffolding Next.js frontend...`)),i(`npx create-next-app@latest frontend --ts --tailwind --eslint --app --src-dir --import-alias "@/*" --use-${a}`,t);let m=["config","hooks","lib","services","types"];for(let f of m)await s.ensureDir(o.join(t,"frontend","src",f));if(g){console.log(n.cyan(`
|
|
414
|
+
\u{1F3A8} Setting up shadcn/ui...`));try{i("npx shadcn@latest init -d",o.join(t,"frontend")),console.log(n.cyan("\u{1F4E6} Adding common shadcn/ui components...")),i(`npx shadcn@latest add ${["button","card","input","label","textarea","dialog","dropdown-menu","table","tabs","checkbox"].join(" ")} -y`,o.join(t,"frontend")),console.log(n.green("\u2705 shadcn/ui and common components initialized successfully!\u2728"))}catch{console.log(n.yellow(`
|
|
415
|
+
\u26A0\uFE0F Warning: Failed to automate shadcn/ui init. You can run "npx shadcn@latest init" in the frontend folder.`))}}await s.outputFile(o.join(t,"backend","src","server.ts"),k(r)),await s.outputFile(o.join(t,"backend","src","app.ts"),j(r)),await s.outputFile(o.join(t,"backend","src","app","config","index.ts"),v),await s.outputFile(o.join(t,"backend","src","app","lib","prisma.ts"),R),await s.outputFile(o.join(t,"backend","src","app","lib","auth.ts"),S),await s.outputFile(o.join(t,"backend","src","app","routes","index.ts"),E),await s.outputFile(o.join(t,"backend","src","app","middleware","globalErrorHandler.ts"),A),await s.outputFile(o.join(t,"backend","src","app","middleware","notFound.ts"),C),await s.outputFile(o.join(t,"backend","src","app","middleware","sanitizeRequest.ts"),P),await s.outputFile(o.join(t,"backend","src","app","utils","catchAsync.ts"),D),await s.outputFile(o.join(t,"backend","src","app","utils","sendResponse.ts"),I),await s.outputFile(o.join(t,"backend","src","app","utils","sanitizer.ts"),O),await s.outputFile(o.join(t,"backend","src","app","errorHelpers","ApiError.ts"),F),await s.outputFile(o.join(t,"backend","prisma","schema","schema.prisma"),$),await s.outputFile(o.join(t,"backend","prisma","schema","auth.prisma"),N);let y=["meal.prisma","order.prisma","provider.prisma","review.prisma"];for(let f of y)await s.outputFile(o.join(t,"backend","prisma","schema",f),"// ${schema.split('.')[0].charAt(0).toUpperCase() + schema.split('.')[0].slice(1)} model\n");await s.outputFile(o.join(t,"backend","prisma.config.ts"),q),await s.outputFile(o.join(t,"backend","tsconfig.json"),H),await s.outputFile(o.join(t,".gitignore"),M),await s.outputFile(o.join(t,"LICENSE"),L),await s.outputFile(o.join(t,"README.md"),U(r)),await s.outputFile(o.join(t,"CODE_OF_CONDUCT.md"),z),await s.outputFile(o.join(t,".env"),`DATABASE_URL="postgresql://postgres:postgres@localhost:5432/${r}"
|
|
416
|
+
JWT_SECRET="your-secret-key"
|
|
417
|
+
NODE_ENV="development"
|
|
418
|
+
PORT=8000`);let re={name:`${r}-backend`,version:"1.0.0",type:"module",scripts:{test:'echo "Error: no test specified" && exit 1',dev:"nodemon --exec tsx src/server.ts",build:"prisma generate && tsup src/server.ts --format esm --platform node --target node20 --outDir dist --external pg-native",postinstall:"prisma generate",start:"node dist/server.js","prisma:generate":"prisma generate","prisma:migrate":"prisma migrate dev","prisma:studio":"prisma studio",seed:"tsx prisma/seed.ts",setup:"pnpm install && pnpm add @prisma/adapter-pg pg && pnpm add -D @types/pg && pnpm prisma:generate",predev:"pnpm run prisma:generate",init:"pnpm run prisma:generate && pnpm run prisma:migrate --name init",lint:"eslint src/**/*.ts","lint:fix":"eslint src/**/*.ts --fix",format:"prettier --write .",push:"prisma db push",pull:"prisma db pull"},dependencies:{"@prisma/adapter-pg":"^7.5.0","@prisma/client":"^7.5.0","better-auth":"^1.5.6","cookie-parser":"^1.4.7",cors:"^2.8.6",dompurify:"^3.3.3",dotenv:"^17.3.1",express:"^5.2.1","express-rate-limit":"^8.3.1",helmet:"^8.1.0","http-status":"^2.1.0",jsdom:"^29.0.1",jsonwebtoken:"^9.0.3",morgan:"^1.10.1",pg:"^8.20.0",winston:"^3.19.0",zod:"^4.3.6"},devDependencies:{"@types/cookie-parser":"^1.4.10","@types/cors":"^2.8.19","@types/express":"^5.0.6","@types/node":"^20.19.37","@types/pg":"^8.20.0","@types/morgan":"^1.9.10","@types/jsdom":"^21.1.7",prisma:"^7.5.0",tsx:"^4.21.0",nodemon:"^3.1.14",tsup:"^8.5.1",typescript:"^5.9.3",eslint:"^9.21.0",prettier:"^3.5.2"}};await s.writeJson(o.join(t,"backend","package.json"),re,{spaces:2}),d.succeed(n.green("\u2705 Project structure created! \u2728")),c&&(console.log(n.yellow(`
|
|
288
419
|
\u{1F4E6} Finalizing dependencies with ${a}...
|
|
289
|
-
`)),i(`${a} install`,
|
|
420
|
+
`)),i(`${a} install`,o.join(t,"backend"))),console.log(n.cyan("To get started:")),console.log(n.white(` cd ${r}`)),console.log(n.white(` cd backend && ${a} dev
|
|
290
421
|
`)),console.log(n.white(` cd frontend && ${a} dev
|
|
291
|
-
`))}catch(
|
|
422
|
+
`))}catch(m){d.fail(n.red("\u274C Failed to initialize project.")),console.error(m),process.exit(1)}};import l from"fs-extra";import b from"path";import p from"chalk";import pe from"ora";var B=(e,r)=>`import { Request, Response } from 'express';
|
|
292
423
|
import httpStatus from 'http-status';
|
|
293
424
|
import catchAsync from '../../utils/catchAsync.js';
|
|
294
425
|
import sendResponse from '../../utils/sendResponse.js';
|
|
@@ -307,7 +438,7 @@ const create${e} = catchAsync(async (req: Request, res: Response) => {
|
|
|
307
438
|
export const ${e}Controller = {
|
|
308
439
|
create${e},
|
|
309
440
|
};
|
|
310
|
-
`,
|
|
441
|
+
`,W=(e,r)=>`import { ${e} } from '@prisma/client';
|
|
311
442
|
import prisma from '../../lib/prisma.js';
|
|
312
443
|
|
|
313
444
|
const create${e}IntoDB = async (payload: any) => {
|
|
@@ -318,7 +449,7 @@ const create${e}IntoDB = async (payload: any) => {
|
|
|
318
449
|
export const ${e}Service = {
|
|
319
450
|
create${e}IntoDB,
|
|
320
451
|
};
|
|
321
|
-
`,
|
|
452
|
+
`,G=(e,r)=>`import { Router } from 'express';
|
|
322
453
|
import { ${e}Controller } from './${r}.controller.js';
|
|
323
454
|
|
|
324
455
|
const router = Router();
|
|
@@ -326,10 +457,10 @@ const router = Router();
|
|
|
326
457
|
router.post('/create-${r}', ${e}Controller.create${e});
|
|
327
458
|
|
|
328
459
|
export const ${e}Routes = router;
|
|
329
|
-
`,
|
|
460
|
+
`,V=e=>`export type I${e} = {
|
|
330
461
|
// Define interface
|
|
331
462
|
};
|
|
332
|
-
`,
|
|
463
|
+
`,J=e=>`import { z } from 'zod';
|
|
333
464
|
|
|
334
465
|
const create${e}ValidationSchema = z.object({
|
|
335
466
|
body: z.object({
|
|
@@ -340,11 +471,11 @@ const create${e}ValidationSchema = z.object({
|
|
|
340
471
|
export const ${e}Validations = {
|
|
341
472
|
create${e}ValidationSchema,
|
|
342
473
|
};
|
|
343
|
-
`,
|
|
344
|
-
`,
|
|
474
|
+
`,Y=e=>`export const ${e}SearchableFields = [];
|
|
475
|
+
`,K=e=>`model ${e} {
|
|
345
476
|
id String @id @default(uuid())
|
|
346
477
|
name String
|
|
347
478
|
createdAt DateTime @default(now())
|
|
348
479
|
updatedAt DateTime @updatedAt
|
|
349
480
|
}
|
|
350
|
-
`;var
|
|
481
|
+
`;var X=async e=>{e||(console.log(p.red("\u274C Error: Module name is required.")),process.exit(1));let r=e.charAt(0).toUpperCase()+e.slice(1),a=e.toLowerCase(),g=l.existsSync("backend")?"backend":".",c=b.join(g,"src","app","module",r);l.existsSync(b.join(g,"src","app","module"))||(console.log(p.red("\u274C Error: This command must be run inside your shakil-stack project root or backend directory.")),process.exit(1)),l.existsSync(c)&&(console.log(p.red(`\u274C Error: Module ${r} already exists.`)),process.exit(1));let t=pe(`\u{1F6E0}\uFE0F Generating module: ${p.cyan(r)}...`).start();try{await l.ensureDir(c);let d={"controller.ts":B(r,a),"service.ts":W(r,a),"route.ts":G(r,a),"interface.ts":V(r),"validation.ts":J(r),"constant.ts":Y(r)};await l.outputFile(b.join(g,"prisma","schema",`${a}.prisma`),K(r));for(let[m,y]of Object.entries(d))await l.outputFile(b.join(c,`${a}.${m}`),y);t.succeed(p.green(`\u2705 Module ${r} generated successfully! \u2728`)),console.log(p.gray(`Created at: ${c}`))}catch(d){t.fail(p.red("\u274C Failed to generate module.")),console.error(d)}};import ce from"fs-extra";import de from"chalk";var Q=async()=>{let e=h(),r=ce.existsSync("backend")?"backend":".";console.log(de.cyan(`\u{1F3D7}\uFE0F Building backend with ${e}...`)),i(`${e} run build`,r)};import me from"fs-extra";import w from"chalk";var Z=async e=>{let r=me.existsSync("backend")?"backend":".";e==="generate"?(console.log(w.cyan("\u{1F504} Generating Prisma client...")),i("npx prisma generate",r)):e==="migrate"?(console.log(w.cyan("\u{1F680} Running Prisma migrations...")),i("npx prisma migrate dev",r)):console.log(w.red(`\u274C Error: Unknown prisma subcommand: ${e}`))};var ge=ue(import.meta.url),ee=T.dirname(ge),fe=T.resolve(ee,te.existsSync(T.resolve(ee,"../../package.json"))?"../../package.json":"../package.json"),he=te.readJsonSync(fe),u=new le;u.name("shakil-stack").description("Full-stack EchoNet-style project generator CLI").version(he.version);u.command("init").description("Initialize a new full-stack project").argument("[projectName]","Name of the project").action(e=>{x(e)});u.command("generate").alias("g").description("Generate a new module").argument("<type>","Type of generation (module)").argument("<name>","Name of the module").action((e,r)=>{e==="module"?X(r):console.log(`\u274C Error: Unknown generation type: ${e}`)});u.command("build").description("Build the backend for production").action(()=>{Q()});u.command("prisma").description("Prisma utilities").argument("<subcommand>","generate | migrate").action(e=>{Z(e)});process.argv.slice(2).length?u.parse(process.argv):x();
|