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/.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/CHANGELOG.md b/CHANGELOG.md index 5f56228..82dca0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,5 @@ # Changelog - -## next - -### Changed - -- πŸ”§ ci: fix global install script [[c549323](https://github.com/ngx-devs/ngx-devs-cli/commit/c5493238feb4f9138538632e6189cbdc7d8a80ce)] -- πŸ”§ ci: install changelog globally [[b57ca29](https://github.com/ngx-devs/ngx-devs-cli/commit/b57ca298fc97b37ddd018b31ae585c6e2c8df4c3)] -- πŸ”§ ci: update changelog script [[33993dd](https://github.com/ngx-devs/ngx-devs-cli/commit/33993dd500ed44f60f45836231f86ac58780458a)] - -### Miscellaneous - -- 🚧 chore: remove other changelog plugins [[0719447](https://github.com/ngx-devs/ngx-devs-cli/commit/0719447e49ba7ca83d66933052a3bd017d93ddb0)] -- 🚧 chore: change releaserc from js to json [[6909cd3](https://github.com/ngx-devs/ngx-devs-cli/commit/6909cd3f53a438016bd1db4036f5111731dee124)] - - ## 1.9.0 (2022-05-28) 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/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"] }