@dolphjs/cli 0.1.1 → 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.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/dist/generators/generate_controller.js +65 -0
  3. package/dist/generators/generate_model.js +61 -0
  4. package/dist/generators/generate_mysql.js +63 -0
  5. package/dist/generators/generate_routes.js +59 -0
  6. package/dist/generators/generate_service.js +63 -0
  7. package/dist/generators/resolvers/resolve_controller_content.js +19 -0
  8. package/dist/generators/resolvers/resolve_model_content.js +37 -0
  9. package/dist/generators/resolvers/resolve_routes_content.js +19 -0
  10. package/dist/generators/resolvers/resolve_service_content.js +19 -0
  11. package/dist/generators/templates/controller_template.js +83 -0
  12. package/dist/generators/templates/model_template.js +168 -0
  13. package/dist/generators/templates/mysql_config_template.js +59 -0
  14. package/dist/generators/templates/routes_template.js +86 -0
  15. package/dist/generators/templates/service_template.js +172 -0
  16. package/dist/index.js +30 -0
  17. package/dist/registers/register_routes.js +145 -0
  18. package/dist/registers/server_file_routes.js +74 -0
  19. package/dist/types/config.js +1 -0
  20. package/dist/utils/get_root_dir_path.js +11 -0
  21. package/dist/utils/get_user_config_path.js +10 -0
  22. package/dist/utils/init_helper_function.js +90 -0
  23. package/dist/utils/package_description.js +6 -0
  24. package/dist/utils/package_generator.js +73 -0
  25. package/dist/utils/package_init.js +11 -0
  26. package/dist/utils/read_package_json.js +9 -0
  27. package/dist/utils/read_user_config.js +67 -0
  28. package/dist/utils/read_user_config_path.js +19 -0
  29. package/dist/utils/write_dolph_config.js +9 -0
  30. package/dist/utils/write_gitignore.js +12 -0
  31. package/dist/utils/write_package_json.js +68 -0
  32. package/dist/utils/write_swrcc.js +48 -0
  33. package/dist/utils/write_tsconfig.js +45 -0
  34. package/dist/utils/write_user_config.js +16 -0
  35. package/package.json +47 -40
  36. package/CODE_OF_CONDUCT.md +0 -76
  37. package/CONTRIBUTING.md +0 -91
  38. package/new-app.mjs +0 -209
  39. package/readme.md +0 -25
  40. package/utils/constants/packageManagers.mjs +0 -3
  41. package/utils/constants/types.mjs +0 -4
  42. package/utils/dependencies.mjs +0 -24
  43. package/utils/js-func/packageData.mjs +0 -20
  44. package/utils/js-func/writeSubFile.mjs +0 -96
  45. package/utils/js-oop/packageData.mjs +0 -19
  46. package/utils/js-oop/writeSubFileJsOop.mjs +0 -94
  47. package/utils/ts-func/copySubFolder.mjs +0 -58
  48. package/utils/ts-func/gitignoreData.mjs +0 -11
  49. package/utils/ts-func/nodemonData.mjs +0 -12
  50. package/utils/ts-func/packageData.mjs +0 -23
  51. package/utils/ts-func/readmeData.mjs +0 -293
  52. package/utils/ts-func/swcrcData.mjs +0 -49
  53. package/utils/ts-func/tsconfigFile.mjs +0 -55
  54. package/utils/ts-oop/copySubFolder.mjs +0 -71
  55. package/utils/ts-oop/gitignoreData.mjs +0 -11
  56. package/utils/ts-oop/nodemonData.mjs +0 -12
  57. package/utils/ts-oop/packageData.mjs +0 -23
  58. package/utils/ts-oop/readmeData.mjs +0 -292
  59. package/utils/ts-oop/swcrcData.mjs +0 -49
  60. package/utils/ts-oop/tsconfigFile.mjs +0 -55
package/package.json CHANGED
@@ -1,54 +1,61 @@
1
1
  {
2
2
  "name": "@dolphjs/cli",
3
- "version": "0.1.1",
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
- },
3
+ "version": "1.0.0",
4
+ "description": "The dolphjs-cli is a tool for efficient intialization and management of a dolphjs project",
5
+ "main": "./dist/index.js",
6
+ "repository": "https://github.com/dolphjs/dolph-cli.git",
7
+ "author": "<https://github.com/Xlaez>",
8
+ "license": "MIT",
9
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"
10
+ "lint": "eslint .",
11
+ "check-lint": "eslint [0-9]*.ts",
12
+ "clean": "rimraf ./dist",
13
+ "build": "tsc ./lib/index.ts --esModuleInterop true --target ES2020 --module nodenext --moduleResolution nodenext --outDir dist",
14
+ "start": "npm run clean && npm run build && node ./dist/index.js",
15
+ "dev": "ts-node ./lib/index.ts",
16
+ "dev:start": "node ./dist/index.js",
17
+ "pub": "npm run clean && npm run build"
27
18
  },
