Son CV dans un terminal web en Javascript! https://terminal-cv.gregandev.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.3 KiB

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.loadConfig = loadConfig;
1 year ago
exports.default = void 0;
var _posthtml = _interopRequireDefault(require("posthtml"));
var _cosmiconfig = require("cosmiconfig");
var _safe = _interopRequireDefault(require("./presets/safe"));
var _ampSafe = _interopRequireDefault(require("./presets/ampSafe"));
var _max = _interopRequireDefault(require("./presets/max"));
var _package = _interopRequireDefault(require("../package.json"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const presets = {
safe: _safe.default,
ampSafe: _ampSafe.default,
max: _max.default
};
function loadConfig(options, preset, configPath) {
var _options;
if (!((_options = options) !== null && _options !== void 0 && _options.skipConfigLoading)) {
const explorer = (0, _cosmiconfig.cosmiconfigSync)(_package.default.name);
const rc = configPath ? explorer.load(configPath) : explorer.search();
if (rc) {
const {
preset: presetName
} = rc.config;
if (presetName) {
if (!preset && presets[presetName]) {
preset = presets[presetName];
}
delete rc.config.preset;
}
if (!options) {
options = rc.config;
}
}
}
return [options || {}, preset || _safe.default];
}
function htmlnano(optionsRun, presetRun) {
let [options, preset] = loadConfig(optionsRun, presetRun);
return function minifier(tree) {
options = { ...preset,
...options
};
let promise = Promise.resolve(tree);
for (const [moduleName, moduleOptions] of Object.entries(options)) {
if (!moduleOptions) {
// The module is disabled
continue;
}
if (_safe.default[moduleName] === undefined) {
throw new Error('Module "' + moduleName + '" is not defined');
}
let module = require('./modules/' + moduleName);
promise = promise.then(tree => module.default(tree, options, moduleOptions));
}
return promise;
};
}
htmlnano.process = function (html, options, preset, postHtmlOptions) {
return (0, _posthtml.default)([htmlnano(options, preset)]).process(html, postHtmlOptions);
};
htmlnano.presets = presets;
var _default = htmlnano;
exports.default = _default;