UNPKG

ngx-pug-builders

Version:
64 lines 2.78 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.addPugRules = exports.transformConfig = exports.isPromise = void 0; const cosmiconfig_1 = require("cosmiconfig"); const path_1 = require("path"); const webpack_merge_1 = require("webpack-merge"); // eslint-disable-next-line prefer-arrow/prefer-arrow-functions function isPromise(promise) { return !!promise && typeof promise.then === 'function'; } exports.isPromise = isPromise; const transformConfig = (config) => { const oldConfig = config || ((input) => input); return ((input) => __awaiter(void 0, void 0, void 0, function* () { const oldResult = oldConfig(input); if (isPromise(oldResult)) { const result = yield oldResult; return (0, exports.addPugRules)(result); } return (0, exports.addPugRules)(oldResult); })); }; exports.transformConfig = transformConfig; const addPugRules = (config) => __awaiter(void 0, void 0, void 0, function* () { const explorer = (0, cosmiconfig_1.cosmiconfig)('pug'); const result = yield explorer.search(); let pugOptions; if (result && result.config && !result.isEmpty) { pugOptions = result.config; const configDirPath = (0, path_1.dirname)(result.filepath); if (configDirPath) { if (pugOptions.root) { pugOptions.root = (0, path_1.resolve)(configDirPath, pugOptions.root); } if (pugOptions.basedir) { pugOptions.basedir = (0, path_1.resolve)(configDirPath, pugOptions.basedir); } } } return (0, webpack_merge_1.merge)(config, { module: { rules: [ { test: /\.(pug|jade)$/, use: [ { loader: 'apply-loader' }, Object.assign({ loader: 'simple-pug-loader' }, (pugOptions ? { options: pugOptions } : {})) ] } ] } }); }); exports.addPugRules = addPugRules; //# sourceMappingURL=utils.js.map