Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 5ec1d98

Browse files
jschwartyBrocco
authored andcommitted
feat(@schematics/angular): Add interface schematic
1 parent b94ccc5 commit 5ec1d98

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

packages/schematics/angular/collection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"description": "Create an enumeration.",
2121
"schema": "./enum/schema.json"
2222
},
23+
"interface": {
24+
"factory": "./interface",
25+
"description": "Create an interface.",
26+
"schema": "./interface/schema.json"
27+
},
2328
"module": {
2429
"factory": "./module",
2530
"description": "Create an Angular module.",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export interface <%= prefix %><%= classify(name) %> {
2+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
// TODO: replace `options: any` with an actual type generated from the schema.
9+
// tslint:disable:no-any
10+
import {
11+
Rule,
12+
apply,
13+
branchAndMerge,
14+
chain,
15+
mergeWith,
16+
move,
17+
template,
18+
url,
19+
} from '@angular-devkit/schematics';
20+
import * as stringUtils from '../strings';
21+
22+
23+
export default function (options: any): Rule {
24+
options.prefix = options.prefix ? options.prefix : '';
25+
options.type = !!options.type ? `.${options.type}` : '';
26+
27+
const templateSource = apply(url('./files'), [
28+
template({
29+
...stringUtils,
30+
...options,
31+
}),
32+
move(options.sourceDir),
33+
]);
34+
35+
return chain([
36+
branchAndMerge(chain([
37+
mergeWith(templateSource),
38+
])),
39+
]);
40+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "SchematicsAngularInterface",
4+
"title": "Angular Interface Options Schema",
5+
"type": "object",
6+
"properties": {
7+
"name": {
8+
"type": "string"
9+
},
10+
"path": {
11+
"type": "string",
12+
"default": "app"
13+
},
14+
"sourceDir": {
15+
"type": "string",
16+
"default": "src"
17+
},
18+
"prefix": {
19+
"type": "string",
20+
"default": "",
21+
"description": "Specifies the prefix to use."
22+
},
23+
"type": {
24+
"type": "string",
25+
"description": "Specifies the type of interface.",
26+
"default": ""
27+
}
28+
},
29+
"required": [
30+
"name"
31+
]
32+
}

0 commit comments

Comments
 (0)