liferay-npm-bundler-improved
Version:
A non-official but ultrafast drop-in replacement for the liferay-npm-bundler
1,430 lines (1,151 loc) • 73.3 kB
JavaScript
#!/usr/bin/env node
"use strict";
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e3) { throw _e3; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e4) { didErr = true; err = _e4; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
require("regenerator-runtime/runtime");
var x = require("dotenv"),
o = require("fs"),
c = require("path"),
l = require("util"),
E = require("chalk"),
F = require("dayjs"),
T = require("readline"),
z = require("archiver"),
C = require("vite"),
A = require("ws"),
N = require("chokidar"),
L = require("arg");
function y(r) {
return r && _typeof(r) == "object" && "default" in r ? r : {
"default": r
};
}
function _(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 M = _(x),
d = y(E),
O = y(F),
H = y(T),
J = y(z),
q = y(L),
I = "liferay-npm-bundler-improved",
k = "1.5.1";
var D = /*#__PURE__*/function (_Error) {
_inherits(D, _Error);
var _super = _createSuper(D);
function D(e) {
var _this;
_classCallCheck(this, D);
_this = _super.call(this, e);
_this.name = "CopySourcesException";
return _this;
}
return _createClass(D);
}( /*#__PURE__*/_wrapNativeSuper(Error));
var P = /*#__PURE__*/function (_Error2) {
_inherits(P, _Error2);
var _super2 = _createSuper(P);
function P(e) {
var _this2;
_classCallCheck(this, P);
_this2 = _super2.call(this, e);
_this2.name = "MissingEntryFileException";
return _this2;
}
return _createClass(P);
}( /*#__PURE__*/_wrapNativeSuper(Error));
var p;
(function (r) {
r.progress = "progress", r.live = "live", r.success = "success", r.warn = "warn", r.error = "error";
})(p || (p = {}));
var W = /*#__PURE__*/function () {
function W() {
_classCallCheck(this, W);
this.start = performance.now(), this.warnings = [];
}
_createClass(W, [{
key: "log",
value: function log(e) {
var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : p.progress;
var s = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
H["default"].clearLine(process.stdout, 0), H["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 === p.live ? "".concat(this.getPrefix(t), ": ").concat(d["default"].gray(e)) : "".concat(this.getPrefix(t), ": ").concat(e);
}
}, {
key: "getPrefix",
value: function getPrefix(e) {
return e === p.progress || e === p.warn ? "".concat(this.getType(e), " going on ").concat(this.getTime()) : e === p.live ? "".concat(this.getType(e), " at ").concat(O["default"]().format("HH:mm:ss")) : "".concat(this.getType(e), " in ").concat(this.getTime());
}
}, {
key: "getType",
value: function getType(e) {
switch (e) {
case p.progress:
case p.live:
return d["default"].blue(e);
case p.success:
return d["default"].green(e);
case p.warn:
return d["default"].yellow(e);
case p.error:
return d["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, p.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 += d["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 += d["default"].yellow(i);
}
s && this.log(a, p.success, !0);
}
}, {
key: "warn",
value: function warn(e) {
this.warnings.push(e), this.log(e, p.warn);
}
}, {
key: "error",
value: function error(e) {
this.log(e, p.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(d["default"].yellow(s), e);
});
}
}]);
return W;
}();
var h = new W();
var m = /*#__PURE__*/function (_Error3) {
_inherits(m, _Error3);
var _super3 = _createSuper(m);
function m(e) {
var _this4;
_classCallCheck(this, m);
_this4 = _super3.call(this, e);
_this4.name = "FaultyConfigurationException";
return _this4;
}
return _createClass(m);
}( /*#__PURE__*/_wrapNativeSuper(Error));
var R = /*#__PURE__*/function () {
function R() {
_classCallCheck(this, R);
this.configuration = {}, this.processed = {
availableLanguageIds: [],
fields: []
}, this.languageFiles = new Map();
}
_createClass(R, [{
key: "resolve",
value: function () {
var _resolve = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(e, t) {
var _this$configuration$s;
var s, _iterator, _step, a, i;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
this.languageFiles = t;
_context.prev = 1;
_context.next = 4;
return l.promisify(o.access)(e);
case 4:
_context.next = 9;
break;
case 6:
_context.prev = 6;
_context.t0 = _context["catch"](1);
throw new m("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 9:
_context.next = 11;
return l.promisify(o.readFile)(e);
case 11:
s = _context.sent;
if (s.toString()) {
_context.next = 14;
break;
}
throw new m("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 14:
_context.prev = 14;
this.configuration = JSON.parse(s.toString());
_context.next = 21;
break;
case 18:
_context.prev = 18;
_context.t1 = _context["catch"](14);
throw new m("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 21:
((_this$configuration$s = this.configuration.system) === null || _this$configuration$s === void 0 ? void 0 : _this$configuration$s.name) && h.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 24:
case "end":
return _context.stop();
}
}
}, _callee, this, [[1, 6], [14, 18]]);
}));
function resolve(_x, _x2) {
return _resolve.apply(this, arguments);
}
return resolve;
}()
}, {
key: "process",
value: function () {
var _process = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(e) {
var _i, _Object$entries, _Object$entries$_i, t, s, a, i, n, _i2, _Object$entries2, _Object$entries2$_i, u, f;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_i = 0, _Object$entries = Object.entries(this.configuration.portletInstance.fields);
case 1:
if (!(_i < _Object$entries.length)) {
_context2.next = 12;
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.next = 6;
break;
}
throw new m("the portlet instance configuration \"".concat(t, "\" contains an unknown data type \"").concat(s.type, "\". the allowed types are 'float' | 'number' | 'string' | 'boolean'"));
case 6:
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), u = _Object$entries2$_i[0], f = _Object$entries2$_i[1];
n.options.push({
value: u,
label: this.getTranslation(f, e)
});
}
}
this.processed.fields.push(n);
case 9:
_i++;
_context2.next = 1;
break;
case 12:
case "end":
return _context2.stop();
}
}
}, _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),
f = new RegExp("^".concat(e, "=(.*)$"), "gm").exec(i);
f ? s[n] = f[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";
}
}
}]);
return R;
}();
var B = /*#__PURE__*/function (_Error4) {
_inherits(B, _Error4);
var _super4 = _createSuper(B);
function B(e) {
var _this5;
_classCallCheck(this, B);
_this5 = _super4.call(this, e);
_this5.name = "DeploymentException";
return _this5;
}
return _createClass(B);
}( /*#__PURE__*/_wrapNativeSuper(Error));
var Y = /*#__PURE__*/function () {
function Y() {
_classCallCheck(this, Y);
}
_createClass(Y, [{
key: "deploy",
value: function () {
var _deploy = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(e, t, s) {
var a;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
a = e;
e.endsWith("/") || (a = "".concat(e).concat(c.sep));
_context3.prev = 2;
_context3.next = 5;
return l.promisify(o.copyFile)(t, "".concat(a).concat(s, ".jar"));
case 5:
_context3.next = 10;
break;
case 7:
_context3.prev = 7;
_context3.t0 = _context3["catch"](2);
throw new B("Could not deploy ".concat(s, ".jar to ").concat(a));
case 10:
case "end":
return _context3.stop();
}
}
}, _callee3, null, [[2, 7]]);
}));
function deploy(_x4, _x5, _x6) {
return _deploy.apply(this, arguments);
}
return deploy;
}()
}]);
return Y;
}();
var V = /*#__PURE__*/function () {
function V() {
_classCallCheck(this, V);
this.localizationPath = "features".concat(c.sep, "localization"), this.hasLocalization = !1, this.configurationPath = "", this.hasConfiguration = !1, this.headerCSSPath = "", this.hasHeaderCSS = !1;
}
_createClass(V, [{
key: "resolve",
value: function () {
var _resolve2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
var e;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.prev = 0;
_context4.next = 3;
return l.promisify(o.readFile)(".".concat(c.sep, ".npmbundlerrc"));
case 3:
e = _context4.sent;
_context4.next = 6;
return JSON.parse(e.toString());
case 6:
this.npmbundlerrc = _context4.sent;
_context4.next = 11;
break;
case 9:
_context4.prev = 9;
_context4.t0 = _context4["catch"](0);
case 11:
case "end":
return _context4.stop();
}
}
}, _callee4, this, [[0, 9]]);
}));
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, c.sep).split(c.sep);
i.pop(), this.localizationPath = i.join(c.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, c.sep)), e.portlet["com.liferay.portlet.header-portlet-css"] && (this.hasHeaderCSS = !0, this.headerCSSPath = e.portlet["com.liferay.portlet.header-portlet-css"]);
}
}]);
return V;
}();
var v = /*#__PURE__*/function () {
function v() {
_classCallCheck(this, v);
}
_createClass(v, null, [{
key: "createFolderStructure",
value: function () {
var _createFolderStructure = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(e) {
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.prev = 0;
_context5.next = 3;
return l.promisify(o.mkdir)(e, {
recursive: !0
});
case 3:
_context5.next = 7;
break;
case 5:
_context5.prev = 5;
_context5.t0 = _context5["catch"](0);
case 7:
case "end":
return _context5.stop();
}
}
}, _callee5, null, [[0, 5]]);
}));
function createFolderStructure(_x7) {
return _createFolderStructure.apply(this, arguments);
}
return createFolderStructure;
}()
}, {
key: "getFiles",
value: function () {
var _getFiles = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(e) {
var _this6 = this;
var t, s;
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return l.promisify(o.readdir)(e);
case 2:
t = _context7.sent;
_context7.next = 5;
return Promise.all(t.map( /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(a) {
var i;
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
i = c.resolve(e, a);
_context6.next = 3;
return l.promisify(o.stat)(i);
case 3:
if (!_context6.sent.isDirectory()) {
_context6.next = 9;
break;
}
_context6.next = 6;
return _this6.getFiles(i);
case 6:
_context6.t0 = _context6.sent;
_context6.next = 10;
break;
case 9:
_context6.t0 = i;
case 10:
return _context6.abrupt("return", _context6.t0);
case 11:
case "end":
return _context6.stop();
}
}
}, _callee6);
}));
return function (_x9) {
return _ref.apply(this, arguments);
};
}()));
case 5:
s = _context7.sent;
return _context7.abrupt("return", Array.from(s.reduce(function (a, i) {
return a.concat(i);
}, [])));
case 7:
case "end":
return _context7.stop();
}
}
}, _callee7);
}));
function getFiles(_x8) {
return _getFiles.apply(this, arguments);
}
return getFiles;
}()
}]);
return v;
}();
var Z = /*#__PURE__*/function () {
function Z() {
_classCallCheck(this, Z);
this.outputPath = "", this.archive = J["default"]("zip");
}
_createClass(Z, [{
key: "initialize",
value: function () {
var _initialize = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(e) {
var _e$createJar;
var t, s;
return regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
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(c.sep).concat(this.name, ".jar");
_context8.next = 6;
return v.createFolderStructure(".".concat(c.sep).concat(t));
case 6:
this.output = o.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 10:
case "end":
return _context8.stop();
}
}
}, _callee8, this);
}));
function initialize(_x10) {
return _initialize.apply(this, arguments);
}
return initialize;
}()
}, {
key: "setName",
value: function setName(e) {
this.name = "".concat(e.name, "-").concat(e.version);
}
}, {
key: "create",
value: function () {
var _create = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() {
return regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
_context9.next = 2;
return this.archive.finalize();
case 2:
case "end":
return _context9.stop();
}
}
}, _callee9, this);
}));
function create() {
return _create.apply(this, arguments);
}
return create;
}()
}]);
return Z;
}();
var b = /*#__PURE__*/function (_Error5) {
_inherits(b, _Error5);
var _super5 = _createSuper(b);
function b(e) {
var _this7;
_classCallCheck(this, b);
_this7 = _super5.call(this, e);
_this7.name = "InvalidPackageException";
return _this7;
}
return _createClass(b);
}( /*#__PURE__*/_wrapNativeSuper(Error));
var G = /*#__PURE__*/function () {
function G() {
_classCallCheck(this, G);
}
_createClass(G, [{
key: "resolve",
value: function () {
var _resolve3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {
var e;
return regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
_context10.next = 2;
return l.promisify(o.readFile)("./package.json");
case 2:
e = _context10.sent;
_context10.next = 5;
return JSON.parse(e.toString());
case 5:
this.pack = _context10.sent;
case 6:
case "end":
return _context10.stop();
}
}
}, _callee10, 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 b("required property \"main\" doesn't exist in the package.json file.");
} else throw new b("required property \"version\" doesn't exist in the package.json file.");
} else throw new b("required property \"name\" doesn't exist in the package.json file.");
}
}]);
return G;
}();
var K = /*#__PURE__*/function () {
function K(e) {
_classCallCheck(this, K);
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;
}
_createClass(K, [{
key: "prepare",
value: function () {
var _prepare = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11(e, t, s, a) {
return regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
this.entryPathJs = e, this.entryPathCss = a, this.hasLocalization = t.hasLocalization, this.localizationPath = t.localizationPath, this.packageHandler = s;
case 1:
case "end":
return _context11.stop();
}
}
}, _callee11, this);
}));
function prepare(_x11, _x12, _x13, _x14) {
return _prepare.apply(this, arguments);
}
return prepare;
}()
}, {
key: "serve",
value: function () {
var _serve = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() {
var _this8 = this;
var e;
return regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) {
switch (_context13.prev = _context13.next) {
case 0:
_context13.next = 2;
return C.build({
logLevel: "silent",
build: {
watch: {
include: ["**/*"]
},
rollupOptions: {
plugins: [{
name: "replace",
closeBundle: function closeBundle() {
_this8.rebuildAmount++, _this8.send();
}
}]
}
}
})["catch"](function () {});
case 2:
e = _context13.sent;
this.hasLocalization && N.watch(this.localizationPath + "/**/*", {
persistent: !0
}).on("change", function () {
_this8.send();
}).on("unlink", function () {
_this8.send();
}), e.on("event", function (t) {
if (t.code === "ERROR") {
h.live("".concat(d["default"].red("error"), " ").concat(t.error.message)), h.live("".concat(d["default"].red("bundle failed to rebuild"), ". error sent to ").concat(d["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 _s2 = 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(_s2);
}
} catch (err) {
_iterator4.e(err);
} finally {
_iterator4.f();
}
h.live("rebuilding bundle...");
}
}), this.server = new A.WebSocketServer({
port: this.port
}), h.live("serving websocket server on port ".concat(d["default"].blue(this.port)), !0), this.server.on("connection", /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12(t) {
return regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
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:
case "end":
return _context12.stop();
}
}
}, _callee12);
}));
return function (_x15) {
return _ref2.apply(this, arguments);
};
}());
case 4:
case "end":
return _context13.stop();
}
}
}, _callee13, this);
}));
function serve() {
return _serve.apply(this, arguments);
}
return serve;
}()
}, {
key: "send",
value: function () {
var _send = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14(e) {
var t, s, a, i, _iterator5, _step5, n;
return regeneratorRuntime.wrap(function _callee14$(_context14) {
while (1) {
switch (_context14.prev = _context14.next) {
case 0:
_context14.prev = 0;
_context14.next = 3;
return l.promisify(o.readFile)(this.entryPathJs);
case 3:
t = _context14.sent.toString();
_context14.prev = 4;
if (!this.hasLocalization) {
_context14.next = 11;
break;
}
_context14.next = 8;
return this.translate(t);
case 8:
_context14.t0 = _context14.sent;
_context14.next = 12;
break;
case 11:
_context14.t0 = t;
case 12:
s = _context14.t0;
_context14.next = 18;
break;
case 15:
_context14.prev = 15;
_context14.t1 = _context14["catch"](4);
h.live("".concat(d["default"].yellow("failed to resolve the language keys."), " the bundle will be served as it is.")), s = t;
case 18:
a = "";
_context14.t2 = this.entryPathCss;
if (!_context14.t2) {
_context14.next = 24;
break;
}
_context14.next = 23;
return l.promisify(o.readFile)(this.entryPathCss);
case 23:
a = _context14.sent.toString();
case 24:
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, h.live("bundle rebuilt ".concat(d["default"].blue(this.rebuildAmount.toString() + (this.rebuildAmount > 1 ? " times" : " time")), " and sent to ").concat(d["default"].blue(this.sockets.length.toString() + (this.sockets.length === 1 ? " client" : " clients"))));
_context14.next = 31;
break;
case 29:
_context14.prev = 29;
_context14.t3 = _context14["catch"](0);
case 31:
case "end":
return _context14.stop();
}
}
}, _callee14, this, [[0, 29], [4, 15]]);
}));
function send(_x16) {
return _send.apply(this, arguments);
}
return send;
}()
}, {
key: "translate",
value: function () {
var _translate = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15(e) {
var t, s, a, _iterator6, _step6, n, u, i, _iterator7, _step7, _n2, _u, _iterator8, _step8, f, j, g, _ret;
return regeneratorRuntime.wrap(function _callee15$(_context15) {
while (1) {
switch (_context15.prev = _context15.next) {
case 0:
t = e;
s = new Map();
_context15.prev = 2;
_context15.next = 5;
return l.promisify(o.access)(this.localizationPath);
case 5:
_context15.next = 10;
break;
case 7:
_context15.prev = 7;
_context15.t0 = _context15["catch"](2);
return _context15.abrupt("return", (h.warn("the configured localization path is not present in your file structure. the bundle will be returned without modification."), e));
case 10:
_context15.next = 12;
return l.promisify(o.readdir)(this.localizationPath);
case 12:
a = _context15.sent;
_iterator6 = _createForOfIteratorHelper(a);
_context15.prev = 14;
_iterator6.s();
case 16:
if ((_step6 = _iterator6.n()).done) {
_context15.next = 24;
break;
}
n = _step6.value;
_context15.next = 20;
return l.promisify(o.readFile)("".concat(this.localizationPath).concat(c.sep).concat(n));
case 20:
u = _context15.sent.toString();
s.set(n, u);
case 22:
_context15.next = 16;
break;
case 24:
_context15.next = 29;
break;
case 26:
_context15.prev = 26;
_context15.t1 = _context15["catch"](14);
_iterator6.e(_context15.t1);
case 29:
_context15.prev = 29;
_iterator6.f();
return _context15.finish(29);
case 32:
if (!(s.size === 0)) {
_context15.next = 34;
break;
}
return _context15.abrupt("return", e);
case 34:
i = t.match(/Liferay.Language.get\(.*?\)/gm);
_iterator7 = _createForOfIteratorHelper(i);
_context15.prev = 36;
_iterator7.s();
case 38:
if ((_step7 = _iterator7.n()).done) {
_context15.next = 67;
break;
}
_n2 = _step7.value;
_u = /\(.*?\)/.exec(_n2).toString();
if (!_u) {
_context15.next = 65;
break;
}
_u = _u.slice(2), _u = _u.slice(0, -2);
_iterator8 = _createForOfIteratorHelper(s.values());
_context15.prev = 44;
_iterator8.s();
case 46:
if ((_step8 = _iterator8.n()).done) {
_context15.next = 57;
break;
}
f = _step8.value;
j = new RegExp("^".concat(_u, "=(.*)$"), "gm"), g = f.match(j);
if (!(g && Array.isArray(g) && g.length === 0)) {
_context15.next = 51;
break;
}
return _context15.abrupt("continue", 55);
case 51:
if (!(g[0].split("=").length > 0)) {
_context15.next = 55;
break;
}
_ret = function () {
var $ = g[0].split("=")[1];
if ($) {
t = t.replace(_n2, function () {
return "'".concat($, "'");
});
return "break";
}
}();
if (!(_ret === "break")) {
_context15.next = 55;
break;
}
return _context15.abrupt("break", 57);
case 55:
_context15.next = 46;
break;
case 57:
_context15.next = 62;
break;
case 59:
_context15.prev = 59;
_context15.t2 = _context15["catch"](44);
_iterator8.e(_context15.t2);
case 62:
_context15.prev = 62;
_iterator8.f();
return _context15.finish(62);
case 65:
_context15.next = 38;
break;
case 67:
_context15.next = 72;
break;
case 69:
_context15.prev = 69;
_context15.t3 = _context15["catch"](36);
_iterator7.e(_context15.t3);
case 72:
_context15.prev = 72;
_iterator7.f();
return _context15.finish(72);
case 75:
return _context15.abrupt("return", t);
case 76:
case "end":
return _context15.stop();
}
}
}, _callee15, this, [[2, 7], [14, 26, 29, 32], [36, 69, 72, 75], [44, 59, 62, 65]]);
}));
function translate(_x17) {
return _translate.apply(this, arguments);
}
return translate;
}()
}]);
return K;
}();
var S = /*#__PURE__*/function (_Error6) {
_inherits(S, _Error6);
var _super6 = _createSuper(S);
function S(e) {
var _this9;
_classCallCheck(this, S);
_this9 = _super6.call(this, e);
_this9.name = "TemplatesNotFoundException";
return _this9;
}
return _createClass(S);
}( /*#__PURE__*/_wrapNativeSuper(Error));
var w = /*#__PURE__*/function () {
function w(e) {
_classCallCheck(this, w);
this.base = "".concat(c.sep, "dist").concat(c.sep, "templates"), this.name = e;
}
_createClass(w, [{
key: "resolve",
value: function () {
var _resolve4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee16() {
var e;
return regeneratorRuntime.wrap(function _callee16$(_context16) {
while (1) {
switch (_context16.prev = _context16.next) {
case 0:
e = __dirname.split(c.sep);
e.pop(), e = e.join(c.sep), this.path = "".concat(e).concat(c.sep).concat(this.base).concat(c.sep).concat(this.name);
_context16.prev = 2;
_context16.next = 5;
return l.promisify(o.access)(this.path);
case 5:
_context16.next = 10;
break;
case 7:
_context16.prev