UNPKG

@luban-cli/cli-plugin-service

Version:
73 lines 2.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigPluginAPI = exports.CommandPluginAPI = void 0; const path_1 = __importDefault(require("path")); class PluginAPI { constructor(id, service) { this.id = id; this.service = service; } getContext() { return this.service.context; } resolve(_path) { return path_1.default.resolve(this.service.context, _path); } getClientSideEntryFile() { return path_1.default.resolve(this.service.context, "src/.luban/client.entry.tsx"); } getServerSideClientEntryFile() { return path_1.default.resolve(this.service.context, "src/.luban/server.entry.tsx"); } getMockConfig() { return this.service.mockConfig; } getRegisteredCommands() { return this.service.commands; } } class CommandPluginAPI extends PluginAPI { registerCommand(name, opts, callback) { let commandCallback = callback; // if opts is function, ignore callback param if (typeof opts === "function") { commandCallback = opts; opts = {}; } if (typeof commandCallback === "function") { this.service.commands[name] = { commandCallback, opts }; } } addWebpackConfig(name) { this.service.addWebpackConfigQueueItem(name); } resolveWebpackConfig(name) { return this.service.resolveWebpackConfig(name); } } exports.CommandPluginAPI = CommandPluginAPI; class ConfigPluginAPI extends PluginAPI { configureWebpack(name, fn) { const configQueue = this.service.webpackConfigQueue.get(name); configQueue === null || configQueue === void 0 ? void 0 : configQueue.rawCallback.push(fn); } configureAllWebpack(fn) { this.service.webpackConfigQueue.forEach((queue) => { queue.rawCallback.push(fn); }); } chainWebpack(name, fn) { const configQueue = this.service.webpackConfigQueue.get(name); configQueue === null || configQueue === void 0 ? void 0 : configQueue.chainCallback.push(fn); } chainAllWebpack(fn) { this.service.webpackConfigQueue.forEach((queue) => { queue.chainCallback.push(fn); }); } } exports.ConfigPluginAPI = ConfigPluginAPI; //# sourceMappingURL=PluginAPI.js.map