UNPKG

barro

Version:

Flexible barrel file generation for Javascript and Typescript with watching built-in.

61 lines 2.34 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseBarrel = exports.parseBarrels = void 0; const path_1 = __importDefault(require("path")); const parseStringArray_1 = require("./parseStringArray"); function parseBarrels(value) { if (Array.isArray(value)) { return value.map((v) => parseBarrel(v)); } if (value && Array.isArray(value.barro)) { return value.barro.map(parseBarrel); } return [parseBarrel(value)]; } exports.parseBarrels = parseBarrels; function parseBarrel(value) { if (value === null || typeof value !== "object") { throw new Error("Invalid barrel config. Config must be an object."); } const { barro: configWrapper, out, matchDirectory, match, matchIgnore, template, banner, } = value; /** * Check if the config has a top-level `barro` key. * If it does, use that as the config. * This is needed to use package.json as a barro config. */ if (configWrapper) { return parseBarrel(configWrapper); } if (typeof out !== "string") { throw new Error(`Expected out to be a string. Got ${typeof out}.`); } // Default the match directory to the directory the index is being output into. let parsedMatchDirectory; if (typeof matchDirectory === "string") { parsedMatchDirectory = matchDirectory; } else { parsedMatchDirectory = path_1.default.parse(out).dir; } const parsedMatch = typeof match === "string" ? match : parseStringArray_1.parseStringArray(match, "match"); const parsedMatchIgnore = matchIgnore ? parseStringArray_1.parseStringArray(matchIgnore, "matchIgnore") : undefined; const parsedTemplate = typeof template === "string" || typeof template === "function" ? template : undefined; const parsedBanner = typeof banner === "string" ? banner : undefined; return { out, matchDirectory: parsedMatchDirectory, template: parsedTemplate, banner: parsedBanner, matchIgnore: parsedMatchIgnore, match: parsedMatch, }; } exports.parseBarrel = parseBarrel; //# sourceMappingURL=parseBarrel.js.map