├── test └── .gitkeep ├── schematics ├── demo │ ├── files │ │ └── .gitkeep │ ├── schema.ts │ ├── index.spec.ts │ ├── index.ts │ └── schema.json ├── nest-add │ ├── files │ │ └── .gitkeep │ ├── index.spec.ts │ ├── schema.ts │ ├── schema.json │ └── index.ts └── collection.json ├── src ├── index.ts ├── public_api.ts └── module │ ├── index.ts │ ├── config.ts │ ├── library-name.service.ts │ └── library-name.module.ts ├── docs └── articles │ ├── extra-file.md │ ├── extra-section │ └── extra-file.md │ └── summary.json ├── .prettierrc ├── .commitlintrc.js ├── .gitignore ├── .compodocrc.json ├── jest.config.js ├── CONTRIBUTING.md ├── tsconfig.json ├── .releaserc.json ├── .eslintrc.json ├── .github └── workflows │ ├── build.yml │ └── release.yml ├── tools ├── emoji-replacer.js ├── package.sh └── setup.js ├── tsconfig.schematics.json ├── LICENSE ├── package.json ├── README.md └── CHANGELOG.md /test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /schematics/demo/files/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /schematics/nest-add/files/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './public_api'; 2 | -------------------------------------------------------------------------------- /src/public_api.ts: -------------------------------------------------------------------------------- 1 | export * from './module'; 2 | -------------------------------------------------------------------------------- /docs/articles/extra-file.md: -------------------------------------------------------------------------------- 1 | # Extra doc file 2 | Bla bla bla. 3 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } 5 | -------------------------------------------------------------------------------- /schematics/demo/schema.ts: -------------------------------------------------------------------------------- 1 | export interface DemoOptions { 2 | catType: string; 3 | } 4 | -------------------------------------------------------------------------------- /.commitlintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-conventional'] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.log 3 | 4 | node_modules/ 5 | dist/ 6 | docs/dist/ 7 | coverage/ 8 | -------------------------------------------------------------------------------- /docs/articles/extra-section/extra-file.md: -------------------------------------------------------------------------------- 1 | # Extra doc file for `Extra section` 2 | Bla bla bla. 3 | -------------------------------------------------------------------------------- /schematics/demo/index.spec.ts: -------------------------------------------------------------------------------- 1 | describe('demo Test Case', () => { 2 | 3 | it('should ...', () => { 4 | expect(true).toBeTruthy(); 5 | }) 6 | 7 | }) 8 | -------------------------------------------------------------------------------- /.compodocrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@compodoc/compodoc/src/config/schema.json", 3 | "output": "docs/dist", 4 | "includes": "docs/articles" 5 | } 6 | -------------------------------------------------------------------------------- /schematics/nest-add/index.spec.ts: -------------------------------------------------------------------------------- 1 | describe('nest-add Test Case', () => { 2 | 3 | it('should ...', () => { 4 | expect(true).toBeTruthy(); 5 | }) 6 | 7 | }) 8 | -------------------------------------------------------------------------------- /src/module/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | MODULE_CONFIG, LibraryNameConfig, 3 | } from './config' 4 | 5 | export { LibraryNameModule } from './library-name.module'; 6 | export { LibraryNameService } from './library-name.service'; 7 | -------------------------------------------------------------------------------- /docs/articles/summary.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "title": "Extra file", 4 | "file": "extra-file.md" 5 | }, 6 | { 7 | "title": "Extra section", 8 | "file": "extra-file.md", 9 | "children": [ 10 | { 11 | "title": "Extra file", 12 | "file": "extra-section/extra-file.md" 13 | } 14 | ] 15 | } 16 | ] 17 | -------------------------------------------------------------------------------- /schematics/nest-add/schema.ts: -------------------------------------------------------------------------------- 1 | import { Path } from '@angular-devkit/core'; 2 | 3 | export interface NestAddOptions { 4 | name: string; 5 | module: Path; 6 | path: Path; 7 | sourceRoot?: string; 8 | language: string; 9 | metadata: string; 10 | staticOptions: { 11 | name: string; 12 | value: Record; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /schematics/demo/index.ts: -------------------------------------------------------------------------------- 1 | import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; 2 | import { DemoOptions } from './schema'; 3 | 4 | export function demoSchematic(_options: DemoOptions): Rule { 5 | return (tree: Tree, _context: SchematicContext) => { 6 | console.warn(`${_options.catType} cat says: 😻 Meow!`); 7 | return tree; 8 | }; 9 | } 10 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | // For a detailed explanation regarding each configuration property, visit: 2 | // https://jestjs.io/docs/en/configuration.html 3 | 4 | module.exports = { 5 | preset: 'ts-jest', 6 | testEnvironment: 'node', 7 | collectCoverage: true, 8 | moduleFileExtensions: ['ts', 'js'], 9 | collectCoverageFrom: [ 10 | "schematics/**", 11 | "src/**", 12 | ] 13 | }; 14 | -------------------------------------------------------------------------------- /schematics/demo/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/schema", 3 | "id": "SchematicsDemo", 4 | "title": "Demo Schema", 5 | "type": "object", 6 | "properties": { 7 | "catType": { 8 | "type": "string", 9 | "minLength": 1, 10 | "$default": { 11 | "$source": "argv", 12 | "index": 0 13 | }, 14 | "x-prompt": "What type of cat do you want?" 15 | } 16 | }, 17 | "required": [ 18 | "catType" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /schematics/collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json", 3 | "schematics": { 4 | "nest-add": { 5 | "description": "A blank schematic.", 6 | "factory": "./nest-add/index#nestAdd", 7 | "schema": "./nest-add/schema.json" 8 | }, 9 | "demo": { 10 | "description": "A demo schematic.", 11 | "factory": "./demo/index#demoSchematic", 12 | "schema": "./demo/schema.json" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/module/config.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Injector Token for Module configuration 3 | */ 4 | export const MODULE_CONFIG = Symbol('MODULE_CONFIG'); 5 | 6 | /** 7 | * Defines the available options to configure the Module 8 | */ 9 | export interface LibraryNameConfig { 10 | /** 11 | * An awesome & powerful value 12 | */ 13 | value: string; 14 | } 15 | 16 | /** 17 | * Default Module configuration if is not provided 18 | */ 19 | export const DEFAULT_MODULE_CONFIG: LibraryNameConfig = { 20 | value: '' 21 | }; 22 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # :package: :rocket: [Semantic Releasing](https://semantic-release.gitbook.io/semantic-release/) 4 | 5 | This repository works with Semantic Releasing & Semantic Versioning. 6 | 7 | # :notebook: [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) 8 | 9 | Your commits should match with Conventional Commits standard. 10 | 11 | ## Allowed scopes: 12 | 13 | | Scope | Description | 14 | | --- | --- | 15 | | <__scope__> | Description of <__scope__> | 16 | | ... | ... | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "noImplicitAny": false, 6 | "removeComments": true, 7 | "noLib": false, 8 | "allowSyntheticDefaultImports": true, 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "target": "es2017", 12 | "sourceMap": true, 13 | "allowJs": true, 14 | "outDir": "dist", 15 | "baseUrl": "src", 16 | }, 17 | "include": [ 18 | "src/**/*" 19 | ], 20 | "exclude": [ 21 | "node_modules", 22 | "**/*.spec.ts" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /.releaserc.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "@semantic-release/commit-analyzer", 4 | "@semantic-release/release-notes-generator", 5 | [ 6 | "@semantic-release/changelog", 7 | { 8 | "changelogFile": "CHANGELOG.md" 9 | } 10 | ], 11 | [ 12 | "@semantic-release/npm", 13 | { 14 | "pkgRoot": "dist" 15 | } 16 | ], 17 | [ 18 | "@semantic-release/git", 19 | { 20 | "assets": [ 21 | "CHANGELOG.md", 22 | "package.json", 23 | "package-lock.json" 24 | ] 25 | } 26 | ] 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es6": true, 5 | "node": true 6 | }, 7 | "extends": [ 8 | "eslint:recommended", 9 | "plugin:@typescript-eslint/eslint-recommended" 10 | ], 11 | "globals": { 12 | "Atomics": "readonly", 13 | "SharedArrayBuffer": "readonly" 14 | }, 15 | "parser": "@typescript-eslint/parser", 16 | "parserOptions": { 17 | "ecmaVersion": 2018, 18 | "sourceType": "module" 19 | }, 20 | "plugins": [ 21 | "@typescript-eslint" 22 | ], 23 | "rules": { 24 | "indent": ["error", 2], 25 | "@typescript-eslint/no-unused-vars": [2, {"args": "none"} ] 26 | } 27 | } -------------------------------------------------------------------------------- /src/module/library-name.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Inject } from '@nestjs/common'; 2 | import { MODULE_CONFIG, LibraryNameConfig } from './config'; 3 | 4 | /** 5 | * Useful service 6 | */ 7 | @Injectable() 8 | export class LibraryNameService { 9 | 10 | /** 11 | * Creates a new `LibraryNameService` 12 | * @param config Provided configuration 13 | */ 14 | constructor( 15 | @Inject(MODULE_CONFIG) private config: LibraryNameConfig 16 | ) {} 17 | 18 | /** 19 | * Prints configuration 20 | */ 21 | public printConfig(): void { 22 | console.warn(`Provided configuration:\n ${JSON.stringify(this.config)}`); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build Library and Schematics 2 | 3 | on: 4 | push: 5 | branches: 6 | master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | build: 13 | 14 | runs-on: ubuntu-latest 15 | 16 | strategy: 17 | matrix: 18 | node-version: [8.x, 10.x, 12.x] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Use Node.js ${{ matrix.node-version }} 23 | uses: actions/setup-node@v1 24 | with: 25 | node-version: ${{ matrix.node-version }} 26 | - run: npm install 27 | - run: npm run build --if-present 28 | - run: npm test 29 | env: 30 | CI: true 31 | -------------------------------------------------------------------------------- /tools/emoji-replacer.js: -------------------------------------------------------------------------------- 1 | const replace = require('replace-in-file'); 2 | const emoji = require('node-emoji'); 3 | 4 | let latestFile = 'docs/dist'; 5 | 6 | const options = { 7 | files: 'docs/dist/*', 8 | from: /:[a-z0-9]+:/g, 9 | to: (...args) => { 10 | if (!(args[3] == latestFile)) { 11 | console.log(`\n🔃 🔎 Replacements found over ${args[3]}\n`); 12 | } 13 | latestFile = args[3]; 14 | const emojiReplacement = emoji.get(args[0]); 15 | console.log(`${args[0]} => ${emojiReplacement}`); 16 | return emojiReplacement; 17 | } 18 | }; 19 | 20 | try { 21 | replace.sync(options); 22 | } catch (error) { 23 | console.error('Error occurred:', error); 24 | } 25 | -------------------------------------------------------------------------------- /schematics/nest-add/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/schema", 3 | "id": "SchematicsAdd", 4 | "title": "Add Schema", 5 | "type": "object", 6 | "properties": { 7 | "path": { 8 | "type": "string", 9 | "format": "path", 10 | "description": "The path to create the controller." 11 | }, 12 | "sourceRoot": { 13 | "type": "string", 14 | "description": "Nest controller source root directory." 15 | }, 16 | "module": { 17 | "type": "string", 18 | "description": "Allows specification of the declaring module." 19 | }, 20 | "staticOptions": { 21 | "type": "string", 22 | "description": "Foo" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/module/library-name.module.ts: -------------------------------------------------------------------------------- 1 | import { Module, DynamicModule } from '@nestjs/common'; 2 | import { LibraryNameConfig, MODULE_CONFIG, DEFAULT_MODULE_CONFIG } from './config'; 3 | import { LibraryNameService } from './library-name.service'; 4 | 5 | /** 6 | * LibraryName description 7 | */ 8 | @Module({}) 9 | export class LibraryNameModule { 10 | 11 | /** 12 | * Register the module 13 | * @param config configuration for module 14 | */ 15 | static register(config: LibraryNameConfig): DynamicModule { 16 | return { 17 | module: LibraryNameModule, 18 | providers: [ 19 | { 20 | provide: MODULE_CONFIG, 21 | useValue: config || DEFAULT_MODULE_CONFIG 22 | }, 23 | LibraryNameService 24 | ], 25 | exports: [ 26 | LibraryNameService 27 | ] 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /tsconfig.schematics.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "lib": [ 5 | "es2018", 6 | "dom" 7 | ], 8 | "declaration": true, 9 | "module": "commonjs", 10 | "moduleResolution": "node", 11 | "noEmitOnError": true, 12 | "noFallthroughCasesInSwitch": true, 13 | "noImplicitAny": true, 14 | "noImplicitThis": true, 15 | "noUnusedParameters": true, 16 | "noUnusedLocals": true, 17 | "rootDir": "schematics", 18 | "outDir": "dist/schematics", 19 | "skipDefaultLibCheck": true, 20 | "skipLibCheck": true, 21 | "sourceMap": true, 22 | "strictNullChecks": false, 23 | "target": "es6", 24 | "types": [ 25 | "node" 26 | ] 27 | }, 28 | "include": [ 29 | "schematics/**/*", 30 | ], 31 | "exclude": [ 32 | "node_modules", 33 | "schematics/*/files/**/*", 34 | "**/*.spec.ts" 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /tools/package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Generate package 4 | 5 | echo '📦 Packaging the Schematics...' 6 | 7 | # Copy Schema 8 | cp schematics/collection.json dist/schematics/collection.json 9 | echo '🔹 schema copied ✅' 10 | 11 | # Copy Schemas 12 | for file in schematics/*/schema.json; do 13 | cp ${file} dist/${file} 14 | done 15 | echo '🔹 schemas copied ✅' 16 | 17 | # Copy Schematic 18 | for dir in schematics/*/; do 19 | cp -r ${dir}files dist/${dir} 20 | done 21 | echo '🔹