1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.updateJestConfig = void 0;
|
4 | const path = require("path");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function updateJestConfig(tree, schema, project) {
|
13 | const jestConfigPath = path.join(schema.relativeToRootDestination, 'jest.config.ts');
|
14 | if (tree.exists(jestConfigPath)) {
|
15 | const oldContent = tree.read(jestConfigPath, 'utf-8');
|
16 | const findName = new RegExp(`'${schema.projectName}'`, 'g');
|
17 | const findDir = new RegExp(project.root, 'g');
|
18 | const newContent = oldContent
|
19 | .replace(findName, `'${schema.newProjectName}'`)
|
20 | .replace(findDir, schema.relativeToRootDestination);
|
21 | tree.write(jestConfigPath, newContent);
|
22 | }
|
23 |
|
24 | const rootJestConfigPath = '/jest.config.ts';
|
25 | if (!tree.exists(rootJestConfigPath)) {
|
26 | return;
|
27 | }
|
28 | const findProject = `'<rootDir>/${project.root}'`;
|
29 | const oldRootJestConfigContent = tree.read(rootJestConfigPath, 'utf-8');
|
30 | const usingJestProjects = oldRootJestConfigContent.includes('getJestProjects()');
|
31 | const newRootJestConfigContent = oldRootJestConfigContent.replace(findProject, usingJestProjects ? `` : `'<rootDir>/${schema.relativeToRootDestination}'`);
|
32 | tree.write(rootJestConfigPath, newRootJestConfigContent);
|
33 | }
|
34 | exports.updateJestConfig = updateJestConfig;
|
35 |
|
\ | No newline at end of file |