diff --git a/.eslintrc.js b/.eslintrc.js index e5102c0..3da2b82 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,15 +5,10 @@ module.exports = { parser: '@typescript-eslint/parser', parserOptions: { ecmaVersion: 2020, - sourceType: 'module', + sourceType: 'module' }, - extends: [ - 'plugin:@typescript-eslint/recommended', - 'prettier', - 'plugin:prettier/recommended', - ], + extends: ['plugin:@typescript-eslint/recommended', 'prettier'], rules: { - '@typescript-eslint/no-unused-vars': 'error', - 'prettier/prettier': ['none', { trailingComma: 'es5' }], - }, -} + '@typescript-eslint/no-unused-vars': 'error' + } +}; diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7149c13..04aab93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,9 +33,15 @@ jobs: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: npm run release - - name: πŸ“œ Generate Gitmoji Changelog - run: npx gitmoji-changelog + - name: πŸ”§ Install Gitmoji Changelog + if: github.ref == 'refs/heads/main' + run: npm i -g gitmoji-changelog + + - name: πŸ“œ Generate Changelog + if: github.ref == 'refs/heads/main' + run: gitmoji-changelog - uses: stefanzweifel/git-auto-commit-action@v4 + if: github.ref == 'refs/heads/main' with: - commit_message: ':pencil: docs: update changelog [skip ci]' + commit_message: ':memo: docs: update changelog [skip ci]' diff --git a/.prettierrc b/.prettierrc index 2293c8d..f795224 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,6 +1,5 @@ { "trailingComma": "none", - "endOfLine": "auto", "singleQuote": true, "printWidth": 120 } diff --git a/.releaserc.js b/.releaserc.js deleted file mode 100644 index 5df8bfe..0000000 --- a/.releaserc.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - branches: ['main'], - plugins: [ - [ - 'semantic-release-gitmoji', - { - releaseRules: { - major: [':boom:'], - minor: [':sparkles:'], - patch: [':bug:', ':package:'] - } - } - ], - '@semantic-release/github', - '@semantic-release/npm', - ['@semantic-release/git', { assets: ['package.json', 'CHANGELOG.md'] }] - ] -}; diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..4c21f50 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,18 @@ +{ + "branches": ["main"], + "plugins": [ + [ + "semantic-release-gitmoji", + { + "releaseRules": { + "major": [":boom:"], + "minor": [":sparkles:"], + "patch": [":bug:", ":package:"] + } + } + ], + "@semantic-release/github", + "@semantic-release/npm", + ["@semantic-release/git", { "assets": ["package.json", "CHANGELOG.md"] }] + ] +} diff --git a/CHANGELOG.md b/CHANGELOG.md index ab7c201..82dca0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,203 @@ -# 1.0.0 (2022-04-14) +# Changelog + +## 1.9.0 (2022-05-28) + +### Added + +- ✨ feat: common command component [[c1d879e](https://github.com/ngx-devs/ngx-devs-cli/commit/c1d879ecf6d30df89e548fd8369d188424513362)] + +### Changed + +- πŸ”§ ci: fix release script [[e385407](https://github.com/ngx-devs/ngx-devs-cli/commit/e38540727e226006b7d55dd62d20ae19491b7120)] +- πŸ”§ ci: update action steps [[212bde7](https://github.com/ngx-devs/ngx-devs-cli/commit/212bde752e9fc0cf03874ecfbaca3ea760fd1301)] + +### Miscellaneous + +- chore(release): 1.9.0 [skip ci] [[fe1d8ca](https://github.com/ngx-devs/ngx-devs-cli/commit/fe1d8ca94e6df55133b66661b9680a623f6f3c0b)] +- πŸ“ docs: update readme features [[ccf5839](https://github.com/ngx-devs/ngx-devs-cli/commit/ccf5839e68106f8a242e50498293e9579a68e87d)] +- πŸ“¦ refactor(widget): print file log order [[5428161](https://github.com/ngx-devs/ngx-devs-cli/commit/54281615ee380ff53920c857ee6acddb0458e9f7)] +- 🚧 chore: remove .vscode from git ignore [[7c44ab6](https://github.com/ngx-devs/ngx-devs-cli/commit/7c44ab6d3e3cfb0205e9e49308b680631569ca97)] +- πŸ“¦ refactor: migrate test files structure [[1a4c565](https://github.com/ngx-devs/ngx-devs-cli/commit/1a4c5658df6dc012cbec80498f67c576ce4be6a3)] + + + +## 1.8.0 (2022-05-13) + +### Added + +- ✨ feat: path parameter support for page component command [[059349c](https://github.com/ngx-devs/ngx-devs-cli/commit/059349c850e21ef9b73f6c1739a366ef93b190aa)] + +### Miscellaneous + +- chore(release): 1.8.0 [skip ci] [[4d2b06a](https://github.com/ngx-devs/ngx-devs-cli/commit/4d2b06ade4ff634ec2b9364f9cf8143e633f52cb)] +- πŸ“¦ refactor: extract component name and path logic to function [[d77300f](https://github.com/ngx-devs/ngx-devs-cli/commit/d77300fce2317ec660bba86a15bd72dff9fc7140)] + + + +## 1.7.0 (2022-05-12) + +### Added + +- ✨ feat: generate dialog component [[26f9b0d](https://github.com/ngx-devs/ngx-devs-cli/commit/26f9b0d124e7b0e35c8284803b8d99bb0ce5d810)] + +### Fixed + +- πŸ› fix: version command description [[f2dc910](https://github.com/ngx-devs/ngx-devs-cli/commit/f2dc91019ca981ff58421f673772fee0079f0bd2)] + +### Miscellaneous + +- chore(release): 1.7.0 [skip ci] [[9b36467](https://github.com/ngx-devs/ngx-devs-cli/commit/9b364670c6a65a8f1c07f98536cec395f1e3960b)] + + + +## 1.6.0 (2022-05-10) + +### Added + +- ✨ feat(cli): support for --path option [[d268046](https://github.com/ngx-devs/ngx-devs-cli/commit/d268046af7e83a8683494bfe81581206645e3216)] + +### Miscellaneous + +- chore(release): 1.6.0 [skip ci] [[1189b6a](https://github.com/ngx-devs/ngx-devs-cli/commit/1189b6af7b505ff30ec63e09b2ca5587be200318)] +- 🚧 chore(prettierrc): change printWidth to 120 [[7b00ac7](https://github.com/ngx-devs/ngx-devs-cli/commit/7b00ac70f4c1775a4aa29ee2c7979c7fabb38992)] + + + +## 1.5.0 (2022-05-09) + +### Added + +- ✨ feat: new command [[3924c05](https://github.com/ngx-devs/ngx-devs-cli/commit/3924c05b992e98229f2738720156ef80b8857e15)] + +### Fixed + +- πŸ› fix: copy-templates script [[18260d1](https://github.com/ngx-devs/ngx-devs-cli/commit/18260d1484642c619b735f9d3a382e0feed5802b)] + +### Miscellaneous + +- chore(release): 1.5.0 [skip ci] [[449b3d8](https://github.com/ngx-devs/ngx-devs-cli/commit/449b3d894bf8199589069906c1c7031b0a4e36ba)] +- 🚧 chore: ignore template folder [[b3d53f1](https://github.com/ngx-devs/ngx-devs-cli/commit/b3d53f15ccf5ad14b96f53acfab14b3017535958)] +- 🚧 chore: exclude src from ts compile [[cb184e5](https://github.com/ngx-devs/ngx-devs-cli/commit/cb184e584d39b88c5405073afd6b387386074379)] +- 🚧 chore: regenerate lock file [[7c15f60](https://github.com/ngx-devs/ngx-devs-cli/commit/7c15f6027ee3684d908ea2dddf5b486b782faba1)] +- 🚧 chore: ignore src folder on tests [[eaa0f65](https://github.com/ngx-devs/ngx-devs-cli/commit/eaa0f65bbc342b33ab8d7cdd4e5909b87765838e)] +- 🚧 chore: update releaserc config [[dfe4b2a](https://github.com/ngx-devs/ngx-devs-cli/commit/dfe4b2acea9beaa249c69837f0e65da815583834)] +- 🚧 chore: update releaserc plugins order [[d85100a](https://github.com/ngx-devs/ngx-devs-cli/commit/d85100a21d8edcd4bc0ad6cd650f0037cfbe3b02)] + + + +## 1.4.0 (2022-04-20) + +### Added + +- ✨ feat: add commitTemplate [[24fe3df](https://github.com/ngx-devs/ngx-devs-cli/commit/24fe3df274c758d78229b4b967be3fe010d60123)] + +### Miscellaneous + +- πŸ§ͺ test: merge test files [[0dd2c0d](https://github.com/ngx-devs/ngx-devs-cli/commit/0dd2c0dcd08ea99db156793e2ec843d537ae5b83)] +- 🚧 chore: add @semantic-release/changelog [[fc11ea2](https://github.com/ngx-devs/ngx-devs-cli/commit/fc11ea25ba9d878538896adafd235fde9e3ac7d2)] + + + +## 1.3.0 (2022-04-20) + +### Added + +- ✨ feat: page component command [[5ad5245](https://github.com/ngx-devs/ngx-devs-cli/commit/5ad52459dfd347b9d4ff32d66c6ebb7005785d29)] + +### Fixed + +- ✏️ docs: update readme emoji styles [[1893a2f](https://github.com/ngx-devs/ngx-devs-cli/commit/1893a2fe8b44dd619bb4d3a5135c9f63fe9e9d25)] +- ✏️ docs: add sections on readme [[1eef2b8](https://github.com/ngx-devs/ngx-devs-cli/commit/1eef2b8386cbbf416e5090e283bf5eebd90a573f)] + +### Miscellaneous + +- 🚧 chore: remove unnecessary job [[8b931fc](https://github.com/ngx-devs/ngx-devs-cli/commit/8b931fc700067b0c8be41e456c868c6347cb129f)] +- 🚧 chore: add build steps [[e5d67bb](https://github.com/ngx-devs/ngx-devs-cli/commit/e5d67bb3d88d5a36e8770f4bf5e71731045b3656)] +- πŸ“¦ refactor: update ci name [[3a3048a](https://github.com/ngx-devs/ngx-devs-cli/commit/3a3048a17faf1243dbbca25d4977873f6040358a)] +- 🚧 chore: split jobs into separete files [[9056908](https://github.com/ngx-devs/ngx-devs-cli/commit/9056908c1a7db4cf025d1e4d944d4aa01827b43e)] +- merge pull request [#7](https://github.com/ngx-devs/ngx-devs-cli/issues/7) from ngx-devs/feature/page-component-command [[54b72f1](https://github.com/ngx-devs/ngx-devs-cli/commit/54b72f18724e4c0ad3e54804e1f67c2bc75a9e25)] +- 🚧 chore: separate publish from build on ci workflow [[c3cd817](https://github.com/ngx-devs/ngx-devs-cli/commit/c3cd817c1bfbf2a8d43cce8f3f41305e962a6ce1)] + + + +## 1.2.0 (2022-04-20) + +### Added + +- ✨ feat: update package name to org schema [[d206158](https://github.com/ngx-devs/ngx-devs-cli/commit/d20615898104f56d55f918155415281541127429)] + + + +## 1.1.0 (2022-04-20) + +### Added + +- ✨ feat: generate widget component [[b13d083](https://github.com/ngx-devs/ngx-devs-cli/commit/b13d083c3890ae84dc0b24634748ebab9ea54637)] + +### Changed + +- πŸ”§ ci: add tests step [[9c400dc](https://github.com/ngx-devs/ngx-devs-cli/commit/9c400dcfe6dfc461ddb1d5d42d2dd3bedb11ee15)] +- πŸ”§ ci: add ci pipeline [[8465702](https://github.com/ngx-devs/ngx-devs-cli/commit/84657028bcacec1ed53fa35ff24c1898f70cf5cc)] + +### Fixed + +- πŸ› fix: how to read hbs template [[b588a5b](https://github.com/ngx-devs/ngx-devs-cli/commit/b588a5b31774e58ded214d7684ae24b65425bb30)] +- πŸ› fix: add missing path import on releaserc [[724e4ab](https://github.com/ngx-devs/ngx-devs-cli/commit/724e4abe2e6896fe1d2a53fd470a39d812df5e05)] +- ✏️ docs: add npm badge [[6eef97c](https://github.com/ngx-devs/ngx-devs-cli/commit/6eef97cb0778ab9eaa02d44decdf8cd18bf932b9)] +- πŸ› fix: read of package.json [[8987913](https://github.com/ngx-devs/ngx-devs-cli/commit/89879131ca88481c6c05bc9ce665ab49235827c8)] + +### Miscellaneous + +- 🚧 chore: move release branch to config file [[f130783](https://github.com/ngx-devs/ngx-devs-cli/commit/f130783841972f71c23bfbd4298feb16fd29ffd9)] +- πŸ“¦ refactor: add main release branch on package json [[9e255fe](https://github.com/ngx-devs/ngx-devs-cli/commit/9e255fe4a7490b088ad05cd8cad1da0f12b06f7f)] +- πŸ“¦ refactor: add release branchs [[4497ec3](https://github.com/ngx-devs/ngx-devs-cli/commit/4497ec34b95b208c191849ae7c945e4d973c474c)] +- 🚧 chore: update template directory [[bb73391](https://github.com/ngx-devs/ngx-devs-cli/commit/bb73391b8d5d18a19f2b03471dfc803ad53353a9)] +- 🚧 chore: change cz changelog to semantic-release-gitmoji [[b9287dd](https://github.com/ngx-devs/ngx-devs-cli/commit/b9287dde67f0efbee1576e943feddc0214c283f4)] +- 🚧 chore: update commitlint to use gitmoji [[214155e](https://github.com/ngx-devs/ngx-devs-cli/commit/214155e9a1e80d600ec02e79ef755b962b31332c)] +- refactor: update page command description [[8bd0796](https://github.com/ngx-devs/ngx-devs-cli/commit/8bd0796dbccb230da582f56d76263004e712e28a)] +- merge pull request [#5](https://github.com/ngx-devs/ngx-devs-cli/issues/5) from ngx-devs/feature/generate-widget-component-command [[f68134f](https://github.com/ngx-devs/ngx-devs-cli/commit/f68134face6cb18c61f16e39227db9404a5c93f2)] +- 🚧 chore: releaserc plugins config [[62f9e15](https://github.com/ngx-devs/ngx-devs-cli/commit/62f9e15621548376aff28ff0f224a9c59b61d14c)] +- 🚧 chore: add releaserc file [[e992abc](https://github.com/ngx-devs/ngx-devs-cli/commit/e992abc24d4271254f2356834bc177d88e73de30)] +- πŸ“¦ refactor: update widget command description [[c8b3747](https://github.com/ngx-devs/ngx-devs-cli/commit/c8b374753eb4b0b98dcf9cd1f2b54c4e98b85684)] +- merge pull request [#4](https://github.com/ngx-devs/ngx-devs-cli/issues/4) from ngx-devs/feature/generate-widget-component-command [[95a0659](https://github.com/ngx-devs/ngx-devs-cli/commit/95a0659a0d493cf780bf064c5be3783a05ffc8ca)] +- πŸ“¦ refactor: remove unnecessary temporary variable [[11275a9](https://github.com/ngx-devs/ngx-devs-cli/commit/11275a96577326dc1d4d36e5ac315828ad55c74f)] +- πŸ“¦ refactor: add workflows folder [[85200dc](https://github.com/ngx-devs/ngx-devs-cli/commit/85200dcccc24452e1937d0fc36fa9baea867fd7c)] +- 🚧 chore: update branch name from master to main [[eb99811](https://github.com/ngx-devs/ngx-devs-cli/commit/eb99811dee89fdf2e765936457ecd7dc3c5a980d)] +- πŸ“¦ refactor: change version to custom command [[6bc3f5c](https://github.com/ngx-devs/ngx-devs-cli/commit/6bc3f5c515074af827eea356d9b2b53f432108d4)] +- 🚧 chore: update husky hooks [[8e578a9](https://github.com/ngx-devs/ngx-devs-cli/commit/8e578a9fed167fd37da05417fd632732bb2b0138)] +- 🚧 chore: add build commit type [[3dd43b1](https://github.com/ngx-devs/ngx-devs-cli/commit/3dd43b180adc6b0a568014f40430286ccfbcdef6)] +- 🚧 chore: add husky [[d324982](https://github.com/ngx-devs/ngx-devs-cli/commit/d32498286b9b8803d8681c60ac681a67acc559ee)] +- 🚧 chore: add custom cz config [[38faf08](https://github.com/ngx-devs/ngx-devs-cli/commit/38faf08f09aba5e8235174e8ede2d5d12c9b1805)] + + + +## 1.0.0 (2022-04-14) + +### Added + +- ✨ feat: page component command [[5610901](https://github.com/ngx-devs/ngx-devs-cli/commit/5610901c3c6c791376cba04d0d50542bced195f3)] +- ✨ feat: show default commands on cli start [[659887d](https://github.com/ngx-devs/ngx-devs-cli/commit/659887de9a16f73517d3f34e67b058716b90a435)] +- πŸŽ‰ initial: base cli structure [[90da611](https://github.com/ngx-devs/ngx-devs-cli/commit/90da611c563a8cc59acc8cac8d24e6c26ecc4e99)] + +### Changed + +- πŸ”§ ci: add target branchs [[f58ed87](https://github.com/ngx-devs/ngx-devs-cli/commit/f58ed87c68e4bdf1165cfaa01ebc7ff08ee376f8)] +- πŸ”§ ci: set private to false [[e850a3a](https://github.com/ngx-devs/ngx-devs-cli/commit/e850a3ad16114bd30327a10bc26b51de9d878b40)] +- πŸ—οΈ build: upgrade from 0.0.1 to 0.0.2 [[03f8ca1](https://github.com/ngx-devs/ngx-devs-cli/commit/03f8ca131df18533fae6fe0afd2f31f088e66c75)] + +### Fixed + +- πŸ› fix: update node version from 12 to 16 [[5f54ccb](https://github.com/ngx-devs/ngx-devs-cli/commit/5f54ccb71ed7c2f675c472635f7912e3038ae4ef)] + +### Miscellaneous + +- chore(release): 1.0.0 [skip ci] [[96569cd](https://github.com/ngx-devs/ngx-devs-cli/commit/96569cdb30d3f4563afef098ece4131175ba9b27)] +- 🧱 build: add publishConfig [[f9bb212](https://github.com/ngx-devs/ngx-devs-cli/commit/f9bb212186869e832884c2d22a1afea2619951b7)] +- refactor: add workflows folder ([#2](https://github.com/ngx-devs/ngx-devs-cli/issues/2)) [[b21504e](https://github.com/ngx-devs/ngx-devs-cli/commit/b21504eee9cb6b320095e970fc92899cfa51c07b)] +- feat: add ci-cd integration and semantic release ([#1](https://github.com/ngx-devs/ngx-devs-cli/issues/1)) [[8e3513b](https://github.com/ngx-devs/ngx-devs-cli/commit/8e3513b24d9bc029d505ef4fa7f389324608d684)] +- πŸ§ͺ test(commands/version): ensure outputs package.json version [[5bb5a02](https://github.com/ngx-devs/ngx-devs-cli/commit/5bb5a024c3b968dddd3395618f407a0d20b629b1)] +- πŸ“¦ refactor: cli home styles [[76882a8](https://github.com/ngx-devs/ngx-devs-cli/commit/76882a8df37ad28da8fade1ab68891a182815ff6)] +- 🚧 chore: fix eslint and prettier conflig [[69e6ccb](https://github.com/ngx-devs/ngx-devs-cli/commit/69e6ccb850df1706e6da2dd296ac11eb5b007d78)] -### Features -* add ci-cd integration and semantic release ([#1](https://github.com/ngx-devs/ngx-devs-cli/issues/1)) ([8e3513b](https://github.com/ngx-devs/ngx-devs-cli/commit/8e3513b24d9bc029d505ef4fa7f389324608d684)) diff --git a/cli-test-setup.ts b/cli-test-setup.ts deleted file mode 100644 index e2b9352..0000000 --- a/cli-test-setup.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { filesystem, system } from 'gluegun'; - -export const cli = async (cmd) => system.run('node ' + filesystem.path(__dirname, 'bin', 'ngx-devs-cli') + ` ${cmd}`); diff --git a/commitlint.config.js b/commitlint.config.js index 5af671a..1255ea2 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1 +1,6 @@ -module.exports = { extends: ['gitmoji'] }; +module.exports = { + extends: ['gitmoji'], + rules: { + 'header-max-length': [0, 'always', 80] + } +}; diff --git a/jest.config.js b/jest.config.js index 7db2a68..39b7f00 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,7 +7,7 @@ module.exports = { testPathIgnorePatterns: ['/build/', '/templates/'], globals: { 'ts-jest': { - tsConfig: 'tsconfig.spec.json' + tsconfig: 'tsconfig.spec.json' } } }; diff --git a/package-lock.json b/package-lock.json index ed261ae..140e039 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ngx-devs/cli", - "version": "1.0.0", + "version": "1.9.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ngx-devs/cli", - "version": "1.0.0", + "version": "1.9.0", "license": "MIT", "dependencies": { "gluegun": "latest" @@ -18,7 +18,6 @@ "@commitlint/cli": "^16.2.3", "@commitlint/config-conventional": "^16.2.1", "@ngx-devs/commitlint-plugin-imperative": "^1.1.1", - "@semantic-release/changelog": "^6.0.1", "@semantic-release/git": "^10.0.1", "@types/jest": "^26.0.20", "@types/node": "^12.7.11", @@ -27,7 +26,6 @@ "commitizen": "^4.2.4", "commitlint-config-gitmoji": "^2.2.5", "copyfiles": "^2.4.1", - "cz-conventional-changelog": "^3.3.0", "eslint": "^7.22.0", "eslint-config-prettier": "^8.1.0", "eslint-plugin-prettier": "^3.3.1", @@ -2009,48 +2007,6 @@ "@octokit/openapi-types": "^11.2.0" } }, - "node_modules/@semantic-release/changelog": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/@semantic-release/changelog/-/changelog-6.0.1.tgz", - "integrity": "sha512-FT+tAGdWHr0RCM3EpWegWnvXJ05LQtBkQUaQRIExONoXjVjLuOILNm4DEKNaV+GAQyJjbLRVs57ti//GypH6PA==", - "dev": true, - "dependencies": { - "@semantic-release/error": "^3.0.0", - "aggregate-error": "^3.0.0", - "fs-extra": "^9.0.0", - "lodash": "^4.17.4" - }, - "engines": { - "node": ">=14.17" - }, - "peerDependencies": { - "semantic-release": ">=18.0.0" - } - }, - "node_modules/@semantic-release/changelog/node_modules/fs-extra": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", - "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", - "dev": true, - "dependencies": { - "at-least-node": "^1.0.0", - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@semantic-release/changelog/node_modules/universalify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", - "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/@semantic-release/commit-analyzer": { "version": "9.0.2", "resolved": "https://registry.npmjs.org/@semantic-release/commit-analyzer/-/commit-analyzer-9.0.2.tgz", @@ -3027,6 +2983,7 @@ "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", "dev": true, + "peer": true, "engines": { "node": ">= 4.0.0" } @@ -5440,97 +5397,6 @@ "integrity": "sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk=", "dev": true }, - "node_modules/cz-conventional-changelog": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/cz-conventional-changelog/-/cz-conventional-changelog-3.3.0.tgz", - "integrity": "sha512-U466fIzU5U22eES5lTNiNbZ+d8dfcHcssH4o7QsdWaCcRs/feIPCxKYSWkYBNs5mny7MvEfwpTLWjvbm94hecw==", - "dev": true, - "dependencies": { - "chalk": "^2.4.1", - "commitizen": "^4.0.3", - "conventional-commit-types": "^3.0.0", - "lodash.map": "^4.5.1", - "longest": "^2.0.1", - "word-wrap": "^1.0.3" - }, - "engines": { - "node": ">= 10" - }, - "optionalDependencies": { - "@commitlint/load": ">6.1.1" - } - }, - "node_modules/cz-conventional-changelog/node_modules/ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "dependencies": { - "color-convert": "^1.9.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/cz-conventional-changelog/node_modules/chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/cz-conventional-changelog/node_modules/color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "dependencies": { - "color-name": "1.1.3" - } - }, - "node_modules/cz-conventional-changelog/node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true - }, - "node_modules/cz-conventional-changelog/node_modules/escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true, - "engines": { - "node": ">=0.8.0" - } - }, - "node_modules/cz-conventional-changelog/node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/cz-conventional-changelog/node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/dargs": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/dargs/-/dargs-7.0.0.tgz", @@ -20634,38 +20500,6 @@ "@octokit/openapi-types": "^11.2.0" } }, - "@semantic-release/changelog": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/@semantic-release/changelog/-/changelog-6.0.1.tgz", - "integrity": "sha512-FT+tAGdWHr0RCM3EpWegWnvXJ05LQtBkQUaQRIExONoXjVjLuOILNm4DEKNaV+GAQyJjbLRVs57ti//GypH6PA==", - "dev": true, - "requires": { - "@semantic-release/error": "^3.0.0", - "aggregate-error": "^3.0.0", - "fs-extra": "^9.0.0", - "lodash": "^4.17.4" - }, - "dependencies": { - "fs-extra": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", - "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", - "dev": true, - "requires": { - "at-least-node": "^1.0.0", - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - } - }, - "universalify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", - "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", - "dev": true - } - } - }, "@semantic-release/commit-analyzer": { "version": "9.0.2", "resolved": "https://registry.npmjs.org/@semantic-release/commit-analyzer/-/commit-analyzer-9.0.2.tgz", @@ -21426,7 +21260,8 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", - "dev": true + "dev": true, + "peer": true }, "atob": { "version": "2.1.2", @@ -23320,79 +23155,6 @@ "integrity": "sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk=", "dev": true }, - "cz-conventional-changelog": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/cz-conventional-changelog/-/cz-conventional-changelog-3.3.0.tgz", - "integrity": "sha512-U466fIzU5U22eES5lTNiNbZ+d8dfcHcssH4o7QsdWaCcRs/feIPCxKYSWkYBNs5mny7MvEfwpTLWjvbm94hecw==", - "dev": true, - "requires": { - "@commitlint/load": ">6.1.1", - "chalk": "^2.4.1", - "commitizen": "^4.0.3", - "conventional-commit-types": "^3.0.0", - "lodash.map": "^4.5.1", - "longest": "^2.0.1", - "word-wrap": "^1.0.3" - }, - "dependencies": { - "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } - }, - "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - } - }, - "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "requires": { - "color-name": "1.1.3" - } - }, - "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true - }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true - }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - } - } - }, "dargs": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/dargs/-/dargs-7.0.0.tgz", diff --git a/package.json b/package.json index da79989..619adb9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@ngx-devs/cli", "license": "MIT", - "version": "1.9.0", + "version": "1.10.0", "private": false, "publishConfig": { "access": "public" @@ -44,7 +44,6 @@ "@commitlint/cli": "^16.2.3", "@commitlint/config-conventional": "^16.2.1", "@ngx-devs/commitlint-plugin-imperative": "^1.1.1", - "@semantic-release/changelog": "^6.0.1", "@semantic-release/git": "^10.0.1", "@types/jest": "^26.0.20", "@types/node": "^12.7.11", @@ -53,7 +52,6 @@ "commitizen": "^4.2.4", "commitlint-config-gitmoji": "^2.2.5", "copyfiles": "^2.4.1", - "cz-conventional-changelog": "^3.3.0", "eslint": "^7.22.0", "eslint-config-prettier": "^8.1.0", "eslint-plugin-prettier": "^3.3.1", diff --git a/readme.md b/readme.md index a458e09..f884b16 100644 --- a/readme.md +++ b/readme.md @@ -80,6 +80,8 @@ ngxd g c sample +--- + ## :robot: Commands ```bash @@ -89,22 +91,22 @@ ngxd new ### Components -##### :hammer_and_wrench: **basic** +##### :hammer_and_wrench: **common** ```bash -# create a new basic component -ngxd generate component basic +# create a new common component +ngxd generate component common # or -ngxd g c b +ngxd g c c ``` -##### :hammer_and_wrench: **widget** +##### :hammer_and_wrench: **dialog** ```bash -# create a new widget component -ngxd generate component widget +# create a new dialog component +ngxd generate component dialog # or -ngxd g c w +ngxd g c d ``` ##### :hammer_and_wrench: **page** @@ -116,13 +118,33 @@ ngxd generate component page ngxd g c p ``` -##### :hammer_and_wrench: **dialog** +##### :hammer_and_wrench: **widget** ```bash -# create a new dialog component -ngxd generate component dialog +# create a new widget component +ngxd generate component widget # or -ngxd g c d +ngxd g c w +``` + +### Services + +##### :hammer_and_wrench: **common** + +```bash +# create a new common service +ngxd generate service common +# or +ngxd g s c +``` + +##### :hammer_and_wrench: **api** + +```bash +# create a new api service +ngxd generate service api +# or +ngxd g s a ``` ## :boy: **Author** diff --git a/src/cli.ts b/src/cli.ts index 961cb15..316c61f 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -5,18 +5,10 @@ async function run(argv) { .brand('ngx-devs-cli') .src(__dirname) .plugins('./node_modules', { matching: 'ngx-devs-cli-*', hidden: true }) - .exclude([ - 'meta', - 'semver', - 'system', - 'http', - 'patching', - 'package-manager' - ]) + .exclude(['meta', 'semver', 'system', 'http', 'patching', 'package-manager']) .create(); - const toolbox = await cli.run(argv); - return toolbox; + return cli.run(argv); } module.exports = { run }; diff --git a/src/commands/generate/component/common/common.test.ts b/src/commands/generate/component/common/common.test.ts index fceacba..4777199 100644 --- a/src/commands/generate/component/common/common.test.ts +++ b/src/commands/generate/component/common/common.test.ts @@ -1,6 +1,6 @@ import { filesystem } from 'gluegun'; -import { cli } from '@ngxd/cli-test-setup'; +import { runNgxdCLI } from '../../../../utils/cli-test-setup'; describe('[Commands: generate common component]', () => { beforeEach(() => { @@ -14,7 +14,7 @@ describe('[Commands: generate common component]', () => { test('should generate a common component with 3 files', async () => { const name = 'sample-with-three-files'; - await cli(`g c c ${name}`); + await runNgxdCLI(`g c c ${name}`); const html = filesystem.read(`${name}/${name}.component.html`); const scss = filesystem.read(`${name}/${name}.component.scss`); @@ -29,7 +29,7 @@ describe('[Commands: generate common component]', () => { test('should generate a common component html with default template

