From 654f90787b894f40ec6ab00b9dce6646a5029b79 Mon Sep 17 00:00:00 2001 From: CreedDE Date: Wed, 4 Oct 2023 20:57:37 +0200 Subject: [PATCH 1/5] install prettier --- package-lock.json | 28 ++++++++++++++++++++++++++-- package.json | 3 +++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 103a6bd..f5d6581 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "startease-cli", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "startease-cli", - "version": "1.1.0", + "version": "1.2.0", "license": "ISC", "dependencies": { "chalk": "^5.3.0", @@ -21,6 +21,9 @@ }, "bin": { "startease-cli": "cli.js" + }, + "devDependencies": { + "prettier": "^3.0.3" } }, "node_modules/@kwsites/file-exists": { @@ -824,6 +827,21 @@ "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, + "node_modules/prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", @@ -1646,6 +1664,12 @@ "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, + "prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true + }, "readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", diff --git a/package.json b/package.json index a12c6ec..f3c9bef 100644 --- a/package.json +++ b/package.json @@ -32,5 +32,8 @@ }, "bin": { "startease-cli": "./cli.js" + }, + "devDependencies": { + "prettier": "^3.0.3" } } From 9ae8be08adba04be8f59267fe1aa3c787dd8dca0 Mon Sep 17 00:00:00 2001 From: CreedDE Date: Wed, 4 Oct 2023 20:59:34 +0200 Subject: [PATCH 2/5] add prettier settings and scripts --- .prettierignore | 3 +++ .prettierrc | 7 +++++++ package.json | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..3fd1f6e --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +node_modules/ +package-lock.json +*.md \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..ec8804f --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "singleQuote": false, + "jsxSingleQuote": false, + "printWidth": 80, + "tabWidth": 2, + "semi": true +} diff --git a/package.json b/package.json index f3c9bef..7e02117 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "main": "./cli.js", "type": "module", "scripts": { - "start": "node ./cli.js" + "start": "node ./cli.js", + "format": "prettier . --write", + "format:check": "prettier . --check" }, "keywords": [ "startease", From 531d75775f82471bbc405a90caadb847b8c7d5f0 Mon Sep 17 00:00:00 2001 From: CreedDE Date: Wed, 4 Oct 2023 20:59:44 +0200 Subject: [PATCH 3/5] format current codebase --- cli.js | 72 +++--- .../expressjs/src/common/config/database.js | 6 +- .../src/common/config/environment.js | 22 +- .../expressjs/src/common/utils/appError.js | 18 +- .../src/common/utils/errorHandler.js | 82 +++---- src/test/expressjs/src/common/utils/helper.js | 6 +- src/test/expressjs/src/common/utils/logger.js | 36 +-- .../modules/controllers/user.controller.js | 20 +- .../expressjs/src/modules/routes/index.js | 11 +- .../src/modules/routes/user.route.js | 16 +- src/test/expressjs/src/server.js | 55 ++--- src/test/nestjs/src/app.module.ts | 2 +- src/test/nestjs/src/common/utils/helper.ts | 6 +- src/utils/create-backend-project.js | 207 ++++++++---------- src/utils/create-frontend-project.js | 38 ++-- src/utils/filemanager.js | 129 ++++++----- src/utils/prompts.js | 44 ++-- src/utils/stack-options.js | 62 +++--- src/utils/useGradient.js | 3 - templates/backend/django/base/asgi.js | 2 +- templates/backend/django/base/env.js | 2 +- templates/backend/django/base/manage.js | 2 +- templates/backend/django/base/settings.js | 2 +- templates/backend/django/base/wsgi.js | 2 +- .../django/django-temp/static/js/index.js | 2 +- .../django/django-temp/templates/index.html | 24 +- templates/backend/expressjs/base/database.js | 2 +- .../backend/expressjs/base/package-json.js | 32 +-- templates/backend/expressjs/base/server.js | 4 +- .../src/common/config/environment.js | 16 +- .../src/common/utils/appError.js | 18 +- .../src/common/utils/errorHandler.js | 82 +++---- .../expressjs-temp/src/common/utils/helper.js | 6 +- .../expressjs-temp/src/common/utils/logger.js | 36 +-- .../modules/controllers/user.controller.js | 20 +- .../src/modules/routes/index.js | 11 +- .../src/modules/routes/user.route.js | 16 +- templates/backend/nestjs/base/app-module.js | 4 +- templates/backend/nestjs/base/databases.js | 2 +- templates/backend/nestjs/base/environment.js | 2 +- .../nestjs/base/nestjs-package-json.js | 143 ++++++------ .../nestjs-temp/src/common/utils/helper.ts | 6 +- .../react-javascript-temp/.eslintrc.cjs | 22 +- .../reactjs/react-javascript-temp/index.html | 2 +- .../reactjs/react-javascript-temp/src/App.jsx | 14 +- .../react-javascript-temp/src/main.jsx | 12 +- .../react-javascript-temp/vite.config.js | 6 +- .../react-typescript-temp/.eslintrc.cjs | 18 +- .../reactjs/react-typescript-temp/index.html | 2 +- .../reactjs/react-typescript-temp/src/App.tsx | 14 +- .../react-typescript-temp/src/main.tsx | 12 +- .../react-typescript-temp/vite.config.ts | 6 +- 52 files changed, 674 insertions(+), 705 deletions(-) diff --git a/cli.js b/cli.js index f9c002f..7a09473 100755 --- a/cli.js +++ b/cli.js @@ -1,10 +1,10 @@ #!/usr/bin/env node -import figlet from "figlet" -import { program } from "commander" -import chalk from "chalk" -import useGradient from "./src/utils/useGradient.js" -import { createBackendProject } from "./src/utils/create-backend-project.js" +import figlet from "figlet"; +import { program } from "commander"; +import chalk from "chalk"; +import useGradient from "./src/utils/useGradient.js"; +import { createBackendProject } from "./src/utils/create-backend-project.js"; import { promptBackendFramework, promptDatabase, @@ -14,62 +14,62 @@ import { promptOrm, promptProjectName, promptProjectStack, -} from "./src/utils/prompts.js" -import { createFrontendProject } from "./src/utils/create-frontend-project.js" +} from "./src/utils/prompts.js"; +import { createFrontendProject } from "./src/utils/create-frontend-project.js"; -const toolName = "StartEase" -const jsBackendStacks = ["expressjs", "nestjs"] +const toolName = "StartEase"; +const jsBackendStacks = ["expressjs", "nestjs"]; -program.version("1.0.0").description("StartEase CLI") +program.version("1.0.0").description("StartEase CLI"); program .description("Scaffold a new project with StartEase") .action(async () => { - await startProject() - }) + await startProject(); + }); -program.parse(process.argv) +program.parse(process.argv); async function startProject() { - let framework - let projectName - let projectStack - let initDB - let database - let orm - let language + let framework; + let projectName; + let projectStack; + let initDB; + let database; + let orm; + let language; const initialMsg = `Simplify Project Setup with the. ${chalk.green( - toolName - )} CLI Tool.` + toolName, + )} CLI Tool.`; // render cli title - renderTitle() - console.log(chalk.white(initialMsg)) + renderTitle(); + console.log(chalk.white(initialMsg)); - projectName = await promptProjectName() - projectStack = await promptProjectStack() + projectName = await promptProjectName(); + projectStack = await promptProjectStack(); /** * start prompts */ if (projectStack === "frontend") { - framework = await promptFrontendFramework() - language = await promptFrontendLanguage() + framework = await promptFrontendFramework(); + language = await promptFrontendLanguage(); - await createFrontendProject(projectName, framework, language) + await createFrontendProject(projectName, framework, language); } else if (projectStack === "backend") { - framework = await promptBackendFramework() + framework = await promptBackendFramework(); - initDB = await promptInitDatabase() + initDB = await promptInitDatabase(); if (initDB) { - database = await promptDatabase() + database = await promptDatabase(); - orm = await promptOrm(database) + orm = await promptOrm(database); } - await createBackendProject(projectName, framework, database, orm) + await createBackendProject(projectName, framework, database, orm); } } @@ -83,9 +83,9 @@ function renderTitle() { verticalLayout: "default", width: 80, whitespaceBreak: true, - } + }; useGradient({ title: figlet.textSync("StartEase", figletConfig), - }) + }); } diff --git a/src/test/expressjs/src/common/config/database.js b/src/test/expressjs/src/common/config/database.js index 10930aa..2bc5258 100644 --- a/src/test/expressjs/src/common/config/database.js +++ b/src/test/expressjs/src/common/config/database.js @@ -1,11 +1,11 @@ -import mongoose from 'mongoose'; -import { ENVIRONMENT } from './environment'; +import mongoose from "mongoose"; +import { ENVIRONMENT } from "./environment"; export const connectDb = async () => { try { const conn = await mongoose.connect(ENVIRONMENT.DB.URL, { useNewUrlParser: true, - useUnifiedTopology: true + useUnifiedTopology: true, }); console.log(`MongoDB Connected: ${conn.connection.host}`); diff --git a/src/test/expressjs/src/common/config/environment.js b/src/test/expressjs/src/common/config/environment.js index a717a7c..a500a00 100644 --- a/src/test/expressjs/src/common/config/environment.js +++ b/src/test/expressjs/src/common/config/environment.js @@ -1,13 +1,13 @@ -import * as dotenv from 'dotenv'; -dotenv.config() +import * as dotenv from "dotenv"; +dotenv.config(); export const ENVIRONMENT = { - APP: { - NAME: process.env.APP_NAME, - PORT: process.env.PORT || 3000, - ENV: process.env.APP_ENV - }, - DB: { - URL: process.env.DB_URL - } -} \ No newline at end of file + APP: { + NAME: process.env.APP_NAME, + PORT: process.env.PORT || 3000, + ENV: process.env.APP_ENV, + }, + DB: { + URL: process.env.DB_URL, + }, +}; diff --git a/src/test/expressjs/src/common/utils/appError.js b/src/test/expressjs/src/common/utils/appError.js index 537f0a5..f676614 100644 --- a/src/test/expressjs/src/common/utils/appError.js +++ b/src/test/expressjs/src/common/utils/appError.js @@ -8,14 +8,14 @@ */ export default class AppError extends Error { - constructor(message, statusCode, data) { - super(message); + constructor(message, statusCode, data) { + super(message); - this.statusCode = statusCode; - this.status = `${statusCode}`.startsWith("4") ? "fail" : "error"; - this.isOperational = true; - this.data = data; + this.statusCode = statusCode; + this.status = `${statusCode}`.startsWith("4") ? "fail" : "error"; + this.isOperational = true; + this.data = data; - Error.captureStackTrace(this, this.constructor); - } -} \ No newline at end of file + Error.captureStackTrace(this, this.constructor); + } +} diff --git a/src/test/expressjs/src/common/utils/errorHandler.js b/src/test/expressjs/src/common/utils/errorHandler.js index 9905225..b11c88b 100644 --- a/src/test/expressjs/src/common/utils/errorHandler.js +++ b/src/test/expressjs/src/common/utils/errorHandler.js @@ -1,6 +1,6 @@ import timeout from "connect-timeout"; -import {ENVIRONMENT} from "../config/environment.js"; -import {logger} from "./logger.js"; +import { ENVIRONMENT } from "../config/environment.js"; +import { logger } from "./logger.js"; /** * Wraps an async function to handle errors. @@ -9,63 +9,63 @@ import {logger} from "./logger.js"; * @return {function} - The wrapped function. */ export const catchAsync = (fn) => { - return (req, res, next) => { - fn(req, res, next).catch((err) => next(err)); - }; + return (req, res, next) => { + fn(req, res, next).catch((err) => next(err)); + }; }; /** * Error handler */ export const handleError = (err, req, res, next) => { - err.statusCode = err.statusCode || 500; - err.message = err.message || "Something went wrong"; - err.data = err.data || null; + err.statusCode = err.statusCode || 500; + err.message = err.message || "Something went wrong"; + err.data = err.data || null; - const { statusCode, message, data } = err; + const { statusCode, message, data } = err; - logger.error( - `${statusCode} - ${message} - ${req.originalUrl} - ${req.method} - ${req.ip}` - ); + logger.error( + `${statusCode} - ${message} - ${req.originalUrl} - ${req.method} - ${req.ip}`, + ); - if (err.timeout) { - return res.status(408).send({ - success: false, - data: null, - message: "Request timeout", - }); - } - - if (statusCode === 404) { - return res.status(statusCode).json({ - success: false, - data: null, - message: message ?? "resource not found", - }); - } + if (err.timeout) { + return res.status(408).send({ + success: false, + data: null, + message: "Request timeout", + }); + } - if (ENVIRONMENT.APP.ENV === 'local') { - console.log("==== Error ==== : ", err.stack); + if (statusCode === 404) { + return res.status(statusCode).json({ + success: false, + data: null, + message: message ?? "resource not found", + }); + } - return res.status(statusCode).json({ - success: false, - data: data, - message: message, - stackTrace: err.stack, - }); - } + if (ENVIRONMENT.APP.ENV === "local") { + console.log("==== Error ==== : ", err.stack); return res.status(statusCode).json({ - success: false, - data: data, - message: message, + success: false, + data: data, + message: message, + stackTrace: err.stack, }); + } + + return res.status(statusCode).json({ + success: false, + data: data, + message: message, + }); }; /** * Timeout middleware */ export const timeoutMiddleware = timeout({ - time: 1000 * 60, - message: "Request timeout", + time: 1000 * 60, + message: "Request timeout", }); diff --git a/src/test/expressjs/src/common/utils/helper.js b/src/test/expressjs/src/common/utils/helper.js index c37ec35..f4dfcf6 100644 --- a/src/test/expressjs/src/common/utils/helper.js +++ b/src/test/expressjs/src/common/utils/helper.js @@ -1,6 +1,4 @@ -import { - randomBytes, -} from 'crypto'; +import { randomBytes } from "crypto"; /** * Generates a random string of the specified length. @@ -9,5 +7,5 @@ import { * @return {string} - The generated random string. */ export function generateRandomString(length) { - return randomBytes(length).toString('hex'); + return randomBytes(length).toString("hex"); } diff --git a/src/test/expressjs/src/common/utils/logger.js b/src/test/expressjs/src/common/utils/logger.js index 389c2f2..a987650 100644 --- a/src/test/expressjs/src/common/utils/logger.js +++ b/src/test/expressjs/src/common/utils/logger.js @@ -1,22 +1,22 @@ -import winston from 'winston'; +import winston from "winston"; export const logger = winston.createLogger({ - level: 'info', - format: winston.format.combine( - winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), - winston.format.printf(({ level, message, timestamp }) => { - const logEntry = `${timestamp} ${level}: ${message}`; - return logEntry.replace(/\u001b\[0m/g, ''); - }) - ), - transports: [ - new winston.transports.Console(), - new winston.transports.File({ filename: 'logs/info.log', level: 'info' }) - ] -}) + level: "info", + format: winston.format.combine( + winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), + winston.format.printf(({ level, message, timestamp }) => { + const logEntry = `${timestamp} ${level}: ${message}`; + return logEntry.replace(/\u001b\[0m/g, ""); + }), + ), + transports: [ + new winston.transports.Console(), + new winston.transports.File({ filename: "logs/info.log", level: "info" }), + ], +}); export const stream = { - write: (message) => { - logger.info(message.trim()); - } -} \ No newline at end of file + write: (message) => { + logger.info(message.trim()); + }, +}; diff --git a/src/test/expressjs/src/modules/controllers/user.controller.js b/src/test/expressjs/src/modules/controllers/user.controller.js index 89f2edb..1a49165 100644 --- a/src/test/expressjs/src/modules/controllers/user.controller.js +++ b/src/test/expressjs/src/modules/controllers/user.controller.js @@ -1,15 +1,15 @@ import AppError from "../../common/utils/appError.js"; -import {catchAsync} from "../../common/utils/errorHandler.js"; +import { catchAsync } from "../../common/utils/errorHandler.js"; export const getUser = catchAsync(async (req, res) => { - const user = { - name: 'jc', - email: 'coder' - } + const user = { + name: "jc", + email: "coder", + }; - if(!user){ - throw new AppError('User not found', 404); - } + if (!user) { + throw new AppError("User not found", 404); + } - return res.status(200).json(user); -}) \ No newline at end of file + return res.status(200).json(user); +}); diff --git a/src/test/expressjs/src/modules/routes/index.js b/src/test/expressjs/src/modules/routes/index.js index 803cdf0..6173e70 100644 --- a/src/test/expressjs/src/modules/routes/index.js +++ b/src/test/expressjs/src/modules/routes/index.js @@ -1,10 +1,9 @@ -import {Router} from "express"; +import { Router } from "express"; const router = Router(); -import {userRoutes} from "./user.route.js"; - +import { userRoutes } from "./user.route.js"; export const setRoutes = () => { - router.use('/user', userRoutes()); - return router; -}; \ No newline at end of file + router.use("/user", userRoutes()); + return router; +}; diff --git a/src/test/expressjs/src/modules/routes/user.route.js b/src/test/expressjs/src/modules/routes/user.route.js index 6a90a00..870ec25 100644 --- a/src/test/expressjs/src/modules/routes/user.route.js +++ b/src/test/expressjs/src/modules/routes/user.route.js @@ -1,13 +1,13 @@ -import {Router} from "express"; -import {getUser} from "../controllers/user.controller.js"; +import { Router } from "express"; +import { getUser } from "../controllers/user.controller.js"; const router = Router(); export const userRoutes = () => { - /** - * get user - */ - router.get('/', getUser) + /** + * get user + */ + router.get("/", getUser); - return router; -} \ No newline at end of file + return router; +}; diff --git a/src/test/expressjs/src/server.js b/src/test/expressjs/src/server.js index 0fc5add..bd40e6d 100644 --- a/src/test/expressjs/src/server.js +++ b/src/test/expressjs/src/server.js @@ -1,12 +1,16 @@ -import {ENVIRONMENT} from "./common/config/environment.js"; -import express from 'express'; +import { ENVIRONMENT } from "./common/config/environment.js"; +import express from "express"; import AppError from "./common/utils/appError.js"; -import {setRoutes} from "./modules/routes/index.js"; -import {catchAsync, handleError, timeoutMiddleware} from "./common/utils/errorHandler.js"; +import { setRoutes } from "./modules/routes/index.js"; +import { + catchAsync, + handleError, + timeoutMiddleware, +} from "./common/utils/errorHandler.js"; import cors from "cors"; import helmet from "helmet"; -import {stream} from "./common/utils/logger.js"; -import morgan from 'morgan' +import { stream } from "./common/utils/logger.js"; +import morgan from "morgan"; import { connectDb } from "./common/config/database.js"; /** @@ -21,33 +25,35 @@ const appName = ENVIRONMENT.APP.NAME; */ app.use(helmet()); app.use(cors()); -app.use(express.json({limit: "50mb"})); -app.use(express.urlencoded({limit: "50mb", extended: true})); +app.use(express.json({ limit: "50mb" })); +app.use(express.urlencoded({ limit: "50mb", extended: true })); app.disable("x-powered-by"); /** * Logger Middleware */ app.use( - morgan(ENVIRONMENT.APP.ENV !== "local" ? "combined" : "dev", { stream }) + morgan(ENVIRONMENT.APP.ENV !== "local" ? "combined" : "dev", { stream }), ); // append request time to all request app.use((req, res, next) => { - req.requestTime = new Date().toISOString(); - next(); + req.requestTime = new Date().toISOString(); + next(); }); /** * Initialize routes */ -app.use('/', setRoutes()) +app.use("/", setRoutes()); // catch 404 and forward to error handler -app.all("*", catchAsync(async (req, res) => { - throw new AppError('route not found', 404) -})); - +app.all( + "*", + catchAsync(async (req, res) => { + throw new AppError("route not found", 404); + }), +); /** * Error handler middlewares @@ -55,23 +61,20 @@ app.all("*", catchAsync(async (req, res) => { app.use(timeoutMiddleware); app.use(handleError); - /** * status check */ app.get("*", (req, res) => - res.send({ - Time: new Date(), - status: "running", - }) + res.send({ + Time: new Date(), + status: "running", + }), ); - /** * Bootstrap server */ const server = app.listen(port, () => { - connectDb() - console.log(`=> ${appName} app listening on port ${port}!`) - } -); \ No newline at end of file + connectDb(); + console.log(`=> ${appName} app listening on port ${port}!`); +}); diff --git a/src/test/nestjs/src/app.module.ts b/src/test/nestjs/src/app.module.ts index daec199..1b8318c 100644 --- a/src/test/nestjs/src/app.module.ts +++ b/src/test/nestjs/src/app.module.ts @@ -2,7 +2,7 @@ import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { UserModule } from './module/v1/user/user.module'; -import { DatabaseModule } from "./module/v1/database/database.module"; +import { DatabaseModule } from './module/v1/database/database.module'; @Module({ imports: [UserModule, DatabaseModule], diff --git a/src/test/nestjs/src/common/utils/helper.ts b/src/test/nestjs/src/common/utils/helper.ts index 8a1efeb..e65566b 100644 --- a/src/test/nestjs/src/common/utils/helper.ts +++ b/src/test/nestjs/src/common/utils/helper.ts @@ -1,6 +1,4 @@ -import { - randomBytes, -} from 'crypto'; +import { randomBytes } from 'crypto'; /** * Generates a random string of the specified length. @@ -9,5 +7,5 @@ import { * @return {string} - The generated random string. */ export function generateRandomString(length: number): string { - return randomBytes(length).toString('hex'); + return randomBytes(length).toString('hex'); } diff --git a/src/utils/create-backend-project.js b/src/utils/create-backend-project.js index f77f33d..8514dad 100644 --- a/src/utils/create-backend-project.js +++ b/src/utils/create-backend-project.js @@ -5,22 +5,25 @@ import { getTemplateDir, updateFileContent, writeToFile, -} from './filemanager.js'; -import { AppModuleContent } from '../../templates/backend/nestjs/base/app-module.js'; -import path from 'path'; -import {MongodbDatabaseConfig, MongodbSchema} from '../../templates/backend/nestjs/base/databases.js'; +} from "./filemanager.js"; +import { AppModuleContent } from "../../templates/backend/nestjs/base/app-module.js"; +import path from "path"; +import { + MongodbDatabaseConfig, + MongodbSchema, +} from "../../templates/backend/nestjs/base/databases.js"; import { NEST_MONGOOSE_PACKAGE, - NestjsPackageJsonTemplate -} from '../../templates/backend/nestjs/base/nestjs-package-json.js'; -import { ENVIRONMENT_TEMPLATE } from '../../templates/backend/nestjs/base/environment.js'; -import { EXPRESSJS_SERVER_TEMPLATE } from '../../templates/backend/expressjs/base/server.js'; + NestjsPackageJsonTemplate, +} from "../../templates/backend/nestjs/base/nestjs-package-json.js"; +import { ENVIRONMENT_TEMPLATE } from "../../templates/backend/nestjs/base/environment.js"; +import { EXPRESSJS_SERVER_TEMPLATE } from "../../templates/backend/expressjs/base/server.js"; import { ExpressJsMongodbMongooseConnectionTemplate, - ExpressJsMongoDbMongooseSampleSchema -} from '../../templates/backend/expressjs/base/database.js'; -import { ExpressJsPackageJsonTemplate } from '../../templates/backend/expressjs/base/package-json.js'; -import { ExpressJsEnvironmentTemplate } from '../../templates/backend/expressjs/base/config.js'; + ExpressJsMongoDbMongooseSampleSchema, +} from "../../templates/backend/expressjs/base/database.js"; +import { ExpressJsPackageJsonTemplate } from "../../templates/backend/expressjs/base/package-json.js"; +import { ExpressJsEnvironmentTemplate } from "../../templates/backend/expressjs/base/config.js"; import { DJANGO_MANAGER } from "../../templates/backend/django/base/manage.js"; import { DJANGO_WSGI } from "../../templates/backend/django/base/wsgi.js"; import { DJANGO_ASGI } from "../../templates/backend/django/base/asgi.js"; @@ -29,23 +32,23 @@ import { DJANGO_ENV_VARIABLES } from "../../templates/backend/django/base/env.js // third-party imports -import ora from 'ora'; +import ora from "ora"; import shell from "shelljs"; import crypto from "crypto"; /** * loader */ -let stages = [{ message: 'Creating Project ...', duration: 2000 }]; +let stages = [{ message: "Creating Project ...", duration: 2000 }]; async function startSpinner() { for (const stage of stages) { const spinner = ora(stage.message).start(); await new Promise((resolve) => setTimeout(resolve, stage.duration)); - spinner.succeed(stage.message.replace('...', ' completed.')); + spinner.succeed(stage.message.replace("...", " completed.")); } - stages = [{ message: 'Creating Project ...', duration: 2000 }]; + stages = [{ message: "Creating Project ...", duration: 2000 }]; } /** @@ -56,23 +59,23 @@ export async function createBackendProject( projectName, framework, database, - orm + orm, ) { try { const destinationPath = path.join( process.cwd(), - projectName ?? `project-starter-${framework}-template` + projectName ?? `project-starter-${framework}-template`, ); - if (framework === 'nestjs') { - let appModules = ''; - let appModuleImports = ''; + if (framework === "nestjs") { + let appModules = ""; + let appModuleImports = ""; let packageJson = NestjsPackageJsonTemplate; - let environmentInterface = ''; - let environmentContent = ''; + let environmentInterface = ""; + let environmentContent = ""; // copy nestjs template to directory - copyFile(getTemplateDir('backend/nestjs/nestjs-temp'), destinationPath); + copyFile(getTemplateDir("backend/nestjs/nestjs-temp"), destinationPath); // update app module file content writeToFile(`${destinationPath}/src/app.module.ts`, AppModuleContent); @@ -80,32 +83,32 @@ export async function createBackendProject( // add environment file writeToFile( `${destinationPath}/src/common/configs/environment.ts`, - ENVIRONMENT_TEMPLATE + ENVIRONMENT_TEMPLATE, ); if (database) { - stages.push({ message: 'Adding Database Module ...', duration: 1000 }); + stages.push({ message: "Adding Database Module ...", duration: 1000 }); switch (database) { - case 'mongodb': + case "mongodb": switch (orm) { - case 'mongoose': + case "mongoose": // write db config createAndUpdateFile( `${destinationPath}/src/module/v1/database/database.module.ts`, - MongodbDatabaseConfig + MongodbDatabaseConfig, ); // create sample schema file for db createAndUpdateFile( `${destinationPath}/src/module/v1/database/sample.schema.ts`, - MongodbSchema + MongodbSchema, ); // add mongoose dependencies packageJson.dependencies = { ...packageJson.dependencies, - ...NEST_MONGOOSE_PACKAGE.dependencies + ...NEST_MONGOOSE_PACKAGE.dependencies, }; // update environment @@ -115,14 +118,14 @@ export async function createBackendProject( URL: process.env.DB_URL,}`; // update app module - appModules += 'DatabaseModule'; + appModules += "DatabaseModule"; appModuleImports += 'import { DatabaseModule } from "./module/v1/database/database.module";'; break; default: packageJson.dependencies = { ...packageJson.dependencies, - ...NestjsPackageJsonTemplate.dependencies + ...NestjsPackageJsonTemplate.dependencies, }; break; } @@ -132,76 +135,76 @@ export async function createBackendProject( // update app module updateFileContent( - `${destinationPath}/src/app.module.ts`, - AppModuleContent, - { - new_modules_path: appModuleImports, - new_modules: appModules - } + `${destinationPath}/src/app.module.ts`, + AppModuleContent, + { + new_modules_path: appModuleImports, + new_modules: appModules, + }, ); // update environment config file updateFileContent( - `${destinationPath}/src/common/configs/environment.ts`, - ENVIRONMENT_TEMPLATE, - { - environment_interface: environmentInterface, - environment_content: environmentContent - } + `${destinationPath}/src/common/configs/environment.ts`, + ENVIRONMENT_TEMPLATE, + { + environment_interface: environmentInterface, + environment_content: environmentContent, + }, ); // update packageJsonFile createAndUpdateFile( `${destinationPath}/package.json`, - JSON.stringify(packageJson) + JSON.stringify(packageJson), ); // success message stages.push({ message: `Backend project created successfully! : ${destinationPath}`, - duration: 1000 + duration: 1000, }); await startSpinner(); - } else if (framework === 'expressjs') { - let database_config = ''; - let database_config_import = ''; - let additional_environment_variables = ''; + } else if (framework === "expressjs") { + let database_config = ""; + let database_config_import = ""; + let additional_environment_variables = ""; let packageJson = ExpressJsPackageJsonTemplate; // copy expressjs template to directory copyFile( - getTemplateDir('backend/expressjs/expressjs-temp'), - destinationPath + getTemplateDir("backend/expressjs/expressjs-temp"), + destinationPath, ); // add server.js file writeToFile( `${destinationPath}/src/server.js`, - EXPRESSJS_SERVER_TEMPLATE + EXPRESSJS_SERVER_TEMPLATE, ); if (database) { - stages.push({ message: 'Adding Database Module ...', duration: 1000 }); + stages.push({ message: "Adding Database Module ...", duration: 1000 }); // create schema folder createFolder(`${destinationPath}/src/modules/schemas`); switch (database) { - case 'mongodb': + case "mongodb": switch (orm) { - case 'mongoose': + case "mongoose": default: // create db config file createAndUpdateFile( `${destinationPath}/src/common/config/database.js`, - ExpressJsMongodbMongooseConnectionTemplate + ExpressJsMongodbMongooseConnectionTemplate, ); // create sample schema file createAndUpdateFile( `${destinationPath}/src/modules/schemas/sample.schema.js`, - ExpressJsMongoDbMongooseSampleSchema + ExpressJsMongoDbMongooseSampleSchema, ); // update database config for server js file @@ -211,7 +214,7 @@ export async function createBackendProject( // update packageJson packageJson.dependencies = { ...packageJson.dependencies, - mongoose: '^7.5.2' + mongoose: "^7.5.2", }; // update db config @@ -228,70 +231,57 @@ export async function createBackendProject( EXPRESSJS_SERVER_TEMPLATE, { database_config, - database_config_import - } + database_config_import, + }, ); // add and update config file updateFileContent( `${destinationPath}/src/common/config/environment.js`, ExpressJsEnvironmentTemplate, - { additional_environment_variables } + { additional_environment_variables }, ); // add package json file createAndUpdateFile( `${destinationPath}/package.json`, - JSON.stringify(ExpressJsPackageJsonTemplate) + JSON.stringify(ExpressJsPackageJsonTemplate), ); // success message stages.push({ message: `Backend project created successfully! : ${destinationPath}`, - duration: 1000 + duration: 1000, }); await startSpinner(); } else if (framework === "django") { - // django does not support some file namings so the name has to be parsed into a valid python identifier. projectName = projectName.replaceAll(/[-\. ]/g, ""); // copy django template to directory - copyFile(getTemplateDir("backend/django/django-temp"), destinationPath) + copyFile(getTemplateDir("backend/django/django-temp"), destinationPath); // rename project name in final source - + shell.mv( `${destinationPath}/django_boilerplate`, - `${destinationPath}/${projectName}` + `${destinationPath}/${projectName}`, ); - writeToFile( - `${destinationPath}/.env`, - DJANGO_ENV_VARIABLES - ); + writeToFile(`${destinationPath}/.env`, DJANGO_ENV_VARIABLES); - writeToFile( - `${destinationPath}/manage.py`, - DJANGO_MANAGER - ); + writeToFile(`${destinationPath}/manage.py`, DJANGO_MANAGER); writeToFile( `${destinationPath}/${projectName}/settings.py`, - DJANGO_SETTINGS + DJANGO_SETTINGS, ); - writeToFile( - `${destinationPath}/${projectName}/wsgi.py`, - DJANGO_WSGI - ); + writeToFile(`${destinationPath}/${projectName}/wsgi.py`, DJANGO_WSGI); - writeToFile( - `${destinationPath}/${projectName}/asgi.py`, - DJANGO_ASGI - ); + writeToFile(`${destinationPath}/${projectName}/asgi.py`, DJANGO_ASGI); // uses sqlite by default for now till support for postgresql is added. @@ -304,56 +294,48 @@ export async function createBackendProject( */ // add updates to django starter files - - updateFileContent( - `${destinationPath}/.env`, - DJANGO_ENV_VARIABLES, - { - SECRET_KEY: crypto.randomUUID().split("-").join("") - } - ); - updateFileContent( - `${destinationPath}/manage.py`, - DJANGO_MANAGER, - { - projectName - } - ); + updateFileContent(`${destinationPath}/.env`, DJANGO_ENV_VARIABLES, { + SECRET_KEY: crypto.randomUUID().split("-").join(""), + }); + + updateFileContent(`${destinationPath}/manage.py`, DJANGO_MANAGER, { + projectName, + }); updateFileContent( `${destinationPath}/${projectName}/wsgi.py`, DJANGO_WSGI, { - projectName - } + projectName, + }, ); updateFileContent( `${destinationPath}/${projectName}/asgi.py`, DJANGO_ASGI, { - projectName - } + projectName, + }, ); updateFileContent( `${destinationPath}/${projectName}/settings.py`, DJANGO_SETTINGS, { - projectName - } + projectName, + }, ); if (shell.which("git")) { // initialize git for the final source - + stages.push({ - message: 'Initializing git ...', - duration: 1000 + message: "Initializing git ...", + duration: 1000, }); - shell.cd(`${destinationPath}`) + shell.cd(`${destinationPath}`); shell.exec(`git init`); shell.exec(`git add .`); shell.exec(`git commit -m "Initial commit"`); @@ -363,11 +345,10 @@ export async function createBackendProject( // success message stages.push({ message: `Backend project created successfully! : ${destinationPath}`, - duration: 1000 + duration: 1000, }); await startSpinner(); - } } catch (e) { console.log(`Error Creating Backend Project: ${e}`); diff --git a/src/utils/create-frontend-project.js b/src/utils/create-frontend-project.js index 5ce6277..62c7fae 100644 --- a/src/utils/create-frontend-project.js +++ b/src/utils/create-frontend-project.js @@ -1,20 +1,20 @@ -import { copyFile, getTemplateDir } from "./filemanager.js" -import path from "path" -import ora from "ora" +import { copyFile, getTemplateDir } from "./filemanager.js"; +import path from "path"; +import ora from "ora"; /** * loader */ -let stages = [{ message: "Creating Project ...", duration: 2000 }] +let stages = [{ message: "Creating Project ...", duration: 2000 }]; async function startSpinner() { for (const stage of stages) { - const spinner = ora(stage.message).start() - await new Promise((resolve) => setTimeout(resolve, stage.duration)) - spinner.succeed(stage.message.replace("...", " completed.")) + const spinner = ora(stage.message).start(); + await new Promise((resolve) => setTimeout(resolve, stage.duration)); + spinner.succeed(stage.message.replace("...", " completed.")); } - stages = [{ message: "Creating Project ...", duration: 2000 }] + stages = [{ message: "Creating Project ...", duration: 2000 }]; } /** @@ -28,8 +28,8 @@ export async function createFrontendProject(projectName, framework, language) { try { const destinationPath = path.join( process.cwd(), - projectName ?? `project-starter-${framework}-template` - ) + projectName ?? `project-starter-${framework}-template`, + ); if (framework === "reactjs") { // copy files based on the language chosen @@ -37,17 +37,17 @@ export async function createFrontendProject(projectName, framework, language) { case "javascript": copyFile( getTemplateDir(`frontend/reactjs/react-javascript-temp`), - destinationPath - ) - break + destinationPath, + ); + break; case "typescript": copyFile( getTemplateDir(`frontend/reactjs/react-typescript-temp`), - destinationPath - ) + destinationPath, + ); default: - break + break; } // success message @@ -56,11 +56,11 @@ export async function createFrontendProject(projectName, framework, language) { language.charAt(0).toUpperCase() + language.slice(1) } created successfully! : ${destinationPath}`, duration: 1000, - }) + }); - await startSpinner() + await startSpinner(); } } catch (e) { - console.log(`Error Creating Frontend Project: ${e}`) + console.log(`Error Creating Frontend Project: ${e}`); } } diff --git a/src/utils/filemanager.js b/src/utils/filemanager.js index fb0e829..0e2845b 100644 --- a/src/utils/filemanager.js +++ b/src/utils/filemanager.js @@ -1,6 +1,6 @@ -import fs from 'fs-extra'; -import * as path from 'path'; -import {fileURLToPath} from "url"; +import fs from "fs-extra"; +import * as path from "path"; +import { fileURLToPath } from "url"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -9,26 +9,26 @@ const __dirname = path.dirname(__filename); * checks if a directory is empty */ export function isDirectoryEmpty(dir) { - try { - return fs.readdirSync(dir).length === 0; - } catch (error) { - console.log(error); - return false; - } + try { + return fs.readdirSync(dir).length === 0; + } catch (error) { + console.log(error); + return false; + } } /** * empty a directory */ export function emptyDirectory(path, cb = null) { - // check if node module folder exist and remove firstly - if (fs.existsSync(`${path}/node_modules`)) { - fs.removeSync(`${path}/node_modules`); - } + // check if node module folder exist and remove firstly + if (fs.existsSync(`${path}/node_modules`)) { + fs.removeSync(`${path}/node_modules`); + } - fs.emptyDirSync(path); + fs.emptyDirSync(path); - cb && cb(); + cb && cb(); } /** @@ -37,24 +37,23 @@ export function emptyDirectory(path, cb = null) { * this would delete any {{sample}} that is not sent in datas */ export function updateFileContent(filePath, newContent, datas) { - try { - // Replace placeholders like {{template_string}} with values from datas - const updatedContent = newContent.replace(/{{\s*[\w.]+\s*}}/g, (match) => { - const key = match.replace(/[{}]/g, '').trim(); - - if (datas[key] !== undefined) { - return datas[key]; - } + try { + // Replace placeholders like {{template_string}} with values from datas + const updatedContent = newContent.replace(/{{\s*[\w.]+\s*}}/g, (match) => { + const key = match.replace(/[{}]/g, "").trim(); - return match; // If the dynamic data doesn't exist, keep the placeholder - }); + if (datas[key] !== undefined) { + return datas[key]; + } - // Write the updated content back to the file - fs.writeFileSync(filePath, updatedContent, 'utf8'); + return match; // If the dynamic data doesn't exist, keep the placeholder + }); - } catch (err) { - console.error(`Error updating file '${filePath}': ${err}`); - } + // Write the updated content back to the file + fs.writeFileSync(filePath, updatedContent, "utf8"); + } catch (err) { + console.error(`Error updating file '${filePath}': ${err}`); + } } /** @@ -62,11 +61,11 @@ export function updateFileContent(filePath, newContent, datas) { * @param {*} filePath */ export function removeFile(filePath) { - try { - fs.unlink(filePath); - } catch (err) { - console.error(`Error removing file '${filePath}': ${err}`); - } + try { + fs.unlink(filePath); + } catch (err) { + console.error(`Error removing file '${filePath}': ${err}`); + } } /** @@ -74,11 +73,11 @@ export function removeFile(filePath) { * @param {*} folderPath */ export function removeFolder(folderPath) { - try { - fs.remove(folderPath); - } catch (err) { - console.error(`Error removing folder '${folderPath}': ${err}`); - } + try { + fs.remove(folderPath); + } catch (err) { + console.error(`Error removing folder '${folderPath}': ${err}`); + } } /** @@ -87,11 +86,11 @@ export function removeFolder(folderPath) { * @param {*} content */ export function writeToFile(filePath, content) { - try { - fs.writeFileSync(filePath, content, 'utf8'); - } catch (err) { - console.log(`writeToFile error ${filePath}, error: ${err}`); - } + try { + fs.writeFileSync(filePath, content, "utf8"); + } catch (err) { + console.log(`writeToFile error ${filePath}, error: ${err}`); + } } /** @@ -100,18 +99,18 @@ export function writeToFile(filePath, content) { * @param {*} destination */ export function copyFile(source, destination) { - // destination = path.join(process.cwd(), destination); - fs.copySync(source, destination, { - filter: (src, dest) => { - const relativePath = path.relative(source, src); + // destination = path.join(process.cwd(), destination); + fs.copySync(source, destination, { + filter: (src, dest) => { + const relativePath = path.relative(source, src); - if (relativePath.startsWith('node_modules')) { - return false; - } + if (relativePath.startsWith("node_modules")) { + return false; + } - return true; - } - }); + return true; + }, + }); } /** @@ -120,9 +119,9 @@ export function copyFile(source, destination) { * @param {*} content */ export function createAndUpdateFile(path, content) { - fs.outputFile(path, content, (err) => { - if (err) return console.log(err); - }); + fs.outputFile(path, content, (err) => { + if (err) return console.log(err); + }); } /** @@ -130,11 +129,11 @@ export function createAndUpdateFile(path, content) { * @param {*} path */ export function createFolder(path) { - fs.ensureDir(path, (err) => { - if (err) { - console.log(`createFolder success`); - } - }); + fs.ensureDir(path, (err) => { + if (err) { + console.log(`createFolder success`); + } + }); } /** @@ -143,5 +142,5 @@ export function createFolder(path) { * @returns {string} */ export const getTemplateDir = (filePath) => { - return path.join(__dirname, '..', '../templates', filePath); -}; \ No newline at end of file + return path.join(__dirname, "..", "../templates", filePath); +}; diff --git a/src/utils/prompts.js b/src/utils/prompts.js index f220bd3..1feea40 100644 --- a/src/utils/prompts.js +++ b/src/utils/prompts.js @@ -1,4 +1,4 @@ -import inquirer from "inquirer" +import inquirer from "inquirer"; export async function promptProjectName() { const ans = await inquirer.prompt([ @@ -7,9 +7,9 @@ export async function promptProjectName() { name: "projectName", message: "Enter project name:", }, - ]) + ]); - return ans.projectName + return ans.projectName; } export async function promptProjectStack() { @@ -20,9 +20,9 @@ export async function promptProjectStack() { message: "Choose your stack:", choices: ["Frontend", "Backend"], }, - ]) + ]); - return ans.projectStack.toLowerCase() + return ans.projectStack.toLowerCase(); } export async function promptFrontendFramework() { @@ -33,9 +33,9 @@ export async function promptFrontendFramework() { message: "Choose a framework:", choices: ["ReactJs"], }, - ]) + ]); - return ans.framework.toLowerCase().replace(/ /g, "-") + return ans.framework.toLowerCase().replace(/ /g, "-"); } export async function promptFrontendLanguage() { @@ -46,9 +46,9 @@ export async function promptFrontendLanguage() { message: "Choose Your Preferred Language:", choices: ["JavaScript", "TypeScript"], }, - ]) + ]); - return ans.language.toLowerCase().replace(/ /g, "-") + return ans.language.toLowerCase().replace(/ /g, "-"); } export async function promptBackendFramework() { @@ -59,13 +59,13 @@ export async function promptBackendFramework() { message: "Choose a framework:", choices: ["NestJS", "ExpressJs", "Django"], }, - ]) + ]); - return ans.framework.toLowerCase().replace(/ /g, "-") + return ans.framework.toLowerCase().replace(/ /g, "-"); } export async function promptDatabase(framework) { - const choices = framework === "django" ? ["SQLite3"] : ["MongoDB"] + const choices = framework === "django" ? ["SQLite3"] : ["MongoDB"]; const ans = await inquirer.prompt([ { @@ -74,9 +74,9 @@ export async function promptDatabase(framework) { message: "select a database", choices, }, - ]) + ]); - return ans.database.toLowerCase() + return ans.database.toLowerCase(); } export async function promptInitDatabase() { @@ -87,19 +87,19 @@ export async function promptInitDatabase() { message: "Initialize Database?", default: false, }, - ]) + ]); - return ans.initDB + return ans.initDB; } export async function promptOrm(database) { - database = database?.toLowerCase() ?? "" - let ormChoices = [] + database = database?.toLowerCase() ?? ""; + let ormChoices = []; if (database === "mongodb") { - ormChoices = ["Mongoose"] + ormChoices = ["Mongoose"]; } else { - ormChoices = ["Typeorm"] + ormChoices = ["Typeorm"]; } const ans = await inquirer.prompt([ @@ -109,7 +109,7 @@ export async function promptOrm(database) { message: "select your preferred ORM", choices: ormChoices, }, - ]) + ]); - return ans.database.toLowerCase() + return ans.database.toLowerCase(); } diff --git a/src/utils/stack-options.js b/src/utils/stack-options.js index 9e4f52f..ff11496 100644 --- a/src/utils/stack-options.js +++ b/src/utils/stack-options.js @@ -1,50 +1,50 @@ export const STACK_OPTIONS = { - "stacks": [ + stacks: [ { - "name": "backend", - "frameworks": [ + name: "backend", + frameworks: [ { - "name": "nestjs", - "key": "nestjs" + name: "nestjs", + key: "nestjs", }, { - "name": "expressjs", - "key": "expressjs" - } + name: "expressjs", + key: "expressjs", + }, ], - "databases": [ + databases: [ { - "name": "mongodb", - "key": "-db1" + name: "mongodb", + key: "-db1", }, { - "name": "postgresql", - "key": "-db2" + name: "postgresql", + key: "-db2", }, { - "name": "mysql", - "key": "-db3" - } + name: "mysql", + key: "-db3", + }, ], - "orms": [ + orms: [ { - "name": "mongoose", - "key": "-orm1" + name: "mongoose", + key: "-orm1", }, { - "name": "typeorm", - "key": "-orm2" - } + name: "typeorm", + key: "-orm2", + }, ], }, { - "name": "frontend", - "frameworks": [ - { - "name": "reactjs", - "key": "reactjs" - } - ] - } - ] + name: "frontend", + frameworks: [ + { + name: "reactjs", + key: "reactjs", + }, + ], + }, + ], }; diff --git a/src/utils/useGradient.js b/src/utils/useGradient.js index de7ffd0..efa1812 100644 --- a/src/utils/useGradient.js +++ b/src/utils/useGradient.js @@ -1,13 +1,10 @@ import gradient from "gradient-string"; - - const colors = { gold: "#FFD700", crimson: "#DC143C", }; - const useGradient = (opt) => { const titleColor = opt.colors ?? Object.values(colors); const title = gradient(titleColor)(opt.title ?? ""); diff --git a/templates/backend/django/base/asgi.js b/templates/backend/django/base/asgi.js index 91feaf1..3d1257d 100644 --- a/templates/backend/django/base/asgi.js +++ b/templates/backend/django/base/asgi.js @@ -5,4 +5,4 @@ from django.core.asgi import get_asgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{projectName}}.settings') application = get_asgi_application() -` +`; diff --git a/templates/backend/django/base/env.js b/templates/backend/django/base/env.js index 49bd4f3..8769571 100644 --- a/templates/backend/django/base/env.js +++ b/templates/backend/django/base/env.js @@ -1,3 +1,3 @@ export const DJANGO_ENV_VARIABLES = `DEBUG=True SECRET_KEY={{SECRET_KEY}} -` +`; diff --git a/templates/backend/django/base/manage.js b/templates/backend/django/base/manage.js index 5dc3c12..4db0c28 100644 --- a/templates/backend/django/base/manage.js +++ b/templates/backend/django/base/manage.js @@ -20,4 +20,4 @@ def main(): if __name__ == '__main__': main() -` +`; diff --git a/templates/backend/django/base/settings.js b/templates/backend/django/base/settings.js index 8f93394..73ff497 100644 --- a/templates/backend/django/base/settings.js +++ b/templates/backend/django/base/settings.js @@ -108,4 +108,4 @@ STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),) DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' -` +`; diff --git a/templates/backend/django/base/wsgi.js b/templates/backend/django/base/wsgi.js index af55389..4b1038f 100644 --- a/templates/backend/django/base/wsgi.js +++ b/templates/backend/django/base/wsgi.js @@ -5,4 +5,4 @@ from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{projectName}}.settings') application = get_wsgi_application() -` +`; diff --git a/templates/backend/django/django-temp/static/js/index.js b/templates/backend/django/django-temp/static/js/index.js index b05fc0a..4484123 100644 --- a/templates/backend/django/django-temp/static/js/index.js +++ b/templates/backend/django/django-temp/static/js/index.js @@ -1 +1 @@ -console.log("Hello Django") +console.log("Hello Django"); diff --git a/templates/backend/django/django-temp/templates/index.html b/templates/backend/django/django-temp/templates/index.html index f6316ad..7921a25 100644 --- a/templates/backend/django/django-temp/templates/index.html +++ b/templates/backend/django/django-temp/templates/index.html @@ -1,15 +1,15 @@ - + {% load static %} - - - - - - Hello Django - - -

Hello Django!

- - + + + + + + Hello Django + + +

Hello Django!

+ + diff --git a/templates/backend/expressjs/base/database.js b/templates/backend/expressjs/base/database.js index cbacc65..cef0328 100644 --- a/templates/backend/expressjs/base/database.js +++ b/templates/backend/expressjs/base/database.js @@ -15,7 +15,7 @@ export const connectDb = async () => { process.exit(1); } }; -` +`; export const ExpressJsMongoDbMongooseSampleSchema = ` import mongoose from "mongoose"; diff --git a/templates/backend/expressjs/base/package-json.js b/templates/backend/expressjs/base/package-json.js index 0ec4a88..7320ada 100644 --- a/templates/backend/expressjs/base/package-json.js +++ b/templates/backend/expressjs/base/package-json.js @@ -1,21 +1,21 @@ export const ExpressJsPackageJsonTemplate = { - name: 'startease-expressjs-project', - version: '1.0.0', - description: 'Expressjs project generated using startease CLI tool', - main: 'index.js', - type: 'module', + name: "startease-expressjs-project", + version: "1.0.0", + description: "Expressjs project generated using startease CLI tool", + main: "index.js", + type: "module", scripts: { - dev: 'node --watch src/server.js' + dev: "node --watch src/server.js", }, - author: '', - license: 'ISC', + author: "", + license: "ISC", dependencies: { - 'connect-timeout': '^1.9.0', - cors: '^2.8.5', - dotenv: '^16.3.1', - express: '^4.18.2', - helmet: '^7.0.0', - morgan: '^1.10.0', - winston: '^3.10.0' - } + "connect-timeout": "^1.9.0", + cors: "^2.8.5", + dotenv: "^16.3.1", + express: "^4.18.2", + helmet: "^7.0.0", + morgan: "^1.10.0", + winston: "^3.10.0", + }, }; diff --git a/templates/backend/expressjs/base/server.js b/templates/backend/expressjs/base/server.js index f0227bd..2e19a09 100644 --- a/templates/backend/expressjs/base/server.js +++ b/templates/backend/expressjs/base/server.js @@ -1,4 +1,4 @@ -export const EXPRESSJS_SERVER_TEMPLATE = ` +export const EXPRESSJS_SERVER_TEMPLATE = ` import {ENVIRONMENT} from "./common/config/environment.js"; import express from 'express'; import AppError from "./common/utils/appError.js"; @@ -76,4 +76,4 @@ app.listen(port, () => { {{database_config}} } ); -` \ No newline at end of file +`; diff --git a/templates/backend/expressjs/expressjs-temp/src/common/config/environment.js b/templates/backend/expressjs/expressjs-temp/src/common/config/environment.js index 0bda0a9..4d80671 100644 --- a/templates/backend/expressjs/expressjs-temp/src/common/config/environment.js +++ b/templates/backend/expressjs/expressjs-temp/src/common/config/environment.js @@ -1,10 +1,10 @@ -import * as dotenv from 'dotenv'; -dotenv.config() +import * as dotenv from "dotenv"; +dotenv.config(); export const ENVIRONMENT = { - APP: { - NAME: process.env.APP_NAME, - PORT: process.env.PORT || 3000, - ENV: process.env.APP_ENV - } -} \ No newline at end of file + APP: { + NAME: process.env.APP_NAME, + PORT: process.env.PORT || 3000, + ENV: process.env.APP_ENV, + }, +}; diff --git a/templates/backend/expressjs/expressjs-temp/src/common/utils/appError.js b/templates/backend/expressjs/expressjs-temp/src/common/utils/appError.js index 537f0a5..f676614 100644 --- a/templates/backend/expressjs/expressjs-temp/src/common/utils/appError.js +++ b/templates/backend/expressjs/expressjs-temp/src/common/utils/appError.js @@ -8,14 +8,14 @@ */ export default class AppError extends Error { - constructor(message, statusCode, data) { - super(message); + constructor(message, statusCode, data) { + super(message); - this.statusCode = statusCode; - this.status = `${statusCode}`.startsWith("4") ? "fail" : "error"; - this.isOperational = true; - this.data = data; + this.statusCode = statusCode; + this.status = `${statusCode}`.startsWith("4") ? "fail" : "error"; + this.isOperational = true; + this.data = data; - Error.captureStackTrace(this, this.constructor); - } -} \ No newline at end of file + Error.captureStackTrace(this, this.constructor); + } +} diff --git a/templates/backend/expressjs/expressjs-temp/src/common/utils/errorHandler.js b/templates/backend/expressjs/expressjs-temp/src/common/utils/errorHandler.js index 9905225..b11c88b 100644 --- a/templates/backend/expressjs/expressjs-temp/src/common/utils/errorHandler.js +++ b/templates/backend/expressjs/expressjs-temp/src/common/utils/errorHandler.js @@ -1,6 +1,6 @@ import timeout from "connect-timeout"; -import {ENVIRONMENT} from "../config/environment.js"; -import {logger} from "./logger.js"; +import { ENVIRONMENT } from "../config/environment.js"; +import { logger } from "./logger.js"; /** * Wraps an async function to handle errors. @@ -9,63 +9,63 @@ import {logger} from "./logger.js"; * @return {function} - The wrapped function. */ export const catchAsync = (fn) => { - return (req, res, next) => { - fn(req, res, next).catch((err) => next(err)); - }; + return (req, res, next) => { + fn(req, res, next).catch((err) => next(err)); + }; }; /** * Error handler */ export const handleError = (err, req, res, next) => { - err.statusCode = err.statusCode || 500; - err.message = err.message || "Something went wrong"; - err.data = err.data || null; + err.statusCode = err.statusCode || 500; + err.message = err.message || "Something went wrong"; + err.data = err.data || null; - const { statusCode, message, data } = err; + const { statusCode, message, data } = err; - logger.error( - `${statusCode} - ${message} - ${req.originalUrl} - ${req.method} - ${req.ip}` - ); + logger.error( + `${statusCode} - ${message} - ${req.originalUrl} - ${req.method} - ${req.ip}`, + ); - if (err.timeout) { - return res.status(408).send({ - success: false, - data: null, - message: "Request timeout", - }); - } - - if (statusCode === 404) { - return res.status(statusCode).json({ - success: false, - data: null, - message: message ?? "resource not found", - }); - } + if (err.timeout) { + return res.status(408).send({ + success: false, + data: null, + message: "Request timeout", + }); + } - if (ENVIRONMENT.APP.ENV === 'local') { - console.log("==== Error ==== : ", err.stack); + if (statusCode === 404) { + return res.status(statusCode).json({ + success: false, + data: null, + message: message ?? "resource not found", + }); + } - return res.status(statusCode).json({ - success: false, - data: data, - message: message, - stackTrace: err.stack, - }); - } + if (ENVIRONMENT.APP.ENV === "local") { + console.log("==== Error ==== : ", err.stack); return res.status(statusCode).json({ - success: false, - data: data, - message: message, + success: false, + data: data, + message: message, + stackTrace: err.stack, }); + } + + return res.status(statusCode).json({ + success: false, + data: data, + message: message, + }); }; /** * Timeout middleware */ export const timeoutMiddleware = timeout({ - time: 1000 * 60, - message: "Request timeout", + time: 1000 * 60, + message: "Request timeout", }); diff --git a/templates/backend/expressjs/expressjs-temp/src/common/utils/helper.js b/templates/backend/expressjs/expressjs-temp/src/common/utils/helper.js index c37ec35..f4dfcf6 100644 --- a/templates/backend/expressjs/expressjs-temp/src/common/utils/helper.js +++ b/templates/backend/expressjs/expressjs-temp/src/common/utils/helper.js @@ -1,6 +1,4 @@ -import { - randomBytes, -} from 'crypto'; +import { randomBytes } from "crypto"; /** * Generates a random string of the specified length. @@ -9,5 +7,5 @@ import { * @return {string} - The generated random string. */ export function generateRandomString(length) { - return randomBytes(length).toString('hex'); + return randomBytes(length).toString("hex"); } diff --git a/templates/backend/expressjs/expressjs-temp/src/common/utils/logger.js b/templates/backend/expressjs/expressjs-temp/src/common/utils/logger.js index 389c2f2..a987650 100644 --- a/templates/backend/expressjs/expressjs-temp/src/common/utils/logger.js +++ b/templates/backend/expressjs/expressjs-temp/src/common/utils/logger.js @@ -1,22 +1,22 @@ -import winston from 'winston'; +import winston from "winston"; export const logger = winston.createLogger({ - level: 'info', - format: winston.format.combine( - winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), - winston.format.printf(({ level, message, timestamp }) => { - const logEntry = `${timestamp} ${level}: ${message}`; - return logEntry.replace(/\u001b\[0m/g, ''); - }) - ), - transports: [ - new winston.transports.Console(), - new winston.transports.File({ filename: 'logs/info.log', level: 'info' }) - ] -}) + level: "info", + format: winston.format.combine( + winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), + winston.format.printf(({ level, message, timestamp }) => { + const logEntry = `${timestamp} ${level}: ${message}`; + return logEntry.replace(/\u001b\[0m/g, ""); + }), + ), + transports: [ + new winston.transports.Console(), + new winston.transports.File({ filename: "logs/info.log", level: "info" }), + ], +}); export const stream = { - write: (message) => { - logger.info(message.trim()); - } -} \ No newline at end of file + write: (message) => { + logger.info(message.trim()); + }, +}; diff --git a/templates/backend/expressjs/expressjs-temp/src/modules/controllers/user.controller.js b/templates/backend/expressjs/expressjs-temp/src/modules/controllers/user.controller.js index 89f2edb..1a49165 100644 --- a/templates/backend/expressjs/expressjs-temp/src/modules/controllers/user.controller.js +++ b/templates/backend/expressjs/expressjs-temp/src/modules/controllers/user.controller.js @@ -1,15 +1,15 @@ import AppError from "../../common/utils/appError.js"; -import {catchAsync} from "../../common/utils/errorHandler.js"; +import { catchAsync } from "../../common/utils/errorHandler.js"; export const getUser = catchAsync(async (req, res) => { - const user = { - name: 'jc', - email: 'coder' - } + const user = { + name: "jc", + email: "coder", + }; - if(!user){ - throw new AppError('User not found', 404); - } + if (!user) { + throw new AppError("User not found", 404); + } - return res.status(200).json(user); -}) \ No newline at end of file + return res.status(200).json(user); +}); diff --git a/templates/backend/expressjs/expressjs-temp/src/modules/routes/index.js b/templates/backend/expressjs/expressjs-temp/src/modules/routes/index.js index 803cdf0..6173e70 100644 --- a/templates/backend/expressjs/expressjs-temp/src/modules/routes/index.js +++ b/templates/backend/expressjs/expressjs-temp/src/modules/routes/index.js @@ -1,10 +1,9 @@ -import {Router} from "express"; +import { Router } from "express"; const router = Router(); -import {userRoutes} from "./user.route.js"; - +import { userRoutes } from "./user.route.js"; export const setRoutes = () => { - router.use('/user', userRoutes()); - return router; -}; \ No newline at end of file + router.use("/user", userRoutes()); + return router; +}; diff --git a/templates/backend/expressjs/expressjs-temp/src/modules/routes/user.route.js b/templates/backend/expressjs/expressjs-temp/src/modules/routes/user.route.js index 6a90a00..870ec25 100644 --- a/templates/backend/expressjs/expressjs-temp/src/modules/routes/user.route.js +++ b/templates/backend/expressjs/expressjs-temp/src/modules/routes/user.route.js @@ -1,13 +1,13 @@ -import {Router} from "express"; -import {getUser} from "../controllers/user.controller.js"; +import { Router } from "express"; +import { getUser } from "../controllers/user.controller.js"; const router = Router(); export const userRoutes = () => { - /** - * get user - */ - router.get('/', getUser) + /** + * get user + */ + router.get("/", getUser); - return router; -} \ No newline at end of file + return router; +}; diff --git a/templates/backend/nestjs/base/app-module.js b/templates/backend/nestjs/base/app-module.js index 1f8703c..1cdba7e 100644 --- a/templates/backend/nestjs/base/app-module.js +++ b/templates/backend/nestjs/base/app-module.js @@ -1,4 +1,4 @@ -export const AppModuleContent = ` +export const AppModuleContent = ` import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; @@ -11,4 +11,4 @@ import { UserModule } from './module/v1/user/user.module'; providers: [AppService], }) export class AppModule {} -` \ No newline at end of file +`; diff --git a/templates/backend/nestjs/base/databases.js b/templates/backend/nestjs/base/databases.js index dc6e90a..6110a7d 100644 --- a/templates/backend/nestjs/base/databases.js +++ b/templates/backend/nestjs/base/databases.js @@ -38,4 +38,4 @@ import { ENVIRONMENT } from 'src/common/configs/environment'; imports: [MongooseModule.forRoot(ENVIRONMENT.DB.URL)], }) export class DatabaseModule {} -`; \ No newline at end of file +`; diff --git a/templates/backend/nestjs/base/environment.js b/templates/backend/nestjs/base/environment.js index 93753ba..d3e2fcf 100644 --- a/templates/backend/nestjs/base/environment.js +++ b/templates/backend/nestjs/base/environment.js @@ -19,4 +19,4 @@ export const ENVIRONMENT: IEnvironment = { }, {{environment_content}} }; -` \ No newline at end of file +`; diff --git a/templates/backend/nestjs/base/nestjs-package-json.js b/templates/backend/nestjs/base/nestjs-package-json.js index 231e48c..2308e7a 100644 --- a/templates/backend/nestjs/base/nestjs-package-json.js +++ b/templates/backend/nestjs/base/nestjs-package-json.js @@ -1,77 +1,76 @@ export const NestjsPackageJsonTemplate = { - name: 'startease-nestjs-project', - private: true, - version: '1.0.0', - description: 'NestJs project generated using startease CLI tool', - license: 'MIT', - scripts: { - build: 'nest build', - format: 'prettier --write "src/**/*.ts" "test/**/*.ts"', - start: 'nest start', - 'start:dev': 'nest start --watch', - 'start:debug': 'nest start --debug --watch', - 'start:prod': 'node dist/main', - lint: 'eslint "{src,apps,libs,test}/**/*.ts" --fix', - test: 'jest', - 'test:watch': 'jest --watch', - 'test:cov': 'jest --coverage', - 'test:debug': - 'node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand', - 'test:e2e': 'jest --config ./test/jest-e2e.json' + name: "startease-nestjs-project", + private: true, + version: "1.0.0", + description: "NestJs project generated using startease CLI tool", + license: "MIT", + scripts: { + build: "nest build", + format: 'prettier --write "src/**/*.ts" "test/**/*.ts"', + start: "nest start", + "start:dev": "nest start --watch", + "start:debug": "nest start --debug --watch", + "start:prod": "node dist/main", + lint: 'eslint "{src,apps,libs,test}/**/*.ts" --fix', + test: "jest", + "test:watch": "jest --watch", + "test:cov": "jest --coverage", + "test:debug": + "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", + "test:e2e": "jest --config ./test/jest-e2e.json", + }, + dependencies: { + "@nestjs/common": "^10.0.0", + "@nestjs/core": "^10.0.0", + "@nestjs/platform-express": "^10.0.0", + "class-transformer": "^0.5.1", + "class-validator": "^0.14.0", + dotenv: "^16.3.1", + helmet: "^7.0.0", + "reflect-metadata": "^0.1.13", + rxjs: "^7.8.1", + }, + devDependencies: { + "@nestjs/cli": "^10.0.1", + "@nestjs/schematics": "^10.0.1", + "@nestjs/testing": "^10.0.0", + "@swc/cli": "^0.1.62", + "@swc/core": "^1.3.64", + "@types/express": "^4.17.17", + "@types/jest": "^29.5.2", + "@types/node": "^20.3.1", + "@types/supertest": "^2.0.12", + "@typescript-eslint/eslint-plugin": "^5.59.11", + "@typescript-eslint/parser": "^5.59.11", + eslint: "^8.42.0", + "eslint-config-prettier": "^8.8.0", + "eslint-plugin-prettier": "^4.2.1", + jest: "^29.5.0", + prettier: "^2.8.8", + "source-map-support": "^0.5.21", + supertest: "^6.3.3", + "ts-jest": "^29.1.0", + "ts-loader": "^9.4.3", + "ts-node": "^10.9.1", + "tsconfig-paths": "^4.2.0", + typescript: "^5.1.3", + }, + jest: { + moduleFileExtensions: ["js", "json", "ts"], + rootDir: "src", + testRegex: ".*\\.spec\\.ts$", + transform: { + "^.+\\.(t|j)s$": "ts-jest", }, - dependencies: { - '@nestjs/common': '^10.0.0', - '@nestjs/core': '^10.0.0', - '@nestjs/platform-express': '^10.0.0', - 'class-transformer': '^0.5.1', - 'class-validator': '^0.14.0', - dotenv: '^16.3.1', - helmet: '^7.0.0', - 'reflect-metadata': '^0.1.13', - rxjs: '^7.8.1' - }, - devDependencies: { - '@nestjs/cli': '^10.0.1', - '@nestjs/schematics': '^10.0.1', - '@nestjs/testing': '^10.0.0', - '@swc/cli': '^0.1.62', - '@swc/core': '^1.3.64', - '@types/express': '^4.17.17', - '@types/jest': '^29.5.2', - '@types/node': '^20.3.1', - '@types/supertest': '^2.0.12', - '@typescript-eslint/eslint-plugin': '^5.59.11', - '@typescript-eslint/parser': '^5.59.11', - eslint: '^8.42.0', - 'eslint-config-prettier': '^8.8.0', - 'eslint-plugin-prettier': '^4.2.1', - jest: '^29.5.0', - prettier: '^2.8.8', - 'source-map-support': '^0.5.21', - supertest: '^6.3.3', - 'ts-jest': '^29.1.0', - 'ts-loader': '^9.4.3', - 'ts-node': '^10.9.1', - 'tsconfig-paths': '^4.2.0', - typescript: '^5.1.3' - }, - jest: { - moduleFileExtensions: ['js', 'json', 'ts'], - rootDir: 'src', - testRegex: '.*\\.spec\\.ts$', - transform: { - '^.+\\.(t|j)s$': 'ts-jest' - }, - collectCoverageFrom: ['**/*.(t|j)s'], - coverageDirectory: '../coverage', - testEnvironment: 'node' - } + collectCoverageFrom: ["**/*.(t|j)s"], + coverageDirectory: "../coverage", + testEnvironment: "node", + }, }; - export const NEST_MONGOOSE_PACKAGE = { - "dependencies": { - "@nestjs/mongoose": "^10.0.1", - "mongoose": "^7.5.2", - } -} \ No newline at end of file + dependencies: { + "@nestjs/mongoose": "^10.0.1", + mongoose: "^7.5.2", + }, +}; diff --git a/templates/backend/nestjs/nestjs-temp/src/common/utils/helper.ts b/templates/backend/nestjs/nestjs-temp/src/common/utils/helper.ts index 8a1efeb..e65566b 100644 --- a/templates/backend/nestjs/nestjs-temp/src/common/utils/helper.ts +++ b/templates/backend/nestjs/nestjs-temp/src/common/utils/helper.ts @@ -1,6 +1,4 @@ -import { - randomBytes, -} from 'crypto'; +import { randomBytes } from 'crypto'; /** * Generates a random string of the specified length. @@ -9,5 +7,5 @@ import { * @return {string} - The generated random string. */ export function generateRandomString(length: number): string { - return randomBytes(length).toString('hex'); + return randomBytes(length).toString('hex'); } diff --git a/templates/frontend/reactjs/react-javascript-temp/.eslintrc.cjs b/templates/frontend/reactjs/react-javascript-temp/.eslintrc.cjs index 4dcb439..333a011 100644 --- a/templates/frontend/reactjs/react-javascript-temp/.eslintrc.cjs +++ b/templates/frontend/reactjs/react-javascript-temp/.eslintrc.cjs @@ -2,19 +2,19 @@ module.exports = { root: true, env: { browser: true, es2020: true }, extends: [ - 'eslint:recommended', - 'plugin:react/recommended', - 'plugin:react/jsx-runtime', - 'plugin:react-hooks/recommended', + "eslint:recommended", + "plugin:react/recommended", + "plugin:react/jsx-runtime", + "plugin:react-hooks/recommended", ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, - settings: { react: { version: '18.2' } }, - plugins: ['react-refresh'], + ignorePatterns: ["dist", ".eslintrc.cjs"], + parserOptions: { ecmaVersion: "latest", sourceType: "module" }, + settings: { react: { version: "18.2" } }, + plugins: ["react-refresh"], rules: { - 'react-refresh/only-export-components': [ - 'warn', + "react-refresh/only-export-components": [ + "warn", { allowConstantExport: true }, ], }, -} +}; diff --git a/templates/frontend/reactjs/react-javascript-temp/index.html b/templates/frontend/reactjs/react-javascript-temp/index.html index 87955ad..ea708fd 100644 --- a/templates/frontend/reactjs/react-javascript-temp/index.html +++ b/templates/frontend/reactjs/react-javascript-temp/index.html @@ -1,4 +1,4 @@ - + diff --git a/templates/frontend/reactjs/react-javascript-temp/src/App.jsx b/templates/frontend/reactjs/react-javascript-temp/src/App.jsx index a570e2d..f69ad80 100644 --- a/templates/frontend/reactjs/react-javascript-temp/src/App.jsx +++ b/templates/frontend/reactjs/react-javascript-temp/src/App.jsx @@ -1,10 +1,10 @@ -import { useState } from "react" -import reactLogo from "./assets/react.svg" -import StartEaseLogo from "/startease.svg" -import "./App.css" +import { useState } from "react"; +import reactLogo from "./assets/react.svg"; +import StartEaseLogo from "/startease.svg"; +import "./App.css"; function App() { - const [count, setCount] = useState(0) + const [count, setCount] = useState(0); return ( <> @@ -29,7 +29,7 @@ function App() { Click on the StartEase and React logos to learn more

- ) + ); } -export default App +export default App; diff --git a/templates/frontend/reactjs/react-javascript-temp/src/main.jsx b/templates/frontend/reactjs/react-javascript-temp/src/main.jsx index 54b39dd..c990053 100644 --- a/templates/frontend/reactjs/react-javascript-temp/src/main.jsx +++ b/templates/frontend/reactjs/react-javascript-temp/src/main.jsx @@ -1,10 +1,10 @@ -import React from 'react' -import ReactDOM from 'react-dom/client' -import App from './App.jsx' -import './index.css' +import React from "react"; +import ReactDOM from "react-dom/client"; +import App from "./App.jsx"; +import "./index.css"; -ReactDOM.createRoot(document.getElementById('root')).render( +ReactDOM.createRoot(document.getElementById("root")).render( , -) +); diff --git a/templates/frontend/reactjs/react-javascript-temp/vite.config.js b/templates/frontend/reactjs/react-javascript-temp/vite.config.js index 5a33944..9cc50ea 100644 --- a/templates/frontend/reactjs/react-javascript-temp/vite.config.js +++ b/templates/frontend/reactjs/react-javascript-temp/vite.config.js @@ -1,7 +1,7 @@ -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], -}) +}); diff --git a/templates/frontend/reactjs/react-typescript-temp/.eslintrc.cjs b/templates/frontend/reactjs/react-typescript-temp/.eslintrc.cjs index d6c9537..6e8698b 100644 --- a/templates/frontend/reactjs/react-typescript-temp/.eslintrc.cjs +++ b/templates/frontend/reactjs/react-typescript-temp/.eslintrc.cjs @@ -2,17 +2,17 @@ module.exports = { root: true, env: { browser: true, es2020: true }, extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:react-hooks/recommended', + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:react-hooks/recommended", ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parser: '@typescript-eslint/parser', - plugins: ['react-refresh'], + ignorePatterns: ["dist", ".eslintrc.cjs"], + parser: "@typescript-eslint/parser", + plugins: ["react-refresh"], rules: { - 'react-refresh/only-export-components': [ - 'warn', + "react-refresh/only-export-components": [ + "warn", { allowConstantExport: true }, ], }, -} +}; diff --git a/templates/frontend/reactjs/react-typescript-temp/index.html b/templates/frontend/reactjs/react-typescript-temp/index.html index a187f97..61da7e8 100644 --- a/templates/frontend/reactjs/react-typescript-temp/index.html +++ b/templates/frontend/reactjs/react-typescript-temp/index.html @@ -1,4 +1,4 @@ - + diff --git a/templates/frontend/reactjs/react-typescript-temp/src/App.tsx b/templates/frontend/reactjs/react-typescript-temp/src/App.tsx index 836a9bc..f327de4 100644 --- a/templates/frontend/reactjs/react-typescript-temp/src/App.tsx +++ b/templates/frontend/reactjs/react-typescript-temp/src/App.tsx @@ -1,10 +1,10 @@ -import { useState } from "react" -import reactLogo from "./assets/react.svg" -import StartEaseLogo from "/startease.svg" -import "./App.css" +import { useState } from "react"; +import reactLogo from "./assets/react.svg"; +import StartEaseLogo from "/startease.svg"; +import "./App.css"; function App() { - const [count, setCount] = useState(0) + const [count, setCount] = useState(0); return ( <> @@ -29,7 +29,7 @@ function App() { Click on the StartEase and React logos to learn more

- ) + ); } -export default App +export default App; diff --git a/templates/frontend/reactjs/react-typescript-temp/src/main.tsx b/templates/frontend/reactjs/react-typescript-temp/src/main.tsx index 3d7150d..f25366e 100644 --- a/templates/frontend/reactjs/react-typescript-temp/src/main.tsx +++ b/templates/frontend/reactjs/react-typescript-temp/src/main.tsx @@ -1,10 +1,10 @@ -import React from 'react' -import ReactDOM from 'react-dom/client' -import App from './App.tsx' -import './index.css' +import React from "react"; +import ReactDOM from "react-dom/client"; +import App from "./App.tsx"; +import "./index.css"; -ReactDOM.createRoot(document.getElementById('root')!).render( +ReactDOM.createRoot(document.getElementById("root")!).render( , -) +); diff --git a/templates/frontend/reactjs/react-typescript-temp/vite.config.ts b/templates/frontend/reactjs/react-typescript-temp/vite.config.ts index 5a33944..9cc50ea 100644 --- a/templates/frontend/reactjs/react-typescript-temp/vite.config.ts +++ b/templates/frontend/reactjs/react-typescript-temp/vite.config.ts @@ -1,7 +1,7 @@ -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], -}) +}); From 2b1b50628176ff7bc242b03efcc32e0374f3b4f6 Mon Sep 17 00:00:00 2001 From: Ogunnusi Abayomi Joseph <70065792+drsimplegraffiti@users.noreply.github.com> Date: Thu, 5 Oct 2023 13:53:48 +0100 Subject: [PATCH 4/5] Compression package added --- package-lock.json | 4 ++-- templates/backend/expressjs/base/database.js | 1 + templates/backend/expressjs/base/server.js | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 103a6bd..cd61d88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "startease-cli", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "startease-cli", - "version": "1.1.0", + "version": "1.2.0", "license": "ISC", "dependencies": { "chalk": "^5.3.0", diff --git a/templates/backend/expressjs/base/database.js b/templates/backend/expressjs/base/database.js index cbacc65..c5d06d5 100644 --- a/templates/backend/expressjs/base/database.js +++ b/templates/backend/expressjs/base/database.js @@ -4,6 +4,7 @@ import { ENVIRONMENT } from './environment.js'; export const connectDb = async () => { try { + const conn = await mongoose.connect(ENVIRONMENT.DB.URL, { useNewUrlParser: true, useUnifiedTopology: true diff --git a/templates/backend/expressjs/base/server.js b/templates/backend/expressjs/base/server.js index f0227bd..aff776f 100644 --- a/templates/backend/expressjs/base/server.js +++ b/templates/backend/expressjs/base/server.js @@ -6,6 +6,7 @@ import {setRoutes} from "./modules/routes/index.js"; import {catchAsync, handleError, timeoutMiddleware} from "./common/utils/errorHandler.js"; import cors from "cors"; import helmet from "helmet"; +import compression from "compression"; import {stream} from "./common/utils/logger.js"; import morgan from 'morgan' {{database_config_import}} @@ -25,6 +26,7 @@ app.use(cors()); app.use(express.json({limit: "50mb"})); app.use(express.urlencoded({limit: "50mb", extended: true})); app.disable("x-powered-by"); +app.use(compression()); /** * Logger Middleware From d08cc824998326a34056f71ea7eda2227e63a72d Mon Sep 17 00:00:00 2001 From: CreedDE Date: Fri, 6 Oct 2023 12:53:53 +0200 Subject: [PATCH 5/5] rename script and add github job --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ package.json | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8e260c4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: CI + +on: + push: + branches: + - master + - dev + pull_request: + +jobs: + prettier: + name: Pretier Check + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v3 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Run Prettier Check + run: "npm install && npm run lint" diff --git a/package.json b/package.json index 7e02117..c7a4843 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "start": "node ./cli.js", "format": "prettier . --write", - "format:check": "prettier . --check" + "lint": "prettier . --check" }, "keywords": [ "startease",