UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

35 lines (29 loc) 1.11 kB
'use strict'; const path = require('path'); const jscodeshift = require(path.resolve(__dirname, '../../../../build-v2/node_modules/jscodeshift')); const { transformBadgeConfig, transformBadgeMethods } = require('../_shared.cjs'); const SCRIPT_RE = /(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi; module.exports = function transformer(fileInfo, api) { if (!/\.html?$/i.test(fileInfo.path)) { return undefined; } let changed = false; const result = fileInfo.source.replace(SCRIPT_RE, (match, open, body, close) => { const j = (api && api.jscodeshift) ? api.jscodeshift : jscodeshift.withParser('babel'); let root; try { root = j(body); } catch (e) { return match; } const c1 = transformBadgeConfig(root, j); const c2 = transformBadgeMethods(root, j); if (c1 || c2) { changed = true; return open + root.toSource({ quote: 'single' }) + close; } return match; }); return changed ? result : undefined; }; module.exports.aiInstructions = `Renames Badge configuration options and methods inside inline <script> blocks in HTML files.`;