sample works

', async () => { const name = 'sample-with-default-template'; - await cli(`g c c ${name}`); + await runNgxdCLI(`g c c ${name}`); const html = filesystem.read(`${name}/${name}.component.html`); @@ -39,7 +39,7 @@ describe('[Commands: generate common component]', () => { test('should generate a common component with correct templateUrl: and styleUrls ', async () => { const name = 'sample-style-template-url'; - await cli(`g c c ${name}`); + await runNgxdCLI(`g c c ${name}`); const ts = filesystem.read(`${name}/${name}.component.ts`); diff --git a/src/commands/generate/component/component.ts b/src/commands/generate/component/component.ts index 74721f4..efdc59d 100644 --- a/src/commands/generate/component/component.ts +++ b/src/commands/generate/component/component.ts @@ -6,12 +6,12 @@ import { findCommand } from '../../../utils/functions.helper'; const COMMAND: GluegunCommand = { name: 'component', alias: ['c'], - description: 'Cria um componente Angular de tipo especΓ­fico', + description: 'Cria um componente Angular', run: async (toolbox: GluegunToolbox) => { const { parameters, prompt } = toolbox; - let componentName = parameters.first; + const componentName = parameters.first; const QUESTION = 'Qual tipo de componente vocΓͺ deseja criar?'; const TYPES = ['common', 'page', 'widget', 'layout', 'dialog']; @@ -27,7 +27,7 @@ const COMMAND: GluegunCommand = { const command = findCommand(toolbox, componentType); toolbox.parameters.first = componentName; - command.run(toolbox); + command?.run(toolbox); } }; diff --git a/src/commands/generate/component/dialog/dialog.test.ts b/src/commands/generate/component/dialog/dialog.test.ts index 897b56b..59aeb13 100644 --- a/src/commands/generate/component/dialog/dialog.test.ts +++ b/src/commands/generate/component/dialog/dialog.test.ts @@ -1,6 +1,6 @@ import { filesystem } from 'gluegun'; -import { cli } from '@ngxd/cli-test-setup'; +import { runNgxdCLI } from '../../../../utils/cli-test-setup'; describe('[Commands: generate dialog component]', () => { const name = 'gdc'; @@ -16,7 +16,7 @@ describe('[Commands: generate dialog component]', () => { }); test('should generate a dialog component with 3 files', async () => { - await cli(`g c d ${name}`); + await runNgxdCLI(`g c d ${name}`); const html = filesystem.read(`${name}/${name}.dialog.html`); const scss = filesystem.read(`${name}/${name}.dialog.scss`); @@ -28,14 +28,14 @@ describe('[Commands: generate dialog component]', () => { }); test('should generate a dialog component html with default template