19
+ "type": "module",
28
20
  "engines": {
29
- "node": ">=14.0.0"
21
+ "node": ">=18.0.0"
30
22
  },
31
23
  "publishConfig": {
32
24
  "access": "public"
33
25
  },
34
- "author": "Ghostcod3r <https://github.com/chrisegbaaaibon>",
35
- "maintainers": [
36
- "Christopher Egbaaibon <https://github.com/chrisegbaaaibon>",
37
- "Utibeabasi Ekong <https://github.com/Xlaez>"
26
+ "keywords": [
27
+ "Dolphjs-cli",
28
+ "Dolphjs-cli",
29
+ "Dolphjs",
30
+ "Dolph",
31
+ "NodeJs",
32
+ "cli"
38
33
  ],
39
- "contributors": [
40
- "Utibeabasi Ekong <https://github.com/Xlaez>"
34
+ "files": [
35
+ "dist/**/*"
41
36
  ],
42
- "repository": "https://github.com/dolphjs/cli",
43
- "license": "MIT",
37
+ "bin": {
38
+ "dolph-cli": "./dist/index.js",
39
+ "dc": "./dist/index.js"
40
+ },
44
41
  "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"
42
+ "chalk": "^5.3.0",
43
+ "commander": "^11.1.0",
44
+ "figlet": "^1.7.0",
45
+ "inquirer": "^9.2.12",
46
+ "js-yaml": "^4.1.0",
47
+ "rimraf": "^5.0.5"
48
+ },
49
+ "devDependencies": {
50
+ "@types/figlet": "^1.5.8",
51
+ "@types/inquirer": "^9.0.7",
52
+ "@types/node": "^20.9.1",
53
+ "dotenv": "^16.3.1",
54
+ "eslint": "^8.54.0",
55
+ "eslint-config-airbnb-base": "^15.0.0",
56
+ "eslint-plugin-import": "^2.29.0",
57
+ "ts-node": "^10.9.1",
58
+ "tslint": "^6.1.3",
59
+ "typescript": "^5.2.2"
53
60
  }
54
61
  }
