├── .eslintrc.json ├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── NOTICE ├── README.md ├── jest.config.js ├── lib ├── actions │ ├── create.action.js │ └── generate.action.js ├── commands │ ├── commands.js │ ├── create │ │ ├── create.cmd.js │ │ └── create.prompt.js │ └── generate │ │ └── module.cmd.js ├── config │ ├── cli.config.js │ ├── cli.json │ └── config.js ├── enums │ ├── engine.enums.js │ ├── lang.enums.js │ └── module.enum.js ├── index.js └── service │ ├── fs │ └── fs.js │ ├── generator │ ├── generator.modules.js │ ├── generator.project.js │ └── templates │ │ └── express │ │ ├── app.js │ │ ├── bin │ │ └── www │ │ │ └── server.js │ │ ├── components │ │ └── greeting │ │ │ ├── greeting.controller.js │ │ │ └── greeting.dal.js │ │ └── modules │ │ ├── controller.js │ │ └── dal.js │ └── utils │ ├── getModule.js │ └── getTemplate.js ├── package.json ├── skylite.png ├── src ├── actions │ ├── create.action.ts │ └── generate.action.ts ├── commands │ ├── commands.ts │ ├── create │ │ ├── create.cmd.ts │ │ └── create.prompt.ts │ └── generate │ │ └── module.cmd.ts ├── config │ ├── cli.config.test.ts │ ├── cli.config.ts │ ├── cli.json │ ├── config.test.ts │ └── config.ts ├── enums │ ├── engine.enums.ts │ ├── lang.enums.ts │ └── module.enum.ts ├── index.ts └── service │ ├── fs │ ├── fs.test.ts │ └── fs.ts │ ├── generator │ ├── generator.modules.ts │ ├── generator.project.ts │ └── templates │ │ └── express │ │ ├── app.js │ │ ├── bin │ │ └── www │ │ │ └── server.js │ │ ├── components │ │ └── greeting │ │ │ ├── greeting.controller.js │ │ │ └── greeting.dal.js │ │ ├── modules │ │ ├── controller.js │ │ └── dal.js │ │ ├── package.json │ │ └── tsconfig.json │ └── utils │ ├── getModule.test.ts │ ├── getModule.ts │ ├── getTemplate.test.ts │ └── getTemplate.ts └── tsconfig.json /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "commonjs": true, 4 | "es2021": true, 5 | "node": true 6 | }, 7 | "extends": [ 8 | "airbnb-base" 9 | ], 10 | "parser": "@typescript-eslint/parser", 11 | "parserOptions": { 12 | "ecmaVersion": 12 13 | }, 14 | "plugins": [ 15 | "@typescript-eslint", 16 | "ejs" 17 | ], 18 | "rules": { 19 | "import/extensions": "off", 20 | "import/no-unresolved": "off", 21 | "import/prefer-default-export": "off", 22 | "no-console": "off", 23 | "max-len": [1, 150, 4] 24 | }, 25 | "overrides": [ 26 | { 27 | "files": ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"], 28 | "rules": { 29 | "no-undef": "off" 30 | } 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Node template 3 | 4 | .idea 5 | package-lock.json 6 | .nyc_output 7 | coverage 8 | *.lcov 9 | 10 | # Logs 11 | logs 12 | *.log 13 | npm-debug.log* 14 | yarn-debug.log* 15 | yarn-error.log* 16 | lerna-debug.log* 17 | 18 | # Diagnostic reports (https://nodejs.org/api/report.html) 19 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 20 | 21 | # Runtime data 22 | pids 23 | *.pid 24 | *.seed 25 | *.pid.lock 26 | 27 | # Directory for instrumented libs generated by jscoverage/JSCover 28 | lib-cov 29 | 30 | # Coverage directory used by tools like istanbul 31 | coverage 32 | *.lcov 33 | 34 | # nyc test coverage 35 | .nyc_output 36 | 37 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 38 | .grunt 39 | 40 | # Bower dependency directory (https://bower.io/) 41 | bower_components 42 | 43 | # node-waf configuration 44 | .lock-wscript 45 | 46 | # Compiled binary addons (https://nodejs.org/api/addons.html) 47 | build/Release 48 | 49 | # Dependency directories 50 | node_modules/ 51 | jspm_packages/ 52 | 53 | # Snowpack dependency directory (https://snowpack.dev/) 54 | web_modules/ 55 | 56 | # TypeScript cache 57 | *.tsbuildinfo 58 | 59 | # Optional npm cache directory 60 | .npm 61 | 62 | # Optional eslint cache 63 | .eslintcache 64 | 65 | # Microbundle cache 66 | .rpt2_cache/ 67 | .rts2_cache_cjs/ 68 | .rts2_cache_es/ 69 | .rts2_cache_umd/ 70 | 71 | # Optional REPL history 72 | .node_repl_history 73 | 74 | # Output of 'npm pack' 75 | *.tgz 76 | 77 | # Yarn Integrity file 78 | .yarn-integrity 79 | 80 | # dotenv environment variables file 81 | .env 82 | .env.test 83 | 84 | # parcel-bundler cache (https://parceljs.org/) 85 | .cache 86 | .parcel-cache 87 | 88 | # Next.js build output 89 | .next 90 | out 91 | 92 | # Nuxt.js build / generate output 93 | .nuxt 94 | dist 95 | 96 | # Gatsby files 97 | .cache/ 98 | # Comment in the public line in if your project uses Gatsby and not Next.js 99 | # https://nextjs.org/blog/next-9-1#public-directory-support 100 | # public 101 | 102 | # vuepress build output 103 | .vuepress/dist 104 | 105 | # Serverless directories 106 | .serverless/ 107 | 108 | # FuseBox cache 109 | .fusebox/ 110 | 111 | # DynamoDB Local files 112 | .dynamodb/ 113 | 114 | # TernJS port file 115 | .tern-port 116 | 117 | # Stores VSCode versions used for testing VSCode extensions 118 | .vscode-test 119 | 120 | # yarn v2 121 | .yarn/cache 122 | .yarn/unplugged 123 | .yarn/build-state.yml 124 | .yarn/install-state.gz 125 | .pnp.* 126 | 127 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | tsconfig.json 2 | src 3 | skylite.png 4 | 5 | .idea 6 | .eslintrc.json 7 | .travis.yml 8 | CHANGELOG.md 9 | jest.config.js 10 | *.test.js 11 | *.test.ts 12 | 13 | ### Backup template 14 | *.bak 15 | *.gho 16 | *.ori 17 | *.orig 18 | *.tmp 19 | 20 | ### Node template 21 | # Logs 22 | logs 23 | *.log 24 | npm-debug.log* 25 | yarn-debug.log* 26 | yarn-error.log* 27 | lerna-debug.log* 28 | 29 | # Diagnostic reports (https://nodejs.org/api/report.html) 30 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 31 | 32 | # Runtime data 33 | pids 34 | *.pid 35 | *.seed 36 | *.pid.lock 37 | 38 | # Directory for instrumented libs generated by jscoverage/JSCover 39 | lib-cov 40 | coverage 41 | coverage.lcov 42 | 43 | # Coverage directory used by tools like istanbul 44 | 45 | # nyc test coverage 46 | 47 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 48 | .grunt 49 | 50 | # Bower dependency directory (https://bower.io/) 51 | bower_components 52 | 53 | # node-waf configuration 54 | .lock-wscript 55 | 56 | # Compiled binary addons (https://nodejs.org/api/addons.html) 57 | build/Release 58 | 59 | # Dependency directories 60 | node_modules/ 61 | jspm_packages/ 62 | 63 | # Snowpack dependency directory (https://snowpack.dev/) 64 | web_modules/ 65 | 66 | # TypeScript cache 67 | *.tsbuildinfo 68 | 69 | # Optional npm cache directory 70 | .npm 71 | 72 | # Optional eslint cache 73 | .eslintcache 74 | 75 | # Microbundle cache 76 | .rpt2_cache/ 77 | .rts2_cache_cjs/ 78 | .rts2_cache_es/ 79 | .rts2_cache_umd/ 80 | 81 | # Optional REPL history 82 | .node_repl_history 83 | 84 | # Output of 'npm pack' 85 | *.tgz 86 | 87 | # Yarn Integrity file 88 | .yarn-integrity 89 | 90 | # dotenv environment variables file 91 | .env 92 | .env.test 93 | 94 | # parcel-bundler cache (https://parceljs.org/) 95 | .cache 96 | .parcel-cache 97 | 98 | # Next.js build output 99 | .next 100 | out 101 | 102 | # Nuxt.js build / generate output 103 | .nuxt 104 | dist 105 | 106 | # Gatsby files 107 | .cache/ 108 | # Comment in the public line in if your project uses Gatsby and not Next.js 109 | # https://nextjs.org/blog/next-9-1#public-directory-support 110 | # public 111 | 112 | # vuepress build output 113 | .vuepress/dist 114 | 115 | # Serverless directories 116 | .serverless/ 117 | 118 | # FuseBox cache 119 | .fusebox/ 120 | 121 | # DynamoDB Local files 122 | .dynamodb/ 123 | 124 | # TernJS port file 125 | .tern-port 126 | 127 | # Stores VSCode versions used for testing VSCode extensions 128 | .vscode-test 129 | 130 | # yarn v2 131 | .yarn/cache 132 | .yarn/unplugged 133 | .yarn/build-state.yml 134 | .yarn/install-state.gz 135 | .pnp.* 136 | 137 | ### Example user template template 138 | ### Example user template 139 | 140 | # IntelliJ project files 141 | *.iml 142 | gen 143 | ### Archives template 144 | # It's better to unpack these files and commit the raw source because 145 | # git has its own built in compression methods. 146 | *.7z 147 | *.jar 148 | *.rar 149 | *.zip 150 | *.gz 151 | *.gzip 152 | *.bzip 153 | *.bzip2 154 | *.bz2 155 | *.xz 156 | *.lzma 157 | *.cab 158 | *.xar 159 | 160 | # Packing-only formats 161 | *.iso 162 | *.tar 163 | 164 | # Package management formats 165 | *.dmg 166 | *.xpi 167 | *.gem 168 | *.egg 169 | *.deb 170 | *.rpm 171 | *.msi 172 | *.msm 173 | *.msp 174 | *.txz 175 | 176 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "10" 4 | script: 5 | - jest --clearCache 6 | - npm install -g codecov 7 | - npm run lint 8 | - npm run build 9 | - npm run test 10 | after_success: 11 | - codecov 12 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ### [1.0.15](https://github.com/SlDo/skylite-cli/compare/v1.0.14...v1.0.15) (2021-01-15) 6 | 7 | ### [1.0.14](https://github.com/SlDo/skylite-cli/compare/v1.0.13...v1.0.14) (2021-01-15) 8 | 9 | ### [1.0.13](https://github.com/SlDo/skylite-cli/compare/v1.0.12...v1.0.13) (2021-01-14) 10 | 11 | ### [1.0.12](https://github.com/SlDo/skylite-cli/compare/v1.0.11...v1.0.12) (2021-01-14) 12 | 13 | ### [1.0.11](https://github.com/SlDo/skylite-cli/compare/v1.0.10...v1.0.11) (2021-01-14) 14 | 15 | ### [1.0.10](https://github.com/SlDo/skylite-cli/compare/v1.0.9...v1.0.10) (2021-01-14) 16 | 17 | ### [1.0.9](https://github.com/SlDo/skylite-cli/compare/v1.0.8...v1.0.9) (2021-01-14) 18 | 19 | ### [1.0.8](https://github.com/SlDo/skylite-cli/compare/v1.0.7...v1.0.8) (2021-01-14) 20 | 21 | ### [1.0.7](https://github.com/SlDo/skylite-cli/compare/v1.0.6...v1.0.7) (2021-01-14) 22 | 23 | ### [1.0.6](https://github.com/SlDo/skylite-cli/compare/v1.0.5...v1.0.6) (2021-01-14) 24 | 25 | ### [1.0.5](https://github.com/SlDo/skylite-cli/compare/v1.0.4...v1.0.5) (2021-01-14) 26 | 27 | ### [1.0.4](https://github.com/SlDo/skylite-cli/compare/v1.0.3...v1.0.4) (2021-01-13) 28 | 29 | ### [1.0.3](https://github.com/SlDo/sncli/compare/v1.0.2...v1.0.3) (2021-01-13) 30 | 31 | ### [1.0.2](https://github.com/SlDo/sncli/compare/v1.0.1...v1.0.2) (2021-01-12) 32 | 33 | ### 1.0.1 (2021-01-12) 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2021 Slava Dodonov 2 | Licensed under the Apache License, Version 2.0 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Skylite logo](https://github.com/SlDo/skylite-cli/blob/main/skylite.png?raw=true) 2 | 3 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/7088018572284836b2d8a9cd8144e286)](https://app.codacy.com/gh/SlDo/skylite-cli?utm_source=github.com&utm_medium=referral&utm_content=SlDo/skylite-cli&utm_campaign=Badge_Grade) 4 | [![codecov](https://codecov.io/gh/SlDo/skylite-cli/branch/main/graph/badge.svg?token=FXCIP5Z5VS)](https://codecov.io/gh/SlDo/skylite-cli) 5 | ![GitHub package.json version](https://img.shields.io/github/package-json/v/sldo/skylite-cli) 6 | ![Downloads](https://img.shields.io/npm/dt/skylite) 7 | ![GitHub issues](https://img.shields.io/github/issues/sldo/skylite-cli) 8 | ![NPM](https://img.shields.io/npm/l/skylite?color=blue) 9 | 10 | Skylite is created for **fast generation of productive Nodes.js applications.** It solves the problem of generating a startup project, as well as its modules (such as controller and dal) 11 | 12 | ## Installation 13 | 14 | ``` 15 | npm install -g skylite 16 | ``` 17 | 18 | ## Usage 19 | 20 | 💻 **Creating a project** 21 | 22 | ``` 23 | skylite create 24 | cd 25 | npm i 26 | ``` 27 | 28 | 🔌 **Creating a controller** 29 | 30 | ``` 31 | cd 32 | skylite generate controller 33 | ``` 34 | 35 | 🗃 **Creating a DAL** 36 | 37 | ``` 38 | cd 39 | skylite generate dal 40 | ``` 41 | 42 | ## License 43 | 44 | [Apache 2.0](https://github.com/SlDo/skylite-cli/blob/main/LICENSE) 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | testEnvironment: 'node', 4 | modulePathIgnorePatterns: ['templates'], 5 | collectCoverage: true, 6 | transform: { 7 | '^.+\\.(ts|js|html)$': 'ts-jest', 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /lib/actions/create.action.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __generator = (this && this.__generator) || function (thisArg, body) { 12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 14 | function verb(n) { return function (v) { return step([n, v]); }; } 15 | function step(op) { 16 | if (f) throw new TypeError("Generator is already executing."); 17 | while (_) try { 18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 19 | if (y = 0, t) op = [op[0] & 2, t.value]; 20 | switch (op[0]) { 21 | case 0: case 1: t = op; break; 22 | case 4: _.label++; return { value: op[1], done: false }; 23 | case 5: _.label++; y = op[1]; op = [0]; continue; 24 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 25 | default: 26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 30 | if (t[2]) _.ops.pop(); 31 | _.trys.pop(); continue; 32 | } 33 | op = body.call(thisArg, _); 34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 36 | } 37 | }; 38 | var __importDefault = (this && this.__importDefault) || function (mod) { 39 | return (mod && mod.__esModule) ? mod : { "default": mod }; 40 | }; 41 | Object.defineProperty(exports, "__esModule", { value: true }); 42 | var chalk_1 = __importDefault(require("chalk")); 43 | var inquirer_1 = __importDefault(require("inquirer")); 44 | var path_1 = __importDefault(require("path")); 45 | var fs_1 = require("../service/fs/fs"); 46 | var index_1 = require("../index"); 47 | var create_prompt_1 = __importDefault(require("../commands/create/create.prompt")); 48 | var generator_project_1 = require("../service/generator/generator.project"); 49 | function createCMD(projectName) { 50 | return __awaiter(this, void 0, void 0, function () { 51 | var projectPath, _a, _b, lang, engine; 52 | return __generator(this, function (_c) { 53 | switch (_c.label) { 54 | case 0: 55 | projectPath = process.cwd().replace(/\\/g, '/') + "/" + projectName; 56 | if (fs_1.isPathExist(path_1.default.join(process.cwd(), projectName))) { 57 | return [2 /*return*/, console.log("\n " + chalk_1.default.redBright.bold('ERROR!') + "\n " + chalk_1.default.whiteBright('A project with this name has already been created in the current directory') + "\n ")]; 58 | } 59 | _a = !fs_1.isPathExist(path_1.default.join(process.cwd(), projectName)); 60 | if (!_a) return [3 /*break*/, 2]; 61 | return [4 /*yield*/, index_1.config.isProjectExist(projectPath)]; 62 | case 1: 63 | _a = (_c.sent()); 64 | _c.label = 2; 65 | case 2: 66 | if (!_a) return [3 /*break*/, 4]; 67 | return [4 /*yield*/, index_1.config.deleteProject(projectPath)]; 68 | case 3: 69 | _c.sent(); 70 | _c.label = 4; 71 | case 4: return [4 /*yield*/, inquirer_1.default.prompt(create_prompt_1.default)]; 72 | case 5: 73 | _b = _c.sent(), lang = _b.lang, engine = _b.engine; 74 | return [2 /*return*/, generator_project_1.newProjectGenerator(projectName, projectPath, { 75 | template: engine, 76 | lang: lang, 77 | })]; 78 | } 79 | }); 80 | }); 81 | } 82 | exports.default = createCMD; 83 | -------------------------------------------------------------------------------- /lib/actions/generate.action.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __generator = (this && this.__generator) || function (thisArg, body) { 12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 14 | function verb(n) { return function (v) { return step([n, v]); }; } 15 | function step(op) { 16 | if (f) throw new TypeError("Generator is already executing."); 17 | while (_) try { 18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 19 | if (y = 0, t) op = [op[0] & 2, t.value]; 20 | switch (op[0]) { 21 | case 0: case 1: t = op; break; 22 | case 4: _.label++; return { value: op[1], done: false }; 23 | case 5: _.label++; y = op[1]; op = [0]; continue; 24 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 25 | default: 26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 30 | if (t[2]) _.ops.pop(); 31 | _.trys.pop(); continue; 32 | } 33 | op = body.call(thisArg, _); 34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 36 | } 37 | }; 38 | var __importDefault = (this && this.__importDefault) || function (mod) { 39 | return (mod && mod.__esModule) ? mod : { "default": mod }; 40 | }; 41 | Object.defineProperty(exports, "__esModule", { value: true }); 42 | var chalk_1 = __importDefault(require("chalk")); 43 | var generator_modules_1 = require("../service/generator/generator.modules"); 44 | var index_1 = require("../index"); 45 | var module_enum_1 = require("../enums/module.enum"); 46 | function generateModule(moduleType, name) { 47 | return __awaiter(this, void 0, void 0, function () { 48 | var currentProject, pathToProject, _a, type, lang; 49 | return __generator(this, function (_b) { 50 | switch (_b.label) { 51 | case 0: return [4 /*yield*/, index_1.config.getProject(process.cwd().replace(/\\/g, '/'))]; 52 | case 1: 53 | currentProject = _b.sent(); 54 | if (currentProject == null) { 55 | return [2 /*return*/, console.log("\n " + chalk_1.default.redBright.bold('ERROR!') + "\n " + chalk_1.default.whiteBright('The project doesn\'t exist in this path') + "\n ")]; 56 | } 57 | pathToProject = currentProject.pathToProject, _a = currentProject.template, type = _a.type, lang = _a.lang; 58 | switch (true) { 59 | case /c|controller/.test(moduleType): 60 | return [2 /*return*/, generator_modules_1.newModule(pathToProject, module_enum_1.ModuleEnum.CONTROLLER, name, { type: type, lang: lang })]; 61 | case /d|dal/.test(moduleType): 62 | return [2 /*return*/, generator_modules_1.newModule(pathToProject, module_enum_1.ModuleEnum.DAL, name, { type: type, lang: lang })]; 63 | default: 64 | return [2 /*return*/, console.log('This command is not allowed')]; 65 | } 66 | return [2 /*return*/]; 67 | } 68 | }); 69 | }); 70 | } 71 | exports.default = generateModule; 72 | -------------------------------------------------------------------------------- /lib/commands/commands.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | require("./create/create.cmd"); 4 | require("./generate/module.cmd"); 5 | -------------------------------------------------------------------------------- /lib/commands/create/create.cmd.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | var commander_1 = __importDefault(require("commander")); 7 | var create_action_1 = __importDefault(require("../../actions/create.action")); 8 | commander_1.default 9 | .command('create ') 10 | .alias('c') 11 | .description('Create a new Node.js application') 12 | .action(create_action_1.default); 13 | -------------------------------------------------------------------------------- /lib/commands/create/create.prompt.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var lang_enums_1 = require("../../enums/lang.enums"); 4 | var engine_enums_1 = require("../../enums/engine.enums"); 5 | exports.default = [ 6 | { 7 | type: 'list', 8 | name: 'lang', 9 | message: 'What language do you want to use?', 10 | choices: [ 11 | { name: 'TypeScript', value: lang_enums_1.LangEnums.TS }, 12 | { name: 'JavaScript', value: lang_enums_1.LangEnums.JS }, 13 | ], 14 | }, 15 | { 16 | type: 'list', 17 | name: 'engine', 18 | message: 'What engine do you want to use?', 19 | choices: [ 20 | { name: 'Express', value: engine_enums_1.EngineEnums.EXPRESS }, 21 | ], 22 | }, 23 | ]; 24 | -------------------------------------------------------------------------------- /lib/commands/generate/module.cmd.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | var commander_1 = __importDefault(require("commander")); 7 | var generate_action_1 = __importDefault(require("../../actions/generate.action")); 8 | commander_1.default 9 | .command('generate [name]') 10 | .alias('g') 11 | .description('Create a new Node.js module for the application') 12 | .action(generate_action_1.default); 13 | -------------------------------------------------------------------------------- /lib/config/cli.config.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | exports.getTemplateByID = void 0; 7 | var cli_json_1 = __importDefault(require("./cli.json")); 8 | function getTemplateByID(id) { 9 | return cli_json_1.default.templates.find(function (template) { return template.id === id; }); 10 | } 11 | exports.getTemplateByID = getTemplateByID; 12 | -------------------------------------------------------------------------------- /lib/config/cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "templates": [ 3 | { 4 | "name": "Express", 5 | "id": 1 6 | } 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /lib/config/config.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __generator = (this && this.__generator) || function (thisArg, body) { 12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 14 | function verb(n) { return function (v) { return step([n, v]); }; } 15 | function step(op) { 16 | if (f) throw new TypeError("Generator is already executing."); 17 | while (_) try { 18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 19 | if (y = 0, t) op = [op[0] & 2, t.value]; 20 | switch (op[0]) { 21 | case 0: case 1: t = op; break; 22 | case 4: _.label++; return { value: op[1], done: false }; 23 | case 5: _.label++; y = op[1]; op = [0]; continue; 24 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 25 | default: 26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 30 | if (t[2]) _.ops.pop(); 31 | _.trys.pop(); continue; 32 | } 33 | op = body.call(thisArg, _); 34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 36 | } 37 | }; 38 | var __spreadArrays = (this && this.__spreadArrays) || function () { 39 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; 40 | for (var r = Array(s), k = 0, i = 0; i < il; i++) 41 | for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) 42 | r[k] = a[j]; 43 | return r; 44 | }; 45 | var __importDefault = (this && this.__importDefault) || function (mod) { 46 | return (mod && mod.__esModule) ? mod : { "default": mod }; 47 | }; 48 | Object.defineProperty(exports, "__esModule", { value: true }); 49 | exports.Config = void 0; 50 | var fs_extra_1 = __importDefault(require("fs-extra")); 51 | var fs_1 = require("../service/fs/fs"); 52 | var Config = /** @class */ (function () { 53 | // eslint-disable-next-line no-useless-constructor 54 | function Config(jsonPath) { 55 | this.jsonPath = jsonPath; 56 | if (!fs_1.isPathExist(jsonPath)) { 57 | fs_extra_1.default.outputJSONSync(jsonPath, []); 58 | } 59 | } 60 | Config.prototype.addProject = function (project) { 61 | return __awaiter(this, void 0, void 0, function () { 62 | var config, isExist; 63 | return __generator(this, function (_a) { 64 | switch (_a.label) { 65 | case 0: return [4 /*yield*/, this.get()]; 66 | case 1: 67 | config = _a.sent(); 68 | return [4 /*yield*/, this.isProjectExist(project.pathToProject)]; 69 | case 2: 70 | isExist = _a.sent(); 71 | if (!!isExist) return [3 /*break*/, 4]; 72 | return [4 /*yield*/, this.write(__spreadArrays(config, [project]))]; 73 | case 3: 74 | _a.sent(); 75 | _a.label = 4; 76 | case 4: return [2 /*return*/]; 77 | } 78 | }); 79 | }); 80 | }; 81 | Config.prototype.getProject = function (pathToProject) { 82 | return __awaiter(this, void 0, void 0, function () { 83 | var config; 84 | return __generator(this, function (_a) { 85 | switch (_a.label) { 86 | case 0: return [4 /*yield*/, this.get()]; 87 | case 1: 88 | config = _a.sent(); 89 | return [2 /*return*/, config.find(function (project) { return project.pathToProject === pathToProject; })]; 90 | } 91 | }); 92 | }); 93 | }; 94 | Config.prototype.deleteProject = function (pathToProject) { 95 | return __awaiter(this, void 0, void 0, function () { 96 | var config; 97 | return __generator(this, function (_a) { 98 | switch (_a.label) { 99 | case 0: return [4 /*yield*/, this.get()]; 100 | case 1: 101 | config = _a.sent(); 102 | return [4 /*yield*/, this.write(config.filter(function (project) { return project.pathToProject !== pathToProject; }))]; 103 | case 2: 104 | _a.sent(); 105 | return [2 /*return*/]; 106 | } 107 | }); 108 | }); 109 | }; 110 | Config.prototype.write = function (content) { 111 | return __awaiter(this, void 0, void 0, function () { 112 | return __generator(this, function (_a) { 113 | return [2 /*return*/, fs_extra_1.default.writeJSON(this.jsonPath, content)]; 114 | }); 115 | }); 116 | }; 117 | Config.prototype.get = function () { 118 | return __awaiter(this, void 0, void 0, function () { 119 | return __generator(this, function (_a) { 120 | return [2 /*return*/, fs_extra_1.default.readJSON(this.jsonPath)]; 121 | }); 122 | }); 123 | }; 124 | Config.prototype.isProjectExist = function (path) { 125 | return __awaiter(this, void 0, void 0, function () { 126 | var config; 127 | return __generator(this, function (_a) { 128 | switch (_a.label) { 129 | case 0: return [4 /*yield*/, this.get()]; 130 | case 1: 131 | config = _a.sent(); 132 | return [2 /*return*/, config.findIndex(function (currentProject) { return currentProject.pathToProject === path; }) !== -1]; 133 | } 134 | }); 135 | }); 136 | }; 137 | return Config; 138 | }()); 139 | exports.Config = Config; 140 | -------------------------------------------------------------------------------- /lib/enums/engine.enums.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.EngineEnums = void 0; 4 | var EngineEnums; 5 | (function (EngineEnums) { 6 | EngineEnums[EngineEnums["EXPRESS"] = 1] = "EXPRESS"; 7 | })(EngineEnums = exports.EngineEnums || (exports.EngineEnums = {})); 8 | -------------------------------------------------------------------------------- /lib/enums/lang.enums.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.LangEnums = void 0; 4 | var LangEnums; 5 | (function (LangEnums) { 6 | LangEnums[LangEnums["TS"] = 1] = "TS"; 7 | LangEnums[LangEnums["JS"] = 2] = "JS"; 8 | })(LangEnums = exports.LangEnums || (exports.LangEnums = {})); 9 | -------------------------------------------------------------------------------- /lib/enums/module.enum.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.ModuleEnum = void 0; 4 | var ModuleEnum; 5 | (function (ModuleEnum) { 6 | ModuleEnum["CONTROLLER"] = "controller"; 7 | ModuleEnum["DAL"] = "dal"; 8 | })(ModuleEnum = exports.ModuleEnum || (exports.ModuleEnum = {})); 9 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | "use strict"; 3 | var __importDefault = (this && this.__importDefault) || function (mod) { 4 | return (mod && mod.__esModule) ? mod : { "default": mod }; 5 | }; 6 | Object.defineProperty(exports, "__esModule", { value: true }); 7 | exports.config = void 0; 8 | var chalk_1 = __importDefault(require("chalk")); 9 | var boxen_1 = __importDefault(require("boxen")); 10 | var commander_1 = __importDefault(require("commander")); 11 | require("./commands/commands"); 12 | var os_1 = __importDefault(require("os")); 13 | var config_1 = require("./config/config"); 14 | var log = console.log; 15 | commander_1.default.version('- Version: 0.0.1', '-v, -V, --version', 'output the current version'); 16 | log(boxen_1.default("\n " + chalk_1.default.hex('#a7c5eb').bold('WELCOME!') + " \n " + chalk_1.default.whiteBright('Skylite CLI can help you to create a powerful Node.js application') + "\n", { padding: 1, borderColor: '#a7c5eb' })); 17 | exports.config = new config_1.Config(os_1.default.homedir() + "/.slcli/config.json"); 18 | commander_1.default.parse(process.argv); 19 | -------------------------------------------------------------------------------- /lib/service/fs/fs.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __generator = (this && this.__generator) || function (thisArg, body) { 12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 14 | function verb(n) { return function (v) { return step([n, v]); }; } 15 | function step(op) { 16 | if (f) throw new TypeError("Generator is already executing."); 17 | while (_) try { 18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 19 | if (y = 0, t) op = [op[0] & 2, t.value]; 20 | switch (op[0]) { 21 | case 0: case 1: t = op; break; 22 | case 4: _.label++; return { value: op[1], done: false }; 23 | case 5: _.label++; y = op[1]; op = [0]; continue; 24 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 25 | default: 26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 30 | if (t[2]) _.ops.pop(); 31 | _.trys.pop(); continue; 32 | } 33 | op = body.call(thisArg, _); 34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 36 | } 37 | }; 38 | var __importDefault = (this && this.__importDefault) || function (mod) { 39 | return (mod && mod.__esModule) ? mod : { "default": mod }; 40 | }; 41 | Object.defineProperty(exports, "__esModule", { value: true }); 42 | exports.getFilesPaths = exports.renameFile = exports.writeFile = exports.isPathExist = exports.copy = exports.createFile = void 0; 43 | var fs_extra_1 = __importDefault(require("fs-extra")); 44 | var globby_1 = __importDefault(require("globby")); 45 | var path_1 = __importDefault(require("path")); 46 | function createFile(filePath, fileName, content) { 47 | if (content === void 0) { content = ''; } 48 | return fs_extra_1.default.outputFile(path_1.default.join(filePath, fileName), content); 49 | } 50 | exports.createFile = createFile; 51 | function copy(fromPath, newPath, params) { 52 | return fs_extra_1.default.copy(fromPath, newPath, params); 53 | } 54 | exports.copy = copy; 55 | function isPathExist(folderPath) { 56 | return fs_extra_1.default.existsSync(folderPath); 57 | } 58 | exports.isPathExist = isPathExist; 59 | function writeFile(file, data) { 60 | return fs_extra_1.default.outputFile(file, data); 61 | } 62 | exports.writeFile = writeFile; 63 | function renameFile(dest, src) { 64 | return fs_extra_1.default.rename(dest, src); 65 | } 66 | exports.renameFile = renameFile; 67 | function getFilesPaths(filePath, pattern, files) { 68 | return __awaiter(this, void 0, void 0, function () { 69 | return __generator(this, function (_a) { 70 | return [2 /*return*/, globby_1.default(filePath + "/" + pattern, { 71 | expandDirectories: { 72 | files: files, 73 | }, 74 | })]; 75 | }); 76 | }); 77 | } 78 | exports.getFilesPaths = getFilesPaths; 79 | -------------------------------------------------------------------------------- /lib/service/generator/generator.modules.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __generator = (this && this.__generator) || function (thisArg, body) { 12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 14 | function verb(n) { return function (v) { return step([n, v]); }; } 15 | function step(op) { 16 | if (f) throw new TypeError("Generator is already executing."); 17 | while (_) try { 18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 19 | if (y = 0, t) op = [op[0] & 2, t.value]; 20 | switch (op[0]) { 21 | case 0: case 1: t = op; break; 22 | case 4: _.label++; return { value: op[1], done: false }; 23 | case 5: _.label++; y = op[1]; op = [0]; continue; 24 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 25 | default: 26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 30 | if (t[2]) _.ops.pop(); 31 | _.trys.pop(); continue; 32 | } 33 | op = body.call(thisArg, _); 34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 36 | } 37 | }; 38 | var __importDefault = (this && this.__importDefault) || function (mod) { 39 | return (mod && mod.__esModule) ? mod : { "default": mod }; 40 | }; 41 | Object.defineProperty(exports, "__esModule", { value: true }); 42 | exports.newModule = void 0; 43 | var ejs_1 = __importDefault(require("ejs")); 44 | var chalk_1 = __importDefault(require("chalk")); 45 | var fs_1 = require("../fs/fs"); 46 | var cli_config_1 = require("../../config/cli.config"); 47 | var getModule_1 = __importDefault(require("../utils/getModule")); 48 | function newModule(dest, moduleType, moduleName, options) { 49 | return __awaiter(this, void 0, void 0, function () { 50 | var type, lang, modulePath, controllerContent; 51 | return __generator(this, function (_a) { 52 | switch (_a.label) { 53 | case 0: 54 | type = options.type, lang = options.lang; 55 | modulePath = getModule_1.default(cli_config_1.getTemplateByID(type).name, moduleType + ".js"); 56 | if (modulePath == null) { 57 | return [2 /*return*/, console.log("\n " + chalk_1.default.redBright.bold('ERROR!') + "\n " + chalk_1.default.whiteBright('The template is deleted or does not exist') + "\n ")]; 58 | } 59 | return [4 /*yield*/, ejs_1.default.renderFile(modulePath, { lang: lang, name: moduleName })]; 60 | case 1: 61 | controllerContent = _a.sent(); 62 | return [2 /*return*/, fs_1.createFile(dest + "/components/" + moduleName, moduleName + "." + moduleType + "." + (lang === 1 ? 'ts' : 'js'), controllerContent)]; 63 | } 64 | }); 65 | }); 66 | } 67 | exports.newModule = newModule; 68 | -------------------------------------------------------------------------------- /lib/service/generator/generator.project.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __generator = (this && this.__generator) || function (thisArg, body) { 12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 14 | function verb(n) { return function (v) { return step([n, v]); }; } 15 | function step(op) { 16 | if (f) throw new TypeError("Generator is already executing."); 17 | while (_) try { 18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 19 | if (y = 0, t) op = [op[0] & 2, t.value]; 20 | switch (op[0]) { 21 | case 0: case 1: t = op; break; 22 | case 4: _.label++; return { value: op[1], done: false }; 23 | case 5: _.label++; y = op[1]; op = [0]; continue; 24 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 25 | default: 26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 30 | if (t[2]) _.ops.pop(); 31 | _.trys.pop(); continue; 32 | } 33 | op = body.call(thisArg, _); 34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 36 | } 37 | }; 38 | var __importDefault = (this && this.__importDefault) || function (mod) { 39 | return (mod && mod.__esModule) ? mod : { "default": mod }; 40 | }; 41 | Object.defineProperty(exports, "__esModule", { value: true }); 42 | exports.newProjectGenerator = void 0; 43 | var ejs_1 = __importDefault(require("ejs")); 44 | var uuid_1 = require("uuid"); 45 | var chalk_1 = __importDefault(require("chalk")); 46 | var fs_1 = require("../fs/fs"); 47 | var index_1 = require("../../index"); 48 | var cli_config_1 = require("../../config/cli.config"); 49 | var lang_enums_1 = require("../../enums/lang.enums"); 50 | var getTemplate_1 = __importDefault(require("../utils/getTemplate")); 51 | function newProjectGenerator(projectName, pathProject, options) { 52 | return __awaiter(this, void 0, void 0, function () { 53 | var template, lang, templatePath, filterFilesDist, files; 54 | var _this = this; 55 | return __generator(this, function (_a) { 56 | switch (_a.label) { 57 | case 0: 58 | template = options.template, lang = options.lang; 59 | templatePath = getTemplate_1.default(cli_config_1.getTemplateByID(template).name); 60 | if (templatePath == null) { 61 | return [2 /*return*/, console.log("\n " + chalk_1.default.redBright.bold('ERROR!') + "\n " + chalk_1.default.whiteBright('The template is deleted or does not exist') + "\n ")]; 62 | } 63 | filterFilesDist = function (src, dest) { 64 | if (lang !== lang_enums_1.LangEnums.TS) { 65 | return !dest.includes('modules') && !dest.includes('tsconfig.json'); 66 | } 67 | return !dest.includes('modules'); 68 | }; 69 | return [4 /*yield*/, fs_1.copy(templatePath, pathProject, { filter: filterFilesDist, overwrite: false })]; 70 | case 1: 71 | _a.sent(); 72 | return [4 /*yield*/, fs_1.getFilesPaths(pathProject, '**/*.(js|json)', ['!modules'])]; 73 | case 2: 74 | files = _a.sent(); 75 | return [4 /*yield*/, Promise.all(files.map(function (file) { return __awaiter(_this, void 0, void 0, function () { 76 | var renderFile, tsExtension, writableFile; 77 | return __generator(this, function (_a) { 78 | switch (_a.label) { 79 | case 0: return [4 /*yield*/, ejs_1.default.renderFile(file, { lang: lang })]; 80 | case 1: 81 | renderFile = _a.sent(); 82 | tsExtension = file.replace(/\.js$/i, '.ts'); 83 | writableFile = lang === lang_enums_1.LangEnums.TS ? tsExtension : file; 84 | if (!(lang === lang_enums_1.LangEnums.TS)) return [3 /*break*/, 3]; 85 | return [4 /*yield*/, fs_1.renameFile(file, tsExtension)]; 86 | case 2: 87 | _a.sent(); 88 | _a.label = 3; 89 | case 3: return [4 /*yield*/, fs_1.writeFile(writableFile, renderFile)]; 90 | case 4: 91 | _a.sent(); 92 | return [2 /*return*/]; 93 | } 94 | }); 95 | }); }))]; 96 | case 3: 97 | _a.sent(); 98 | return [2 /*return*/, index_1.config.addProject({ 99 | projectID: uuid_1.v4(), 100 | projectName: projectName, 101 | pathToProject: pathProject, 102 | template: { 103 | type: template, 104 | lang: lang, 105 | }, 106 | })]; 107 | } 108 | }); 109 | }); 110 | } 111 | exports.newProjectGenerator = newProjectGenerator; 112 | -------------------------------------------------------------------------------- /lib/service/generator/templates/express/app.js: -------------------------------------------------------------------------------- 1 | <%_ if (lang == 1) { _%> 2 | import express, { Router } from 'express'; 3 | 4 | export const app: express.Application = express(); 5 | export const router: Router = express.Router(); 6 | 7 | import('./components/greeting/greeting.controller').createController(router); 8 | <%_ } else { _%> 9 | const express = require('express'); 10 | 11 | const app = express(); 12 | const router = express.Router(); 13 | 14 | require('./components/greeting/greeting.controller').createController(router); 15 | <%_ } _%> 16 | 17 | app.use('/api', router); 18 | 19 | <%_ if (lang == 0) { _%> 20 | module.exports = { router, app }; 21 | <%_ } _%> 22 | -------------------------------------------------------------------------------- /lib/service/generator/templates/express/bin/www/server.js: -------------------------------------------------------------------------------- 1 | <%_ if (lang == 1) { _%> 2 | import { app } from '../../app'; 3 | import http from 'http'; 4 | <%_ } else { _%> 5 | const { app } = require('../../app'); 6 | const http = require('http'); 7 | <%_ } _%> 8 | app.set('port', process.env.PORT || '3000'); 9 | 10 | <% if (lang == 1) { %>export <% } %>const server = http.createServer(app).listen(app.get('port')); 11 | 12 | <%_ if (lang == 0) { _%> 13 | module.exports = server; 14 | <%_ } _%> 15 | -------------------------------------------------------------------------------- /lib/service/generator/templates/express/components/greeting/greeting.controller.js: -------------------------------------------------------------------------------- 1 | <%_ if (lang == 1) { _%> 2 | import { Router } from 'express'; 3 | import { greeting } from './greeting.dal'; 4 | 5 | export function createController(router: Router): void { 6 | router.get('/hello', greeting); 7 | } 8 | <%_ } else { _%> 9 | const { greeting } = require('./greeting.dal'); 10 | 11 | module.exports = { 12 | createController(router) { 13 | router.get('/hello', greeting); 14 | } 15 | } 16 | <%_ } _%> 17 | -------------------------------------------------------------------------------- /lib/service/generator/templates/express/components/greeting/greeting.dal.js: -------------------------------------------------------------------------------- 1 | <%_ if (lang == 1) { _%> 2 | import { Request, Response } from 'express'; 3 | 4 | export function greeting(req: Request, res: Response): Response { 5 | return res.send('Hello!').end(200); 6 | } 7 | <%_ } else { _%> 8 | module.exports.greeting = function greeting(req, res) { 9 | return res.send('Hello!').end(200); 10 | } 11 | <%_ } _%> 12 | -------------------------------------------------------------------------------- /lib/service/generator/templates/express/modules/controller.js: -------------------------------------------------------------------------------- 1 | <%_ if (lang == 1) { _%> 2 | import { Router } from 'express'; 3 | 4 | export function createController(router: Router): void { 5 | router.get('/<%- name %>'); 6 | } 7 | <%_ } else { _%> 8 | module.exports = { 9 | createController(router) { 10 | router.get('/<%- name %>'); 11 | } 12 | } 13 | <%_ } _%> 14 | -------------------------------------------------------------------------------- /lib/service/generator/templates/express/modules/dal.js: -------------------------------------------------------------------------------- 1 | <%_ if (lang == 1) { _%> 2 | import { Request, Response } from 'express'; 3 | 4 | export function dal(req: Request, res: Response): Response { 5 | return res.send('<%- name %>!').end(200); 6 | } 7 | <%_ } else { _%> 8 | module.exports.dal = function dal(req, res) { 9 | return res.send('<%- name %>!').end(200); 10 | } 11 | <%_ } _%> 12 | -------------------------------------------------------------------------------- /lib/service/utils/getModule.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | var path_1 = __importDefault(require("path")); 7 | var getTemplate_1 = __importDefault(require("./getTemplate")); 8 | function getModulePath(templateName, moduleName) { 9 | var templatePath = getTemplate_1.default(templateName); 10 | if (templatePath == null) 11 | return undefined; 12 | return path_1.default.join(templatePath, 'modules', moduleName); 13 | } 14 | exports.default = getModulePath; 15 | -------------------------------------------------------------------------------- /lib/service/utils/getTemplate.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | var path_1 = __importDefault(require("path")); 7 | var fs_1 = require("../fs/fs"); 8 | function getTemplatePath(templateName) { 9 | var templatePath = path_1.default.join(__dirname, '../generator', 'templates', templateName.toLowerCase()); 10 | if (!fs_1.isPathExist(templatePath)) 11 | return undefined; 12 | return templatePath; 13 | } 14 | exports.default = getTemplatePath; 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "skylite", 3 | "version": "1.0.15", 4 | "description": "The Skylite CLI for creating a powerful Node.js applications ", 5 | "main": "lib/index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/SlDo/skylite-cli" 9 | }, 10 | "keywords": [ 11 | "typescipt", 12 | "javascript", 13 | "ts", 14 | "js", 15 | "cli", 16 | "node.js", 17 | "structure" 18 | ], 19 | "dependencies": { 20 | "boxen": "^5.0.0", 21 | "chalk": "^4.1.0", 22 | "commander": "^6.2.1", 23 | "ejs": "^3.1.5", 24 | "fs-extra": "^9.0.1", 25 | "globby": "^11.0.2", 26 | "inquirer": "^7.3.3", 27 | "uuid": "^8.3.2" 28 | }, 29 | "devDependencies": { 30 | "@types/boxen": "^3.0.1", 31 | "@types/chalk": "^2.2.0", 32 | "@types/commander": "^2.12.2", 33 | "@types/ejs": "^3.0.5", 34 | "@types/fs-extra": "^9.0.6", 35 | "@types/globby": "^9.1.0", 36 | "@types/inquirer": "^7.3.1", 37 | "@types/jest": "^26.0.20", 38 | "@types/mock-fs": "^4.13.0", 39 | "@types/node": "^14.14.20", 40 | "@types/uuid": "^8.3.0", 41 | "@typescript-eslint/eslint-plugin": "^4.12.0", 42 | "@typescript-eslint/parser": "^4.12.0", 43 | "codecov": "^3.8.1", 44 | "copyfiles": "^2.4.1", 45 | "eslint": "^7.17.0", 46 | "eslint-config-airbnb-base": "^14.2.1", 47 | "eslint-plugin-ejs": "0.0.2", 48 | "eslint-plugin-import": "^2.22.1", 49 | "jest": "^26.6.3", 50 | "mock-fs": "^4.13.0", 51 | "rimraf": "^3.0.2", 52 | "standard-version": "^9.1.0", 53 | "ts-jest": "^26.4.4", 54 | "ts-node": "^9.1.1", 55 | "typescript": "^4.1.3" 56 | }, 57 | "bin": { 58 | "skylite": "lib/index.js" 59 | }, 60 | "scripts": { 61 | "release": "standard-version", 62 | "release:patch": "npm run release -- --release-as patch", 63 | "release:minor": "npm run release -- --release-as minor", 64 | "release:major": "npm run release -- --release-as major", 65 | "build": "tsc -p . && copyfiles -u 1 src/**/*.js lib/", 66 | "test": "jest --testPathPattern='/src/*' --config ./jest.config.js --runInBand", 67 | "lint": "eslint" 68 | }, 69 | "author": "Slava Dodonov ", 70 | "license": "Apache-2.0", 71 | "licenses": [ 72 | { 73 | "type": "Apache-2.0", 74 | "url": "http://www.apache.org/licenses/LICENSE-2.0" 75 | } 76 | ] 77 | } 78 | -------------------------------------------------------------------------------- /skylite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SlDo/skylite-cli/4e68fcd42e7e926b493d276e7c2f384949c1beeb/skylite.png -------------------------------------------------------------------------------- /src/actions/create.action.ts: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk'; 2 | import inquirer from 'inquirer'; 3 | import path from 'path'; 4 | import { isPathExist } from '../service/fs/fs'; 5 | import { config } from '../index'; 6 | import createPrompt from '../commands/create/create.prompt'; 7 | import { newProjectGenerator } from '../service/generator/generator.project'; 8 | 9 | export default async function createCMD(projectName: string): Promise { 10 | const projectPath: string = `${process.cwd().replace(/\\/g, '/')}/${projectName}`; 11 | 12 | if (isPathExist(path.join(process.cwd(), projectName))) { 13 | return console.log(` 14 | ${chalk.redBright.bold('ERROR!')} 15 | ${chalk.whiteBright('A project with this name has already been created in the current directory')} 16 | `); 17 | } 18 | 19 | if (!isPathExist(path.join(process.cwd(), projectName)) && await config.isProjectExist(projectPath)) { 20 | await config.deleteProject(projectPath); 21 | } 22 | 23 | const { lang, engine } = await inquirer.prompt(createPrompt); 24 | 25 | return newProjectGenerator(projectName, projectPath, { 26 | template: engine, 27 | lang, 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /src/actions/generate.action.ts: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk'; 2 | import { newModule } from '../service/generator/generator.modules'; 3 | import { config } from '../index'; 4 | import { ModuleEnum } from '../enums/module.enum'; 5 | 6 | export default async function generateModule(moduleType: string, name: string): Promise { 7 | const currentProject = await config.getProject(process.cwd().replace(/\\/g, '/')); 8 | 9 | if (currentProject == null) { 10 | return console.log(` 11 | ${chalk.redBright.bold('ERROR!')} 12 | ${chalk.whiteBright('The project doesn\'t exist in this path')} 13 | `); 14 | } 15 | 16 | const { pathToProject, template: { type, lang } } = currentProject; 17 | 18 | switch (true) { 19 | case /c|controller/.test(moduleType): 20 | return newModule(pathToProject, ModuleEnum.CONTROLLER, name, { type, lang }); 21 | case /d|dal/.test(moduleType): 22 | return newModule(pathToProject, ModuleEnum.DAL, name, { type, lang }); 23 | default: 24 | return console.log('This command is not allowed'); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/commands/commands.ts: -------------------------------------------------------------------------------- 1 | import './create/create.cmd'; 2 | import './generate/module.cmd'; 3 | -------------------------------------------------------------------------------- /src/commands/create/create.cmd.ts: -------------------------------------------------------------------------------- 1 | import program from 'commander'; 2 | import createCmd from '../../actions/create.action'; 3 | 4 | program 5 | .command('create ') 6 | .alias('c') 7 | .description('Create a new Node.js application') 8 | .action(createCmd); 9 | -------------------------------------------------------------------------------- /src/commands/create/create.prompt.ts: -------------------------------------------------------------------------------- 1 | import { LangEnums } from '../../enums/lang.enums'; 2 | import { EngineEnums } from '../../enums/engine.enums'; 3 | 4 | export default [ 5 | { 6 | type: 'list', 7 | name: 'lang', 8 | message: 'What language do you want to use?', 9 | choices: [ 10 | { name: 'TypeScript', value: LangEnums.TS }, 11 | { name: 'JavaScript', value: LangEnums.JS }, 12 | ], 13 | }, 14 | { 15 | type: 'list', 16 | name: 'engine', 17 | message: 'What engine do you want to use?', 18 | choices: [ 19 | { name: 'Express', value: EngineEnums.EXPRESS }, 20 | ], 21 | }, 22 | ]; 23 | -------------------------------------------------------------------------------- /src/commands/generate/module.cmd.ts: -------------------------------------------------------------------------------- 1 | import program from 'commander'; 2 | import generateModule from '../../actions/generate.action'; 3 | 4 | program 5 | .command('generate [name]') 6 | .alias('g') 7 | .description('Create a new Node.js module for the application') 8 | .action(generateModule); 9 | -------------------------------------------------------------------------------- /src/config/cli.config.test.ts: -------------------------------------------------------------------------------- 1 | import mock from 'mock-fs'; 2 | import { getTemplateByID } from './cli.config'; 3 | 4 | jest.mock('./cli.json', () => ({ 5 | templates: [ 6 | { 7 | name: 'Test', 8 | id: 1, 9 | }, 10 | ], 11 | }), { virtual: true }); 12 | 13 | describe('cliConfig', () => { 14 | const cliConfig = JSON.stringify({ 15 | templates: [ 16 | { 17 | name: 'Test', 18 | id: 1, 19 | }, 20 | ], 21 | }); 22 | 23 | beforeEach(() => { 24 | mock({ 25 | './cli.json': cliConfig, 26 | }); 27 | }); 28 | 29 | test('it should return the template options from config file', async () => { 30 | expect(await getTemplateByID(1)).toEqual({ 31 | name: 'Test', 32 | id: 1, 33 | }); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /src/config/cli.config.ts: -------------------------------------------------------------------------------- 1 | import configCLI from './cli.json'; 2 | 3 | interface Template { 4 | id: number; 5 | name: string; 6 | } 7 | 8 | export function getTemplateByID(id: number): Template | undefined { 9 | return configCLI.templates.find((template) => template.id === id); 10 | } 11 | -------------------------------------------------------------------------------- /src/config/cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "templates": [ 3 | { 4 | "name": "Express", 5 | "id": 1 6 | } 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /src/config/config.test.ts: -------------------------------------------------------------------------------- 1 | import mock from 'mock-fs'; 2 | import fse from 'fs-extra'; 3 | import { Config } from './config'; 4 | 5 | describe('config', () => { 6 | let config: Config; 7 | 8 | const project = { 9 | projectID: 'tested1', 10 | projectName: 'test', 11 | pathToProject: '/user/project', 12 | template: { 13 | lang: 1, 14 | type: 1, 15 | }, 16 | }; 17 | 18 | beforeEach(async () => { 19 | mock({ 20 | '/user': { 21 | project: {}, 22 | }, 23 | }); 24 | 25 | config = new Config('/user/config.json'); 26 | }); 27 | 28 | test('it should create a new config file', async () => { 29 | expect(await fse.pathExists('/user/config.json')).toBeTruthy(); 30 | }); 31 | 32 | test('it should add a new project', async () => { 33 | await config.addProject(project); 34 | 35 | expect(await fse.readJSON('/user/config.json')).toEqual([project]); 36 | }); 37 | 38 | test('it should return the project from config file', async () => { 39 | await config.addProject(project); 40 | expect(await config.getProject('/user/project')).toEqual(project); 41 | }); 42 | 43 | test('it should delete project from config file', async () => { 44 | await config.addProject(project); 45 | await config.deleteProject('/user/project'); 46 | expect(await fse.readJSON('/user/config.json')).toEqual([]); 47 | }); 48 | 49 | test('it should return true if the project exists', async () => { 50 | await config.addProject(project); 51 | expect(await config.isProjectExist('/user/project')).toBeTruthy(); 52 | }); 53 | 54 | afterEach(async () => { 55 | mock.restore(); 56 | }); 57 | }); 58 | -------------------------------------------------------------------------------- /src/config/config.ts: -------------------------------------------------------------------------------- 1 | import fse from 'fs-extra'; 2 | import { isPathExist } from '../service/fs/fs'; 3 | 4 | interface ConfigParams { 5 | projectID: string; 6 | projectName: string; 7 | pathToProject: string; 8 | template: { 9 | type: number; 10 | lang: number; 11 | }; 12 | } 13 | 14 | export class Config { 15 | // eslint-disable-next-line no-useless-constructor 16 | constructor(public jsonPath: string) { 17 | if (!isPathExist(jsonPath)) { 18 | fse.outputJSONSync(jsonPath, []); 19 | } 20 | } 21 | 22 | async addProject(project: ConfigParams) { 23 | const config = await this.get(); 24 | const isExist = await this.isProjectExist(project.pathToProject); 25 | 26 | if (!isExist) { 27 | await this.write([...config, project]); 28 | } 29 | } 30 | 31 | async getProject(pathToProject: string) { 32 | const config = await this.get(); 33 | 34 | return config.find((project: ConfigParams) => project.pathToProject === pathToProject); 35 | } 36 | 37 | async deleteProject(pathToProject: string) { 38 | const config = await this.get(); 39 | 40 | await this.write(config.filter((project: ConfigParams) => project.pathToProject !== pathToProject)); 41 | } 42 | 43 | async write(content: ConfigParams[]): Promise { 44 | return fse.writeJSON(this.jsonPath, content); 45 | } 46 | 47 | async get() { 48 | return fse.readJSON(this.jsonPath); 49 | } 50 | 51 | async isProjectExist(path: string) { 52 | const config = await this.get(); 53 | return config.findIndex((currentProject: ConfigParams) => currentProject.pathToProject === path) !== -1; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/enums/engine.enums.ts: -------------------------------------------------------------------------------- 1 | export enum EngineEnums { 2 | EXPRESS = 1 3 | } 4 | -------------------------------------------------------------------------------- /src/enums/lang.enums.ts: -------------------------------------------------------------------------------- 1 | export enum LangEnums { 2 | TS = 1, JS 3 | } 4 | -------------------------------------------------------------------------------- /src/enums/module.enum.ts: -------------------------------------------------------------------------------- 1 | export enum ModuleEnum { 2 | CONTROLLER = 'controller', DAL = 'dal' 3 | } 4 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import chalk from 'chalk'; 4 | import boxen from 'boxen'; 5 | import program from 'commander'; 6 | import './commands/commands'; 7 | import os from 'os'; 8 | import { Config } from './config/config'; 9 | 10 | const { log } = console; 11 | 12 | program.version('- Version: 0.0.1', '-v, -V, --version', 'output the current version'); 13 | 14 | log(boxen(` 15 | ${chalk.hex('#a7c5eb').bold('WELCOME!')} 16 | ${chalk.whiteBright('Skylite CLI can help you to create a powerful Node.js application')} 17 | `, { padding: 1, borderColor: '#a7c5eb' })); 18 | 19 | export const config = new Config(`${os.homedir()}/.slcli/config.json`); 20 | 21 | program.parse(process.argv); 22 | -------------------------------------------------------------------------------- /src/service/fs/fs.test.ts: -------------------------------------------------------------------------------- 1 | import mock from 'mock-fs'; 2 | import fse from 'fs-extra'; 3 | 4 | import { 5 | createFile, copy, isPathExist, writeFile, getFilesPaths, renameFile 6 | } from './fs'; 7 | 8 | beforeEach(async () => { 9 | mock({ 10 | '/test': { 11 | copy: { 12 | 'copy.txt': 'this file was copied', 13 | }, 14 | copyDest: {}, 15 | }, 16 | }); 17 | }); 18 | 19 | describe('fs module', () => { 20 | test('it should create a new file with content', async () => { 21 | const content: string = 'Hello from jest!'; 22 | await createFile('/test', 'test.txt', content); 23 | 24 | expect(await fse.readFile('/test/test.txt', 'utf-8')).toBe(content); 25 | }); 26 | 27 | test('it should copy files from path', async () => { 28 | await copy('/test/copy', '/test/copyDest'); 29 | 30 | expect(fse.existsSync('/test/copyDest/copy.txt')).toBeTruthy(); 31 | }); 32 | 33 | test('it should return true if a path exist', async () => { 34 | expect(await isPathExist('/test')).toBeTruthy(); 35 | }); 36 | 37 | test('it should rename a file', async () => { 38 | await renameFile('/test/copy/copy.txt', '/test/copy/copy.ini'); 39 | expect(await fse.pathExists('/test/copy/copy.ini')).toBeTruthy(); 40 | }); 41 | 42 | test('it should write a content in some file', async () => { 43 | const content = 'Jest!'; 44 | await writeFile('/test/jest.txt', content); 45 | 46 | expect(await fse.readFile('/test/jest.txt', 'utf-8')).toBe(content); 47 | }); 48 | 49 | test('it should return files path in some folder', async () => { 50 | expect(await getFilesPaths('/test/copy', '**/*.txt')).toContain('/test/copy/copy.txt'); 51 | }); 52 | }); 53 | 54 | afterEach(async () => { 55 | mock.restore(); 56 | }); 57 | -------------------------------------------------------------------------------- /src/service/fs/fs.ts: -------------------------------------------------------------------------------- 1 | import fse from 'fs-extra'; 2 | import globby from 'globby'; 3 | import path from 'path'; 4 | 5 | export function createFile(filePath: string, fileName: string, content: string = '') { 6 | return fse.outputFile(path.join(filePath, fileName), content); 7 | } 8 | 9 | export function copy(fromPath: string, newPath: string, params?: fse.CopyOptions): Promise { 10 | return fse.copy(fromPath, newPath, params); 11 | } 12 | 13 | export function isPathExist(folderPath: string) { 14 | return fse.existsSync(folderPath); 15 | } 16 | 17 | export function writeFile(file: string, data: string) { 18 | return fse.outputFile(file, data); 19 | } 20 | 21 | export function renameFile(dest: string, src: string) { 22 | return fse.rename(dest, src); 23 | } 24 | 25 | export async function getFilesPaths(filePath: string, pattern: string, files?: string[]): Promise { 26 | return globby(`${filePath}/${pattern}`, { 27 | expandDirectories: { 28 | files, 29 | }, 30 | }); 31 | } 32 | -------------------------------------------------------------------------------- /src/service/generator/generator.modules.ts: -------------------------------------------------------------------------------- 1 | import ejs from 'ejs'; 2 | import chalk from 'chalk'; 3 | import { createFile } from '../fs/fs'; 4 | import { getTemplateByID } from '../../config/cli.config'; 5 | import getModulePath from '../utils/getModule'; 6 | 7 | interface Module { 8 | type: number; 9 | lang: number; 10 | } 11 | 12 | export async function newModule(dest: string, moduleType: string, moduleName: string, options: Module): Promise { 13 | const { type, lang } = options; 14 | 15 | const modulePath = getModulePath(getTemplateByID(type)!.name, `${moduleType}.js`); 16 | 17 | if (modulePath == null) { 18 | return console.log(` 19 | ${chalk.redBright.bold('ERROR!')} 20 | ${chalk.whiteBright('The template is deleted or does not exist')} 21 | `); 22 | } 23 | 24 | const controllerContent = await ejs.renderFile(modulePath, { lang, name: moduleName }); 25 | return createFile(`${dest}/components/${moduleName}`, `${moduleName}.${moduleType}.${lang === 1 ? 'ts' : 'js'}`, controllerContent); 26 | } 27 | -------------------------------------------------------------------------------- /src/service/generator/generator.project.ts: -------------------------------------------------------------------------------- 1 | import ejs from 'ejs'; 2 | import { v4 as uuidv4 } from 'uuid'; 3 | import chalk from 'chalk'; 4 | import { 5 | getFilesPaths, writeFile, copy, renameFile, 6 | } from '../fs/fs'; 7 | import { config } from '../../index'; 8 | import { getTemplateByID } from '../../config/cli.config'; 9 | import { LangEnums } from '../../enums/lang.enums'; 10 | import getTemplatePath from '../utils/getTemplate'; 11 | 12 | interface ProjectOptions { 13 | lang: number; 14 | template: number; 15 | } 16 | 17 | export async function newProjectGenerator(projectName: string, pathProject: string, options: ProjectOptions) { 18 | const { template, lang } = options; 19 | 20 | const templatePath = getTemplatePath(getTemplateByID(template)!.name); 21 | 22 | if (templatePath == null) { 23 | return console.log(` 24 | ${chalk.redBright.bold('ERROR!')} 25 | ${chalk.whiteBright('The template is deleted or does not exist')} 26 | `); 27 | } 28 | 29 | const filterFilesDist = (src: string, dest: string) => { 30 | if (lang !== LangEnums.TS) { 31 | return !dest.includes('modules') && !dest.includes('tsconfig.json'); 32 | } 33 | 34 | return !dest.includes('modules'); 35 | }; 36 | 37 | await copy(templatePath, pathProject, { filter: filterFilesDist, overwrite: false }); 38 | 39 | const files: string[] = await getFilesPaths(pathProject, '**/*.(js|json)', ['!modules']); 40 | 41 | await Promise.all( 42 | files.map(async (file: string) => { 43 | const renderFile: string = await ejs.renderFile(file, { lang }); 44 | const tsExtension = file.replace(/\.js$/i, '.ts'); 45 | const writableFile = lang === LangEnums.TS ? tsExtension : file; 46 | if (lang === LangEnums.TS) { 47 | await renameFile(file, tsExtension); 48 | } 49 | await writeFile(writableFile, renderFile); 50 | }), 51 | ); 52 | 53 | return config.addProject({ 54 | projectID: uuidv4(), 55 | projectName, 56 | pathToProject: pathProject, 57 | template: { 58 | type: template, 59 | lang, 60 | }, 61 | }); 62 | } 63 | -------------------------------------------------------------------------------- /src/service/generator/templates/express/app.js: -------------------------------------------------------------------------------- 1 | <%_ if (lang == 1) { _%> 2 | import express, { Router } from 'express'; 3 | 4 | export const app: express.Application = express(); 5 | export const router: Router = express.Router(); 6 | 7 | import('./components/greeting/greeting.controller').createController(router); 8 | <%_ } else { _%> 9 | const express = require('express'); 10 | 11 | const app = express(); 12 | const router = express.Router(); 13 | 14 | require('./components/greeting/greeting.controller').createController(router); 15 | <%_ } _%> 16 | 17 | app.use('/api', router); 18 | 19 | <%_ if (lang == 0) { _%> 20 | module.exports = { router, app }; 21 | <%_ } _%> 22 | -------------------------------------------------------------------------------- /src/service/generator/templates/express/bin/www/server.js: -------------------------------------------------------------------------------- 1 | <%_ if (lang == 1) { _%> 2 | import { app } from '../../app'; 3 | import http from 'http'; 4 | <%_ } else { _%> 5 | const { app } = require('../../app'); 6 | const http = require('http'); 7 | <%_ } _%> 8 | app.set('port', process.env.PORT || '3000'); 9 | 10 | <% if (lang == 1) { %>export <% } %>const server = http.createServer(app).listen(app.get('port')); 11 | 12 | <%_ if (lang == 0) { _%> 13 | module.exports = server; 14 | <%_ } _%> 15 | -------------------------------------------------------------------------------- /src/service/generator/templates/express/components/greeting/greeting.controller.js: -------------------------------------------------------------------------------- 1 | <%_ if (lang == 1) { _%> 2 | import { Router } from 'express'; 3 | import { greeting } from './greeting.dal'; 4 | 5 | export function createController(router: Router): void { 6 | router.get('/hello', greeting); 7 | } 8 | <%_ } else { _%> 9 | const { greeting } = require('./greeting.dal'); 10 | 11 | module.exports = { 12 | createController(router) { 13 | router.get('/hello', greeting); 14 | } 15 | } 16 | <%_ } _%> 17 | -------------------------------------------------------------------------------- /src/service/generator/templates/express/components/greeting/greeting.dal.js: -------------------------------------------------------------------------------- 1 | <%_ if (lang == 1) { _%> 2 | import { Request, Response } from 'express'; 3 | 4 | export function greeting(req: Request, res: Response): Response { 5 | return res.send('Hello!').end(200); 6 | } 7 | <%_ } else { _%> 8 | module.exports.greeting = function greeting(req, res) { 9 | return res.send('Hello!').end(200); 10 | } 11 | <%_ } _%> 12 | -------------------------------------------------------------------------------- /src/service/generator/templates/express/modules/controller.js: -------------------------------------------------------------------------------- 1 | <%_ if (lang == 1) { _%> 2 | import { Router } from 'express'; 3 | 4 | export function createController(router: Router): void { 5 | router.get('/<%- name %>'); 6 | } 7 | <%_ } else { _%> 8 | module.exports = { 9 | createController(router) { 10 | router.get('/<%- name %>'); 11 | } 12 | } 13 | <%_ } _%> 14 | -------------------------------------------------------------------------------- /src/service/generator/templates/express/modules/dal.js: -------------------------------------------------------------------------------- 1 | <%_ if (lang == 1) { _%> 2 | import { Request, Response } from 'express'; 3 | 4 | export function dal(req: Request, res: Response): Response { 5 | return res.send('<%- name %>!').end(200); 6 | } 7 | <%_ } else { _%> 8 | module.exports.dal = function dal(req, res) { 9 | return res.send('<%- name %>!').end(200); 10 | } 11 | <%_ } _%> 12 | -------------------------------------------------------------------------------- /src/service/generator/templates/express/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "templates", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | <%_ if (lang == 1) { _%> 8 | "start": "npm run build:live", 9 | "build": "tsc -p ..", 10 | "build:live": "nodemon --watch 'src/**/*.ts' --exec \"ts-node\" src/index.ts" 11 | <%_ } else { _%> 12 | "start": "npm run ./bin/www/server" 13 | <%_ } _%> 14 | }, 15 | "keywords": [], 16 | "author": "", 17 | "license": "ISC", 18 | "devDependencies": { 19 | <%_ if (lang == 1) { _%> 20 | "@types/express": "^4.17.9", 21 | "@types/node": "^14.14.20", 22 | "typescript": "^4.1.3" 23 | <%_ } _%> 24 | }, 25 | "dependencies": { 26 | "express": "^4.17.1" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/service/generator/templates/express/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Basic Options */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ 8 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ 9 | "lib": ["es6","dom"], /* Specify library files to be included in the compilation. */ 10 | // "allowJs": true, /* Allow javascript files to be compiled. */ 11 | // "checkJs": true, /* Report errors in .js files. */ 12 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 13 | // "declaration": true, /* Generates corresponding '.d.ts' file. */ 14 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 15 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 16 | // "outFile": "./", /* Concatenate and emit output to single file. */ 17 | "outDir": "lib", /* Redirect output structure to the directory. */ 18 | "rootDir": "src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 19 | // "composite": true, /* Enable project compilation */ 20 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ 21 | // "removeComments": true, /* Do not emit comments to output. */ 22 | // "noEmit": true, /* Do not emit outputs. */ 23 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 24 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 25 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 26 | 27 | /* Strict Type-Checking Options */ 28 | "strict": true, /* Enable all strict type-checking options. */ 29 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 30 | // "strictNullChecks": true, /* Enable strict null checks. */ 31 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 32 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 33 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 34 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 35 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 36 | 37 | /* Additional Checks */ 38 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 39 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 40 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 41 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 42 | // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ 43 | 44 | /* Module Resolution Options */ 45 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 46 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 47 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 48 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 49 | // "typeRoots": [], /* List of folders to include type definitions from. */ 50 | // "types": [], /* Type declaration files to be included in compilation. */ 51 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 52 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 53 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 54 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 55 | 56 | /* Source Map Options */ 57 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 58 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 59 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 60 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 61 | 62 | /* Experimental Options */ 63 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 64 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 65 | 66 | /* Advanced Options */ 67 | "resolveJsonModule": true, /* Include modules imported with '.json' extension */ 68 | "skipLibCheck": true, /* Skip type checking of declaration files. */ 69 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/service/utils/getModule.test.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import getModulePath from './getModule'; 3 | 4 | describe('getModulePath', () => { 5 | test('it should return the path to module', async () => { 6 | const expressTemplate = path.join(__dirname, '../generator', 'templates/express/modules/dal.js'); 7 | expect(getModulePath('express', 'dal.js')).toBe(expressTemplate); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /src/service/utils/getModule.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import getTemplatePath from './getTemplate'; 3 | 4 | export default function getModulePath(templateName: string, moduleName: string): string | undefined { 5 | const templatePath: string | undefined = getTemplatePath(templateName); 6 | 7 | if (templatePath == null) return undefined; 8 | 9 | return path.join(templatePath, 'modules', moduleName); 10 | } 11 | -------------------------------------------------------------------------------- /src/service/utils/getTemplate.test.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import getTemplatePath from './getTemplate'; 3 | 4 | describe('getModulePath', () => { 5 | test('it should return the path to template', async () => { 6 | const expressTemplate = path.join(__dirname, '../generator', 'templates/express'); 7 | expect(getTemplatePath('express')).toBe(expressTemplate); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /src/service/utils/getTemplate.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import { isPathExist } from '../fs/fs'; 3 | 4 | export default function getTemplatePath(templateName: string): string | undefined { 5 | const templatePath: string = path.join(__dirname, '../generator', 'templates', templateName.toLowerCase()); 6 | 7 | if (!isPathExist(templatePath)) return undefined; 8 | 9 | return templatePath; 10 | } 11 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es5", 5 | "outDir": "./lib", 6 | "esModuleInterop": true, 7 | "resolveJsonModule": true 8 | }, 9 | "exclude": [ 10 | "src/**/*.test.ts" 11 | ] 12 | } 13 | --------------------------------------------------------------------------------