-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
component.ts
45 lines (38 loc) · 1.38 KB
/
component.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
42
43
44
45
import { addStyleDependencies } from '../../utils/styles';
import type { SupportedStyles } from '@nrwl/react';
import { componentGenerator as reactComponentGenerator } from '@nrwl/react';
import { convertNxGenerator, getProjects, Tree } from '@nrwl/devkit';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
interface Schema {
name: string;
project: string;
style: SupportedStyles;
directory?: string;
flat?: boolean;
}
function getDirectory(host: Tree, options: Schema) {
const workspace = getProjects(host);
const projectType = workspace.get(options.project).projectType;
return options.directory
? options.directory
: projectType === 'application'
? 'components'
: undefined;
}
/*
* This schematic is basically the React one, but for Next we need
* extra dependencies for css, sass, less, styl style options.
*/
export async function componentGenerator(host: Tree, options: Schema) {
const componentInstall = await reactComponentGenerator(host, {
...options,
directory: getDirectory(host, options),
pascalCaseFiles: false,
classComponent: false,
routing: false,
});
const styledInstall = addStyleDependencies(host, options.style);
return runTasksInSerial(styledInstall, componentInstall);
}
export default componentGenerator;
export const componentSchematic = convertNxGenerator(componentGenerator);