sample works

', async () => { - await cli(`g c d ${name}`); + await runNgxdCLI(`g c d ${name}`); const html = filesystem.read(`${name}/${name}.dialog.html`); expect(html).toContain(`

${name} works

`); }); test('should generate a dialog component with correct templateUrl: and styleUrls ', async () => { - await cli(`g c d ${name}`); + await runNgxdCLI(`g c d ${name}`); const ts = filesystem.read(`${name}/${name}.dialog.ts`); diff --git a/src/commands/generate/component/page/page.test.ts b/src/commands/generate/component/page/page.test.ts index 18fad73..507579b 100644 --- a/src/commands/generate/component/page/page.test.ts +++ b/src/commands/generate/component/page/page.test.ts @@ -1,6 +1,6 @@ import { filesystem } from 'gluegun'; -import { cli } from '@ngxd/cli-test-setup'; +import { runNgxdCLI } from '../../../../utils/cli-test-setup'; describe('[Commands: generate page component]', () => { const name = 'gpc'; @@ -16,7 +16,7 @@ describe('[Commands: generate page component]', () => { }); test('should generate a page component with 3 files', async () => { - await cli(`g c p ${name}`); + await runNgxdCLI(`g c p ${name}`); const html = filesystem.read(`${name}/${name}.page.html`); const scss = filesystem.read(`${name}/${name}.page.scss`); @@ -28,14 +28,14 @@ describe('[Commands: generate page component]', () => { }); test('should generate a page component html with default template

sample works

', async () => { - await cli(`g c p ${name}`); + await runNgxdCLI(`g c p ${name}`); const html = filesystem.read(`${name}/${name}.page.html`); expect(html).toContain(`

