-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathindex.ts
41 lines (37 loc) · 1.4 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { chain, externalSchematic } from '@angular-devkit/schematics';
/**
* We are able to use the full, unaltered Schema directly from @schematics/angular
* The applicable json file is copied from node_modules as a prebuiid step to ensure
* they stay in sync.
*/
import type { Schema as AngularSchema } from '@schematics/angular/library/schema';
import {
addESLintTargetToProject,
createESLintConfigForProject,
} from '../utils';
interface Schema extends AngularSchema {
setParserOptionsProject?: boolean;
}
function eslintRelatedChanges(options: Schema) {
return chain([
// Create the ESLint config file for the project
createESLintConfigForProject(
options.name,
options.setParserOptionsProject ?? false,
),
// Update the lint builder and config in angular.json
addESLintTargetToProject(options.name, 'lint'),
]);
}
export default function (options: Schema): Rule {
return (host: Tree, context: SchematicContext) => {
// Remove angular-eslint specific options before passing to the Angular schematic
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { setParserOptionsProject, ...angularOptions } = options;
return chain([
externalSchematic('@schematics/angular', 'library', angularOptions),
eslintRelatedChanges(options),
])(host, context);
};
}