UNPKG

st-bundle

Version:

CLI for watching and bundling SpringType projects.

51 lines (50 loc) 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const createStylesheetProps_1 = require("../../config/createStylesheetProps"); const pluginUtils_1 = require("../pluginUtils"); const shared_1 = require("./shared"); const stylusHandler_1 = require("../../stylesheet/stylus/stylusHandler"); function pluginStylusCapture(props) { const { ctx, module, opts } = props; if (!ctx.isInstalled('stylus')) { ctx.fatal(`Fatal error when capturing ${module.props.absPath}`, [ 'Module "stylus" is required, Please install it using the following command', 'npm install stylus --save-dev', ]); return; } ctx.log.info('stylus', module.props.absPath); props.module.read(); props.module.captured = true; const stylusProcessor = stylusHandler_1.stylusHandler({ ctx: ctx, module, options: opts.stylesheet }); if (!stylusProcessor) return; // A shared handler that takes care of development/production render // as well as setting according flags // It also accepts extra properties (like asText) to handle text rendering shared_1.cssContextHandler({ ctx, module: module, options: opts.stylesheet, processor: stylusProcessor, shared: opts, }); } exports.pluginStylusCapture = pluginStylusCapture; function pluginStylus(a, b) { return (ctx) => { let [opts, matcher] = pluginUtils_1.parsePluginOptions(a, b, {}); opts.stylesheet = createStylesheetProps_1.createStylesheetProps({ ctx, stylesheet: opts.stylesheet || {} }); ctx.ict.on('bundle_resolve_module', props => { const { module } = props; if (props.module.captured || !matcher) { return; } if (matcher.test(module.props.absPath)) { pluginStylusCapture({ ctx, module, opts: opts }); } return props; }); }; } exports.pluginStylus = pluginStylus;