@nrwl/workspace
Version:
33 lines • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateCypressConfig = void 0;
const path = require("path");
/**
* Updates the videos and screenshots folders in the cypress.json/cypress.config.ts if it exists (i.e. we're moving an e2e project)
*
* (assume relative paths have been updated previously)
*
* @param schema The options provided to the schematic
*/
function updateCypressConfig(tree, schema, project) {
const cypressJsonPath = path.join(schema.relativeToRootDestination, 'cypress.json');
if (tree.exists(cypressJsonPath)) {
const cypressJson = JSON.parse(tree.read(cypressJsonPath).toString('utf-8'));
cypressJson.videosFolder = cypressJson.videosFolder.replace(project.root, schema.relativeToRootDestination);
cypressJson.screenshotsFolder = cypressJson.screenshotsFolder.replace(project.root, schema.relativeToRootDestination);
tree.write(cypressJsonPath, JSON.stringify(cypressJson));
return tree;
}
const cypressConfigPath = path.join(schema.relativeToRootDestination, 'cypress.config.ts');
if (tree.exists(cypressConfigPath)) {
const oldContent = tree.read(cypressConfigPath, 'utf-8');
const findName = new RegExp(`'${schema.projectName}'`, 'g');
const findDir = new RegExp(project.root, 'g');
const newContent = oldContent
.replace(findName, `'${schema.newProjectName}'`)
.replace(findDir, schema.relativeToRootDestination);
tree.write(cypressConfigPath, newContent);
}
}
exports.updateCypressConfig = updateCypressConfig;
//# sourceMappingURL=update-cypress-config.js.map