]> git.proxmox.com Git - mirror_novnc.git/blame - utils/make-module-transform.js
Use ES6 modules natively via Polyfill
[mirror_novnc.git] / utils / make-module-transform.js
CommitLineData
ae510306
SR
1var through = require('through2');
2
3var singleLineRe = /\/\* \[module\] ((.(?!\*\/))+) \*\//g;
4var multiLineRe = /\/\* \[module\]\n(( * .+\n)+) \*\//g;
5
6var skipAsModule = /\/\* \[begin skip-as-module\] \*\/(.|\n)+\/\* \[end skip-as-module\] \*\//g;
7
8module.exports = function (file) {
9 var stream = through(function (buf, enc, next) {
10 var bufStr = buf.toString('utf8');
11 bufStr = bufStr.replace(singleLineRe, "$1");
12 bufStr = bufStr.replace(multiLineRe, function (match, mainLines) {
13 return mainLines.split(" * ").join("");
14 });
15
16 bufStr = bufStr.replace(skipAsModule, "");
17
18 this.push(bufStr);
19 next();
20 });
21
22 stream._is_make_module = true;
23
24 return stream;
25};