@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.16 kB
JavaScript
;
const path = require('path');
const jscodeshift = require(path.resolve(__dirname, '../../../../build-v2/node_modules/jscodeshift'));
const { transformListViewMessages, transformScrollerMessages } = 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 = transformListViewMessages(root, j);
const c2 = transformScrollerMessages(root, j);
if (c1 || c2) {
changed = true;
return open + root.toSource({ quote: 'single' }) + close;
}
return match;
});
return changed ? result : undefined;
};
module.exports.aiInstructions = `Nests Mobile ListView and Mobile Scroller message options inside a messages object in inline <script> blocks in HTML files.`;