Skip to content

Commit

Permalink
feat(schematics): wrap angular schematic for component and workspace …
Browse files Browse the repository at this point in the history
…generation
  • Loading branch information
GerritRiesch94 committed Dec 16, 2021
1 parent f4af481 commit 67cee3d
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 16 deletions.
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "A blank schematics",
"scripts": {
"build": "tsc -p tsconfig.json",
"test": "jest"
"test": "jest",
"localtest:component": "schematics .:component"
},
"keywords": [
"schematics"
Expand All @@ -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": {
Expand Down
11 changes: 8 additions & 3 deletions src/collection.json
Original file line number Diff line number Diff line change
@@ -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"

}
}
}
12 changes: 12 additions & 0 deletions src/component/index.ts
Original file line number Diff line number Diff line change
@@ -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', {})
]);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand Down
10 changes: 0 additions & 10 deletions src/custom-angular-schematics/index.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/workspace/index.ts
Original file line number Diff line number Diff line change
@@ -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'})
]);
};
}
16 changes: 16 additions & 0 deletions src/workspace/index_spec.ts
Original file line number Diff line number Diff line change
@@ -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([]);
});
});

0 comments on commit 67cee3d

Please sign in to comment.