@dolphjs/cli 0.0.1-beta

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/new-app.mjs ADDED
@@ -0,0 +1,352 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { exec, execSync } from "child_process";
4
+ import { mkdirSync } from "fs";
5
+ import inquirer from "inquirer";
6
+ import chalk from "chalk";
7
+ import ora from "ora";
8
+ import writeTsFilePackage from "./utils/ts-oop/packageData.mjs";
9
+ import writeTsFuncFilePackage from "./utils/ts-func/packageData.mjs";
10
+ import writeJsFIlePackage from "./utils/js-func/packageData.mjs";
11
+ import writeTsFileSwcrc from "./utils/ts-oop/swcrcData.mjs";
12
+ import writeGitignoreFile from "./utils/ts-oop/gitignoreData.mjs";
13
+ import writeTsNodemonFile from "./utils/ts-oop/nodemonData.mjs";
14
+ import writeReadmeFile from "./utils/ts-oop/readmeData.mjs";
15
+ import writeTsOopSubFile from "./utils/ts-oop/copySubFolder.mjs";
16
+ import writeTsFuncSubFile from "./utils/ts-func/copySubFolder.mjs";
17
+ import writeSubFileJsFunc from "./utils/js-func/writeSubFile.mjs";
18
+ import writeSubFileJsOop from "./utils/js-oop/writeSubFileJsOop.mjs";
19
+ import writeTsconfigFile from "./utils/ts-oop/tsconfigFile.mjs";
20
+ import { jsFunc, jsOop, tsFunc, tsOop } from "./utils/constants/types.mjs";
21
+ import { npm, pnpm, yarn } from "./utils/constants/packageManagers.mjs";
22
+ import {
23
+ dependencies,
24
+ devDependencies,
25
+ tsDependencies,
26
+ tsDevDependencies,
27
+ } from "./utils/dependencies.mjs";
28
+
29
+ const program = new Command();
30
+
31
+ program
32
+ .version("1.0.0")
33
+ .command("create-app <app-name>")
34
+ .description("Create a new dolphJs application")
35
+ .action(async (appName) => {
36
+ try {
37
+ console.log(
38
+ chalk.blueBright("Initializing your dolphJs application...") + "🐬"
39
+ );
40
+ const options = [tsOop, tsFunc, jsOop, jsFunc];
41
+ const { selectedOption } = await inquirer.prompt([
42
+ {
43
+ type: "list",
44
+ name: "selectedOption",
45
+ message: "How do you want to write your application ? 🤔:",
46
+ choices: options,
47
+ },
48
+ ]);
49
+
50
+ const packageManagerOptions = [npm, yarn, pnpm];
51
+ const { selectedPackageManagerOption } = await inquirer.prompt([
52
+ {
53
+ type: "list",
54
+ name: "selectedPackageManagerOption",
55
+ message: "Which is your preffered package manager ? :",
56
+ choices: packageManagerOptions,
57
+ },
58
+ ]);
59
+ console.info(chalk.green(`Using ${selectedPackageManagerOption}!`));
60
+ console.log(
61
+ chalk.green(`Getting your application ready for ${selectedOption}!`)
62
+ );
63
+ mkdirSync(appName);
64
+ process.chdir(appName);
65
+ if (selectedOption === tsOop) {
66
+ writeTsFilePackage(appName);
67
+ writeTsFileSwcrc();
68
+ writeGitignoreFile();
69
+ writeTsNodemonFile();
70
+ writeReadmeFile();
71
+ writeTsconfigFile();
72
+ mkdirSync("src");
73
+ mkdirSync("src/config");
74
+ mkdirSync("src/controllers");
75
+ mkdirSync("src/interfaces");
76
+ mkdirSync("src/routes");
77
+ writeTsOopSubFile();
78
+ }
79
+ if (selectedOption === tsFunc) {
80
+ writeTsFuncFilePackage(appName);
81
+ writeTsFileSwcrc();
82
+ writeGitignoreFile();
83
+ writeTsNodemonFile();
84
+ writeTsconfigFile();
85
+ writeReadmeFile();
86
+ mkdirSync("src");
87
+ mkdirSync("src/config");
88
+ mkdirSync("src/controllers");
89
+ mkdirSync("src/routes");
90
+ writeTsFuncSubFile();
91
+ }
92
+
93
+ if (selectedOption === jsFunc) {
94
+ writeJsFIlePackage(appName);
95
+ writeReadmeFile();
96
+ writeGitignoreFile();
97
+ mkdirSync("src");
98
+ mkdirSync("src/config");
99
+ mkdirSync("src/controllers");
100
+ mkdirSync("src/routes");
101
+ writeSubFileJsFunc();
102
+ }
103
+
104
+ if (selectedOption === jsOop) {
105
+ writeJsFIlePackage(appName);
106
+ writeReadmeFile();
107
+ writeGitignoreFile();
108
+ mkdirSync("src");
109
+ mkdirSync("src/config");
110
+ mkdirSync("src/controllers");
111
+ mkdirSync("src/routes");
112
+ writeSubFileJsOop();
113
+ }
114
+
115
+ // install dependencies using child process execSync
116
+ try {
117
+ const spinner = ora("Installing dependencies...").start();
118
+ let installCommand = "yarn add";
119
+ let runMsg = "yarn dev";
120
+
121
+ switch (selectedPackageManagerOption) {
122
+ case npm:
123
+ installCommand = "npm install";
124
+ runMsg = "npm run dev";
125
+ break;
126
+ case pnpm:
127
+ installCommand = "pnpm add";
128
+ runMsg = "pnpm dev";
129
+ case yarn:
130
+ installCommand = installCommand;
131
+ default:
132
+ break;
133
+ }
134
+
135
+ if (selectedOption === jsFunc || selectedOption === jsOop) {
136
+ execSync(`${installCommand} ${dependencies.join(" ")}`);
137
+ } else if (selectedOption === tsFunc || selectedOption === tsOop) {
138
+ execSync(`${installCommand} ${tsDependencies.join(" ")}`);
139
+ }
140
+ spinner.succeed("Dependencies installed!");
141
+
142
+ // prompt user to select an option
143
+
144
+ // create app directory and copy files
145
+
146
+ // update package.json file
147
+ console.log(chalk.yellow("Updating package.json..."));
148
+ // install dev dependencies
149
+ const spinner2 = ora("Installing dev dependencies...").start();
150
+
151
+ if (selectedOption === jsFunc || selectedOption === jsOop) {
152
+ exec(`${installCommand} ${devDependencies.join(" ")}`);
153
+ } else if (selectedOption === tsFunc || selectedOption === tsOop) {
154
+ exec(`${installCommand} ${tsDevDependencies.join(" ")}`);
155
+ }
156
+
157
+ spinner2.succeed("Dev dependencies installed!");
158
+
159
+ // show completion message
160
+ console.log(
161
+ chalk.green(
162
+ `Done! Your app has been created. Navigate to your app by running "cd ${appName}" and then run ${chalk.bgGreen(
163
+ runMsg
164
+ )}`
165
+ )
166
+ );
167
+ } catch (error) {
168
+ console.log(chalk.redBright("\nError creating your app", error));
169
+ }
170
+ } catch (error) {
171
+ console.log(chalk.redBright("Error creating your app", error));
172
+ }
173
+ });
174
+
175
+ program
176
+ .version("1.0.0")
177
+ .command("create-app <app-name>")
178
+ .description("Create a new dolphJs application")
179
+ .action(async (appName) => {
180
+ try {
181
+ console.log(
182
+ chalk.blueBright("Initializing your dolphJs application...") + "🐬"
183
+ );
184
+ const options = [tsOop, tsFunc, jsOop, jsFunc];
185
+ const { selectedOption } = await inquirer.prompt([
186
+ {
187
+ type: "list",
188
+ name: "selectedOption",
189
+ message: "How do you want to write your application ? 🤔:",
190
+ choices: options,
191
+ },
192
+ ]);
193
+
194
+ const packageManagerOptions = [npm, yarn, pnpm];
195
+ const { selectedPackageManagerOption } = await inquirer.prompt([
196
+ {
197
+ type: "list",
198
+ name: "selectedPackageManagerOption",
199
+ message: "Which is your preffered package manager ? :",
200
+ choices: packageManagerOptions,
201
+ },
202
+ ]);
203
+ console.info(chalk.green(`Using ${selectedPackageManagerOption}!`));
204
+ console.log(
205
+ chalk.green(`Getting your application ready for ${selectedOption}!`)
206
+ );
207
+ mkdirSync(appName);
208
+ process.chdir(appName);
209
+ if (selectedOption === tsOop) {
210
+ writeTsFilePackage(appName);
211
+ writeTsFileSwcrc();
212
+ writeGitignoreFile();
213
+ writeTsNodemonFile();
214
+ writeReadmeFile();
215
+ writeTsconfigFile();
216
+ mkdirSync("src");
217
+ mkdirSync("src/config");
218
+ mkdirSync("src/controllers");
219
+ mkdirSync("src/interfaces");
220
+ mkdirSync("src/routes");
221
+ writeTsOopSubFile();
222
+ }
223
+ if (selectedOption === tsFunc) {
224
+ writeTsFuncFilePackage(appName);
225
+ writeTsFileSwcrc();
226
+ writeGitignoreFile();
227
+ writeTsNodemonFile();
228
+ writeTsconfigFile();
229
+ writeReadmeFile();
230
+ mkdirSync("src");
231
+ mkdirSync("src/config");
232
+ mkdirSync("src/controllers");
233
+ mkdirSync("src/routes");
234
+ writeTsFuncSubFile();
235
+ }
236
+
237
+ if (selectedOption === jsFunc) {
238
+ writeJsFIlePackage(appName);
239
+ writeReadmeFile();
240
+ writeGitignoreFile();
241
+ mkdirSync("src");
242
+ mkdirSync("src/config");
243
+ mkdirSync("src/controllers");
244
+ mkdirSync("src/routes");
245
+ writeSubFileJsFunc();
246
+ }
247
+
248
+ if (selectedOption === jsOop) {
249
+ writeJsFIlePackage(appName);
250
+ writeReadmeFile();
251
+ writeGitignoreFile();
252
+ mkdirSync("src");
253
+ mkdirSync("src/config");
254
+ mkdirSync("src/controllers");
255
+ mkdirSync("src/routes");
256
+ writeSubFileJsOop();
257
+ }
258
+
259
+ // install dependencies using child process execSync
260
+ try {
261
+ const spinner = ora("Installing dependencies...").start();
262
+ let installCommand = "yarn add";
263
+ let runMsg = "yarn dev";
264
+
265
+ switch (selectedPackageManagerOption) {
266
+ case npm:
267
+ installCommand = "npm install";
268
+ runMsg = "npm run dev";
269
+ break;
270
+ case pnpm:
271
+ installCommand = "pnpm add";
272
+ runMsg = "pnpm dev";
273
+ case yarn:
274
+ installCommand = installCommand;
275
+ default:
276
+ break;
277
+ }
278
+
279
+ if (selectedOption === jsFunc || selectedOption === jsOop) {
280
+ execSync(`${installCommand} ${dependencies.join(" ")}`);
281
+ } else if (selectedOption === tsFunc || selectedOption === tsOop) {
282
+ execSync(`${installCommand} ${tsDependencies.join(" ")}`);
283
+ }
284
+ spinner.succeed("Dependencies installed!");
285
+
286
+ // prompt user to select an option
287
+
288
+ // create app directory and copy files
289
+
290
+ // update package.json file
291
+ console.log(chalk.yellow("Updating package.json..."));
292
+ // install dev dependencies
293
+ const spinner2 = ora("Installing dev dependencies...").start();
294
+
295
+ if (selectedOption === jsFunc || selectedOption === jsOop) {
296
+ exec(`${installCommand} ${devDependencies.join(" ")}`);
297
+ } else if (selectedOption === tsFunc || selectedOption === tsOop) {
298
+ exec(`${installCommand} ${tsDevDependencies.join(" ")}`);
299
+ }
300
+
301
+ spinner2.succeed("Dev dependencies installed!");
302
+
303
+ // show completion message
304
+ console.log(
305
+ chalk.green(
306
+ `Done! Your app has been created. Navigate to your app by running "cd ${appName}" and then run ${chalk.bgGreen(
307
+ runMsg
308
+ )}`
309
+ )
310
+ );
311
+ } catch (error) {
312
+ console.log(chalk.redBright("\nError creating your app", error));
313
+ }
314
+ } catch (error) {
315
+ console.log(chalk.redBright("Error creating your app", error));
316
+ }
317
+ });
318
+
319
+ program.command("help").action(() => {
320
+ console.info(
321
+ chalk.white(
322
+ "The `create-app` command would walk you through a few questions in order to create your app how you desire together with dolphjs' unique and scalable application structure."
323
+ )
324
+ );
325
+ console.info(chalk.blue("Options: "));
326
+ console.info(
327
+ chalk.white(
328
+ "-v, --version output the verson number"
329
+ )
330
+ );
331
+ console.info(
332
+ chalk.white(
333
+ "-h, --version display help for command"
334
+ )
335
+ );
336
+
337
+ console.info(chalk.blue("Commands: "));
338
+ console.info(
339
+ chalk.white(
340
+ "create-app, <app-name> Create a new dolphjs app"
341
+ )
342
+ );
343
+ });
344
+
345
+ program.command("*", { hidden: true }).action(() => {
346
+ console.log(
347
+ chalk.redBright(`Unknown command. See the list of available commands:`)
348
+ );
349
+ program.help();
350
+ });
351
+
352
+ program.parse(process.argv);
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@dolphjs/cli",
3
+ "version": "0.0.1beta",
4
+ "description": "DolphJs is an express.js library for making software development easier by taking care of all the unneccessary tasks developers have to worry about.",
5
+ "main": "new-app.mjs",
6
+ "bin": {
7
+ "dolph": "./new-app.mjs"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "start": "node new-app.mjs",
12
+ "push": "npm publish"
13
+ },
14
+ "keywords": [
15
+ "Dolph-cli",
16
+ "DolphJs",
17
+ "ExpressJs",
18
+ "API",
19
+ "NodeJs",
20
+ "JavaScript",
21
+ "dolphjs",
22
+ "dolph-cli",
23
+ "dolphcli"
24
+ ],
25
+ "sponsor": {
26
+ "url": "https://questgig.com"
27
+ },
28
+ "engines": {
29
+ "node": ">=14.0.0"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "author": "Ghostcod3r <https://github.com/chrisegbaaaibon>",
35
+ "maintainers": [
36
+ "Christopher Egbaaibon <https://github.com/chrisegbaaaibon>",
37
+ "Utibeabasi Ekong <https://github.com/Xlaez>"
38
+ ],
39
+ "contributors": [
40
+ "Utibeabasi Ekong <https://github.com/Xlaez>"
41
+ ],
42
+ "repository": "https://github.com/dolphjs/cli",
43
+ "license": "MIT",
44
+ "dependencies": {
45
+ "@types/handlebars": "^4.1.0",
46
+ "chalk": "^5.2.0",
47
+ "child_process": "^1.0.2",
48
+ "command-not-found": "^0.0.3",
49
+ "commander": "^10.0.0",
50
+ "inquirer": "^9.1.4",
51
+ "ora": "^6.1.2",
52
+ "typescript": "^4.9.5"
53
+ }
54
+ }
package/readme.md ADDED
@@ -0,0 +1,25 @@
1
+ <p align="center">
2
+ <a href="https://www.npmjs.com/package/dolphjs/core" target="blank"><img src="https://github.com/Chrisegbaaaibon/Media/blob/master/Images/DolphJS-logo-small.png?raw=true" width="120" alt="Dolph Logo" /></a>
3
+ </p>
4
+
5
+ # DolphJs-CLI
6
+
7
+ The CLI application provides developers with an easy and fast way to generate a dolphjs application structure.
8
+ It is advisable to always build your applications using the CLI tool so as to maintain the design and pattern dolphjs implements.
9
+
10
+ ## Installation
11
+
12
+ To install the package, run:
13
+
14
+ `npm install @dolphjs/cli -g`
15
+
16
+ ## START
17
+
18
+ To run the CLI application, run:
19
+
20
+ `dolph create-app "app-name"`
21
+
22
+ ## HELP
23
+
24
+ For help run the :
25
+ `dolph help` command
@@ -0,0 +1,3 @@
1
+ export const npm = "npm"
2
+ export const yarn = "yarn"
3
+ export const pnpm = "pnpm"
@@ -0,0 +1,4 @@
1
+ export const tsOop = 'TypeScript - Object Oriented Programming'
2
+ export const tsFunc = 'TypeScript - Functional Programming'
3
+ export const jsOop = 'Javascript - Object Oriented Programming'
4
+ export const jsFunc= 'Javascript - Functional Programming'
@@ -0,0 +1,24 @@
1
+ export const dependencies = [
2
+ "@dolphjs/core",
3
+ "cors",
4
+ "cross-env",
5
+ "dotenv",
6
+ "joi",
7
+ ];
8
+
9
+ export const devDependencies = ["@types/express", "node-config", "nodemon"];
10
+
11
+ export const tsDependencies = [...dependencies, "class-transformer"];
12
+ export const tsDevDependencies = [
13
+ ...devDependencies,
14
+ "@swc/cli",
15
+ "@swc/core",
16
+ "@types/cors",
17
+ "@types/joi",
18
+ "@types/node",
19
+ "ts-node",
20
+ "tsc-alias",
21
+ "tsconfig-paths",
22
+ "typescript",
23
+ "nodemon",
24
+ ];
@@ -0,0 +1,20 @@
1
+ import { writeFileSync } from "fs";
2
+
3
+ export default function writeFilePackage(appName) {
4
+ const packageJsonData = {
5
+ name: appName,
6
+ version: "1.0.0",
7
+ description: "",
8
+ main: "src/index.js",
9
+ scripts: {
10
+ dev: "cross-env NODE_ENV=development nodemon src/index.js",
11
+ start: "cross-env NODE_ENV=production node src/index.js",
12
+ },
13
+ keywords: [],
14
+ author: "",
15
+ license: "ISC",
16
+ dependencies: {},
17
+ devDependencies: {},
18
+ };
19
+ writeFileSync(`./package.json`, JSON.stringify(packageJsonData, null, 2));
20
+ }
@@ -0,0 +1,96 @@
1
+ import { writeFileSync } from "fs";
2
+
3
+ const indexRoute = `const { Router } = '@dolphjs/core';
4
+ const demoRoute = require('./demo.route');
5
+
6
+ const defaultRoutes = [
7
+ \t{
8
+ \t\tpath: '/',
9
+ \t\trouter: demoRoute,
10
+ \t},
11
+ ];
12
+
13
+ module.exports = defaultRoutes;
14
+ `;
15
+
16
+ const demoRoutes =
17
+ "const { Router } = require('@dolphjs/core');\n\
18
+ const { sendMsg } = require('@/controllers/demo.controller');\n\
19
+ \
20
+ const router = Router();\n\
21
+ \
22
+ const path = '/api/v1';\n\
23
+ \
24
+ router.get(`${path}`, sendMsg);\n\
25
+ \
26
+ module.exports = router;\n\
27
+ ";
28
+
29
+ const indexData = `const Dolph = require('@dolphjs/core');
30
+ const defaultRouter = require('./routes');
31
+ const { env, port } = require('./config');
32
+ const helmet = require('helmet');
33
+ const cors = require('cors');
34
+
35
+ const dolph = new Dolph(defaultRouter, port, env, null, [helmet(), cors()]);
36
+ dolph.listen();
37
+ `;
38
+
39
+ const controllerDemo = `const { httpStatus, catchAsync } = require('@dolphjs/core');
40
+
41
+ const sendMsg = catchAsync(async (req, res) => {
42
+ \tconst message =
43
+ \t'Welcome to the API end-point for the Dolph app. If you have problems getting started, visit https://github.com/dolphjs/\tcore#README.MD';
44
+ \tres.status(httpStatus.OK).json({ message });
45
+ });
46
+
47
+ module.exports = { sendMsg };
48
+ `;
49
+
50
+ const configIndex =
51
+ "const dotenv = require('dotenv');\n\
52
+ const path = require('path');\n\
53
+ const Joi = require('joi');\n\
54
+ \n\
55
+ dotenv.config({});\n\
56
+ \n\
57
+ const envVarsSchema = Joi.object()\n\
58
+ \t.keys({\n\
59
+ \t\tNODE_ENV: Joi.string()\n\
60
+ \t\t\t.valid('production', 'development', 'test')\n\
61
+ \t\t\t.required(),\n\
62
+ \t\tPORT: Joi.number().default(1919),\n\
63
+ })\
64
+ .unknown();\n\
65
+ \
66
+ const { value: envVars, error } = envVarsSchema\n\
67
+ \t.prefs({ errors: { label: 'key' } })\n\
68
+ \t.validate(process.env);\n\
69
+ \n\
70
+ if (error) {\n\
71
+ \tthrow new Error(`Config validation error: ${error.message}`);\n\
72
+ }\n\
73
+ \n\
74
+ module.exports = {\n\
75
+ \tenv: envVars.NODE_ENV,\n\
76
+ \tport: envVars.PORT,\n\
77
+ };\
78
+ ";
79
+
80
+ const jsConfigFile = `{
81
+ "compilerOptions": {
82
+ "paths": {
83
+ "@/*": ["./src/*"]
84
+ }
85
+ }
86
+ }
87
+ `;
88
+
89
+ export default function writeSubFileJsFunc() {
90
+ writeFileSync("src/index.js", indexData);
91
+ writeFileSync("src/config/index.js", configIndex);
92
+ writeFileSync("src/routes/demo.route.js", demoRoutes);
93
+ writeFileSync("src/routes/index.js", indexRoute);
94
+ writeFileSync("src/controllers/demo.controller.js", controllerDemo);
95
+ writeFileSync("jsConfig.json", jsConfigFile);
96
+ }
@@ -0,0 +1,19 @@
1
+ import { writeFileSync } from "fs";
2
+
3
+ export default function writeFilePackageJs(appName) {
4
+ const packageJsonData = {
5
+ name: appName,
6
+ version: "1.0.0",
7
+ description: "",
8
+ main: "src/index.js",
9
+ scripts: {
10
+ dev: "cross-env NODE_ENV=development nodemon src/index.js",
11
+ start: "cross-env NODE_ENV=production node src/index.js",
12
+ },
13
+ keywords: [],
14
+ author: "",
15
+ license: "ISC",
16
+ dependencies: {},
17
+ };
18
+ writeFileSync(`./package.json`, JSON.stringify(packageJsonData, null, 2));
19
+ }
@@ -0,0 +1,94 @@
1
+ import { writeFileSync } from "fs";
2
+
3
+ const routeIndex =
4
+ "const { Router } = require('@dolphjs/core');\n\
5
+ const DemoController = require('@/controllers/demo.controller');\n\
6
+ \n\
7
+ class DemoRouter {\n\
8
+ \tpath = '/v1/api';\n\
9
+ \tcontroller = new DemoController();\n\
10
+ \trouter = Router();\
11
+ \n\
12
+ \n\
13
+ \tconstructor() {\n\
14
+ \t this.Routes();\n\
15
+ }\n\
16
+ \n\
17
+ \tRoutes() {\n\
18
+ \t\tthis.router.get(`${this.path}`, this.controller.sendMessage);\n\
19
+ \t}\n\
20
+ }\n\
21
+ \n\
22
+ module.exports = DemoRouter;\
23
+ ";
24
+
25
+ const indexData = `const Dolph = require('@dolphjs/core');
26
+ const { env, port } = require('./config');
27
+ const DemoRouter = require('./routes/demo.route');
28
+ const cors = require('cors');
29
+ const helmet = require('helmet');
30
+
31
+ const dolph = new Dolph([new DemoRouter()], port, env, null, [
32
+ helmet(),
33
+ cors({origin: '*'})
34
+ ]);
35
+ dolph.listen();
36
+ `;
37
+
38
+ const controllerDemo = `const { httpStatus, catchAsync } = require('@dolphjs/core');
39
+
40
+ class DemoController {
41
+ sendMessage = catchAsync(async (req, res) => {
42
+ const message =
43
+ 'Welcome to the API end-point for the Dolph app. If you have problems getting started, visit https://github.com/dolphjs/core#README.MD';
44
+ res.status(httpStatus.OK).json({ message });
45
+ });
46
+ }
47
+
48
+ module.exports = DemoController;
49
+ `;
50
+
51
+ const configIndex =
52
+ "const dotenv = require('dotenv');\n\
53
+ const Joi = require('joi');\n\
54
+ \n\
55
+ dotenv.config({});\n\
56
+ \n\
57
+ const envVarsSchema = Joi.object()\n\
58
+ \t.keys({\n\
59
+ \t\tNODE_ENV: Joi.string()\n\
60
+ \t\t\t.valid('production', 'development', 'test'),\n\
61
+ \t\tPORT: Joi.number().default(1919),\
62
+ \t})\n\
63
+ \t.unknown();\n\
64
+ \n\
65
+ const { value: envVars, error } = envVarsSchema\n\
66
+ \t.prefs({ errors: { label: 'key' } })\n\
67
+ \t.validate(process.env);\n\
68
+ \n\
69
+ if (error) {\n\
70
+ \tthrow new Error(`Config validation error: ${error.message}`);\n\
71
+ }\n\
72
+ \n\
73
+ module.exports = {\n\
74
+ \t\tenv: envVars.NODE_ENV,\
75
+ \t\tport: envVars.PORT,\n\
76
+ };\
77
+ ";
78
+
79
+ const jsConfigFile = `{
80
+ "compilerOptions": {
81
+ "paths": {
82
+ "@/*": ["./src/*"]
83
+ }
84
+ }
85
+ }
86
+ `;
87
+
88
+ export default function writeSubFileJsOop() {
89
+ writeFileSync("src/index.js", indexData);
90
+ writeFileSync("src/config/index.js", configIndex);
91
+ writeFileSync("src/routes/demo.route.js", routeIndex);
92
+ writeFileSync("src/controllers/demo.controller.js", controllerDemo);
93
+ writeFileSync("jsConfig.json", jsConfigFile);
94
+ }