${name} works

`); }); test('should generate a page component with correct templateUrl: and styleUrls ', async () => { - await cli(`g c p ${name}`); + await runNgxdCLI(`g c p ${name}`); const ts = filesystem.read(`${name}/${name}.page.ts`); diff --git a/src/commands/generate/component/widget/widget.test.ts b/src/commands/generate/component/widget/widget.test.ts index 6d86f9a..75fb863 100644 --- a/src/commands/generate/component/widget/widget.test.ts +++ b/src/commands/generate/component/widget/widget.test.ts @@ -1,6 +1,6 @@ import { filesystem } from 'gluegun'; -import { cli } from '@ngxd/cli-test-setup'; +import { runNgxdCLI } from '../../../../utils/cli-test-setup'; describe('[Commands: generate widget component]', () => { const name = 'gwc'; @@ -17,7 +17,7 @@ describe('[Commands: generate widget component]', () => { test('should generate a widget component on provided path', async () => { const path = 'sample-project/components'; - await cli(`g c w ${name} --path=${path}`); + await runNgxdCLI(`g c w ${name} --path=${path}`); const html = filesystem.read(`${path}/${name}/${name}.component.html`); const scss = filesystem.read(`${path}/${name}/${name}.component.scss`); @@ -33,7 +33,7 @@ describe('[Commands: generate widget component]', () => { }); test('should generate widget component with 4 files', async () => { - await cli(`g c w ${name}`); + await runNgxdCLI(`g c w ${name}`); const html = filesystem.read(`${name}/${name}.component.html`); const scss = filesystem.read(`${name}/${name}.component.scss`); @@ -47,14 +47,14 @@ describe('[Commands: generate widget component]', () => { }); test('should generate widget component html with default template

sample works

', async () => { - await cli(`g c w ${name}`); + await runNgxdCLI(`g c w ${name}`); const html = filesystem.read(`${name}/${name}.component.html`); expect(html).toContain(`

