@ifecodes/backend-template 1.0.8 → 1.0.9
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 +22 -0
- package/bin/lib/service-setup.js +16 -0
- package/package.json +1 -1
- package/template/base/gitignore +31 -0
- package/template/features/auth/base/inject.js +2 -1
- package/template/features/auth/bcrypt/inject.js +2 -0
- package/template/features/cors/inject.js +3 -2
- package/template/features/morgan/inject.js +2 -1
package/bin/cli.js
CHANGED
|
@@ -184,6 +184,28 @@ if (!isInMicroserviceProject) {
|
|
|
184
184
|
const readmeContent = generateReadme(config);
|
|
185
185
|
fs.writeFileSync(path.join(target, "README.md"), readmeContent);
|
|
186
186
|
|
|
187
|
+
// Rename gitignore to .gitignore (npm doesn't publish .gitignore files)
|
|
188
|
+
if (config.projectType === "microservice") {
|
|
189
|
+
const servicesDir = path.join(target, "services");
|
|
190
|
+
const allServices = fs.readdirSync(servicesDir).filter((f) =>
|
|
191
|
+
fs.statSync(path.join(servicesDir, f)).isDirectory()
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
for (const service of allServices) {
|
|
195
|
+
const gitignorePath = path.join(servicesDir, service, "gitignore");
|
|
196
|
+
const dotGitignorePath = path.join(servicesDir, service, ".gitignore");
|
|
197
|
+
if (fs.existsSync(gitignorePath)) {
|
|
198
|
+
fs.renameSync(gitignorePath, dotGitignorePath);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
const gitignorePath = path.join(target, "gitignore");
|
|
203
|
+
const dotGitignorePath = path.join(target, ".gitignore");
|
|
204
|
+
if (fs.existsSync(gitignorePath)) {
|
|
205
|
+
fs.renameSync(gitignorePath, dotGitignorePath);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
187
209
|
// Generate .env from .env.example for each service or root
|
|
188
210
|
console.log("📄 Setting up environment files...\n");
|
|
189
211
|
if (config.projectType === "microservice") {
|
package/bin/lib/service-setup.js
CHANGED
|
@@ -14,6 +14,7 @@ export const setupService = async (
|
|
|
14
14
|
let imports = [];
|
|
15
15
|
let middlewares = [];
|
|
16
16
|
let deps = [];
|
|
17
|
+
let devDeps = [];
|
|
17
18
|
let v1Imports = [];
|
|
18
19
|
let v1Routes = [];
|
|
19
20
|
|
|
@@ -61,6 +62,9 @@ export const setupService = async (
|
|
|
61
62
|
imports.push(feature.imports);
|
|
62
63
|
middlewares.push(feature.middleware);
|
|
63
64
|
deps.push(...feature.deps);
|
|
65
|
+
if (feature.devDeps) {
|
|
66
|
+
devDeps.push(...feature.devDeps);
|
|
67
|
+
}
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
|
|
@@ -70,6 +74,9 @@ export const setupService = async (
|
|
|
70
74
|
"../../template/features/auth/base/inject.js"
|
|
71
75
|
);
|
|
72
76
|
deps.push(...baseAuth.deps);
|
|
77
|
+
if (baseAuth.devDeps) {
|
|
78
|
+
devDeps.push(...baseAuth.devDeps);
|
|
79
|
+
}
|
|
73
80
|
|
|
74
81
|
for (const file in baseAuth.files) {
|
|
75
82
|
const fullPath = path.join(serviceRoot, file);
|
|
@@ -103,6 +110,9 @@ export const setupService = async (
|
|
|
103
110
|
`../../template/features/auth/${algo.hasher}/inject.js`
|
|
104
111
|
);
|
|
105
112
|
deps.push(...hashFeature.deps);
|
|
113
|
+
if (hashFeature.devDeps) {
|
|
114
|
+
devDeps.push(...hashFeature.devDeps);
|
|
115
|
+
}
|
|
106
116
|
|
|
107
117
|
for (const file in hashFeature.files) {
|
|
108
118
|
const fullPath = path.join(serviceRoot, file);
|
|
@@ -311,6 +321,12 @@ await connectDB();`
|
|
|
311
321
|
stdio: "inherit",
|
|
312
322
|
});
|
|
313
323
|
}
|
|
324
|
+
if (devDeps.length) {
|
|
325
|
+
execSync(`npm install -D ${devDeps.join(" ")}`, {
|
|
326
|
+
cwd: serviceRoot,
|
|
327
|
+
stdio: "inherit",
|
|
328
|
+
});
|
|
329
|
+
}
|
|
314
330
|
execSync("npm install", { cwd: serviceRoot, stdio: "inherit" });
|
|
315
331
|
installSucceeded = true;
|
|
316
332
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
package-lock.json
|
|
4
|
+
|
|
5
|
+
# Build output
|
|
6
|
+
dist/
|
|
7
|
+
|
|
8
|
+
# Environment variables
|
|
9
|
+
.env
|
|
10
|
+
.env.local
|
|
11
|
+
.env.*.local
|
|
12
|
+
|
|
13
|
+
# Logs
|
|
14
|
+
logs/
|
|
15
|
+
*.log
|
|
16
|
+
npm-debug.log*
|
|
17
|
+
yarn-debug.log*
|
|
18
|
+
|
|
19
|
+
# ESLint
|
|
20
|
+
.eslintcache
|
|
21
|
+
|
|
22
|
+
# OS files
|
|
23
|
+
.DS_Store
|
|
24
|
+
Thumbs.db
|
|
25
|
+
|
|
26
|
+
# IDE
|
|
27
|
+
.vscode/
|
|
28
|
+
.idea/
|
|
29
|
+
*.swp
|
|
30
|
+
*.swo
|
|
31
|
+
|
|
@@ -84,6 +84,7 @@ export const imports = `import { authRoutes } from "./auth";`;
|
|
|
84
84
|
|
|
85
85
|
export const middleware = `router.use("/auth", authRoutes);`;
|
|
86
86
|
|
|
87
|
-
export const deps = ["jsonwebtoken", "
|
|
87
|
+
export const deps = ["jsonwebtoken", "mongoose"];
|
|
88
|
+
export const devDeps = ["@types/jsonwebtoken"];
|
|
88
89
|
|
|
89
90
|
export const targetFile = "src/modules/v1/index.ts";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export const deps = ["cors"
|
|
2
|
-
export const
|
|
1
|
+
export const deps = ["cors"];
|
|
2
|
+
export const devDeps = ["@types/cors"];
|
|
3
|
+
export const imports = `import cors from "cors";\nimport { ENV } from "@/config";`;
|
|
3
4
|
export const middleware = `
|
|
4
5
|
const corsOptions = {
|
|
5
6
|
origin: ENV.ALLOWED_ORIGIN,
|