Skip to content

Commit f22a392

Browse files
Broccohansl
authored andcommitted
feat(@schematics/angular): Add enum schematic
1 parent 016cca7 commit f22a392

4 files changed

Lines changed: 65 additions & 0 deletions

File tree

packages/schematics/angular/collection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"factory": "./component",
1515
"description": "Create an Angular component.",
1616
"schema": "./component/schema.json"
17+
},
18+
"enum": {
19+
"factory": "./enum",
20+
"description": "Create an enumeration.",
21+
"schema": "./enum/schema.json"
1722
}
1823
}
1924
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export class <%= classify(name) %> {
2+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
9+
import {
10+
Rule,
11+
apply,
12+
branchAndMerge,
13+
chain,
14+
mergeWith,
15+
move,
16+
template,
17+
url
18+
} from '@angular-devkit/schematics';
19+
import * as stringUtils from '../strings';
20+
21+
22+
export default function (options: any): Rule {
23+
const templateSource = apply(url('./files'), [
24+
template({
25+
...stringUtils,
26+
...options
27+
}),
28+
move(options.sourceDir)
29+
]);
30+
31+
return chain([
32+
branchAndMerge(chain([
33+
mergeWith(templateSource)
34+
]))
35+
]);
36+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "SchematicsAngularEnum",
4+
"title": "Angular Enum 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+
},
19+
"required": [
20+
"name"
21+
]
22+
}

0 commit comments

Comments
 (0)