siphon-cli
Version:
Simple bundler for web applications. 📦🔧🧡
39 lines (38 loc) • 1.88 kB
JavaScript
;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
var path_1 = require("path");
var _1 = require(".");
var utils_1 = require("../../utils");
var errors_1 = require("../errors");
var createDOMTree_1 = require("../transpilers/mimo/createDOMTree");
var tagNameSearch_1 = require("../transpilers/mimo/tagNameSearch");
function resolveModules(nodes, source, destination, options, assets) {
var mods = (0, tagNameSearch_1.default)(nodes, "module");
var srcName = (0, path_1.basename)(source.toString());
mods.forEach(function (mod) {
var _a;
var _b, _c;
if (!((_b = mod.attributes) === null || _b === void 0 ? void 0 : _b.src))
errors_1.default.enc("MODULE_REQUIRES_SRC", source);
var truePath = (0, utils_1.relativePath)(source, mod.attributes.src);
if ((0, path_1.basename)(truePath) === srcName)
errors_1.default.enc("HTML_SELF_INJECT", source);
if (!(0, utils_1.fileExists)(truePath))
errors_1.default.enc("FILE_NON_EXISTENT", truePath);
var injectNodes = (0, createDOMTree_1.default)(truePath);
var runtime = new _1.default(truePath, destination, options, assets, true);
runtime.resolve(injectNodes);
(_c = mod.parent) === null || _c === void 0 ? void 0 : (_a = _c.children).splice.apply(_a, __spreadArray([mod.childID, 1], injectNodes, false));
});
return nodes;
}
exports.default = resolveModules;