@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
34 lines (28 loc) • 1.06 kB
JavaScript
;
const path = require('path');
const jscodeshift = require(path.resolve(__dirname, '../../../../build-v2/node_modules/jscodeshift'));
const { transformCheckboxTemplate } = 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 c = transformCheckboxTemplate(root, j);
if (c) {
changed = true;
return open + root.toSource({ quote: 'single' }) + close;
}
return match;
});
return changed ? result : undefined;
};
module.exports.aiInstructions = `Migrates TreeView checkboxTemplate option to checkboxes.template inside inline <script> blocks in HTML files.`;