diff --git a/package-lock.json b/package-lock.json index c7cf885..716854d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@angular-devkit/core": "^13.1.2", "@angular-devkit/schematics": "^13.1.2", + "@schematics/angular": "^13.1.2", "typescript": "~4.5.2" }, "devDependencies": { @@ -2081,6 +2082,21 @@ "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" } }, + "node_modules/@schematics/angular": { + "version": "13.1.2", + "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-13.1.2.tgz", + "integrity": "sha512-OMbuOsnzUFjIGeo99NYwIPwjX6udJAiT5Sj5K7QZZYj66HuAqNBMV57J8GPA56edx5mOHZZApWMjXLlOxRXbJA==", + "dependencies": { + "@angular-devkit/core": "13.1.2", + "@angular-devkit/schematics": "13.1.2", + "jsonc-parser": "3.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.15.0 || >=16.10.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + } + }, "node_modules/@sinonjs/commons": { "version": "1.8.3", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz", @@ -7257,6 +7273,16 @@ "chalk": "^4.0.0" } }, + "@schematics/angular": { + "version": "13.1.2", + "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-13.1.2.tgz", + "integrity": "sha512-OMbuOsnzUFjIGeo99NYwIPwjX6udJAiT5Sj5K7QZZYj66HuAqNBMV57J8GPA56edx5mOHZZApWMjXLlOxRXbJA==", + "requires": { + "@angular-devkit/core": "13.1.2", + "@angular-devkit/schematics": "13.1.2", + "jsonc-parser": "3.0.0" + } + }, "@sinonjs/commons": { "version": "1.8.3", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz", diff --git a/package.json b/package.json index 6e01a8c..9daa81e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "A blank schematics", "scripts": { "build": "tsc -p tsconfig.json", - "test": "jest" + "test": "jest", + "localtest:component": "schematics .:component" }, "keywords": [ "schematics" @@ -15,6 +16,7 @@ "dependencies": { "@angular-devkit/core": "^13.1.2", "@angular-devkit/schematics": "^13.1.2", + "@schematics/angular": "^13.1.2", "typescript": "~4.5.2" }, "devDependencies": { diff --git a/src/collection.json b/src/collection.json index ef65856..6e1cfb6 100644 --- a/src/collection.json +++ b/src/collection.json @@ -1,9 +1,14 @@ { "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json", "schematics": { - "custom-angular-schematics": { - "description": "A blank schematic.", - "factory": "./custom-angular-schematics/index#customAngularSchematics" + "component": { + "description": "A schematic for component generation", + "factory": "./component/index#component" + }, + "workspace": { + "description": "A schematic for workspace generation", + "factory": "./workspace/index#workspace" + } } } \ No newline at end of file diff --git a/src/component/index.ts b/src/component/index.ts new file mode 100644 index 0000000..c657167 --- /dev/null +++ b/src/component/index.ts @@ -0,0 +1,12 @@ +import {chain, externalSchematic, Rule, SchematicContext, Tree} from '@angular-devkit/schematics'; + + +// You don't have to export the function as default. You can also have more than one rule factory +// per file. +export function component(_options: any): Rule { + return (_tree: Tree, _context: SchematicContext) => { + return chain([ + externalSchematic('@schematics/angular', 'component', {}) + ]); + }; +} diff --git a/src/custom-angular-schematics/index_spec.ts b/src/component/index_spec.ts similarity index 78% rename from src/custom-angular-schematics/index_spec.ts rename to src/component/index_spec.ts index 1a5bc87..b9dafb2 100644 --- a/src/custom-angular-schematics/index_spec.ts +++ b/src/component/index_spec.ts @@ -4,11 +4,11 @@ import * as path from 'path'; const collectionPath = path.join(__dirname, '../collection.json'); -describe('custom-angular-schematics', () => { +describe('component', () => { it('works', async () => { const runner = new SchematicTestRunner('schematics', collectionPath); const tree = await runner - .runSchematicAsync('custom-angular-schematics', {}, Tree.empty()) + .runSchematicAsync('component', {}, Tree.empty()) .toPromise(); expect(tree.files).toEqual([]); diff --git a/src/custom-angular-schematics/index.ts b/src/custom-angular-schematics/index.ts deleted file mode 100644 index 27f69f6..0000000 --- a/src/custom-angular-schematics/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; - - -// You don't have to export the function as default. You can also have more than one rule factory -// per file. -export function customAngularSchematics(_options: any): Rule { - return (tree: Tree, _context: SchematicContext) => { - return tree; - }; -} diff --git a/src/workspace/index.ts b/src/workspace/index.ts new file mode 100644 index 0000000..ba4bb0d --- /dev/null +++ b/src/workspace/index.ts @@ -0,0 +1,12 @@ +import {chain, externalSchematic, Rule, SchematicContext, Tree} from '@angular-devkit/schematics'; + + +// You don't have to export the function as default. You can also have more than one rule factory +// per file. +export function workspace(_options: any): Rule { + return (_tree: Tree, _context: SchematicContext) => { + return chain([ + externalSchematic('@schematics/angular', 'ng-new', {version: '^13.0.0'}) + ]); + }; +} diff --git a/src/workspace/index_spec.ts b/src/workspace/index_spec.ts new file mode 100644 index 0000000..fb22db6 --- /dev/null +++ b/src/workspace/index_spec.ts @@ -0,0 +1,16 @@ +import { Tree } from '@angular-devkit/schematics'; +import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; +import * as path from 'path'; + +const collectionPath = path.join(__dirname, '../collection.json'); + +describe('workspace', () => { + it('works', async () => { + const runner = new SchematicTestRunner('schematics', collectionPath); + const tree = await runner + .runSchematicAsync('workspace', {}, Tree.empty()) + .toPromise(); + + expect(tree.files).toEqual([]); + }); +});