express-modular-monolith 1.2.0 → 1.2.1
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/bin/cli.js +38 -57
- package/bin/cliQuestions.js +103 -34
- package/bin/config.js +4 -5
- package/package.json +2 -1
- package/templates/javascript/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -6,52 +6,19 @@ import { exec as execCallback } from "node:child_process";
|
|
|
6
6
|
import { promisify } from "node:util";
|
|
7
7
|
import fs from "node:fs/promises";
|
|
8
8
|
import process from "node:process";
|
|
9
|
-
import {
|
|
10
|
-
import { projectName, language, DB } from "./cliQuestions.js";
|
|
9
|
+
import { projectName, language, DB, selectToolByDB } from "./cliQuestions.js";
|
|
11
10
|
import { dbPackages } from "./packages.js";
|
|
12
|
-
import
|
|
13
|
-
import { addEnvBasedOnDBs, JSboilerPlateCodeSetUp, DBboilerCodeSetUp, TSboilerPlateCodeSetUp } from "./config.js";
|
|
11
|
+
import chalk from "chalk"
|
|
12
|
+
import { addEnvBasedOnDBs, JSboilerPlateCodeSetUp, DBboilerCodeSetUp, TSboilerPlateCodeSetUp, spinnerDiscardingStdin } from "./config.js";
|
|
14
13
|
|
|
15
14
|
|
|
16
15
|
const exec = promisify(execCallback);
|
|
17
16
|
|
|
18
|
-
const
|
|
19
|
-
text: "Loading Packages",
|
|
20
|
-
spinner: process.argv[2],
|
|
21
|
-
color: "cyan"
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let modelTool;
|
|
26
|
-
|
|
27
|
-
if (DB === "mongodb") {
|
|
28
|
-
modelTool = await select({
|
|
29
|
-
message: "Choose ODM:",
|
|
30
|
-
choices: [
|
|
31
|
-
{
|
|
32
|
-
name: "Mongoose",
|
|
33
|
-
value: "mongoose"
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
});
|
|
37
|
-
} else {
|
|
38
|
-
modelTool = await select({
|
|
39
|
-
message: "Choose ORM:",
|
|
40
|
-
choices: [
|
|
41
|
-
{
|
|
42
|
-
name: "Drizzle",
|
|
43
|
-
value: "drizzle"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: "Prisma",
|
|
47
|
-
value: "prisma"
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
});
|
|
51
|
-
}
|
|
17
|
+
const modelTool = await selectToolByDB()
|
|
52
18
|
|
|
53
19
|
spinnerDiscardingStdin.start("Installing required packages, wait for a while");
|
|
54
20
|
|
|
21
|
+
|
|
55
22
|
const __filename = fileURLToPath(import.meta.url);
|
|
56
23
|
const __dirname = path.dirname(__filename);
|
|
57
24
|
|
|
@@ -68,29 +35,38 @@ const packageJson = JSON.parse(
|
|
|
68
35
|
|
|
69
36
|
if (projectName === ".") {
|
|
70
37
|
packageJson.name = path.basename(process.cwd());
|
|
71
|
-
}else{
|
|
38
|
+
} else{
|
|
72
39
|
packageJson.name = projectName;
|
|
73
40
|
}
|
|
74
41
|
|
|
75
|
-
const
|
|
42
|
+
const loadDependenciesByDB = async () => {
|
|
76
43
|
|
|
77
|
-
|
|
78
|
-
...packageJson.dependencies,
|
|
79
|
-
...selectedPackages.dependencies
|
|
80
|
-
};
|
|
44
|
+
if(DB === "none") return;
|
|
81
45
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
46
|
+
const selectedPackages = dbPackages[DB][modelTool];
|
|
47
|
+
|
|
48
|
+
packageJson.dependencies = {
|
|
49
|
+
...packageJson.dependencies,
|
|
50
|
+
...selectedPackages.dependencies
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
packageJson.devDependencies = {
|
|
54
|
+
...packageJson.devDependencies,
|
|
55
|
+
...selectedPackages.devDependencies
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
await fs.writeFile(
|
|
59
|
+
packageJsonPath,
|
|
60
|
+
JSON.stringify(packageJson, null, 2)
|
|
61
|
+
).catch((err)=>{
|
|
62
|
+
spinnerDiscardingStdin.fail(err)
|
|
63
|
+
spinnerDiscardingStdin.start()
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await loadDependenciesByDB()
|
|
86
69
|
|
|
87
|
-
await fs.writeFile(
|
|
88
|
-
packageJsonPath,
|
|
89
|
-
JSON.stringify(packageJson, null, 2)
|
|
90
|
-
).catch((err)=>{
|
|
91
|
-
spinnerDiscardingStdin.fail(err)
|
|
92
|
-
spinnerDiscardingStdin.start()
|
|
93
|
-
});
|
|
94
70
|
|
|
95
71
|
let lang;
|
|
96
72
|
|
|
@@ -109,6 +85,7 @@ if (templatePath.includes("typescript")) {
|
|
|
109
85
|
}
|
|
110
86
|
}
|
|
111
87
|
|
|
88
|
+
|
|
112
89
|
await exec("npx gitignore node", {
|
|
113
90
|
cwd: projectPath
|
|
114
91
|
}).catch((err)=>{
|
|
@@ -116,7 +93,7 @@ await exec("npx gitignore node", {
|
|
|
116
93
|
spinnerDiscardingStdin.start()
|
|
117
94
|
});
|
|
118
95
|
|
|
119
|
-
await fs.writeFile(".env", "PORT=8000\n").catch((err)=>{
|
|
96
|
+
await fs.writeFile(path.join(projectPath ,".env"), "PORT=8000\n").catch((err)=>{
|
|
120
97
|
spinnerDiscardingStdin.fail("Failed to create .env file")
|
|
121
98
|
spinnerDiscardingStdin.start()
|
|
122
99
|
}).then(async ()=>{
|
|
@@ -152,4 +129,8 @@ await exec(`git commit -m "Initial commit"`, {
|
|
|
152
129
|
spinnerDiscardingStdin.start()
|
|
153
130
|
});
|
|
154
131
|
|
|
155
|
-
spinnerDiscardingStdin.succeed("Packages successfully installed");
|
|
132
|
+
spinnerDiscardingStdin.succeed(chalk.green("Packages successfully installed"));
|
|
133
|
+
|
|
134
|
+
if(DB !== "none") {
|
|
135
|
+
spinnerDiscardingStdin.info(chalk.yellow("Before starting your dev server set your correct DATABASE_URL in .env"))
|
|
136
|
+
}
|
package/bin/cliQuestions.js
CHANGED
|
@@ -1,38 +1,107 @@
|
|
|
1
1
|
import { input, select } from "@inquirer/prompts";
|
|
2
|
+
import chalk from "chalk"
|
|
2
3
|
|
|
4
|
+
export let projectName;
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
message
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
6
|
+
try {
|
|
7
|
+
projectName = await input({
|
|
8
|
+
message: "Project name:"
|
|
9
|
+
});
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error(chalk.red(error?.message || "User force closed the prompt with SIGINT"))
|
|
12
|
+
process.exit(1)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export let language;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
language = await select({
|
|
19
|
+
message: "Choose a language:",
|
|
20
|
+
choices: [
|
|
21
|
+
{
|
|
22
|
+
name: "JavaScript",
|
|
23
|
+
value: "javascript"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "TypeScript",
|
|
27
|
+
value: "typescript"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
});
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error(chalk.red(error?.message || "User force closed the prompt with SIGINT"))
|
|
33
|
+
process.exit(1)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export let DB;
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
DB = await select({
|
|
40
|
+
message: "Choose a database:",
|
|
41
|
+
choices: [
|
|
42
|
+
{
|
|
43
|
+
name: "PostgreSQL",
|
|
44
|
+
value: "postgresql"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "MySQL",
|
|
48
|
+
value: "mysql"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "MongoDB",
|
|
52
|
+
value: "mongodb"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "None",
|
|
56
|
+
value: "none"
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error(chalk.red(error?.message || "User force closed the prompt with SIGINT"))
|
|
62
|
+
process.exit(1)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let modelTool;
|
|
66
|
+
|
|
67
|
+
export async function selectToolByDB (){
|
|
68
|
+
if(DB === "none") return;
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
if (DB === "mongodb") {
|
|
72
|
+
modelTool = await select({
|
|
73
|
+
message: "Choose ODM:",
|
|
74
|
+
choices: [
|
|
75
|
+
{
|
|
76
|
+
name: "Mongoose",
|
|
77
|
+
value: "mongoose"
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
modelTool = await select({
|
|
83
|
+
message: "Choose ORM:",
|
|
84
|
+
choices: [
|
|
85
|
+
{
|
|
86
|
+
name: "Drizzle",
|
|
87
|
+
value: "drizzle"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "Prisma",
|
|
91
|
+
value: "prisma"
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
});
|
|
36
95
|
}
|
|
37
|
-
|
|
38
|
-
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error(chalk.red(error?.message || "User force closed the prompt with SIGINT"))
|
|
98
|
+
process.exit(1)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return modelTool;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
package/bin/config.js
CHANGED
|
@@ -4,13 +4,12 @@ import ora from "ora";
|
|
|
4
4
|
import { drizzlePostgresBoilerPlate, mongodbConBoilerplateCode } from "./boilerPlateCodes.js";
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
const spinnerDiscardingStdin = ora({
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
export const spinnerDiscardingStdin = ora({
|
|
8
|
+
text: "Loading Packages",
|
|
9
|
+
spinner: "dots14",
|
|
10
10
|
color: "cyan"
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
export const JSboilerPlateCodeSetUp = async (projectPath) => {
|
|
15
14
|
const appJsPath = path.join(projectPath, "/src/app.js")
|
|
16
15
|
|
|
@@ -167,7 +166,7 @@ export const DBboilerCodeSetUp = async (projectPath, DB, modelTool, language) =>
|
|
|
167
166
|
|
|
168
167
|
const targetLine = [3, 9]
|
|
169
168
|
const insertedData = [`import { db } from "./common/config/db.js";
|
|
170
|
-
|
|
169
|
+
import { sql } from "drizzle-orm"`,
|
|
171
170
|
' await db.execute(sql`select 1`)'];
|
|
172
171
|
|
|
173
172
|
const lines = serverJsData.split(/\r?\n/);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-modular-monolith",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "This is a modular monolith project generator for Express.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"author": "Md Khalid Hossain",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@inquirer/prompts": "^8.6.0",
|
|
14
|
+
"chalk": "^6.0.0",
|
|
14
15
|
"ora": "^9.4.1"
|
|
15
16
|
}
|
|
16
17
|
}
|