UNPKG

liferay-npm-bundler-improved

Version:

A non-official but ultrafast drop-in replacement for the liferay-npm-bundler

1,053 lines (1,051 loc) 73.6 kB
#!/usr/bin/env node "use strict"; function _regeneratorValues(e) { if (null != e) { var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"], r = 0; if (t) return t.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) return { next: function next() { return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e }; } }; } throw new TypeError(_typeof(e) + " is not iterable"); } function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); } function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); } function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n4 = 0, F = function F() {}; return { s: F, n: function n() { return _n4 >= r.length ? { done: !0 } : { done: !1, value: r[_n4++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); } function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } require("regenerator-runtime/runtime"); var dotenv = require("dotenv"), fs = require("fs"), path = require("path"), util = require("util"), chalk = require("chalk"), dayjs = require("dayjs"), readline = require("readline"), archiver = require("archiver"), vite = require("vite"), ws = require("ws"), chokidar = require("chokidar"), arg = require("arg"); function _interopDefaultLegacy(r) { return r && _typeof(r) == "object" && "default" in r ? r : { "default": r }; } function _interopNamespace(r) { if (r && r.__esModule) return r; var e = Object.create(null); return r && Object.keys(r).forEach(function (t) { if (t !== "default") { var s = Object.getOwnPropertyDescriptor(r, t); Object.defineProperty(e, t, s.get ? s : { enumerable: !0, get: function get() { return r[t]; } }); } }), e["default"] = r, Object.freeze(e); } var dotenv__namespace = _interopNamespace(dotenv), chalk__default = _interopDefaultLegacy(chalk), dayjs__default = _interopDefaultLegacy(dayjs), readline__default = _interopDefaultLegacy(readline), archiver__default = _interopDefaultLegacy(archiver), arg__default = _interopDefaultLegacy(arg), name = "liferay-npm-bundler-improved", version = "1.6.0"; var CopySourcesException = /*#__PURE__*/function (_Error) { function CopySourcesException(e) { var _this; _classCallCheck(this, CopySourcesException); _this = _callSuper(this, CopySourcesException, [e]); _this.name = "CopySourcesException"; return _this; } _inherits(CopySourcesException, _Error); return _createClass(CopySourcesException); }(/*#__PURE__*/_wrapNativeSuper(Error)); var MissingEntryFileException = /*#__PURE__*/function (_Error2) { function MissingEntryFileException(e) { var _this2; _classCallCheck(this, MissingEntryFileException); _this2 = _callSuper(this, MissingEntryFileException, [e]); _this2.name = "MissingEntryFileException"; return _this2; } _inherits(MissingEntryFileException, _Error2); return _createClass(MissingEntryFileException); }(/*#__PURE__*/_wrapNativeSuper(Error)); var LogType; (function (r) { r.progress = "progress", r.live = "live", r.success = "success", r.warn = "warn", r.error = "error"; })(LogType || (LogType = {})); var LogHandler = /*#__PURE__*/function () { function LogHandler() { _classCallCheck(this, LogHandler); this.start = performance.now(), this.warnings = []; } return _createClass(LogHandler, [{ key: "log", value: function log(e) { var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : LogType.progress; var s = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1; readline__default["default"].clearLine(process.stdout, 0), readline__default["default"].cursorTo(process.stdout, 0), s ? console.log(this.getMessage(e, t)) : process.stdout.write(this.getMessage(e, t)); } }, { key: "getMessage", value: function getMessage(e, t) { return t === LogType.live ? "".concat(this.getPrefix(t), ": ").concat(chalk__default["default"].gray(e)) : "".concat(this.getPrefix(t), ": ").concat(e); } }, { key: "getPrefix", value: function getPrefix(e) { return e === LogType.progress || e === LogType.warn ? "".concat(this.getType(e), " going on ").concat(this.getTime()) : e === LogType.live ? "".concat(this.getType(e), " at ").concat(dayjs__default["default"]().format("HH:mm:ss")) : "".concat(this.getType(e), " in ").concat(this.getTime()); } }, { key: "getType", value: function getType(e) { switch (e) { case LogType.progress: case LogType.live: return chalk__default["default"].blue(e); case LogType.success: return chalk__default["default"].green(e); case LogType.warn: return chalk__default["default"].yellow(e); case LogType.error: return chalk__default["default"].red(e); default: return "Information:"; } } }, { key: "getTime", value: function getTime() { return "".concat(Math.floor(performance.now() - this.start), "ms"); } }, { key: "live", value: function live(e) { var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1; this.log(e, LogType.live, t); } }, { key: "progress", value: function progress(e) { this.log(e); } }, { key: "success", value: function success(e, t) { var s = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1; var a = e; if (t && (a += chalk__default["default"].gray(" (".concat(t, ")"))), this.hasWarnings()) { var i = " "; this.warnings.length === 1 ? i += "there is one warning" : i += "there are ".concat(this.warnings.length, " warnings"), a += chalk__default["default"].yellow(i); } s && this.log(a, LogType.success, !0); } }, { key: "warn", value: function warn(e) { this.warnings.push(e), this.log(e, LogType.warn); } }, { key: "error", value: function error(e) { this.log(e, LogType.error); } }, { key: "hasWarnings", value: function hasWarnings() { return this.warnings.length !== 0; } }, { key: "printWarnings", value: function printWarnings() { var _this3 = this; this.warnings.forEach(function (e, t) { var s = "\u21B3"; _this3.warnings.length !== 1 && (s += " ".concat(t + 1, ".")), console.log(chalk__default["default"].yellow(s), e); }); } }]); }(); var log = new LogHandler(); var FaultyConfigurationException = /*#__PURE__*/function (_Error3) { function FaultyConfigurationException(e) { var _this4; _classCallCheck(this, FaultyConfigurationException); _this4 = _callSuper(this, FaultyConfigurationException, [e]); _this4.name = "FaultyConfigurationException"; return _this4; } _inherits(FaultyConfigurationException, _Error3); return _createClass(FaultyConfigurationException); }(/*#__PURE__*/_wrapNativeSuper(Error)); var ConfigurationHandler = /*#__PURE__*/function () { function ConfigurationHandler() { _classCallCheck(this, ConfigurationHandler); this.configuration = {}, this.processed = { availableLanguageIds: [], fields: [] }, this.languageFiles = new Map(); } return _createClass(ConfigurationHandler, [{ key: "resolve", value: function () { var _resolve = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e, t) { var _this$configuration$s; var s, _iterator, _step, a, i, _t, _t2; return _regenerator().w(function (_context) { while (1) switch (_context.p = _context.n) { case 0: this.languageFiles = t; _context.p = 1; _context.n = 2; return util.promisify(fs.access)(e); case 2: _context.n = 4; break; case 3: _context.p = 3; _t = _context.v; throw new FaultyConfigurationException("the configuration file does not exist in configured path \"".concat(e, "\" although the configuration feature is enabled. remove the configuration feature from the .npmbundlerrc file or create the configuration file.")); case 4: _context.n = 5; return util.promisify(fs.readFile)(e); case 5: s = _context.v; if (s.toString()) { _context.n = 6; break; } throw new FaultyConfigurationException("the configuration file in configured path \"".concat(e, "\" is empty. add the base structure of the configuration file or remove the configuration feature from the .npmbundlerrc file.")); case 6: _context.p = 6; this.configuration = JSON.parse(s.toString()); _context.n = 8; break; case 7: _context.p = 7; _t2 = _context.v; throw new FaultyConfigurationException("the configuration file in configured path \"".concat(e, "\" is not a valid JSON file. fix the configuration file or remove the configuration feature from the .npmbundlerrc file.")); case 8: ((_this$configuration$s = this.configuration.system) === null || _this$configuration$s === void 0 ? void 0 : _this$configuration$s.name) && log.warn("the configuration file in configured path \"".concat(e, "\" contains a system configuration. the system configuration is currently not supported and will be ignored. if you need this feature, add a thumbs up to this ticket: https://github.com/jwanner83/liferay-npm-bundler-improved/issues/55")); _iterator = _createForOfIteratorHelper(t.keys()); try { for (_iterator.s(); !(_step = _iterator.n()).done;) { a = _step.value; i = this.getLocale(a); i && this.processed.availableLanguageIds.push(i); } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } case 9: return _context.a(2); } }, _callee, this, [[6, 7], [1, 3]]); })); function resolve(_x, _x2) { return _resolve.apply(this, arguments); } return resolve; }() }, { key: "process", value: function () { var _process = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) { var _i, _Object$entries, _Object$entries$_i, t, s, a, i, n, _i2, _Object$entries2, _Object$entries2$_i, o, l; return _regenerator().w(function (_context2) { while (1) switch (_context2.n) { case 0: _i = 0, _Object$entries = Object.entries(this.configuration.portletInstance.fields); case 1: if (!(_i < _Object$entries.length)) { _context2.n = 4; break; } _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), t = _Object$entries$_i[0], s = _Object$entries$_i[1]; a = this.getType(s.type, s.options !== void 0); if (a) { _context2.n = 2; break; } throw new FaultyConfigurationException("the portlet instance configuration \"".concat(t, "\" contains an unknown data type \"").concat(s.type, "\". the allowed types are 'float' | 'number' | 'string' | 'boolean'")); case 2: i = this.getDataType(s.type), n = { name: t, label: this.getTranslation(s.name, e), dataType: i, type: a, tip: this.getTranslation(s.description || "", e) }; if (s["default"] && (a === "select" ? n.predefinedValue = { "": "[\"".concat(s["default"], "\"]") } : typeof s["default"] == "boolean" ? n.predefinedValue = { "": s["default"] } : n.predefinedValue = this.getTranslation(s["default"], e)), s.required && (n.required = s.required), s.options) { n.options = []; for (_i2 = 0, _Object$entries2 = Object.entries(s.options); _i2 < _Object$entries2.length; _i2++) { _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2), o = _Object$entries2$_i[0], l = _Object$entries2$_i[1]; n.options.push({ value: o, label: this.getTranslation(l, e) }); } } this.processed.fields.push(n); case 3: _i++; _context2.n = 1; break; case 4: return _context2.a(2); } }, _callee2, this); })); function process(_x3) { return _process.apply(this, arguments); } return process; }() }, { key: "getTranslation", value: function getTranslation(e, t) { var s = {}; if (t.size === 0) return s[""] = e, s; var _iterator2 = _createForOfIteratorHelper(t.entries()), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var _step2$value = _slicedToArray(_step2.value, 2), a = _step2$value[0], i = _step2$value[1]; var n = this.getLocale(a), l = new RegExp("^".concat(e, "=(.*)$"), "gm").exec(i); l ? s[n] = l[1] : n === "" && (s[n] = e); } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } return s; } }, { key: "getLocale", value: function getLocale(e) { return e.includes("_") ? e.split("_")[1].split(".")[0] : ""; } }, { key: "getType", value: function getType(e, t) { switch (e) { case "float": case "number": return "numeric"; case "string": return t ? "select" : "text"; case "boolean": return "checkbox"; } } }, { key: "getDataType", value: function getDataType(e) { switch (e) { case "float": return "double"; case "number": return "integer"; case "string": return "string"; case "boolean": return "boolean"; } } }]); }(); var DeploymentException = /*#__PURE__*/function (_Error4) { function DeploymentException(e) { var _this5; _classCallCheck(this, DeploymentException); _this5 = _callSuper(this, DeploymentException, [e]); _this5.name = "DeploymentException"; return _this5; } _inherits(DeploymentException, _Error4); return _createClass(DeploymentException); }(/*#__PURE__*/_wrapNativeSuper(Error)); var DeploymentHandler = /*#__PURE__*/function () { function DeploymentHandler() { _classCallCheck(this, DeploymentHandler); } return _createClass(DeploymentHandler, [{ key: "deploy", value: function () { var _deploy = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e, t, s) { var a, _t3; return _regenerator().w(function (_context3) { while (1) switch (_context3.p = _context3.n) { case 0: a = e; e.endsWith("/") || (a = "".concat(e).concat(path.sep)); _context3.p = 1; _context3.n = 2; return util.promisify(fs.copyFile)(t, "".concat(a).concat(s, ".jar")); case 2: _context3.n = 4; break; case 3: _context3.p = 3; _t3 = _context3.v; throw new DeploymentException("Could not deploy ".concat(s, ".jar to ").concat(a)); case 4: return _context3.a(2); } }, _callee3, null, [[1, 3]]); })); function deploy(_x4, _x5, _x6) { return _deploy.apply(this, arguments); } return deploy; }() }]); }(); var FeaturesHandler = /*#__PURE__*/function () { function FeaturesHandler() { _classCallCheck(this, FeaturesHandler); this.localizationPath = "features".concat(path.sep, "localization"), this.hasLocalization = !1, this.configurationPath = "", this.hasConfiguration = !1, this.headerCSSPath = "", this.hasHeaderCSS = !1; } return _createClass(FeaturesHandler, [{ key: "resolve", value: function () { var _resolve2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() { var e, _t4; return _regenerator().w(function (_context4) { while (1) switch (_context4.p = _context4.n) { case 0: _context4.p = 0; _context4.n = 1; return util.promisify(fs.readFile)(".".concat(path.sep, ".npmbundlerrc")); case 1: e = _context4.v; _context4.n = 2; return JSON.parse(e.toString()); case 2: this.npmbundlerrc = _context4.v; _context4.n = 4; break; case 3: _context4.p = 3; _t4 = _context4.v; case 4: return _context4.a(2); } }, _callee4, this, [[0, 3]]); })); function resolve() { return _resolve2.apply(this, arguments); } return resolve; }() }, { key: "determine", value: function determine(e) { var _this$npmbundlerrc2, _this$npmbundlerrc2$c, _this$npmbundlerrc2$c2; if (e.portlet["javax.portlet.resource-bundle"] && (this.hasLocalization = !0, this.npmbundlerrc)) { var _this$npmbundlerrc, _this$npmbundlerrc$cr, _this$npmbundlerrc$cr2; var s = (_this$npmbundlerrc = this.npmbundlerrc) === null || _this$npmbundlerrc === void 0 ? void 0 : (_this$npmbundlerrc$cr = _this$npmbundlerrc["create-jar"]) === null || _this$npmbundlerrc$cr === void 0 ? void 0 : (_this$npmbundlerrc$cr2 = _this$npmbundlerrc$cr.features) === null || _this$npmbundlerrc$cr2 === void 0 ? void 0 : _this$npmbundlerrc$cr2.localization; if (s) { var i = s.replace(/\//g, path.sep).split(path.sep); i.pop(), this.localizationPath = i.join(path.sep); } } var t = (_this$npmbundlerrc2 = this.npmbundlerrc) === null || _this$npmbundlerrc2 === void 0 ? void 0 : (_this$npmbundlerrc2$c = _this$npmbundlerrc2["create-jar"]) === null || _this$npmbundlerrc2$c === void 0 ? void 0 : (_this$npmbundlerrc2$c2 = _this$npmbundlerrc2$c.features) === null || _this$npmbundlerrc2$c2 === void 0 ? void 0 : _this$npmbundlerrc2$c2.configuration; t && (this.hasConfiguration = !0, this.configurationPath = t.replace(/\//g, path.sep)), e.portlet["com.liferay.portlet.header-portlet-css"] && (this.hasHeaderCSS = !0, this.headerCSSPath = e.portlet["com.liferay.portlet.header-portlet-css"]); } }]); }(); var FileHandler = /*#__PURE__*/function () { function FileHandler() { _classCallCheck(this, FileHandler); } return _createClass(FileHandler, null, [{ key: "createFolderStructure", value: function () { var _createFolderStructure = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(e) { var _t5; return _regenerator().w(function (_context5) { while (1) switch (_context5.p = _context5.n) { case 0: _context5.p = 0; _context5.n = 1; return util.promisify(fs.mkdir)(e, { recursive: !0 }); case 1: _context5.n = 3; break; case 2: _context5.p = 2; _t5 = _context5.v; case 3: return _context5.a(2); } }, _callee5, null, [[0, 2]]); })); function createFolderStructure(_x7) { return _createFolderStructure.apply(this, arguments); } return createFolderStructure; }() }, { key: "getFiles", value: function () { var _getFiles = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e) { var _this6 = this; var t, s; return _regenerator().w(function (_context7) { while (1) switch (_context7.n) { case 0: _context7.n = 1; return util.promisify(fs.readdir)(e); case 1: t = _context7.v; _context7.n = 2; return Promise.all(t.map(/*#__PURE__*/function () { var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(a) { var i, _t6; return _regenerator().w(function (_context6) { while (1) switch (_context6.n) { case 0: i = path.resolve(e, a); _context6.n = 1; return util.promisify(fs.stat)(i); case 1: if (!_context6.v.isDirectory()) { _context6.n = 3; break; } _context6.n = 2; return _this6.getFiles(i); case 2: _t6 = _context6.v; _context6.n = 4; break; case 3: _t6 = i; case 4: return _context6.a(2, _t6); } }, _callee6); })); return function (_x9) { return _ref.apply(this, arguments); }; }())); case 2: s = _context7.v; return _context7.a(2, Array.from(s.reduce(function (a, i) { return a.concat(i); }, []))); } }, _callee7); })); function getFiles(_x8) { return _getFiles.apply(this, arguments); } return getFiles; }() }]); }(); var JarHandler = /*#__PURE__*/function () { function JarHandler() { var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !1; _classCallCheck(this, JarHandler); this.outputPath = "", this.omitVersion = !1, this.archive = archiver__default["default"]("zip"), this.omitVersion = e; } return _createClass(JarHandler, [{ key: "initialize", value: function () { var _initialize = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(e) { var _e$createJar; var t, s; return _regenerator().w(function (_context8) { while (1) switch (_context8.n) { case 0: t = "dist"; s = e === null || e === void 0 ? void 0 : (_e$createJar = e["create-jar"]) === null || _e$createJar === void 0 ? void 0 : _e$createJar["output-dir"]; s && (t = s); this.outputPath = "".concat(t).concat(path.sep).concat(this.name, ".jar"); _context8.n = 1; return FileHandler.createFolderStructure(".".concat(path.sep).concat(t)); case 1: this.output = fs.createWriteStream(this.outputPath); this.archive.on("warning", function (a) { if (a.code === "ENOENT") console.log("warning", a);else throw a; }); this.archive.on("error", function (a) { throw a; }); this.archive.pipe(this.output); case 2: return _context8.a(2); } }, _callee8, this); })); function initialize(_x0) { return _initialize.apply(this, arguments); } return initialize; }() }, { key: "setName", value: function setName(e) { this.omitVersion ? this.name = e.name : this.name = "".concat(e.name, "-").concat(e.version); } }, { key: "create", value: function () { var _create = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() { return _regenerator().w(function (_context9) { while (1) switch (_context9.n) { case 0: _context9.n = 1; return this.archive.finalize(); case 1: return _context9.a(2); } }, _callee9, this); })); function create() { return _create.apply(this, arguments); } return create; }() }]); }(); var InvalidPackageException = /*#__PURE__*/function (_Error5) { function InvalidPackageException(e) { var _this7; _classCallCheck(this, InvalidPackageException); _this7 = _callSuper(this, InvalidPackageException, [e]); _this7.name = "InvalidPackageException"; return _this7; } _inherits(InvalidPackageException, _Error5); return _createClass(InvalidPackageException); }(/*#__PURE__*/_wrapNativeSuper(Error)); var PackageHandler = /*#__PURE__*/function () { function PackageHandler() { _classCallCheck(this, PackageHandler); } return _createClass(PackageHandler, [{ key: "resolve", value: function () { var _resolve3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() { var e; return _regenerator().w(function (_context0) { while (1) switch (_context0.n) { case 0: _context0.n = 1; return util.promisify(fs.readFile)("./package.json"); case 1: e = _context0.v; _context0.n = 2; return JSON.parse(e.toString()); case 2: this.pack = _context0.v; case 3: return _context0.a(2); } }, _callee0, this); })); function resolve() { return _resolve3.apply(this, arguments); } return resolve; }() }, { key: "validate", value: function validate() { if (this.pack.name) { if (this.pack.version) { if (!this.pack.main) throw new InvalidPackageException("required property \"main\" doesn't exist in the package.json file."); } else throw new InvalidPackageException("required property \"version\" doesn't exist in the package.json file."); } else throw new InvalidPackageException("required property \"name\" doesn't exist in the package.json file."); } }]); }(); var ServeHandler = /*#__PURE__*/function () { function ServeHandler(e) { _classCallCheck(this, ServeHandler); this.sockets = [], this.hasLocalization = !1, this.localizationPath = "", this.entryPathJs = "", this.entryPathCss = "", this.rebuildAmount = 0, this.latestPayload = "", this.packageHandler = void 0, this.server = void 0, this.port = e; } return _createClass(ServeHandler, [{ key: "prepare", value: function () { var _prepare = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(e, t, s, a) { return _regenerator().w(function (_context1) { while (1) switch (_context1.n) { case 0: this.entryPathJs = e, this.entryPathCss = a, this.hasLocalization = t.hasLocalization, this.localizationPath = t.localizationPath, this.packageHandler = s; case 1: return _context1.a(2); } }, _callee1, this); })); function prepare(_x1, _x10, _x11, _x12) { return _prepare.apply(this, arguments); } return prepare; }() }, { key: "serve", value: function () { var _serve = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() { var _this8 = this; var e; return _regenerator().w(function (_context11) { while (1) switch (_context11.n) { case 0: _context11.n = 1; return vite.build({ logLevel: "silent", build: { watch: { include: ["**/*"] }, rollupOptions: { plugins: [{ name: "replace", closeBundle: function closeBundle() { _this8.rebuildAmount++, _this8.send(); } }] } } })["catch"](function () {}); case 1: e = _context11.v; this.hasLocalization && chokidar.watch(this.localizationPath + "/**/*", { persistent: !0 }).on("change", function () { _this8.send(); }).on("unlink", function () { _this8.send(); }), e.on("event", function (t) { if (t.code === "ERROR") { log.live("".concat(chalk__default["default"].red("error"), " ").concat(t.error.message)), log.live("".concat(chalk__default["default"].red("bundle failed to rebuild"), ". error sent to ").concat(chalk__default["default"].blue(_this8.sockets.length.toString() + (_this8.sockets.length === 1 ? " client" : " clients"))), !0); var s = JSON.stringify({ name: "".concat(_this8.packageHandler.pack.name, "@").concat(_this8.packageHandler.pack.version), error: { location: t.error.id, message: t.error.message } }); var _iterator3 = _createForOfIteratorHelper(_this8.sockets), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var a = _step3.value; a.send(s); } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } _this8.latestPayload = s; } if (t.code === "START") { var _s = JSON.stringify({ name: "".concat(_this8.packageHandler.pack.name, "@").concat(_this8.packageHandler.pack.version), updating: !0 }); var _iterator4 = _createForOfIteratorHelper(_this8.sockets), _step4; try { for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { var _a = _step4.value; _a.send(_s); } } catch (err) { _iterator4.e(err); } finally { _iterator4.f(); } log.live("rebuilding bundle..."); } }), this.server = new ws.WebSocketServer({ port: this.port }), log.live("serving websocket server on port ".concat(chalk__default["default"].blue(this.port)), !0), this.server.on("connection", /*#__PURE__*/function () { var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(t) { return _regenerator().w(function (_context10) { while (1) switch (_context10.n) { case 0: _this8.sockets.push(t), _this8.latestPayload ? t.send(_this8.latestPayload) : _this8.send(t), t.on("close", function () { _this8.sockets.splice(_this8.sockets.indexOf(t), 1); }); case 1: return _context10.a(2); } }, _callee10); })); return function (_x13) { return _ref2.apply(this, arguments); }; }()); case 2: return _context11.a(2); } }, _callee11, this); })); function serve() { return _serve.apply(this, arguments); } return serve; }() }, { key: "send", value: function () { var _send = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(e) { var t, s, a, i, _iterator5, _step5, n, _t7, _t8, _t9, _t0; return _regenerator().w(function (_context12) { while (1) switch (_context12.p = _context12.n) { case 0: _context12.p = 0; _context12.n = 1; return util.promisify(fs.readFile)(this.entryPathJs); case 1: t = _context12.v.toString(); _context12.p = 2; if (!this.hasLocalization) { _context12.n = 4; break; } _context12.n = 3; return this.translate(t); case 3: _t7 = _context12.v; _context12.n = 5; break; case 4: _t7 = t; case 5: s = _t7; _context12.n = 7; break; case 6: _context12.p = 6; _t8 = _context12.v; log.live("".concat(chalk__default["default"].yellow("failed to resolve the language keys."), " the bundle will be served as it is.")), s = t; case 7: a = ""; _t9 = this.entryPathCss; if (!_t9) { _context12.n = 9; break; } _context12.n = 8; return util.promisify(fs.readFile)(this.entryPathCss); case 8: a = _context12.v.toString(); case 9: i = JSON.stringify({ name: "".concat(this.packageHandler.pack.name, "@").concat(this.packageHandler.pack.version), script: s, style: a }); if (e) e.send(i);else { _iterator5 = _createForOfIteratorHelper(this.sockets); try { for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { n = _step5.value; n.send(i); } } catch (err) { _iterator5.e(err); } finally { _iterator5.f(); } } this.latestPayload = i, log.live("bundle rebuilt ".concat(chalk__default["default"].blue(this.rebuildAmount.toString() + (this.rebuildAmount > 1 ? " times" : " time")), " and sent to ").concat(chalk__default["default"].blue(this.sockets.length.toString() + (this.sockets.length === 1 ? " client" : " clients")))); _context12.n = 11; break; case 10: _context12.p = 10; _t0 = _context12.v; case 11: return _context12.a(2); } }, _callee12, this, [[2, 6], [0, 10]]); })); function send(_x14) { return _send.apply(this, arguments); } return send; }() }, { key: "translate", value: function () { var _translate = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(e) { var t, s, a, _iterator6, _step6, n, o, i, _iterator7, _step7, _n, _o, _iterator8, _step8, _loop, _ret, _t1, _t10, _t11, _t12; return _regenerator().w(function (_context14) { while (1) switch (_context14.p = _context14.n) { case 0: t = e; s = new Map(); _context14.p = 1; _context14.n = 2; return util.promisify(fs.access)(this.localizationPath); case 2: _context14.n = 4; break; case 3: _context14.p = 3; _t1 = _context14.v; return _context14.a(2, (log.warn("the configured localization path is not present in your file structure. the bundle will be returned without modification."), e)); case 4: _context14.n = 5; return util.promisify(fs.readdir)(this.localizationPath); case 5: a = _context14.v; _iterator6 = _createForOfIteratorHelper(a); _context14.p = 6; _iterator6.s(); case 7: if ((_step6 = _iterator6.n()).done) { _context14.n = 10; break; } n = _step6.value; _context14.n = 8; return util.promisify(fs.readFile)("".concat(this.localizationPath).concat(path.sep).concat(n)); case 8: o = _context14.v.toString(); s.set(n, o); case 9: _context14.n = 7; break; case 10: _context14.n = 12; break; case 11: _context14.p = 11; _t10 = _context14.v; _iterator6.e(_t10); case 12: _context14.p = 12; _iterator6.f(); return _context14.f(12); case 13: if (!(s.size === 0)) { _context14.n = 14; break; } return _context14.a(2, e); case 14: i = t.match(/Liferay.Language.get\(.*?\)/gm); _iterator7 = _createForOfIteratorHelper(i); _context14.p = 15; _iterator7.s(); case 16: if ((_step7 = _iterator7.n()).done) { _context14.n = 26; break; } _n = _step7.value; _o = /\(.*?\)/.exec(_n).toString(); if (!_o) { _context14.n = 25; break; } _o = _o.slice(2), _o = _o.slice(0, -2); _iterator8 = _createForOfIteratorHelper(s.values()); _context14.p = 17; _loop = /*#__PURE__*/_regenerator().m(function _loop() { var l, p, c, h; return _regenerator().w(function (_context13) { while (1) switch (_context13.n) { case 0: l = _step8.value; p = new RegExp("^".concat(_o, "=(.*)$"), "gm"), c = l.match(p); if (!(c && Array.isArray(c) && c.length === 0)) { _context13.n = 1; break; } return _context13.a(2, 0); case 1: if (!(c[0].split("=").length > 0)) { _context13.n = 2; break; } h = c[0].split("=")[1]; if (!h) { _context13.n = 2; break; } t = t.replace(_n, function () { return "'".concat(h, "'"); }); return _context13.a(2, 1); case 2: return _context13.a(2); } }, _loop); }); _iterator8.s(); case 18: if ((_step8 = _iterator8.n()).done) { _context14.n = 22; break; } return _context14.d(_regeneratorValues(_loop()), 19); case 19: _ret = _context14.v; if (!(_ret === 0)) { _context14.n = 20; break; } return _context14.a(3, 21); case 20: if (!(_ret === 1)) { _context14.n = 21; break; } return _context14.a(3, 22); case 21: _context14.n = 18; break; case 22: _context14.n = 24; break; case 23: _context14.p = 23; _t11 = _context14.v; _iterator8.e(_t11); case 24: _context14.p = 24; _iterator8.f(); return _context14.f(24);