UNPKG

@arces-wot/wam

Version:

Web of Thing Application Manager

36 lines 1.33 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var magic_string_1 = __importDefault(require("magic-string")); var path_1 = require("path"); function rollupWoT(options) { var mainFile = options.mainFile; mainFile = path_1.resolve(mainFile); return { name: 'wot', transform: function (code, id) { if (mainFile !== id) { return null; } var moduleName = path_1.basename(id) .split('.') .slice(0, -1) .join('.'); var s = new magic_string_1.default(code); var regex = new RegExp("var\\s*" + moduleName + "\\s*=\\s*{.*};\\s*export\\sdefault\\s" + moduleName + ";$", 'gs'); var m = regex.exec(code); if (m) { s.remove(regex.lastIndex - m[0].length, regex.lastIndex); return { code: s.toString(), map: s.generateMap({ hires: true }), }; } return null; }, }; } exports.default = rollupWoT; //# sourceMappingURL=rollup-wot-plugin.js.map