@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
51 lines (49 loc) • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileReplacementUpgrader = void 0;
const fs_extra_1 = require("fs-extra");
const logger_1 = require("../utils/logger");
const file_replacement_1 = require("../utils/file-replacement");
class FileReplacementUpgrader {
sourceContentFilePath;
writeToFilePath;
messages = {
notFound: '',
sourceFileNotFound: ''
};
/**
* the constructor.
* @param sourceContentFilePath the source file path.
* @param writeToFilePath the write to file path.
* @param fileName the file name.
*/
constructor(sourceContentFilePath, writeToFilePath, fileName) {
this.sourceContentFilePath = sourceContentFilePath;
this.writeToFilePath = writeToFilePath;
this.messages.notFound = `${fileName} writeToFilePath not found at ${this.writeToFilePath}.`;
this.messages.sourceFileNotFound = `${fileName} sourceContentFilePath not found at ${this.sourceContentFilePath}.`;
}
/**
* the run function to resolve the errors.
*/
async run() {
try {
const exists = await (0, fs_extra_1.pathExists)(this.sourceContentFilePath);
const writeToFilePathExists = await (0, fs_extra_1.pathExists)(this.writeToFilePath);
if (!exists) {
logger_1.Logger.log(this.messages.sourceFileNotFound);
}
if (!writeToFilePathExists) {
logger_1.Logger.log(this.messages.notFound);
}
if (exists && writeToFilePathExists) {
await (0, file_replacement_1.fileReplacement)(this.sourceContentFilePath, this.writeToFilePath);
}
}
catch (error) {
logger_1.Logger.error(error);
}
}
}
exports.FileReplacementUpgrader = FileReplacementUpgrader;
//# sourceMappingURL=file-replacement-upgrader.js.map