1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.updateStorybookConfig = void 0;
|
4 | const devkit_1 = require("@nrwl/devkit");
|
5 | const path = require("path");
|
6 | const path_1 = require("path");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function updateStorybookConfig(tree, schema, project) {
|
15 | const oldRelativeRoot = path
|
16 | .relative(path.join(devkit_1.workspaceRoot, `${project.root}/.storybook`), devkit_1.workspaceRoot)
|
17 | .split(path.sep)
|
18 | .join('/');
|
19 | const newRelativeRoot = path
|
20 | .relative(path.join(devkit_1.workspaceRoot, `${schema.relativeToRootDestination}/.storybook`), devkit_1.workspaceRoot)
|
21 | .split(path.sep)
|
22 | .join('/');
|
23 | const storybookDir = path.join(schema.relativeToRootDestination, '.storybook');
|
24 | if (!storybookDir) {
|
25 | return;
|
26 | }
|
27 |
|
28 | updateRecursively(tree, storybookDir, oldRelativeRoot, newRelativeRoot);
|
29 | }
|
30 | exports.updateStorybookConfig = updateStorybookConfig;
|
31 | function updateRecursively(tree, dir, oldRoot, newRoot) {
|
32 | for (const child of tree.children(dir)) {
|
33 | const childPath = (0, path_1.join)(dir, child);
|
34 | if (tree.isFile(childPath)) {
|
35 | const oldContent = tree.read(childPath, 'utf-8');
|
36 | const newContent = oldContent.replace(oldRoot, newRoot);
|
37 | tree.write(childPath, newContent);
|
38 | }
|
39 | else {
|
40 | updateRecursively(tree, childPath, oldRoot, newRoot);
|
41 | }
|
42 | }
|
43 | }
|
44 |
|
\ | No newline at end of file |