-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
fix-storybook-tsconfig.ts
63 lines (52 loc) · 1.52 KB
/
fix-storybook-tsconfig.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
import {
getProjects,
joinPathFragments,
logger,
readJson,
Tree,
writeJson,
formatFiles,
} from '@nrwl/devkit';
import { isFramework, TsConfig } from '../../utils/utilities';
export default async function updateStorybookTsconfig(tree: Tree) {
let changesMade = false;
const projects = getProjects(tree);
projects.forEach((projectConfig, projectName) => {
const targets = projectConfig.targets;
const paths = {
tsConfigStorybook: joinPathFragments(
projectConfig.root,
'.storybook/tsconfig.json'
),
};
const storybookExecutor = Object.keys(targets || {}).find(
(x) => targets[x].executor === '@nrwl/storybook:storybook'
);
const hasStorybookConfig =
storybookExecutor && tree.exists(paths.tsConfigStorybook);
if (!hasStorybookConfig) {
logger.info(
`${projectName}: no storybook configured. skipping migration...`
);
return;
}
const isReactProject = isFramework('react', {
uiFramework: targets[storybookExecutor]?.options
?.uiFramework as Parameters<typeof isFramework>[1]['uiFramework'],
});
if (isReactProject) {
const tsConfig = {
storybook: readJson<TsConfig>(tree, paths.tsConfigStorybook),
};
tsConfig.storybook.compilerOptions = {
...tsConfig.storybook.compilerOptions,
outDir: '',
};
writeJson(tree, paths.tsConfigStorybook, tsConfig.storybook);
changesMade = true;
}
});
if (changesMade) {
await formatFiles(tree);
}
}