UNPKG

1.66 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.updateCypressConfig = void 0;
4const path = require("path");
5/**
6 * Updates the videos and screenshots folders in the cypress.json/cypress.config.ts if it exists (i.e. we're moving an e2e project)
7 *
8 * (assume relative paths have been updated previously)
9 *
10 * @param schema The options provided to the schematic
11 */
12function updateCypressConfig(tree, schema, project) {
13 const cypressJsonPath = path.join(schema.relativeToRootDestination, 'cypress.json');
14 if (tree.exists(cypressJsonPath)) {
15 const cypressJson = JSON.parse(tree.read(cypressJsonPath).toString('utf-8'));
16 cypressJson.videosFolder = cypressJson.videosFolder.replace(project.root, schema.relativeToRootDestination);
17 cypressJson.screenshotsFolder = cypressJson.screenshotsFolder.replace(project.root, schema.relativeToRootDestination);
18 tree.write(cypressJsonPath, JSON.stringify(cypressJson));
19 return tree;
20 }
21 const cypressConfigPath = path.join(schema.relativeToRootDestination, 'cypress.config.ts');
22 if (tree.exists(cypressConfigPath)) {
23 const oldContent = tree.read(cypressConfigPath, 'utf-8');
24 const findName = new RegExp(`'${schema.projectName}'`, 'g');
25 const findDir = new RegExp(project.root, 'g');
26 const newContent = oldContent
27 .replace(findName, `'${schema.newProjectName}'`)
28 .replace(findDir, schema.relativeToRootDestination);
29 tree.write(cypressConfigPath, newContent);
30 }
31}
32exports.updateCypressConfig = updateCypressConfig;
33//# sourceMappingURL=update-cypress-config.js.map
\No newline at end of file