UNPKG

@o3r/core

Version:
29 lines 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("node:fs"); const path = require("node:path"); const architect_1 = require("@angular-devkit/architect"); const utils_1 = require("../utils"); exports.default = (0, architect_1.createBuilder)((0, utils_1.createBuilderWithMetricsIfInstalled)(async (options, context) => { context.reportRunning(); const STEP_NUMBER = options.files.length + 1; context.reportProgress(1, STEP_NUMBER, 'Checking that all files exist'); const fileNames = options.files.map((fileName) => path.resolve(context.workspaceRoot, fileName)); const unexistingFile = fileNames.find((filePath) => !fs.existsSync(filePath)); if (unexistingFile) { return { success: false, error: `${unexistingFile} not found` }; } for (const [i, filePath] of fileNames.entries()) { context.reportProgress(i + 1, STEP_NUMBER, `Modifying ${filePath}`); const fileContent = await fs.promises.readFile(filePath, { encoding: 'utf8' }); const newContent = fileContent.replace(new RegExp(options.searchValue, 'g'), options.replaceValue); await fs.promises.writeFile(filePath, newContent); } return { success: true }; })); //# sourceMappingURL=index.js.map