-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
configuration.ts
97 lines (85 loc) · 2.49 KB
/
configuration.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import {
convertNxGenerator,
formatFiles,
GeneratorCallback,
logger,
readProjectConfiguration,
Tree,
} from '@nrwl/devkit';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
import { cypressProjectGenerator } from '../cypress-project/cypress-project';
import { StorybookConfigureSchema } from './schema';
import { initGenerator } from '../init/init';
import {
addAngularStorybookTask,
addStorybookTask,
configureTsProjectConfig,
configureTsSolutionConfig,
createProjectStorybookDir,
createRootStorybookDir,
updateLintConfig,
} from './util-functions';
import { Linter } from '@nrwl/linter';
import { findStorybookAndBuildTargets } from '../../utils/utilities';
export async function configurationGenerator(
tree: Tree,
rawSchema: StorybookConfigureSchema
) {
const schema = normalizeSchema(rawSchema);
const tasks: GeneratorCallback[] = [];
const { projectType, targets } = readProjectConfiguration(tree, schema.name);
const { buildTarget } = findStorybookAndBuildTargets(targets);
const initTask = await initGenerator(tree, {
uiFramework: schema.uiFramework,
});
tasks.push(initTask);
createRootStorybookDir(tree, schema.js, schema.tsConfiguration);
createProjectStorybookDir(
tree,
schema.name,
schema.uiFramework,
schema.js,
schema.tsConfiguration
);
configureTsProjectConfig(tree, schema);
configureTsSolutionConfig(tree, schema);
updateLintConfig(tree, schema);
if (schema.uiFramework === '@storybook/angular') {
addAngularStorybookTask(tree, schema.name, buildTarget);
} else {
addStorybookTask(tree, schema.name, schema.uiFramework);
}
if (schema.configureCypress) {
if (projectType !== 'application') {
const cypressTask = await cypressProjectGenerator(tree, {
name: schema.name,
js: schema.js,
linter: schema.linter,
directory: schema.cypressDirectory,
standaloneConfig: schema.standaloneConfig,
});
tasks.push(cypressTask);
} else {
logger.warn('There is already an e2e project setup');
}
}
await formatFiles(tree);
return runTasksInSerial(...tasks);
}
function normalizeSchema(
schema: StorybookConfigureSchema
): StorybookConfigureSchema {
const defaults = {
configureCypress: true,
linter: Linter.TsLint,
js: false,
};
return {
...defaults,
...schema,
};
}
export default configurationGenerator;
export const configurationSchematic = convertNxGenerator(
configurationGenerator
);