@@ -1,76 +0,0 @@
1
- # Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to make participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, sex characteristics, gender identity and expression,
9
- level of experience, education, socio-economic status, nationality, personal
10
- appearance, race, religion, or sexual identity and orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- - Using welcoming and inclusive language
18
- - Being respectful of differing viewpoints and experiences
19
- - Gracefully accepting constructive criticism
20
- - Focusing on what is best for the community
21
- - Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- - The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- - Trolling, insulting/derogatory comments, and personal or political attacks
28
- - Public or private harassment
29
- - Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- - Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies within all project spaces, and it also applies when
49
- an individual is representing the project or its community in public spaces.
50
- Examples of representing a project or community include using an official
51
- project e-mail address, posting via an official social media account, or acting
52
- as an appointed representative at an online or offline event. Representation of
53
- a project may be further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at <opensource-conduct@fb.com>. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>
72
-
73
- [homepage]: https://www.contributor-covenant.org
74
-
75
- For answers to common questions about this code of conduct, see
76
- <https://www.contributor-covenant.org/faq>
package/CONTRIBUTING.md DELETED
@@ -1,91 +0,0 @@
1
- # Contributing
2
-
3
- Thank you for your interest in contributing to the DolphJs Docs!
4
-
5
- ## Code of Conduct
6
-
7
- DolphJs has adopted a code of conduct that we expect contributors to adhere to.
8
- Please read the instructions in the [CODE_OF_CONDUCT](CODE_OF_CONDUCT) so
9
- you can understand our ethics.
10
-
11
- **Try to follow your own instructions.**
12
-
13
- When writing step-by-step instructions (e.g. how to install something), try to forget everything you know about the topic, and actually follow the instructions you wrote, a single step at time. Often you will discover that there is implicit knowledge that you forgot to mention, or that there are missing or out-of-order steps in the instructions. Bonus points for getting _somebody else_ to follow the steps and watching what they struggle with. Often it would be something very simple that you have not anticipated.
14
-
15
- ## Guidelines for Code Examples
16
-
17
- ### Syntax
18
-
19
- #### Prefer OOP to Functional Programming
20
-
21
- DolphJS is strictly built with the OOP approach.
22
-
23
- #### Use `const` where possible, otherwise `let`. Don't use `var`
24
-
25
- #### Don't use ES5 features when equivalent ES6 features have no downsides
26
-
27
- #### Don't forget to remove console.log's when finished with them
28
-
29
- #### Ensure that your code is scalable and uses the best implementation e.g prefer code with 0(n) to 0(logn)
30
-
31
- In particular, you should prefer arrow functions `const myFunction = () => ...` to named `functions` for top-level functions.
32
-
33
- ### Style
34
-
35
- - Use semicolons.
36
- - No space between function names and parenthesis (`method() {}` not `method () {}`).
37
- - When in doubt, use the default style favored by [Prettier](https://prettier.io/playground/).
38
-
39
- ### Highlighting
40
-
41
- Use `javascript` as the highlighting language in Markdown code blocks:
42
-
43
- ````
44
- ```javascript
45
- // code
46
- ```
47
- ````
48
-
49
- Sometimes you'll see blocks with numbers.
50
- They tell the website to highlight specific lines.
51
-
52
- You can highlight a single line:
53
-
54
- ````
55
- ```javascipt {2}
56
- function hello() {
57
- // this line will get highlighted
58
- }
59
- ```
60
- ````
61
-
62
- A range of lines:
63
-
64
- ````
65
- ```javascript {2-4}
66
- function hello() {
67
- // these lines
68
- // will get
69
- // highlighted
70
- }
71
- ```
72
- ````
73
-
74
- Or even multiple ranges:
75
-
76
- ````
77
- ```javascript {2-4,6}
78
- function hello() {
79
- // these lines
80
- // will get
81
- // highlighted
82
- console.log('hello');
83
- // also this one
84
- console.log('there');
85
- }
86
- ```
87
- ````
88
-
89
- Be mindful that if you move some code in an example with highlighting, you also need to update the highlighting.
90
-
91
- Don't be afraid to often use highlighting! It is very valuable when you need to focus the reader's attention on a particular detail that's easy to miss.
package/new-app.mjs DELETED
@@ -1,209 +0,0 @@
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("0.1.1")
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
- execSync(`${installCommand} ${devDependencies.join(" ")} -D`);
153
- } else if (selectedOption === tsFunc || selectedOption === tsOop) {
154
- execSync(`${installCommand} ${tsDevDependencies.join(" ")} -D`);
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 ${runMsg}`
163
- )
164
- );
165
- process.exit(1);
166
- } catch (error) {
167
- console.log(chalk.redBright("\nError creating your app", error));
168
- process.exit(1);
169
- }
170
- } catch (error) {
171
- console.log(chalk.redBright("Error creating your app", error));
172
- process.exit(1);
173
- }
174
- });
175
-
176
- program.command("help").action(() => {
177
- console.info(
178
- chalk.white(
179
- "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."
180
- )
181
- );
182
- console.info(chalk.blue("Options: "));
183
- console.info(
184
- chalk.white(
185
- "-v, --version output the verson number"
186
- )
187
- );
188
- console.info(
189
- chalk.white(
190
- "-h, --version display help for command"
191
- )
192
- );
193
-
194
- console.info(chalk.blue("Commands: "));
195
- console.info(
196
- chalk.white(
197
- "create-app, <app-name> Create a new dolphjs app"
198
- )
199
- );
200
- });
201
-
202
- program.command("*", { hidden: true }).action(() => {
203
- console.log(
204
- chalk.redBright(`Unknown command. See the list of available commands:`)
205
- );
206
- program.help();
207
- });
208
-
209
- program.parse(process.argv);
package/readme.md DELETED
@@ -1,25 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- export const npm = "npm"
2
- export const yarn = "yarn"
3
- export const pnpm = "pnpm"
@@ -1,4 +0,0 @@
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'
@@ -1,24 +0,0 @@
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
- ];
@@ -1,20 +0,0 @@
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
- }
@@ -1,96 +0,0 @@
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/core#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
- }
@@ -1,19 +0,0 @@
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
- }