create-express-mongoose-app 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -0
- package/my-test/.env.example +21 -0
- package/my-test/README.md +137 -0
- package/my-test/package.json +38 -0
- package/my-test/src/app.ts +77 -0
- package/my-test/src/config/database.ts +54 -0
- package/my-test/src/config/env.ts +42 -0
- package/my-test/src/config/winston-logger.ts +75 -0
- package/my-test/src/index.ts +3 -0
- package/my-test/src/middleware/error.middleware.ts +88 -0
- package/my-test/src/middleware/request-id.middleware.ts +20 -0
- package/my-test/src/modules/example/example.controller.ts +45 -0
- package/my-test/src/modules/example/example.model.ts +31 -0
- package/my-test/src/modules/example/example.route.ts +20 -0
- package/my-test/src/modules/example/example.service.ts +92 -0
- package/my-test/src/modules/example/example.validation.ts +16 -0
- package/my-test/src/server.ts +57 -0
- package/my-test/src/utils/apiError.ts +63 -0
- package/my-test/src/utils/asyncHandler.ts +7 -0
- package/my-test/src/utils/response.ts +102 -0
- package/my-test/src/utils/validationMiddleware.ts +32 -0
- package/my-test/tsconfig.json +26 -0
- package/my-test/yarn.lock +1149 -0
- package/package.json +35 -0
- package/src/cli.js +126 -0
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-express-mongoose-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI tool to create production-grade Express.js with Mongoose starter projects",
|
|
5
|
+
"main": "src/cli.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-express-mongoose-app": "src/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "node src/cli.js"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"chalk": "^4.1.2",
|
|
14
|
+
"degit": "^2.8.4",
|
|
15
|
+
"ora": "^5.4.1",
|
|
16
|
+
"prompts": "^2.4.2"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=16.0.0"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/mehedihsiam/create-express-mongo-app.git"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"express",
|
|
28
|
+
"mongodb",
|
|
29
|
+
"starter",
|
|
30
|
+
"cli",
|
|
31
|
+
"template"
|
|
32
|
+
],
|
|
33
|
+
"author": "Your Name",
|
|
34
|
+
"license": "MIT"
|
|
35
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import prompts from "prompts";
|
|
5
|
+
import { execSync } from "child_process";
|
|
6
|
+
import * as fs from "fs";
|
|
7
|
+
import * as path from "path";
|
|
8
|
+
import degit from "degit";
|
|
9
|
+
import ora from "ora";
|
|
10
|
+
|
|
11
|
+
const TEMPLATE_REPO = "mehedihsiam/express-mongo-starter.git";
|
|
12
|
+
|
|
13
|
+
async function getProjectConfig() {
|
|
14
|
+
const questions = [
|
|
15
|
+
{
|
|
16
|
+
type: "text",
|
|
17
|
+
name: "projectName",
|
|
18
|
+
message: "What is your project name?",
|
|
19
|
+
initial: "my-express-app",
|
|
20
|
+
validate: (value) => {
|
|
21
|
+
if (!value.match(/^[a-zA-Z0-9-_]+$/)) {
|
|
22
|
+
return "Project name can only contain letters, numbers, dashes, and underscores";
|
|
23
|
+
}
|
|
24
|
+
if (fs.existsSync(value)) {
|
|
25
|
+
return `Directory "${value}" already exists`;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: "select",
|
|
32
|
+
name: "packageManager",
|
|
33
|
+
message: "Which package manager do you want to use?",
|
|
34
|
+
choices: [
|
|
35
|
+
{ title: "npm", value: "npm" },
|
|
36
|
+
{ title: "yarn", value: "yarn" },
|
|
37
|
+
{ title: "pnpm", value: "pnpm" },
|
|
38
|
+
],
|
|
39
|
+
initial: 0,
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const response = await prompts(questions);
|
|
44
|
+
|
|
45
|
+
if (!response.projectName || !response.packageManager) {
|
|
46
|
+
console.log(chalk.red("\nā Project creation cancelled"));
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
projectName: response.projectName,
|
|
52
|
+
packageManager: response.packageManager,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function cloneTemplate(projectName) {
|
|
57
|
+
const spinner = ora("Cloning template repository...").start();
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const d = degit(TEMPLATE_REPO);
|
|
61
|
+
await d.clone(projectName);
|
|
62
|
+
spinner.succeed(chalk.green("Template cloned successfully"));
|
|
63
|
+
} catch (error) {
|
|
64
|
+
spinner.fail(chalk.red("Failed to clone template"));
|
|
65
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function installDependencies(projectName, packageManager) {
|
|
71
|
+
const spinner = ora(
|
|
72
|
+
`Installing dependencies with ${packageManager}...`,
|
|
73
|
+
).start();
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const projectPath = path.join(process.cwd(), projectName);
|
|
77
|
+
process.chdir(projectPath);
|
|
78
|
+
|
|
79
|
+
const commands = {
|
|
80
|
+
npm: "npm install",
|
|
81
|
+
yarn: "yarn install",
|
|
82
|
+
pnpm: "pnpm install",
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const command = commands[packageManager];
|
|
86
|
+
execSync(command, { stdio: "inherit" });
|
|
87
|
+
|
|
88
|
+
spinner.succeed(chalk.green("Dependencies installed successfully"));
|
|
89
|
+
} catch (error) {
|
|
90
|
+
spinner.fail(chalk.red("Failed to install dependencies"));
|
|
91
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function main() {
|
|
97
|
+
console.log(chalk.cyan("\nš Create Express MongoDB App\n"));
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const config = await getProjectConfig();
|
|
101
|
+
|
|
102
|
+
console.log(
|
|
103
|
+
chalk.blue(`\nš Creating project: ${chalk.bold(config.projectName)}`),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
await cloneTemplate(config.projectName);
|
|
107
|
+
await installDependencies(config.projectName, config.packageManager);
|
|
108
|
+
|
|
109
|
+
console.log(chalk.green("\nā Project created successfully!\n"));
|
|
110
|
+
console.log(chalk.cyan("Next steps:"));
|
|
111
|
+
console.log(chalk.gray(` 1. cd ${config.projectName}`));
|
|
112
|
+
console.log(chalk.gray(` 2. cp .env.example .env`));
|
|
113
|
+
console.log(chalk.gray(` 3. ${config.packageManager} run dev`));
|
|
114
|
+
console.log(
|
|
115
|
+
chalk.gray(
|
|
116
|
+
`\nFor more information, visit: https://github.com/${TEMPLATE_REPO}`,
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
console.log("");
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error(chalk.red(`\nā Error: ${error.message}\n`));
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
main();
|