${name} works

`); }); test('should generate a widget component with correct templateUrl: and styleUrls ', async () => { - await cli(`g c w ${name}`); + await runNgxdCLI(`g c w ${name}`); const ts = filesystem.read(`${name}/${name}.component.ts`); diff --git a/src/commands/generate/generate.ts b/src/commands/generate/generate.ts index c9ec8ca..e265f95 100644 --- a/src/commands/generate/generate.ts +++ b/src/commands/generate/generate.ts @@ -8,29 +8,22 @@ const COMMAND: GluegunCommand = { description: 'Cria uma nova entidade', alias: ['g'], run: async (toolbox: GluegunToolbox) => { - const { prompt } = toolbox + const { prompt } = toolbox; - const GENERATE_MODEL_TYPE_QUESTION = - 'Qual o tipo de entidade que vocΓͺ deseja criar?' + const GENERATE_MODEL_TYPE_QUESTION = 'Qual o tipo de entidade que vocΓͺ deseja criar?'; - const GENERATE_MODEL_TYPE_OPTIONS = [ - 'component', - 'directive', - 'guard', - 'interceptor', - 'module', - ] + const GENERATE_MODEL_TYPE_OPTIONS = ['component', 'directive', 'guard', 'interceptor', 'module']; const modelTypeResponse: GluegunAskResponse = await prompt.ask({ type: 'select', name: 'type', message: GENERATE_MODEL_TYPE_QUESTION, - choices: GENERATE_MODEL_TYPE_OPTIONS, - }) + choices: GENERATE_MODEL_TYPE_OPTIONS + }); - const command = findCommand(toolbox, modelTypeResponse.type) - command.run(toolbox) - }, -} + const command = findCommand(toolbox, modelTypeResponse.type); + command?.run(toolbox); + } +}; -module.exports = COMMAND +module.exports = COMMAND; diff --git a/src/commands/generate/service/api/api.test.ts b/src/commands/generate/service/api/api.test.ts new file mode 100644 index 0000000..aeefb6f --- /dev/null +++ b/src/commands/generate/service/api/api.test.ts @@ -0,0 +1,47 @@ +import { filesystem } from 'gluegun'; + +import { runNgxdCLI } from '../../../../utils/cli-test-setup'; + +describe('Commands: [Generate] => [Service] => [Api]', () => { + const name = 'gsc'; + + beforeEach(() => { + jest.useFakeTimers(); + jest.setTimeout(100000); + }); + + afterEach(() => { + jest.clearAllTimers(); + }); + + test('should generate a api service with 2 files', async () => { + await runNgxdCLI(`g s a ${name}`); + + const ts = filesystem.read(`${name}/${name}.api.ts`); + const spec = filesystem.read(`${name}/${name}.api.spec.ts`); + + expect(ts).toBeDefined(); + expect(spec).toBeDefined(); + filesystem.remove(`${name}`); + }); + + test('should generate a api service with correct content ', async () => { + const name = 'fruit'; + + await runNgxdCLI(`g s a ${name}`); + + const ts = filesystem.read(`${name}/${name}.api.ts`); + const spec = filesystem.read(`${name}/${name}.api.spec.ts`); + + expect(ts).toContain(`import { Injectable } from '@angular/core'`); + expect(ts).toContain(`@Injectable({`); + expect(ts).toContain(`providedIn: 'root'`); + expect(ts).toContain(`export class FruitApi {`); + + expect(spec).toContain("describe('FruitApi', () => {"); + expect(spec).toContain("it('should be created', () => {"); + expect(spec).toContain('service = TestBed.inject(FruitApi);'); + + filesystem.remove(`${name}`); + }); +}); diff --git a/src/commands/generate/service/api/api.ts b/src/commands/generate/service/api/api.ts new file mode 100644 index 0000000..7f422c7 --- /dev/null +++ b/src/commands/generate/service/api/api.ts @@ -0,0 +1,59 @@ +import { GluegunCommand, GluegunToolbox } from 'gluegun'; +import { GluegunAskResponse } from 'gluegun/build/types/toolbox/prompt-types'; + +import { printCreated } from '../../../../utils/functions.helper'; + +const COMMAND: GluegunCommand = { + name: 'api', + alias: ['a'], + description: 'cria um serviΓ§o Angular do tipo Api', + run: async (toolbox: GluegunToolbox) => { + const { parameters, print, prompt, template, strings } = toolbox; + + let serviceName = parameters.first; + + if (!serviceName) { + const response: GluegunAskResponse = await prompt.ask({ + type: 'input', + name: 'serviceName', + message: 'Qual o nome do serviΓ§o?', + validate: (value: string) => { + if (!value) { + return 'O nome do serviΓ§o nΓ£o pode ser vazio'; + } + + return true; + } + }); + + serviceName = response.serviceName; + } + + const serviceNameKebab = strings.kebabCase(serviceName); + + template.generate({ + template: 'service.template.ts.ejs', + target: `./${serviceNameKebab}/${serviceNameKebab}.api.ts`, + props: { + type: 'api', + name: serviceName, + ...strings + } + }); + + template.generate({ + template: 'service.template.spec.ts.ejs', + target: `./${serviceNameKebab}/${serviceNameKebab}.api.spec.ts`, + props: { + type: 'api', + name: serviceName, + ...strings + } + }); + + printCreated(print, `${serviceNameKebab}/${serviceNameKebab}.api.ts`); + printCreated(print, `${serviceNameKebab}/${serviceNameKebab}.api.spec.ts`); + } +}; + +module.exports = COMMAND; diff --git a/src/commands/generate/service/common/common.test.ts b/src/commands/generate/service/common/common.test.ts new file mode 100644 index 0000000..750dfc0 --- /dev/null +++ b/src/commands/generate/service/common/common.test.ts @@ -0,0 +1,47 @@ +import { filesystem } from 'gluegun'; + +import { runNgxdCLI } from '../../../../utils/cli-test-setup'; + +describe('Commands: [Generate] => [Service] => [Common]', () => { + const name = 'gsc'; + + beforeEach(() => { + jest.useFakeTimers(); + jest.setTimeout(100000); + }); + + afterEach(() => { + jest.clearAllTimers(); + }); + + test('should generate a common service with 2 files', async () => { + await runNgxdCLI(`g s c ${name}`); + + const ts = filesystem.read(`${name}/${name}.service.ts`); + const spec = filesystem.read(`${name}/${name}.service.spec.ts`); + + expect(ts).toBeDefined(); + expect(spec).toBeDefined(); + filesystem.remove(`${name}`); + }); + + test('should generate a common service with correct content ', async () => { + const name = 'fruit'; + + await runNgxdCLI(`g s c ${name}`); + + const ts = filesystem.read(`${name}/${name}.service.ts`); + const spec = filesystem.read(`${name}/${name}.service.spec.ts`); + + expect(ts).toContain(`import { Injectable } from '@angular/core'`); + expect(ts).toContain(`@Injectable({`); + expect(ts).toContain(`providedIn: 'root'`); + expect(ts).toContain(`export class FruitService {`); + + expect(spec).toContain("describe('FruitService', () => {"); + expect(spec).toContain("it('should be created', () => {"); + expect(spec).toContain('service = TestBed.inject(FruitService);'); + + filesystem.remove(`${name}`); + }); +}); diff --git a/src/commands/generate/service/common/common.ts b/src/commands/generate/service/common/common.ts new file mode 100644 index 0000000..6957eb8 --- /dev/null +++ b/src/commands/generate/service/common/common.ts @@ -0,0 +1,59 @@ +import { GluegunCommand, GluegunToolbox } from 'gluegun'; +import { GluegunAskResponse } from 'gluegun/build/types/toolbox/prompt-types'; + +import { printCreated } from '../../../../utils/functions.helper'; + +const COMMAND: GluegunCommand = { + name: 'common', + alias: ['c'], + description: 'cria um serviΓ§o Angular', + run: async (toolbox: GluegunToolbox) => { + const { parameters, print, prompt, template, strings } = toolbox; + + let serviceName = parameters.first; + + if (!serviceName) { + const response: GluegunAskResponse = await prompt.ask({ + type: 'input', + name: 'serviceName', + message: 'Qual o nome do serviΓ§o?', + validate: (value: string) => { + if (!value) { + return 'O nome do serviΓ§o nΓ£o pode ser vazio'; + } + + return true; + } + }); + + serviceName = response.serviceName; + } + + const serviceNameKebab = strings.kebabCase(serviceName); + + template.generate({ + template: 'service.template.ts.ejs', + target: `./${serviceNameKebab}/${serviceNameKebab}.service.ts`, + props: { + type: 'service', + name: serviceName, + ...strings + } + }); + + template.generate({ + template: 'service.template.spec.ts.ejs', + target: `./${serviceNameKebab}/${serviceNameKebab}.service.spec.ts`, + props: { + type: 'service', + name: serviceName, + ...strings + } + }); + + printCreated(print, `${serviceNameKebab}/${serviceNameKebab}.service.ts`); + printCreated(print, `${serviceNameKebab}/${serviceNameKebab}.service.spec.ts`); + } +}; + +module.exports = COMMAND; diff --git a/src/commands/generate/service/service.ts b/src/commands/generate/service/service.ts new file mode 100644 index 0000000..5ce204f --- /dev/null +++ b/src/commands/generate/service/service.ts @@ -0,0 +1,34 @@ +import { GluegunCommand, GluegunToolbox } from 'gluegun'; +import { GluegunAskResponse } from 'gluegun/build/types/toolbox/prompt-types'; + +import { findCommand } from '../../../utils/functions.helper'; + +const COMMAND: GluegunCommand = { + name: 'service', + alias: ['s'], + description: 'Cria um serviΓ§o Angular', + + run: async (toolbox: GluegunToolbox) => { + const { parameters, prompt } = toolbox; + + const componentName = parameters.first; + + const QUESTION = 'Qual tipo de serviΓ§o vocΓͺ deseja criar?'; + const TYPES = ['common', 'api']; + + const componentTypeResponse: GluegunAskResponse = await prompt.ask({ + type: 'select', + name: 'type', + message: QUESTION, + choices: TYPES + }); + + const componentType = componentTypeResponse.type; + const command = findCommand(toolbox, componentType); + + toolbox.parameters.first = componentName; + command?.run(toolbox); + } +}; + +module.exports = COMMAND; diff --git a/src/commands/ngx-devs-cli.ts b/src/commands/ngx-devs-cli.ts index 5e56e71..447d7af 100644 --- a/src/commands/ngx-devs-cli.ts +++ b/src/commands/ngx-devs-cli.ts @@ -1,5 +1,6 @@ import { GluegunCommand } from 'gluegun'; +import * as packageJson from '../../package.json'; import { ASCII_ART } from '../utils/cli-ascii.const'; import { printVersion } from '../utils/functions.helper'; @@ -9,7 +10,7 @@ const COMMAND: GluegunCommand = { description: 'Inicializa a CLI do NgxDevs', run: async (toolbox) => { const { print } = toolbox; - const version = require('../../package.json').version; + const version = packageJson.version; print.info(ASCII_ART); printVersion(print, version); diff --git a/src/commands/version.ts b/src/commands/version.ts index 4140577..c6a1e6d 100644 --- a/src/commands/version.ts +++ b/src/commands/version.ts @@ -1,6 +1,6 @@ import { GluegunCommand, GluegunToolbox } from 'gluegun'; -import { PackageJSON } from 'gluegun/build/types/toolbox/meta-types'; +import * as packageJson from '../../package.json'; import { printVersion } from '../utils/functions.helper'; const COMMAND: GluegunCommand = { @@ -8,7 +8,6 @@ const COMMAND: GluegunCommand = { alias: ['v', '-v', '--version', '-version'], description: 'Mostra a versΓ£o do NgxDevs', run: async ({ print }: GluegunToolbox) => { - const packageJson: PackageJSON = require('../../package.json'); const version = packageJson?.version; printVersion(print, version); } diff --git a/src/templates/service.template.spec.ts.ejs b/src/templates/service.template.spec.ts.ejs new file mode 100644 index 0000000..96c314c --- /dev/null +++ b/src/templates/service.template.spec.ts.ejs @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { <%= pascalCase(props.name) %><%= pascalCase(props.type) %> } from './<%= kebabCase(props.name) %>.<%= kebabCase(props.type) %>'; + +describe('<%= pascalCase(props.name) %><%= pascalCase(props.type) %>', () => { + let service: <%= pascalCase(props.name) %><%= pascalCase(props.type) %>; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(<%= pascalCase(props.name) %><%= pascalCase(props.type) %>); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/templates/service.template.ts.ejs b/src/templates/service.template.ts.ejs new file mode 100644 index 0000000..181cfe9 --- /dev/null +++ b/src/templates/service.template.ts.ejs @@ -0,0 +1,6 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class <%= pascalCase(props.name) %><%= pascalCase(props.type) %> {} \ No newline at end of file diff --git a/src/utils/cli-ascii.const.ts b/src/utils/cli-ascii.const.ts index 16bda63..2bf2c17 100644 --- a/src/utils/cli-ascii.const.ts +++ b/src/utils/cli-ascii.const.ts @@ -4,4 +4,4 @@ export const ASCII_ART = ` β–ˆβ–ˆβ•”β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•—β–‘β–‘β•šβ–ˆβ–ˆβ–ˆβ•”β•β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β•šβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β€ƒβ€ƒβ–ˆβ–ˆβ•‘β–‘β–‘β•šβ•β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β•šβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ•—β–‘β•šβ•β•β•β•β•β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β–‘β–‘β–‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–‘β–‘β•šβ•β•β•β–ˆβ–ˆβ•—β€ƒβ€ƒβ–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–‘β•šβ–ˆβ–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β•šβ–ˆβ–ˆβ•”β•β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β€ƒβ€ƒβ•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ -β•šβ•β•β–‘β–‘β•šβ•β•β•β–‘β•šβ•β•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β–‘β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β–‘β–‘β•šβ•β•β–‘β–‘β–‘β•šβ•β•β•β•β•β•β–‘β€ƒβ€ƒβ–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β•šβ•β•` +β•šβ•β•β–‘β–‘β•šβ•β•β•β–‘β•šβ•β•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β–‘β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β–‘β–‘β•šβ•β•β–‘β–‘β–‘β•šβ•β•β•β•β•β•β–‘β€ƒβ€ƒβ–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β•šβ•β•`; diff --git a/src/utils/cli-test-setup.ts b/src/utils/cli-test-setup.ts new file mode 100644 index 0000000..c215480 --- /dev/null +++ b/src/utils/cli-test-setup.ts @@ -0,0 +1,7 @@ +import { filesystem, system } from 'gluegun'; + +const src = filesystem.path(__dirname, '..', '..'); + +export async function runNgxdCLI(cmd: string): Promise { + return system.run('node ' + filesystem.path(src, 'bin', 'ngx-devs-cli') + ` ${cmd}`); +} diff --git a/src/utils/functions.helper.ts b/src/utils/functions.helper.ts index 59de434..5b3cbf2 100644 --- a/src/utils/functions.helper.ts +++ b/src/utils/functions.helper.ts @@ -2,21 +2,21 @@ import { GluegunPrint, GluegunToolbox, strings } from 'gluegun'; import { Command } from 'gluegun/build/types/domain/command'; import { GluegunAskResponse, GluegunPrompt } from 'gluegun/build/types/toolbox/prompt-types'; -export function findCommand(toolbox: GluegunToolbox, commandName: string): Command { - return toolbox.runtime.commands.find((command) => command.name === commandName); +export function findCommand(toolbox: GluegunToolbox, commandName: string): Command | undefined { + return toolbox.runtime?.commands?.find((command) => command.name === commandName); } -export function printCreated(print: GluegunPrint, message: string) { +export function printCreated(print: GluegunPrint, message: string): void { const text = print.colors.green('CREATED') + ' ' + print.colors.yellow(message); print.info(text); } -export function printVersion(print: GluegunPrint, version: string) { +export function printVersion(print: GluegunPrint, version: string): void { const text = print.colors.green('version: ') + print.colors.yellow(version); print.info(text); } -export async function getComponentName(prompt: GluegunPrompt) { +export async function getComponentName(prompt: GluegunPrompt): Promise { const response: GluegunAskResponse = await prompt.ask({ type: 'input', name: 'componentName', @@ -33,6 +33,6 @@ export async function getComponentName(prompt: GluegunPrompt) { return strings.kebabCase(response.componentName); } -export function getComponentPath(path: any, componentName: string) { +export function getComponentPath(path: any, componentName: string): string { return path ? `${path}/${componentName}/${componentName}` : `./${componentName}/${componentName}`; } diff --git a/tsconfig.json b/tsconfig.json index 7b7738d..a9f81d1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,18 +6,14 @@ "module": "commonjs", "moduleResolution": "node", "noImplicitAny": false, + "resolveJsonModule": true, "noImplicitThis": true, "noUnusedLocals": true, "sourceMap": false, "outDir": "build", "strict": false, - "target": "es5", - "declaration": true, - "declarationDir": "build/types", - "paths": { - "@ngxd/cli-test-setup": ["./cli-test-setup"] - } + "target": "es5" }, "include": ["src/**/*"], - "exclude": ["node_modules", "src/templates/**", "cli-test-setup.ts", "**/*.test.ts"] + "exclude": ["node_modules", "src/templates/**", "src/utils/cli-test-setup.ts", "**/*.test.ts"] }