@hadss/hmrouter-plugin
Version:
HMRouter Compiler Plugin
75 lines (74 loc) • 3.84 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HMRouterPluginConfig = void 0;
const path_1 = __importDefault(require("path"));
const FileUtil_1 = __importDefault(require("./utils/FileUtil"));
const ConfigConstants_1 = __importDefault(require("./constants/ConfigConstants"));
const CommonConstants_1 = __importDefault(require("./constants/CommonConstants"));
class HMRouterPluginConfig {
constructor(moduleName, modulePath, configDir, param) {
this.moduleName = moduleName;
this.modulePath = modulePath;
this.configDir = configDir;
this.scanDir = param.scanDir ? [...new Set(param.scanDir)] : [ConfigConstants_1.default.DEFAULT_SCAN_DIR];
this.routerMapDir = param.routerMapDir ? param.routerMapDir : ConfigConstants_1.default.DEFAULT_ROUTER_MAP_DIR;
this.builderDir = param.builderDir ? param.builderDir : ConfigConstants_1.default.DEFAULT_BUILD_DIR;
this.annotation = [
ConfigConstants_1.default.ROUTER_ANNOTATION,
ConfigConstants_1.default.ANIMATOR_ANNOTATION,
ConfigConstants_1.default.INTERCEPTOR_ANNOTATION,
ConfigConstants_1.default.LIFECYCLE_ANNOTATION,
ConfigConstants_1.default.SERVICE_ANNOTATION,
ConfigConstants_1.default.SERVICE_PROVIDE_ANNOTATION
];
this.defaultPageTemplate =
param.defaultPageTemplate ? param.defaultPageTemplate : ConfigConstants_1.default.DEFAULT_BUILD_TPL;
this.customPageTemplate = param.customPageTemplate ? param.customPageTemplate : [];
this.saveGeneratedFile = !!param.saveGeneratedFile;
this.autoObfuscation = !!param.autoObfuscation;
}
getScanPath(dir) {
return FileUtil_1.default.pathResolve(this.modulePath, dir);
}
getRelativeSourcePath(filePath) {
return path_1.default.relative(this.modulePath, filePath);
}
getRelativeBuilderPath(filePath) {
return path_1.default.relative(this.builderDir, filePath);
}
getGeneratedFilePath(generatorViewName) {
return FileUtil_1.default.pathResolve(this.modulePath, this.builderDir, generatorViewName + CommonConstants_1.default.ETS_SUFFIX);
}
getBuilderDir() {
return FileUtil_1.default.pathResolve(this.modulePath, this.builderDir);
}
getBuilderFilePath(generatorViewName) {
return path_1.default.join(this.builderDir, generatorViewName + CommonConstants_1.default.ETS_SUFFIX);
}
getRouterMapDir() {
return FileUtil_1.default.pathResolve(this.modulePath, this.routerMapDir, CommonConstants_1.default.ROUTER_MAP_NAME);
}
getModuleRouterMapFilePath(routerMapFileName) {
return FileUtil_1.default.pathResolve(this.modulePath, this.routerMapDir, routerMapFileName + CommonConstants_1.default.JSON_SUFFIX);
}
getRawFilePath() {
return FileUtil_1.default.pathResolve(this.modulePath, CommonConstants_1.default.RAWFILE_DIR);
}
getDefaultTplFilePath() {
let templateFilePath = FileUtil_1.default.pathResolve(this.configDir, this.defaultPageTemplate);
if (FileUtil_1.default.exist(templateFilePath)) {
return templateFilePath;
}
return FileUtil_1.default.pathResolve(__dirname, CommonConstants_1.default.PARENT_DELIMITER + this.defaultPageTemplate);
}
getObfuscationFilePath() {
return FileUtil_1.default.pathResolve(this.modulePath, CommonConstants_1.default.OBFUSCATION_FILE_NAME);
}
getConsumerRulesFilePath() {
return FileUtil_1.default.pathResolve(this.modulePath, CommonConstants_1.default.CONSUMER_FILE_NAME);
}
}
exports.HMRouterPluginConfig = HMRouterPluginConfig;