UNPKG

@wuapi/generator

Version:
72 lines (71 loc) 2.16 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.toLineComment = exports.toBlockComment = exports.ProjectProcessor = exports.BasePlugin = void 0; const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); /** * This is the abstract parent class of all Plug-ins. */ class BasePlugin { /** * Convenient function to get plugin name. * @returns plugin name */ getName() { return this.getDescription().name; } /** * Rewrite a file with texts replaced. * @param src The source file path. * @param dst The destination file path. * @param map The map of texts to replace. */ rewriteFile(src, dst, map) { let content = fs_1.default.readFileSync(src).toString(); for (let key in map) { content = content.split(key).join(map[key]); } fs_1.default.writeFileSync(dst, content); } } exports.BasePlugin = BasePlugin; /** * This is the abstract parent class for project processors. */ class ProjectProcessor { /** * * @param plugin The parent plugin. * @param project The project * @param outputDir The output dir, for All plugins. * @param config The configuration of this plugin. */ constructor(plugin, project, outputDir, config) { this.plugin = plugin; this.project = project; this.config = config; this.rootDir = [outputDir, plugin.getName()].join(path_1.default.sep); } } exports.ProjectProcessor = ProjectProcessor; function toBlockComment(element) { if (element && element.comment) { return "\n/*\n" + element.comment.replace(/^/g, " * ") + "\n */"; } else { return ""; } } exports.toBlockComment = toBlockComment; function toLineComment(element) { if (element && element.comment) { return "\n" + element.comment.replace(/^/g, "// "); } else { return ""; } } exports.toLineComment = toLineComment;