nodejs-quickstart-structure 1.19.0 → 2.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/CHANGELOG.md +320 -301
- package/LICENSE +15 -15
- package/README.md +45 -10
- package/bin/index.js +7 -1
- package/lib/generator.js +139 -139
- package/lib/modules/app-setup.js +401 -401
- package/lib/modules/config-files.js +151 -151
- package/lib/modules/database-setup.js +116 -116
- package/lib/modules/project-setup.js +32 -32
- package/lib/prompts.js +100 -100
- package/package.json +79 -78
- package/templates/clean-architecture/js/src/domain/models/User.js +9 -9
- package/templates/clean-architecture/js/src/errors/ApiError.js +14 -14
- package/templates/clean-architecture/js/src/index.js.ejs +55 -55
- package/templates/clean-architecture/js/src/infrastructure/config/env.js.ejs +47 -47
- package/templates/clean-architecture/js/src/infrastructure/log/logger.js +36 -36
- package/templates/clean-architecture/js/src/infrastructure/log/logger.spec.js.ejs +63 -63
- package/templates/clean-architecture/js/src/infrastructure/webserver/middleware/errorMiddleware.js +30 -30
- package/templates/clean-architecture/js/src/infrastructure/webserver/server.js.ejs +89 -89
- package/templates/clean-architecture/js/src/infrastructure/webserver/swagger.js.ejs +6 -6
- package/templates/clean-architecture/js/src/interfaces/graphql/context.js.ejs +13 -13
- package/templates/clean-architecture/js/src/interfaces/graphql/context.spec.js.ejs +31 -31
- package/templates/clean-architecture/js/src/interfaces/graphql/index.js.ejs +5 -5
- package/templates/clean-architecture/js/src/interfaces/graphql/resolvers/index.js.ejs +6 -6
- package/templates/clean-architecture/js/src/interfaces/graphql/typeDefs/index.js.ejs +6 -6
- package/templates/clean-architecture/js/src/interfaces/routes/api.spec.js.ejs +38 -38
- package/templates/clean-architecture/js/src/usecases/CreateUser.js +14 -14
- package/templates/clean-architecture/js/src/usecases/CreateUser.spec.js.ejs +51 -51
- package/templates/clean-architecture/js/src/usecases/GetAllUsers.js +12 -12
- package/templates/clean-architecture/js/src/usecases/GetAllUsers.spec.js.ejs +61 -61
- package/templates/clean-architecture/js/src/utils/httpCodes.js +9 -9
- package/templates/clean-architecture/ts/src/config/env.ts.ejs +46 -46
- package/templates/clean-architecture/ts/src/config/swagger.ts.ejs +6 -6
- package/templates/clean-architecture/ts/src/domain/user.ts +7 -7
- package/templates/clean-architecture/ts/src/errors/ApiError.ts +15 -15
- package/templates/clean-architecture/ts/src/index.ts.ejs +139 -139
- package/templates/clean-architecture/ts/src/infrastructure/log/logger.spec.ts.ejs +63 -63
- package/templates/clean-architecture/ts/src/infrastructure/log/logger.ts +36 -36
- package/templates/clean-architecture/ts/src/interfaces/graphql/context.spec.ts.ejs +32 -32
- package/templates/clean-architecture/ts/src/interfaces/graphql/context.ts.ejs +17 -17
- package/templates/clean-architecture/ts/src/interfaces/graphql/index.ts.ejs +3 -3
- package/templates/clean-architecture/ts/src/interfaces/graphql/resolvers/index.ts.ejs +4 -4
- package/templates/clean-architecture/ts/src/interfaces/graphql/typeDefs/index.ts.ejs +4 -4
- package/templates/clean-architecture/ts/src/interfaces/routes/userRoutes.spec.ts.ejs +40 -40
- package/templates/clean-architecture/ts/src/usecases/createUser.spec.ts.ejs +51 -51
- package/templates/clean-architecture/ts/src/usecases/createUser.ts +13 -13
- package/templates/clean-architecture/ts/src/usecases/getAllUsers.spec.ts.ejs +63 -63
- package/templates/clean-architecture/ts/src/usecases/getAllUsers.ts +10 -10
- package/templates/clean-architecture/ts/src/utils/errorMiddleware.ts.ejs +27 -27
- package/templates/clean-architecture/ts/src/utils/httpCodes.ts +7 -7
- package/templates/common/.cursorrules.ejs +60 -60
- package/templates/common/.dockerignore +12 -12
- package/templates/common/.env.example.ejs +41 -41
- package/templates/common/.gitlab-ci.yml.ejs +86 -86
- package/templates/common/.lintstagedrc +6 -6
- package/templates/common/.prettierrc +7 -7
- package/templates/common/Dockerfile +73 -73
- package/templates/common/Jenkinsfile.ejs +87 -87
- package/templates/common/SECURITY.md +20 -20
- package/templates/common/_github/workflows/ci.yml.ejs +46 -46
- package/templates/common/_github/workflows/security.yml.ejs +36 -36
- package/templates/common/_gitignore +5 -5
- package/templates/common/_husky/pre-commit +4 -4
- package/templates/common/caching/clean/js/CreateUser.js.ejs +29 -29
- package/templates/common/caching/clean/js/GetAllUsers.js.ejs +37 -37
- package/templates/common/caching/clean/ts/createUser.ts.ejs +27 -27
- package/templates/common/caching/clean/ts/getAllUsers.ts.ejs +34 -34
- package/templates/common/caching/js/memoryCache.js.ejs +60 -60
- package/templates/common/caching/js/memoryCache.spec.js.ejs +101 -101
- package/templates/common/caching/js/redisClient.js.ejs +75 -75
- package/templates/common/caching/js/redisClient.spec.js.ejs +147 -147
- package/templates/common/caching/ts/memoryCache.spec.ts.ejs +102 -102
- package/templates/common/caching/ts/redisClient.spec.ts.ejs +157 -157
- package/templates/common/database/js/database.js.ejs +19 -19
- package/templates/common/database/js/database.spec.js.ejs +56 -56
- package/templates/common/database/js/mongoose.js.ejs +33 -33
- package/templates/common/database/js/mongoose.spec.js.ejs +43 -43
- package/templates/common/database/ts/database.spec.ts.ejs +56 -56
- package/templates/common/database/ts/database.ts.ejs +21 -21
- package/templates/common/database/ts/mongoose.spec.ts.ejs +42 -42
- package/templates/common/database/ts/mongoose.ts.ejs +28 -28
- package/templates/common/docker-compose.yml.ejs +159 -159
- package/templates/common/ecosystem.config.js.ejs +40 -40
- package/templates/common/eslint.config.mjs.ejs +77 -77
- package/templates/common/health/js/healthRoute.spec.js.ejs +70 -70
- package/templates/common/health/ts/healthRoute.spec.ts.ejs +76 -76
- package/templates/common/jest.config.js.ejs +32 -32
- package/templates/common/kafka/js/config/kafka.js +9 -9
- package/templates/common/kafka/js/config/kafka.spec.js.ejs +27 -27
- package/templates/common/kafka/js/messaging/baseConsumer.spec.js.ejs +58 -58
- package/templates/common/kafka/js/messaging/userEventSchema.spec.js.ejs +27 -27
- package/templates/common/kafka/js/services/kafkaService.spec.js.ejs +106 -106
- package/templates/common/kafka/ts/config/kafka.spec.ts.ejs +27 -27
- package/templates/common/kafka/ts/config/kafka.ts +7 -7
- package/templates/common/kafka/ts/messaging/baseConsumer.spec.ts.ejs +50 -50
- package/templates/common/kafka/ts/messaging/baseConsumer.ts.ejs +27 -27
- package/templates/common/kafka/ts/services/kafkaService.spec.ts.ejs +81 -81
- package/templates/common/migrate-mongo-config.js.ejs +31 -31
- package/templates/common/migrations/init.js.ejs +23 -23
- package/templates/common/package.json.ejs +119 -118
- package/templates/common/prompts/add-feature.md.ejs +26 -26
- package/templates/common/prompts/project-context.md.ejs +43 -43
- package/templates/common/prompts/troubleshoot.md.ejs +28 -28
- package/templates/common/public/css/style.css +147 -147
- package/templates/common/scripts/run-e2e.js.ejs +63 -63
- package/templates/common/sonar-project.properties.ejs +27 -27
- package/templates/common/src/utils/errorMiddleware.spec.js.ejs +79 -79
- package/templates/common/src/utils/errorMiddleware.spec.ts.ejs +94 -94
- package/templates/common/tsconfig.json +22 -22
- package/templates/common/views/ejs/index.ejs +55 -55
- package/templates/common/views/pug/index.pug +40 -40
- package/templates/mvc/js/src/config/env.js.ejs +46 -46
- package/templates/mvc/js/src/config/swagger.js.ejs +6 -6
- package/templates/mvc/js/src/errors/ApiError.js +14 -14
- package/templates/mvc/js/src/graphql/context.js.ejs +7 -7
- package/templates/mvc/js/src/graphql/context.spec.js.ejs +29 -29
- package/templates/mvc/js/src/graphql/index.js.ejs +5 -5
- package/templates/mvc/js/src/graphql/resolvers/index.js.ejs +6 -6
- package/templates/mvc/js/src/graphql/typeDefs/index.js.ejs +6 -6
- package/templates/mvc/js/src/index.js.ejs +136 -136
- package/templates/mvc/js/src/utils/errorMiddleware.js +29 -29
- package/templates/mvc/js/src/utils/httpCodes.js +9 -9
- package/templates/mvc/js/src/utils/logger.js +40 -40
- package/templates/mvc/js/src/utils/logger.spec.js.ejs +63 -63
- package/templates/mvc/ts/src/config/env.ts.ejs +45 -45
- package/templates/mvc/ts/src/config/swagger.ts.ejs +6 -6
- package/templates/mvc/ts/src/errors/ApiError.ts +15 -15
- package/templates/mvc/ts/src/graphql/context.spec.ts.ejs +30 -30
- package/templates/mvc/ts/src/graphql/context.ts.ejs +12 -12
- package/templates/mvc/ts/src/graphql/index.ts.ejs +3 -3
- package/templates/mvc/ts/src/graphql/resolvers/index.ts.ejs +4 -4
- package/templates/mvc/ts/src/graphql/typeDefs/index.ts.ejs +4 -4
- package/templates/mvc/ts/src/utils/errorMiddleware.ts.ejs +27 -27
- package/templates/mvc/ts/src/utils/httpCodes.ts +7 -7
- package/templates/mvc/ts/src/utils/logger.spec.ts.ejs +63 -63
- package/templates/mvc/ts/src/utils/logger.ts +36 -36
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import ejs from 'ejs';
|
|
4
|
-
|
|
5
|
-
export const renderPackageJson = async (templatesDir, targetDir, config) => {
|
|
6
|
-
const packageJsonPath = path.join(targetDir, 'package.json');
|
|
7
|
-
const packageTemplate = await fs.readFile(path.join(templatesDir, 'common', 'package.json.ejs'), 'utf-8');
|
|
8
|
-
const packageContent = ejs.render(packageTemplate, { ...config });
|
|
9
|
-
await fs.writeFile(packageJsonPath, packageContent);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const renderDockerCompose = async (templatesDir, targetDir, config) => {
|
|
13
|
-
const dockerComposePath = path.join(targetDir, 'docker-compose.yml');
|
|
14
|
-
const dockerTemplate = await fs.readFile(path.join(templatesDir, 'common', 'docker-compose.yml.ejs'), 'utf-8');
|
|
15
|
-
const dockerContent = ejs.render(dockerTemplate, { ...config });
|
|
16
|
-
await fs.writeFile(dockerComposePath, dockerContent);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const renderReadme = async (templatesDir, targetDir, config) => {
|
|
20
|
-
const readmePath = path.join(targetDir, 'README.md');
|
|
21
|
-
const readmeTemplate = await fs.readFile(path.join(templatesDir, 'common', 'README.md.ejs'), 'utf-8');
|
|
22
|
-
const readmeContent = ejs.render(readmeTemplate, { ...config });
|
|
23
|
-
await fs.writeFile(readmePath, readmeContent);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const renderDockerfile = async (templatesDir, targetDir, config) => {
|
|
27
|
-
const dockerfileTemplate = await fs.readFile(path.join(templatesDir, 'common', 'Dockerfile'), 'utf-8');
|
|
28
|
-
const dockerfileContent = ejs.render(dockerfileTemplate, { ...config });
|
|
29
|
-
await fs.writeFile(path.join(targetDir, 'Dockerfile'), dockerfileContent);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const renderPm2Config = async (templatesDir, targetDir, config) => {
|
|
33
|
-
const pm2ConfigPath = path.join(targetDir, 'ecosystem.config.js');
|
|
34
|
-
const pm2Template = await fs.readFile(path.join(templatesDir, 'common', 'ecosystem.config.js.ejs'), 'utf-8');
|
|
35
|
-
const pm2Content = ejs.render(pm2Template, { ...config });
|
|
36
|
-
await fs.writeFile(pm2ConfigPath, pm2Content);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const renderProfessionalConfig = async (templatesDir, targetDir, config) => {
|
|
40
|
-
const eslintTemplate = await fs.readFile(path.join(templatesDir, 'common', 'eslint.config.mjs.ejs'), 'utf-8');
|
|
41
|
-
const eslintContent = ejs.render(eslintTemplate, { ...config });
|
|
42
|
-
await fs.writeFile(path.join(targetDir, 'eslint.config.mjs'), eslintContent);
|
|
43
|
-
|
|
44
|
-
await fs.copy(path.join(templatesDir, 'common', '.prettierrc'), path.join(targetDir, '.prettierrc'));
|
|
45
|
-
await fs.copy(path.join(templatesDir, 'common', '.lintstagedrc'), path.join(targetDir, '.lintstagedrc'));
|
|
46
|
-
|
|
47
|
-
const jestTemplate = await fs.readFile(path.join(templatesDir, 'common', 'jest.config.js.ejs'), 'utf-8');
|
|
48
|
-
const jestContent = ejs.render(jestTemplate, { ...config });
|
|
49
|
-
await fs.writeFile(path.join(targetDir, 'jest.config.js'), jestContent);
|
|
50
|
-
|
|
51
|
-
// E2E Config
|
|
52
|
-
const jestE2eTemplate = await fs.readFile(path.join(templatesDir, 'common', 'jest.e2e.config.js.ejs'), 'utf-8');
|
|
53
|
-
const jestE2eContent = ejs.render(jestE2eTemplate, { ...config });
|
|
54
|
-
await fs.writeFile(path.join(targetDir, 'jest.e2e.config.js'), jestE2eContent);
|
|
55
|
-
|
|
56
|
-
// 1. Setup Husky pre-commit (Always for Professional Standard)
|
|
57
|
-
const huskyDir = path.join(targetDir, '.husky');
|
|
58
|
-
await fs.ensureDir(huskyDir);
|
|
59
|
-
await fs.copy(path.join(templatesDir, 'common', '_husky', 'pre-commit'), path.join(huskyDir, 'pre-commit'));
|
|
60
|
-
|
|
61
|
-
// 2. Enterprise Security Hardening (Optional)
|
|
62
|
-
if (config.includeSecurity) {
|
|
63
|
-
await fs.copy(path.join(templatesDir, 'common', 'SECURITY.md'), path.join(targetDir, 'SECURITY.md'));
|
|
64
|
-
|
|
65
|
-
const sonarTemplate = await fs.readFile(path.join(templatesDir, 'common', 'sonar-project.properties.ejs'), 'utf-8');
|
|
66
|
-
const sonarContent = ejs.render(sonarTemplate, { ...config });
|
|
67
|
-
await fs.writeFile(path.join(targetDir, 'sonar-project.properties'), sonarContent);
|
|
68
|
-
|
|
69
|
-
const snykTemplate = await fs.readFile(path.join(templatesDir, 'common', '.snyk.ejs'), 'utf-8');
|
|
70
|
-
const snykContent = ejs.render(snykTemplate, { ...config });
|
|
71
|
-
await fs.writeFile(path.join(targetDir, '.snyk'), snykContent);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export const renderAiNativeFiles = async (templatesDir, targetDir, config) => {
|
|
76
|
-
// 1. .cursorrules
|
|
77
|
-
const cursorRulesPath = path.join(targetDir, '.cursorrules');
|
|
78
|
-
const cursorRulesTemplate = await fs.readFile(path.join(templatesDir, 'common', '.cursorrules.ejs'), 'utf-8');
|
|
79
|
-
const cursorRulesContent = ejs.render(cursorRulesTemplate, { ...config });
|
|
80
|
-
await fs.writeFile(cursorRulesPath, cursorRulesContent);
|
|
81
|
-
|
|
82
|
-
// 2. prompts/
|
|
83
|
-
const promptsDirTarget = path.join(targetDir, 'prompts');
|
|
84
|
-
await fs.ensureDir(promptsDirTarget);
|
|
85
|
-
|
|
86
|
-
const promptsSourceDir = path.join(templatesDir, 'common', 'prompts');
|
|
87
|
-
const promptFiles = await fs.readdir(promptsSourceDir);
|
|
88
|
-
|
|
89
|
-
for (const file of promptFiles) {
|
|
90
|
-
if (file.endsWith('.ejs')) {
|
|
91
|
-
const templatePath = path.join(promptsSourceDir, file);
|
|
92
|
-
const targetFilePath = path.join(promptsDirTarget, file.replace('.ejs', ''));
|
|
93
|
-
const templateContent = await fs.readFile(templatePath, 'utf-8');
|
|
94
|
-
const renderedContent = ejs.render(templateContent, { ...config });
|
|
95
|
-
await fs.writeFile(targetFilePath, renderedContent);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export const setupCiCd = async (templatesDir, targetDir, config) => {
|
|
101
|
-
const { ciProvider, includeSecurity } = config;
|
|
102
|
-
if (ciProvider === 'GitHub Actions') {
|
|
103
|
-
const workflowsDir = path.join(targetDir, '.github/workflows');
|
|
104
|
-
await fs.ensureDir(workflowsDir);
|
|
105
|
-
|
|
106
|
-
const ciTemplate = await fs.readFile(path.join(templatesDir, 'common', '_github/workflows/ci.yml.ejs'), 'utf-8');
|
|
107
|
-
const ciContent = ejs.render(ciTemplate, { ...config });
|
|
108
|
-
await fs.writeFile(path.join(workflowsDir, 'ci.yml'), ciContent);
|
|
109
|
-
|
|
110
|
-
if (includeSecurity) {
|
|
111
|
-
const securityTemplate = await fs.readFile(path.join(templatesDir, 'common', '_github/workflows/security.yml.ejs'), 'utf-8');
|
|
112
|
-
const securityContent = ejs.render(securityTemplate, { ...config });
|
|
113
|
-
await fs.writeFile(path.join(workflowsDir, 'security.yml'), securityContent);
|
|
114
|
-
}
|
|
115
|
-
} else if (ciProvider === 'Jenkins') {
|
|
116
|
-
const jenkinsTemplate = await fs.readFile(path.join(templatesDir, 'common', 'Jenkinsfile.ejs'), 'utf-8');
|
|
117
|
-
const jenkinsContent = ejs.render(jenkinsTemplate, { ...config });
|
|
118
|
-
await fs.writeFile(path.join(targetDir, 'Jenkinsfile'), jenkinsContent);
|
|
119
|
-
} else if (ciProvider === 'GitLab CI') {
|
|
120
|
-
const gitlabTemplate = await fs.readFile(path.join(templatesDir, 'common', '.gitlab-ci.yml.ejs'), 'utf-8');
|
|
121
|
-
const gitlabContent = ejs.render(gitlabTemplate, { ...config });
|
|
122
|
-
await fs.writeFile(path.join(targetDir, '.gitlab-ci.yml'), gitlabContent);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export const renderTestSample = async (templatesDir, targetDir, config) => {
|
|
127
|
-
await fs.ensureDir(path.join(targetDir, 'tests'));
|
|
128
|
-
if (config.language === 'TypeScript') {
|
|
129
|
-
const testsTsConfig = {
|
|
130
|
-
"extends": "../tsconfig.json",
|
|
131
|
-
"compilerOptions": {
|
|
132
|
-
"types": ["jest", "node"],
|
|
133
|
-
"rootDir": "..",
|
|
134
|
-
"noEmit": true
|
|
135
|
-
},
|
|
136
|
-
"include": ["**/*.ts", "../src/**/*.ts"]
|
|
137
|
-
};
|
|
138
|
-
await fs.writeFile(path.join(targetDir, 'tests', 'tsconfig.json'), JSON.stringify(testsTsConfig, null, 4));
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export const renderEnvExample = async (templatesDir, targetDir, config) => {
|
|
143
|
-
const envExamplePath = path.join(targetDir, '.env.example');
|
|
144
|
-
const envPath = path.join(targetDir, '.env');
|
|
145
|
-
const envTemplate = await fs.readFile(path.join(templatesDir, 'common', '.env.example.ejs'), 'utf-8');
|
|
146
|
-
|
|
147
|
-
const envContent = ejs.render(envTemplate, { ...config });
|
|
148
|
-
|
|
149
|
-
await fs.writeFile(envExamplePath, envContent);
|
|
150
|
-
await fs.writeFile(envPath, envContent);
|
|
151
|
-
};
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import ejs from 'ejs';
|
|
4
|
+
|
|
5
|
+
export const renderPackageJson = async (templatesDir, targetDir, config) => {
|
|
6
|
+
const packageJsonPath = path.join(targetDir, 'package.json');
|
|
7
|
+
const packageTemplate = await fs.readFile(path.join(templatesDir, 'common', 'package.json.ejs'), 'utf-8');
|
|
8
|
+
const packageContent = ejs.render(packageTemplate, { ...config });
|
|
9
|
+
await fs.writeFile(packageJsonPath, packageContent);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const renderDockerCompose = async (templatesDir, targetDir, config) => {
|
|
13
|
+
const dockerComposePath = path.join(targetDir, 'docker-compose.yml');
|
|
14
|
+
const dockerTemplate = await fs.readFile(path.join(templatesDir, 'common', 'docker-compose.yml.ejs'), 'utf-8');
|
|
15
|
+
const dockerContent = ejs.render(dockerTemplate, { ...config });
|
|
16
|
+
await fs.writeFile(dockerComposePath, dockerContent);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const renderReadme = async (templatesDir, targetDir, config) => {
|
|
20
|
+
const readmePath = path.join(targetDir, 'README.md');
|
|
21
|
+
const readmeTemplate = await fs.readFile(path.join(templatesDir, 'common', 'README.md.ejs'), 'utf-8');
|
|
22
|
+
const readmeContent = ejs.render(readmeTemplate, { ...config });
|
|
23
|
+
await fs.writeFile(readmePath, readmeContent);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const renderDockerfile = async (templatesDir, targetDir, config) => {
|
|
27
|
+
const dockerfileTemplate = await fs.readFile(path.join(templatesDir, 'common', 'Dockerfile'), 'utf-8');
|
|
28
|
+
const dockerfileContent = ejs.render(dockerfileTemplate, { ...config });
|
|
29
|
+
await fs.writeFile(path.join(targetDir, 'Dockerfile'), dockerfileContent);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const renderPm2Config = async (templatesDir, targetDir, config) => {
|
|
33
|
+
const pm2ConfigPath = path.join(targetDir, 'ecosystem.config.js');
|
|
34
|
+
const pm2Template = await fs.readFile(path.join(templatesDir, 'common', 'ecosystem.config.js.ejs'), 'utf-8');
|
|
35
|
+
const pm2Content = ejs.render(pm2Template, { ...config });
|
|
36
|
+
await fs.writeFile(pm2ConfigPath, pm2Content);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const renderProfessionalConfig = async (templatesDir, targetDir, config) => {
|
|
40
|
+
const eslintTemplate = await fs.readFile(path.join(templatesDir, 'common', 'eslint.config.mjs.ejs'), 'utf-8');
|
|
41
|
+
const eslintContent = ejs.render(eslintTemplate, { ...config });
|
|
42
|
+
await fs.writeFile(path.join(targetDir, 'eslint.config.mjs'), eslintContent);
|
|
43
|
+
|
|
44
|
+
await fs.copy(path.join(templatesDir, 'common', '.prettierrc'), path.join(targetDir, '.prettierrc'));
|
|
45
|
+
await fs.copy(path.join(templatesDir, 'common', '.lintstagedrc'), path.join(targetDir, '.lintstagedrc'));
|
|
46
|
+
|
|
47
|
+
const jestTemplate = await fs.readFile(path.join(templatesDir, 'common', 'jest.config.js.ejs'), 'utf-8');
|
|
48
|
+
const jestContent = ejs.render(jestTemplate, { ...config });
|
|
49
|
+
await fs.writeFile(path.join(targetDir, 'jest.config.js'), jestContent);
|
|
50
|
+
|
|
51
|
+
// E2E Config
|
|
52
|
+
const jestE2eTemplate = await fs.readFile(path.join(templatesDir, 'common', 'jest.e2e.config.js.ejs'), 'utf-8');
|
|
53
|
+
const jestE2eContent = ejs.render(jestE2eTemplate, { ...config });
|
|
54
|
+
await fs.writeFile(path.join(targetDir, 'jest.e2e.config.js'), jestE2eContent);
|
|
55
|
+
|
|
56
|
+
// 1. Setup Husky pre-commit (Always for Professional Standard)
|
|
57
|
+
const huskyDir = path.join(targetDir, '.husky');
|
|
58
|
+
await fs.ensureDir(huskyDir);
|
|
59
|
+
await fs.copy(path.join(templatesDir, 'common', '_husky', 'pre-commit'), path.join(huskyDir, 'pre-commit'));
|
|
60
|
+
|
|
61
|
+
// 2. Enterprise Security Hardening (Optional)
|
|
62
|
+
if (config.includeSecurity) {
|
|
63
|
+
await fs.copy(path.join(templatesDir, 'common', 'SECURITY.md'), path.join(targetDir, 'SECURITY.md'));
|
|
64
|
+
|
|
65
|
+
const sonarTemplate = await fs.readFile(path.join(templatesDir, 'common', 'sonar-project.properties.ejs'), 'utf-8');
|
|
66
|
+
const sonarContent = ejs.render(sonarTemplate, { ...config });
|
|
67
|
+
await fs.writeFile(path.join(targetDir, 'sonar-project.properties'), sonarContent);
|
|
68
|
+
|
|
69
|
+
const snykTemplate = await fs.readFile(path.join(templatesDir, 'common', '.snyk.ejs'), 'utf-8');
|
|
70
|
+
const snykContent = ejs.render(snykTemplate, { ...config });
|
|
71
|
+
await fs.writeFile(path.join(targetDir, '.snyk'), snykContent);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const renderAiNativeFiles = async (templatesDir, targetDir, config) => {
|
|
76
|
+
// 1. .cursorrules
|
|
77
|
+
const cursorRulesPath = path.join(targetDir, '.cursorrules');
|
|
78
|
+
const cursorRulesTemplate = await fs.readFile(path.join(templatesDir, 'common', '.cursorrules.ejs'), 'utf-8');
|
|
79
|
+
const cursorRulesContent = ejs.render(cursorRulesTemplate, { ...config });
|
|
80
|
+
await fs.writeFile(cursorRulesPath, cursorRulesContent);
|
|
81
|
+
|
|
82
|
+
// 2. prompts/
|
|
83
|
+
const promptsDirTarget = path.join(targetDir, 'prompts');
|
|
84
|
+
await fs.ensureDir(promptsDirTarget);
|
|
85
|
+
|
|
86
|
+
const promptsSourceDir = path.join(templatesDir, 'common', 'prompts');
|
|
87
|
+
const promptFiles = await fs.readdir(promptsSourceDir);
|
|
88
|
+
|
|
89
|
+
for (const file of promptFiles) {
|
|
90
|
+
if (file.endsWith('.ejs')) {
|
|
91
|
+
const templatePath = path.join(promptsSourceDir, file);
|
|
92
|
+
const targetFilePath = path.join(promptsDirTarget, file.replace('.ejs', ''));
|
|
93
|
+
const templateContent = await fs.readFile(templatePath, 'utf-8');
|
|
94
|
+
const renderedContent = ejs.render(templateContent, { ...config });
|
|
95
|
+
await fs.writeFile(targetFilePath, renderedContent);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const setupCiCd = async (templatesDir, targetDir, config) => {
|
|
101
|
+
const { ciProvider, includeSecurity } = config;
|
|
102
|
+
if (ciProvider === 'GitHub Actions') {
|
|
103
|
+
const workflowsDir = path.join(targetDir, '.github/workflows');
|
|
104
|
+
await fs.ensureDir(workflowsDir);
|
|
105
|
+
|
|
106
|
+
const ciTemplate = await fs.readFile(path.join(templatesDir, 'common', '_github/workflows/ci.yml.ejs'), 'utf-8');
|
|
107
|
+
const ciContent = ejs.render(ciTemplate, { ...config });
|
|
108
|
+
await fs.writeFile(path.join(workflowsDir, 'ci.yml'), ciContent);
|
|
109
|
+
|
|
110
|
+
if (includeSecurity) {
|
|
111
|
+
const securityTemplate = await fs.readFile(path.join(templatesDir, 'common', '_github/workflows/security.yml.ejs'), 'utf-8');
|
|
112
|
+
const securityContent = ejs.render(securityTemplate, { ...config });
|
|
113
|
+
await fs.writeFile(path.join(workflowsDir, 'security.yml'), securityContent);
|
|
114
|
+
}
|
|
115
|
+
} else if (ciProvider === 'Jenkins') {
|
|
116
|
+
const jenkinsTemplate = await fs.readFile(path.join(templatesDir, 'common', 'Jenkinsfile.ejs'), 'utf-8');
|
|
117
|
+
const jenkinsContent = ejs.render(jenkinsTemplate, { ...config });
|
|
118
|
+
await fs.writeFile(path.join(targetDir, 'Jenkinsfile'), jenkinsContent);
|
|
119
|
+
} else if (ciProvider === 'GitLab CI') {
|
|
120
|
+
const gitlabTemplate = await fs.readFile(path.join(templatesDir, 'common', '.gitlab-ci.yml.ejs'), 'utf-8');
|
|
121
|
+
const gitlabContent = ejs.render(gitlabTemplate, { ...config });
|
|
122
|
+
await fs.writeFile(path.join(targetDir, '.gitlab-ci.yml'), gitlabContent);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const renderTestSample = async (templatesDir, targetDir, config) => {
|
|
127
|
+
await fs.ensureDir(path.join(targetDir, 'tests'));
|
|
128
|
+
if (config.language === 'TypeScript') {
|
|
129
|
+
const testsTsConfig = {
|
|
130
|
+
"extends": "../tsconfig.json",
|
|
131
|
+
"compilerOptions": {
|
|
132
|
+
"types": ["jest", "node"],
|
|
133
|
+
"rootDir": "..",
|
|
134
|
+
"noEmit": true
|
|
135
|
+
},
|
|
136
|
+
"include": ["**/*.ts", "../src/**/*.ts"]
|
|
137
|
+
};
|
|
138
|
+
await fs.writeFile(path.join(targetDir, 'tests', 'tsconfig.json'), JSON.stringify(testsTsConfig, null, 4));
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const renderEnvExample = async (templatesDir, targetDir, config) => {
|
|
143
|
+
const envExamplePath = path.join(targetDir, '.env.example');
|
|
144
|
+
const envPath = path.join(targetDir, '.env');
|
|
145
|
+
const envTemplate = await fs.readFile(path.join(templatesDir, 'common', '.env.example.ejs'), 'utf-8');
|
|
146
|
+
|
|
147
|
+
const envContent = ejs.render(envTemplate, { ...config });
|
|
148
|
+
|
|
149
|
+
await fs.writeFile(envExamplePath, envContent);
|
|
150
|
+
await fs.writeFile(envPath, envContent);
|
|
151
|
+
};
|
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import ejs from 'ejs';
|
|
4
|
-
|
|
5
|
-
export const setupDatabase = async (templatesDir, targetDir, config) => {
|
|
6
|
-
const { database, dbName, language, architecture } = config;
|
|
7
|
-
const langExt = language === 'TypeScript' ? 'ts' : 'js';
|
|
8
|
-
|
|
9
|
-
// 1. Migrations
|
|
10
|
-
if (database === 'MongoDB') {
|
|
11
|
-
// Copy migrate-mongo config
|
|
12
|
-
const migrateConfigTemplate = await fs.readFile(path.join(templatesDir, 'common', 'migrate-mongo-config.js.ejs'), 'utf-8');
|
|
13
|
-
const migrateConfigContent = ejs.render(migrateConfigTemplate, { ...config });
|
|
14
|
-
await fs.writeFile(path.join(targetDir, 'migrate-mongo-config.js'), migrateConfigContent);
|
|
15
|
-
|
|
16
|
-
// Setup migrations directory
|
|
17
|
-
await fs.ensureDir(path.join(targetDir, 'migrations'));
|
|
18
|
-
|
|
19
|
-
// Create initial migration file with timestamp
|
|
20
|
-
const timestamp = new Date().toISOString().replace(/[-T:.Z]/g, '').slice(0, 14); // YYYYMMDDHHMMSS
|
|
21
|
-
const migrationTemplate = await fs.readFile(path.join(templatesDir, 'common', 'migrations', 'init.js.ejs'), 'utf-8');
|
|
22
|
-
await fs.writeFile(path.join(targetDir, 'migrations', `${timestamp}-initial-setup.js`), migrationTemplate);
|
|
23
|
-
|
|
24
|
-
} else if (database !== 'None') {
|
|
25
|
-
// Flyway for SQL
|
|
26
|
-
await fs.ensureDir(path.join(targetDir, 'flyway/sql'));
|
|
27
|
-
const dbType = database === 'PostgreSQL' ? 'postgres' : 'mysql';
|
|
28
|
-
const sourceDir = path.join(templatesDir, 'db', dbType);
|
|
29
|
-
|
|
30
|
-
const files = await fs.readdir(sourceDir);
|
|
31
|
-
for (const file of files) {
|
|
32
|
-
if (file.endsWith('.ejs')) {
|
|
33
|
-
const template = await fs.readFile(path.join(sourceDir, file), 'utf-8');
|
|
34
|
-
const content = ejs.render(template, { ...config });
|
|
35
|
-
const targetFileName = file.replace('.ejs', '');
|
|
36
|
-
await fs.writeFile(path.join(targetDir, 'flyway/sql', targetFileName), content);
|
|
37
|
-
} else {
|
|
38
|
-
await fs.copy(path.join(sourceDir, file), path.join(targetDir, 'flyway/sql', file));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 2. Database Config
|
|
44
|
-
if (database !== 'None') {
|
|
45
|
-
const dbConfigFileName = language === 'TypeScript' ? (database === 'MongoDB' ? 'mongoose.ts' : 'database.ts') : (database === 'MongoDB' ? 'mongoose.js' : 'database.js');
|
|
46
|
-
const dbConfigTemplateSource = path.join(templatesDir, 'common', 'database', langExt, `${dbConfigFileName}.ejs`);
|
|
47
|
-
|
|
48
|
-
let dbConfigTarget;
|
|
49
|
-
|
|
50
|
-
if (architecture === 'MVC') {
|
|
51
|
-
await fs.ensureDir(path.join(targetDir, 'src/config'));
|
|
52
|
-
dbConfigTarget = path.join(targetDir, 'src/config', database === 'MongoDB' ? (language === 'TypeScript' ? 'database.ts' : 'database.js') : dbConfigFileName);
|
|
53
|
-
} else {
|
|
54
|
-
// Clean Architecture
|
|
55
|
-
await fs.ensureDir(path.join(targetDir, 'src/infrastructure/database'));
|
|
56
|
-
dbConfigTarget = path.join(targetDir, 'src/infrastructure/database', language === 'TypeScript' ? 'database.ts' : 'database.js');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (await fs.pathExists(dbConfigTemplateSource)) {
|
|
60
|
-
const dbTemplate = await fs.readFile(dbConfigTemplateSource, 'utf-8');
|
|
61
|
-
const dbContent = ejs.render(dbTemplate, { ...config });
|
|
62
|
-
await fs.writeFile(dbConfigTarget, dbContent);
|
|
63
|
-
|
|
64
|
-
// Render Spec
|
|
65
|
-
const specTemplateName = dbConfigFileName.replace(`.${langExt}`, `.spec.${langExt}.ejs`);
|
|
66
|
-
const specTemplateSource = path.join(templatesDir, 'common', 'database', langExt, specTemplateName);
|
|
67
|
-
if (await fs.pathExists(specTemplateSource)) {
|
|
68
|
-
const specTemplate = await fs.readFile(specTemplateSource, 'utf-8');
|
|
69
|
-
const specContent = ejs.render(specTemplate, { ...config });
|
|
70
|
-
const specTarget = dbConfigTarget.replace(`${path.sep}src${path.sep}`, `${path.sep}tests${path.sep}unit${path.sep}`).replace(`.${langExt}`, `.spec.${langExt}`);
|
|
71
|
-
await fs.ensureDir(path.dirname(specTarget));
|
|
72
|
-
await fs.writeFile(specTarget, specContent);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
} else if (architecture === 'MVC') {
|
|
76
|
-
// Even if DB is None, MVC needs src/config for other things (like swagger or general config)
|
|
77
|
-
await fs.ensureDir(path.join(targetDir, 'src/config'));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// 3. Models / Entities
|
|
81
|
-
await generateModels(templatesDir, targetDir, config);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export const generateModels = async (templatesDir, targetDir, config) => {
|
|
85
|
-
const { database, language, architecture } = config;
|
|
86
|
-
const langExt = language === 'TypeScript' ? 'ts' : 'js';
|
|
87
|
-
const modelFileName = language === 'TypeScript' ? 'User.ts' : 'User.js';
|
|
88
|
-
|
|
89
|
-
const sourceModelName = database === 'MongoDB' ? `${modelFileName}.mongoose.ejs` : `${modelFileName}.ejs`;
|
|
90
|
-
const modelTemplateSource = path.join(templatesDir, 'common', 'database', langExt, 'models', sourceModelName);
|
|
91
|
-
let modelTarget;
|
|
92
|
-
|
|
93
|
-
if (architecture === 'MVC') {
|
|
94
|
-
await fs.ensureDir(path.join(targetDir, 'src/models'));
|
|
95
|
-
modelTarget = path.join(targetDir, 'src/models', modelFileName);
|
|
96
|
-
} else {
|
|
97
|
-
await fs.ensureDir(path.join(targetDir, 'src/infrastructure/database/models'));
|
|
98
|
-
modelTarget = path.join(targetDir, 'src/infrastructure/database/models', modelFileName);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (await fs.pathExists(modelTemplateSource)) {
|
|
102
|
-
const modelTemplate = await fs.readFile(modelTemplateSource, 'utf-8');
|
|
103
|
-
const modelContent = ejs.render(modelTemplate, { ...config });
|
|
104
|
-
await fs.writeFile(modelTarget, modelContent);
|
|
105
|
-
|
|
106
|
-
// Render Spec
|
|
107
|
-
const modelSpecTemplateSource = path.join(templatesDir, 'common', 'database', langExt, 'models', `User.spec.${langExt}.ejs`);
|
|
108
|
-
if (await fs.pathExists(modelSpecTemplateSource)) {
|
|
109
|
-
const modelSpecTemplate = await fs.readFile(modelSpecTemplateSource, 'utf-8');
|
|
110
|
-
const modelSpecContent = ejs.render(modelSpecTemplate, { ...config });
|
|
111
|
-
const modelSpecTarget = modelTarget.replace(`${path.sep}src${path.sep}`, `${path.sep}tests${path.sep}unit${path.sep}`).replace(`.${langExt}`, `.spec.${langExt}`);
|
|
112
|
-
await fs.ensureDir(path.dirname(modelSpecTarget));
|
|
113
|
-
await fs.writeFile(modelSpecTarget, modelSpecContent);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
};
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import ejs from 'ejs';
|
|
4
|
+
|
|
5
|
+
export const setupDatabase = async (templatesDir, targetDir, config) => {
|
|
6
|
+
const { database, dbName, language, architecture } = config;
|
|
7
|
+
const langExt = language === 'TypeScript' ? 'ts' : 'js';
|
|
8
|
+
|
|
9
|
+
// 1. Migrations
|
|
10
|
+
if (database === 'MongoDB') {
|
|
11
|
+
// Copy migrate-mongo config
|
|
12
|
+
const migrateConfigTemplate = await fs.readFile(path.join(templatesDir, 'common', 'migrate-mongo-config.js.ejs'), 'utf-8');
|
|
13
|
+
const migrateConfigContent = ejs.render(migrateConfigTemplate, { ...config });
|
|
14
|
+
await fs.writeFile(path.join(targetDir, 'migrate-mongo-config.js'), migrateConfigContent);
|
|
15
|
+
|
|
16
|
+
// Setup migrations directory
|
|
17
|
+
await fs.ensureDir(path.join(targetDir, 'migrations'));
|
|
18
|
+
|
|
19
|
+
// Create initial migration file with timestamp
|
|
20
|
+
const timestamp = new Date().toISOString().replace(/[-T:.Z]/g, '').slice(0, 14); // YYYYMMDDHHMMSS
|
|
21
|
+
const migrationTemplate = await fs.readFile(path.join(templatesDir, 'common', 'migrations', 'init.js.ejs'), 'utf-8');
|
|
22
|
+
await fs.writeFile(path.join(targetDir, 'migrations', `${timestamp}-initial-setup.js`), migrationTemplate);
|
|
23
|
+
|
|
24
|
+
} else if (database !== 'None') {
|
|
25
|
+
// Flyway for SQL
|
|
26
|
+
await fs.ensureDir(path.join(targetDir, 'flyway/sql'));
|
|
27
|
+
const dbType = database === 'PostgreSQL' ? 'postgres' : 'mysql';
|
|
28
|
+
const sourceDir = path.join(templatesDir, 'db', dbType);
|
|
29
|
+
|
|
30
|
+
const files = await fs.readdir(sourceDir);
|
|
31
|
+
for (const file of files) {
|
|
32
|
+
if (file.endsWith('.ejs')) {
|
|
33
|
+
const template = await fs.readFile(path.join(sourceDir, file), 'utf-8');
|
|
34
|
+
const content = ejs.render(template, { ...config });
|
|
35
|
+
const targetFileName = file.replace('.ejs', '');
|
|
36
|
+
await fs.writeFile(path.join(targetDir, 'flyway/sql', targetFileName), content);
|
|
37
|
+
} else {
|
|
38
|
+
await fs.copy(path.join(sourceDir, file), path.join(targetDir, 'flyway/sql', file));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 2. Database Config
|
|
44
|
+
if (database !== 'None') {
|
|
45
|
+
const dbConfigFileName = language === 'TypeScript' ? (database === 'MongoDB' ? 'mongoose.ts' : 'database.ts') : (database === 'MongoDB' ? 'mongoose.js' : 'database.js');
|
|
46
|
+
const dbConfigTemplateSource = path.join(templatesDir, 'common', 'database', langExt, `${dbConfigFileName}.ejs`);
|
|
47
|
+
|
|
48
|
+
let dbConfigTarget;
|
|
49
|
+
|
|
50
|
+
if (architecture === 'MVC') {
|
|
51
|
+
await fs.ensureDir(path.join(targetDir, 'src/config'));
|
|
52
|
+
dbConfigTarget = path.join(targetDir, 'src/config', database === 'MongoDB' ? (language === 'TypeScript' ? 'database.ts' : 'database.js') : dbConfigFileName);
|
|
53
|
+
} else {
|
|
54
|
+
// Clean Architecture
|
|
55
|
+
await fs.ensureDir(path.join(targetDir, 'src/infrastructure/database'));
|
|
56
|
+
dbConfigTarget = path.join(targetDir, 'src/infrastructure/database', language === 'TypeScript' ? 'database.ts' : 'database.js');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (await fs.pathExists(dbConfigTemplateSource)) {
|
|
60
|
+
const dbTemplate = await fs.readFile(dbConfigTemplateSource, 'utf-8');
|
|
61
|
+
const dbContent = ejs.render(dbTemplate, { ...config });
|
|
62
|
+
await fs.writeFile(dbConfigTarget, dbContent);
|
|
63
|
+
|
|
64
|
+
// Render Spec
|
|
65
|
+
const specTemplateName = dbConfigFileName.replace(`.${langExt}`, `.spec.${langExt}.ejs`);
|
|
66
|
+
const specTemplateSource = path.join(templatesDir, 'common', 'database', langExt, specTemplateName);
|
|
67
|
+
if (await fs.pathExists(specTemplateSource)) {
|
|
68
|
+
const specTemplate = await fs.readFile(specTemplateSource, 'utf-8');
|
|
69
|
+
const specContent = ejs.render(specTemplate, { ...config });
|
|
70
|
+
const specTarget = dbConfigTarget.replace(`${path.sep}src${path.sep}`, `${path.sep}tests${path.sep}unit${path.sep}`).replace(`.${langExt}`, `.spec.${langExt}`);
|
|
71
|
+
await fs.ensureDir(path.dirname(specTarget));
|
|
72
|
+
await fs.writeFile(specTarget, specContent);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} else if (architecture === 'MVC') {
|
|
76
|
+
// Even if DB is None, MVC needs src/config for other things (like swagger or general config)
|
|
77
|
+
await fs.ensureDir(path.join(targetDir, 'src/config'));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 3. Models / Entities
|
|
81
|
+
await generateModels(templatesDir, targetDir, config);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const generateModels = async (templatesDir, targetDir, config) => {
|
|
85
|
+
const { database, language, architecture } = config;
|
|
86
|
+
const langExt = language === 'TypeScript' ? 'ts' : 'js';
|
|
87
|
+
const modelFileName = language === 'TypeScript' ? 'User.ts' : 'User.js';
|
|
88
|
+
|
|
89
|
+
const sourceModelName = database === 'MongoDB' ? `${modelFileName}.mongoose.ejs` : `${modelFileName}.ejs`;
|
|
90
|
+
const modelTemplateSource = path.join(templatesDir, 'common', 'database', langExt, 'models', sourceModelName);
|
|
91
|
+
let modelTarget;
|
|
92
|
+
|
|
93
|
+
if (architecture === 'MVC') {
|
|
94
|
+
await fs.ensureDir(path.join(targetDir, 'src/models'));
|
|
95
|
+
modelTarget = path.join(targetDir, 'src/models', modelFileName);
|
|
96
|
+
} else {
|
|
97
|
+
await fs.ensureDir(path.join(targetDir, 'src/infrastructure/database/models'));
|
|
98
|
+
modelTarget = path.join(targetDir, 'src/infrastructure/database/models', modelFileName);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (await fs.pathExists(modelTemplateSource)) {
|
|
102
|
+
const modelTemplate = await fs.readFile(modelTemplateSource, 'utf-8');
|
|
103
|
+
const modelContent = ejs.render(modelTemplate, { ...config });
|
|
104
|
+
await fs.writeFile(modelTarget, modelContent);
|
|
105
|
+
|
|
106
|
+
// Render Spec
|
|
107
|
+
const modelSpecTemplateSource = path.join(templatesDir, 'common', 'database', langExt, 'models', `User.spec.${langExt}.ejs`);
|
|
108
|
+
if (await fs.pathExists(modelSpecTemplateSource)) {
|
|
109
|
+
const modelSpecTemplate = await fs.readFile(modelSpecTemplateSource, 'utf-8');
|
|
110
|
+
const modelSpecContent = ejs.render(modelSpecTemplate, { ...config });
|
|
111
|
+
const modelSpecTarget = modelTarget.replace(`${path.sep}src${path.sep}`, `${path.sep}tests${path.sep}unit${path.sep}`).replace(`.${langExt}`, `.spec.${langExt}`);
|
|
112
|
+
await fs.ensureDir(path.dirname(modelSpecTarget));
|
|
113
|
+
await fs.writeFile(modelSpecTarget, modelSpecContent);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
export const setupProjectDirectory = async (targetDir, projectName) => {
|
|
5
|
-
if (await fs.pathExists(targetDir)) {
|
|
6
|
-
throw new Error(`Directory ${projectName} already exists.`);
|
|
7
|
-
}
|
|
8
|
-
await fs.ensureDir(targetDir);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const copyBaseStructure = async (templatesDir, targetDir, architecture, language) => {
|
|
12
|
-
const structureMap = {
|
|
13
|
-
'MVC': 'mvc',
|
|
14
|
-
'Clean Architecture': 'clean-architecture'
|
|
15
|
-
};
|
|
16
|
-
const archTemplate = structureMap[architecture];
|
|
17
|
-
const langExt = language === 'TypeScript' ? 'ts' : 'js';
|
|
18
|
-
const templatePath = path.join(templatesDir, archTemplate, langExt);
|
|
19
|
-
|
|
20
|
-
await fs.copy(templatePath, targetDir);
|
|
21
|
-
return { archTemplate, langExt, templatePath };
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const copyCommonFiles = async (templatesDir, targetDir, language) => {
|
|
25
|
-
await fs.copy(path.join(templatesDir, 'common', '_gitignore'), path.join(targetDir, '.gitignore'));
|
|
26
|
-
await fs.copy(path.join(templatesDir, 'common', '.dockerignore'), path.join(targetDir, '.dockerignore'));
|
|
27
|
-
await fs.copy(path.join(templatesDir, 'common', '.gitattributes'), path.join(targetDir, '.gitattributes'));
|
|
28
|
-
|
|
29
|
-
if (language === 'TypeScript') {
|
|
30
|
-
await fs.copy(path.join(templatesDir, 'common', 'tsconfig.json'), path.join(targetDir, 'tsconfig.json'));
|
|
31
|
-
}
|
|
32
|
-
};
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
export const setupProjectDirectory = async (targetDir, projectName) => {
|
|
5
|
+
if (await fs.pathExists(targetDir)) {
|
|
6
|
+
throw new Error(`Directory ${projectName} already exists.`);
|
|
7
|
+
}
|
|
8
|
+
await fs.ensureDir(targetDir);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const copyBaseStructure = async (templatesDir, targetDir, architecture, language) => {
|
|
12
|
+
const structureMap = {
|
|
13
|
+
'MVC': 'mvc',
|
|
14
|
+
'Clean Architecture': 'clean-architecture'
|
|
15
|
+
};
|
|
16
|
+
const archTemplate = structureMap[architecture];
|
|
17
|
+
const langExt = language === 'TypeScript' ? 'ts' : 'js';
|
|
18
|
+
const templatePath = path.join(templatesDir, archTemplate, langExt);
|
|
19
|
+
|
|
20
|
+
await fs.copy(templatePath, targetDir);
|
|
21
|
+
return { archTemplate, langExt, templatePath };
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const copyCommonFiles = async (templatesDir, targetDir, language) => {
|
|
25
|
+
await fs.copy(path.join(templatesDir, 'common', '_gitignore'), path.join(targetDir, '.gitignore'));
|
|
26
|
+
await fs.copy(path.join(templatesDir, 'common', '.dockerignore'), path.join(targetDir, '.dockerignore'));
|
|
27
|
+
await fs.copy(path.join(templatesDir, 'common', '.gitattributes'), path.join(targetDir, '.gitattributes'));
|
|
28
|
+
|
|
29
|
+
if (language === 'TypeScript') {
|
|
30
|
+
await fs.copy(path.join(templatesDir, 'common', 'tsconfig.json'), path.join(targetDir, 'tsconfig.json'));
|
|
31
|
+
}
|
|
32
|
+
};
|