UNPKG

@hadss/hmrouter-plugin

Version:

HMRouter Compiler Plugin

60 lines (59 loc) 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CompletionProcessor = void 0; const framework_1 = require("../../framework"); class CompletionProcessor { constructor(context) { this.context = context; this.config = context.config; } execute() { framework_1.Logger.debug(this.context.node.getNodeName(), `Start to delete temporary files...`); if (this.context.config.saveGeneratedFile) { framework_1.Logger.info(this.context.node.getNodeName(), `Save generated file is true, skip deleting temporary files`); return; } this.deleteRouterMapFile(); this.deleteRawFile(); this.deleteGeneratorFile(); if (this.config?.autoObfuscation) { this.deleteObfuscationFile(); } } deleteRouterMapFile() { let routerMapDirPath = this.config.getRouterMapDir(); if (framework_1.PluginFileUtil.exist(routerMapDirPath)) { framework_1.PluginFileUtil.unlinkSync(routerMapDirPath); framework_1.Logger.info(this.context.node.getNodeName(), `Delete router map file successfully, filePath: ${routerMapDirPath}`); } } deleteRawFile() { let rawFilePath = this.config.getRawFilePath(); if (framework_1.PluginFileUtil.exist(rawFilePath)) { framework_1.PluginFileUtil.unlinkSync(rawFilePath); framework_1.Logger.info(this.context.node.getNodeName(), `Delete raw file successfully, filePath: ${rawFilePath}`); } } deleteGeneratorFile() { let builderDirPath = this.config.getBuilderDir(); if (framework_1.PluginFileUtil.exist(builderDirPath)) { framework_1.PluginFileUtil.rmSync(builderDirPath, { recursive: true, }); framework_1.Logger.info(this.context.node.getNodeName(), `Delete generator file successfully, filePath: ${builderDirPath}`); } } deleteObfuscationFile() { let obfuscationFilePath = this.config.getObfuscationFilePath(); if (framework_1.PluginFileUtil.exist(obfuscationFilePath)) { framework_1.PluginFileUtil.unlinkSync(obfuscationFilePath); framework_1.Logger.info(this.context.node.getNodeName(), `Delete obfuscation file successfully, filePath: ${obfuscationFilePath}`); } let consumerRulesPath = this.config.getConsumerRulesFilePath(); if (framework_1.PluginFileUtil.exist(consumerRulesPath)) { framework_1.PluginFileUtil.unlinkSync(consumerRulesPath); framework_1.Logger.info(this.context.node.getNodeName(), `Delete consumer rules file successfully, filePath: ${consumerRulesPath}`); } } } exports.CompletionProcessor = CompletionProcessor;