@shakil-dev/shakil-stack 2.2.4 → 2.2.6
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 +170 -41
- 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 me}from"url";import s from"fs-extra";import r from"path";import n from"chalk";import ne from"ora";import _ from"inquirer";import{execSync as oe}from"child_process";import ye from"fs-extra";var i=(e,o=process.cwd())=>{try{return oe(e,{stdio:"inherit",cwd:o}),!0}catch{return!1}},f=()=>{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,
|
|
@@ -76,7 +76,7 @@ export default {
|
|
|
76
76
|
database_url: process.env.DATABASE_URL,
|
|
77
77
|
jwt_secret: process.env.JWT_SECRET,
|
|
78
78
|
};
|
|
79
|
-
`,
|
|
79
|
+
`,R=`import "dotenv/config";
|
|
80
80
|
import { PrismaClient } from "@prisma/client";
|
|
81
81
|
import pkg from 'pg';
|
|
82
82
|
import { PrismaPg } from '@prisma/adapter-pg';
|
|
@@ -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,16 +203,15 @@ 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
|
-
previewFeatures = ["prismaSchemaFolder"]
|
|
209
208
|
output = "../../generated/prisma"
|
|
210
209
|
}
|
|
211
210
|
|
|
212
211
|
datasource db {
|
|
213
212
|
provider = "postgresql"
|
|
214
213
|
}
|
|
215
|
-
`,
|
|
214
|
+
`,N=`model User {
|
|
216
215
|
id String @id @default(uuid())
|
|
217
216
|
email String @unique
|
|
218
217
|
name String
|
|
@@ -248,7 +247,7 @@ model Account {
|
|
|
248
247
|
updatedAt DateTime @updatedAt
|
|
249
248
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
250
249
|
}
|
|
251
|
-
`,
|
|
250
|
+
`,q=`import "dotenv/config";
|
|
252
251
|
import { defineConfig } from "prisma/config";
|
|
253
252
|
import process from "process";
|
|
254
253
|
|
|
@@ -258,7 +257,7 @@ export default defineConfig({
|
|
|
258
257
|
url: process.env.DATABASE_URL,
|
|
259
258
|
},
|
|
260
259
|
});
|
|
261
|
-
`,
|
|
260
|
+
`,H=`{
|
|
262
261
|
"compilerOptions": {
|
|
263
262
|
"target": "ES2022",
|
|
264
263
|
"module": "NodeNext",
|
|
@@ -277,23 +276,153 @@ export default defineConfig({
|
|
|
277
276
|
"include": ["src/**/*"],
|
|
278
277
|
"exclude": ["node_modules", "dist"]
|
|
279
278
|
}
|
|
280
|
-
`;var
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
279
|
+
`;var L=`MIT License
|
|
280
|
+
|
|
281
|
+
Copyright (c) 2026 Shakil Ahmed Billal
|
|
282
|
+
|
|
283
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
284
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
285
|
+
in the Software without restriction, including without limitation the rights
|
|
286
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
287
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
288
|
+
furnished to do so, subject to the following conditions:
|
|
289
|
+
|
|
290
|
+
The above copyright notice and this permission notice shall be included in all
|
|
291
|
+
copies or substantial portions of the Software.
|
|
292
|
+
|
|
293
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
294
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
295
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
296
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
297
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
298
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
299
|
+
SOFTWARE.
|
|
300
|
+
`,z=`# Contributor Covenant Code of Conduct
|
|
301
|
+
|
|
302
|
+
## Our Pledge
|
|
303
|
+
|
|
304
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
305
|
+
contributors and maintainers pledge to making participation in our project and
|
|
306
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
307
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
308
|
+
education, socio-economic status, nationality, personal appearance, race,
|
|
309
|
+
religion, or sexual identity and orientation.
|
|
310
|
+
|
|
311
|
+
## Our Standards
|
|
312
|
+
|
|
313
|
+
Examples of behavior that contributes to creating a positive environment
|
|
314
|
+
include:
|
|
315
|
+
|
|
316
|
+
* Using welcoming and inclusive language
|
|
317
|
+
* Being respectful of differing viewpoints and experiences
|
|
318
|
+
* Gracefully accepting constructive criticism
|
|
319
|
+
* Focusing on what is best for the community
|
|
320
|
+
* Showing empathy towards other community members
|
|
321
|
+
|
|
322
|
+
Examples of unacceptable behavior by participants include:
|
|
323
|
+
|
|
324
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
325
|
+
advances
|
|
326
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
327
|
+
* Public or private harassment
|
|
328
|
+
* Publishing others' private information, such as a physical or electronic
|
|
329
|
+
address, without explicit permission
|
|
330
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
331
|
+
professional setting
|
|
332
|
+
|
|
333
|
+
## Our Responsibilities
|
|
334
|
+
|
|
335
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
336
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
337
|
+
response to any instances of unacceptable behavior.
|
|
338
|
+
|
|
339
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
340
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
341
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
342
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
343
|
+
threatening, offensive, or harmful.
|
|
344
|
+
|
|
345
|
+
## Scope
|
|
346
|
+
|
|
347
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
348
|
+
when an individual is representing the project or its community. Examples of
|
|
349
|
+
representing a project or community include using an official project e-mail
|
|
350
|
+
address, posting via an official social media account, or acting as an
|
|
351
|
+
appointed representative at an online or offline event. Representation of a
|
|
352
|
+
project may be further defined and clarified by project maintainers.
|
|
353
|
+
|
|
354
|
+
## Enforcement
|
|
355
|
+
|
|
356
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
357
|
+
reported by contacting the project team. All complaints will be reviewed and
|
|
358
|
+
investigated and will result in a response that is deemed necessary and
|
|
359
|
+
appropriate to the circumstances. The project team will maintain confidentiality
|
|
360
|
+
with regard to the reporter of an incident. Further details of specific
|
|
361
|
+
enforcement policies may be posted separately.
|
|
362
|
+
|
|
363
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
364
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
365
|
+
members of the project's leadership.
|
|
366
|
+
|
|
367
|
+
## Attribution
|
|
368
|
+
|
|
369
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
370
|
+
version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
|
371
|
+
|
|
372
|
+
[homepage]: http://contributor-covenant.org
|
|
373
|
+
[version]: http://contributor-covenant.org/version/1/4
|
|
374
|
+
`,M=`node_modules/
|
|
375
|
+
.env
|
|
376
|
+
dist/
|
|
377
|
+
*.log
|
|
378
|
+
.DS_Store
|
|
379
|
+
`,U=e=>`# \u{1F680} ${e}
|
|
380
|
+
|
|
381
|
+
This project was generated using [Shakil-Stack](https://github.com/shakil-ahmed-billal/shakil-stack-cli).
|
|
382
|
+
|
|
383
|
+
## \u{1F4C2} Project Structure
|
|
384
|
+
|
|
385
|
+
\`\`\`text
|
|
386
|
+
${e}/
|
|
387
|
+
\u251C\u2500\u2500 backend/ # Express.js + Prisma
|
|
388
|
+
\u251C\u2500\u2500 frontend/ # Next.js + Tailwind
|
|
389
|
+
\u251C\u2500\u2500 .env # Root environment variables
|
|
390
|
+
\u251C\u2500\u2500 .gitignore # Root gitignore
|
|
391
|
+
\u251C\u2500\u2500 LICENSE # Project license
|
|
392
|
+
\u2514\u2500\u2500 README.md # This file
|
|
393
|
+
\`\`\`
|
|
394
|
+
|
|
395
|
+
## \u{1F680} Getting Started
|
|
396
|
+
|
|
397
|
+
1. **Environment**: Update the root \`.env\` file with your credentials.
|
|
398
|
+
2. **Database**: Migrate your database:
|
|
399
|
+
\`\`\`bash
|
|
400
|
+
cd backend
|
|
401
|
+
pnpm prisma migrate dev
|
|
402
|
+
\`\`\`
|
|
403
|
+
3. **Launch**: Run the development servers:
|
|
404
|
+
- Backend: \`cd backend && pnpm dev\`
|
|
405
|
+
- Frontend: \`cd frontend && pnpm dev\`
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
Built with \u26A1 by **Shakil Ahmed Billal**
|
|
409
|
+
`;var x=async e=>{let o=e;o||(o=(await _.prompt([{type:"input",name:"projectName",message:"What is your project name?",default:"shakil-stack-app"}])).projectName),o||(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:f()},{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=r.join(process.cwd(),o);s.existsSync(t)&&(console.log(n.red(`\u274C Error: Directory ${o} already exists.`)),process.exit(1)),console.log(n.cyan(`
|
|
410
|
+
\u{1F680} Initializing ${n.bold(o)}...
|
|
411
|
+
`));let d=ne("\u{1F6E0}\uFE0F Creating project structure...").start();try{await s.ensureDir(t),await s.ensureDir(r.join(t,"backend","src","app","config")),await s.ensureDir(r.join(t,"backend","src","app","lib")),await s.ensureDir(r.join(t,"backend","src","app","module")),await s.ensureDir(r.join(t,"backend","src","app","routes")),await s.ensureDir(r.join(t,"backend","src","app","middleware")),await s.ensureDir(r.join(t,"backend","src","app","utils")),await s.ensureDir(r.join(t,"backend","src","app","errorHelpers")),await s.ensureDir(r.join(t,"backend","prisma","schema")),console.log(n.cyan(`
|
|
412
|
+
\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 l=["config","hooks","lib","services","types"];for(let y of l)await s.ensureDir(r.join(t,"frontend","src",y));if(g){console.log(n.cyan(`
|
|
413
|
+
\u{1F3A8} Setting up shadcn/ui...`));try{i("npx shadcn@latest init -d",r.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`,r.join(t,"frontend")),console.log(n.green("\u2705 shadcn/ui and common components initialized successfully!\u2728"))}catch{console.log(n.yellow(`
|
|
414
|
+
\u26A0\uFE0F Warning: Failed to automate shadcn/ui init. You can run "npx shadcn@latest init" in the frontend folder.`))}}await s.outputFile(r.join(t,"backend","src","server.ts"),k(o)),await s.outputFile(r.join(t,"backend","src","app.ts"),j(o)),await s.outputFile(r.join(t,"backend","src","app","config","index.ts"),v),await s.outputFile(r.join(t,"backend","src","app","lib","prisma.ts"),R),await s.outputFile(r.join(t,"backend","src","app","lib","auth.ts"),S),await s.outputFile(r.join(t,"backend","src","app","routes","index.ts"),E),await s.outputFile(r.join(t,"backend","src","app","middleware","globalErrorHandler.ts"),A),await s.outputFile(r.join(t,"backend","src","app","middleware","notFound.ts"),C),await s.outputFile(r.join(t,"backend","src","app","middleware","sanitizeRequest.ts"),P),await s.outputFile(r.join(t,"backend","src","app","utils","catchAsync.ts"),D),await s.outputFile(r.join(t,"backend","src","app","utils","sendResponse.ts"),I),await s.outputFile(r.join(t,"backend","src","app","utils","sanitizer.ts"),O),await s.outputFile(r.join(t,"backend","src","app","errorHelpers","ApiError.ts"),F),await s.outputFile(r.join(t,"backend","prisma","schema","schema.prisma"),$),await s.outputFile(r.join(t,"backend","prisma","schema","auth.prisma"),N),await s.outputFile(r.join(t,"backend","prisma.config.ts"),q),await s.outputFile(r.join(t,"backend","tsconfig.json"),H),await s.outputFile(r.join(t,".gitignore"),M),await s.outputFile(r.join(t,"LICENSE"),L),await s.outputFile(r.join(t,"README.md"),U(o)),await s.outputFile(r.join(t,"CODE_OF_CONDUCT.md"),z),await s.outputFile(r.join(t,".env"),`DATABASE_URL="postgresql://postgres:postgres@localhost:5432/${o}"
|
|
415
|
+
JWT_SECRET="your-secret-key"
|
|
416
|
+
NODE_ENV="development"
|
|
417
|
+
PORT=8000`);let b={name:`${o}-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(r.join(t,"backend","package.json"),b,{spaces:2}),d.succeed(n.green("\u2705 Project structure created! \u2728")),c&&(console.log(n.yellow(`
|
|
418
|
+
\u{1F4E6} Finalizing dependencies with ${a}...
|
|
419
|
+
`)),i(`${a} install`,r.join(t,"backend"))),console.log(n.cyan("To get started:")),console.log(n.white(` cd ${o}`)),console.log(n.white(` cd backend && ${a} dev
|
|
420
|
+
`)),console.log(n.white(` cd frontend && ${a} dev
|
|
421
|
+
`))}catch(l){d.fail(n.red("\u274C Failed to initialize project.")),console.error(l),process.exit(1)}};import m from"fs-extra";import h from"path";import p from"chalk";import ie from"ora";var B=(e,o)=>`import { Request, Response } from 'express';
|
|
293
422
|
import httpStatus from 'http-status';
|
|
294
423
|
import catchAsync from '../../utils/catchAsync.js';
|
|
295
424
|
import sendResponse from '../../utils/sendResponse.js';
|
|
296
|
-
import { ${e}Service } from './${
|
|
425
|
+
import { ${e}Service } from './${o}.service.js';
|
|
297
426
|
|
|
298
427
|
const create${e} = catchAsync(async (req: Request, res: Response) => {
|
|
299
428
|
const result = await ${e}Service.create${e}IntoDB(req.body);
|
|
@@ -308,7 +437,7 @@ const create${e} = catchAsync(async (req: Request, res: Response) => {
|
|
|
308
437
|
export const ${e}Controller = {
|
|
309
438
|
create${e},
|
|
310
439
|
};
|
|
311
|
-
`,
|
|
440
|
+
`,W=(e,o)=>`import { ${e} } from '@prisma/client';
|
|
312
441
|
import prisma from '../../lib/prisma.js';
|
|
313
442
|
|
|
314
443
|
const create${e}IntoDB = async (payload: any) => {
|
|
@@ -319,18 +448,18 @@ const create${e}IntoDB = async (payload: any) => {
|
|
|
319
448
|
export const ${e}Service = {
|
|
320
449
|
create${e}IntoDB,
|
|
321
450
|
};
|
|
322
|
-
`,
|
|
323
|
-
import { ${e}Controller } from './${
|
|
451
|
+
`,G=(e,o)=>`import { Router } from 'express';
|
|
452
|
+
import { ${e}Controller } from './${o}.controller.js';
|
|
324
453
|
|
|
325
454
|
const router = Router();
|
|
326
455
|
|
|
327
|
-
router.post('/create-${
|
|
456
|
+
router.post('/create-${o}', ${e}Controller.create${e});
|
|
328
457
|
|
|
329
458
|
export const ${e}Routes = router;
|
|
330
|
-
`,
|
|
459
|
+
`,V=e=>`export type I${e} = {
|
|
331
460
|
// Define interface
|
|
332
461
|
};
|
|
333
|
-
`,
|
|
462
|
+
`,J=e=>`import { z } from 'zod';
|
|
334
463
|
|
|
335
464
|
const create${e}ValidationSchema = z.object({
|
|
336
465
|
body: z.object({
|
|
@@ -341,11 +470,11 @@ const create${e}ValidationSchema = z.object({
|
|
|
341
470
|
export const ${e}Validations = {
|
|
342
471
|
create${e}ValidationSchema,
|
|
343
472
|
};
|
|
344
|
-
`,
|
|
345
|
-
`,
|
|
473
|
+
`,Y=e=>`export const ${e}SearchableFields = [];
|
|
474
|
+
`,K=e=>`model ${e} {
|
|
346
475
|
id String @id @default(uuid())
|
|
347
476
|
name String
|
|
348
477
|
createdAt DateTime @default(now())
|
|
349
478
|
updatedAt DateTime @updatedAt
|
|
350
479
|
}
|
|
351
|
-
`;var
|
|
480
|
+
`;var X=async e=>{e||(console.log(p.red("\u274C Error: Module name is required.")),process.exit(1));let o=e.charAt(0).toUpperCase()+e.slice(1),a=e.toLowerCase(),g=m.existsSync("backend")?"backend":".",c=h.join(g,"src","app","module",o);m.existsSync(h.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)),m.existsSync(c)&&(console.log(p.red(`\u274C Error: Module ${o} already exists.`)),process.exit(1));let t=ie(`\u{1F6E0}\uFE0F Generating module: ${p.cyan(o)}...`).start();try{await m.ensureDir(c);let d={"controller.ts":B(o,a),"service.ts":W(o,a),"route.ts":G(o,a),"interface.ts":V(o),"validation.ts":J(o),"constant.ts":Y(o)};await m.outputFile(h.join(g,"prisma","schema",`${a}.prisma`),K(o));for(let[l,b]of Object.entries(d))await m.outputFile(h.join(c,`${a}.${l}`),b);t.succeed(p.green(`\u2705 Module ${o} 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 pe from"fs-extra";import ce from"chalk";var Q=async()=>{let e=f(),o=pe.existsSync("backend")?"backend":".";console.log(ce.cyan(`\u{1F3D7}\uFE0F Building backend with ${e}...`)),i(`${e} run build`,o)};import de from"fs-extra";import w from"chalk";var Z=async e=>{let o=de.existsSync("backend")?"backend":".";e==="generate"?(console.log(w.cyan("\u{1F504} Generating Prisma client...")),i("npx prisma generate",o)):e==="migrate"?(console.log(w.cyan("\u{1F680} Running Prisma migrations...")),i("npx prisma migrate dev",o)):console.log(w.red(`\u274C Error: Unknown prisma subcommand: ${e}`))};var ue=me(import.meta.url),ee=T.dirname(ue),ge=T.resolve(ee,te.existsSync(T.resolve(ee,"../../package.json"))?"../../package.json":"../package.json"),fe=te.readJsonSync(ge),u=new le;u.name("shakil-stack").description("Full-stack EchoNet-style project generator CLI").version(fe.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,o)=>{e==="module"?X(o):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();
|