Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nhannt committed Jul 29, 2021
1 parent 68d5c94 commit 5e6cc4d
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/options/misc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*jshint node:true*/
'use strict';
"use strict";

var path = require('path');
var path = require("path");

/*
*! Miscellaneous methods
*/

module.exports = function(proto) {
module.exports = function (proto) {
/**
* Use preset
*
Expand All @@ -17,22 +17,23 @@ module.exports = function(proto) {
*
* @param {String|Function} preset preset name or preset function
*/
proto.usingPreset =
proto.preset = function(preset) {
if (typeof preset === 'function') {
proto.usingPreset = proto.preset = function (preset) {
if (typeof preset === "function") {
preset(this);
} else {
try {
var modulePath = path.join(this.options.presets, preset);
var module = require(modulePath);
var module = require(`${modulePath}`);

if (typeof module.load === 'function') {
if (typeof module.load === "function") {
module.load(this);
} else {
throw new Error('preset ' + modulePath + ' has no load() function');
throw new Error("preset " + modulePath + " has no load() function");
}
} catch (err) {
throw new Error('preset ' + modulePath + ' could not be loaded: ' + err.message);
throw new Error(
"preset " + modulePath + " could not be loaded: " + err.message
);
}
}

Expand Down

0 comments on commit 5e6cc4d

Please sign in to comment.