UNPKG

dool-build

Version:
50 lines (38 loc) 1.38 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _glob = require('glob'); var _glob2 = _interopRequireDefault(_glob); var _path = require('path'); var _path2 = _interopRequireDefault(_path); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } function formatName(name) { return name.replace(/^\.\//g, ''); } exports.default = function (files, entry, args) { var newEntry = entry || {}; if (typeof newEntry === 'string' || Array.isArray(newEntry)) { newEntry = { main: newEntry }; } if (Array.isArray(files)) { files.forEach(function (output) { [].concat(_toConsumableArray(_glob2.default.sync(output, { cwd: args.cwd, nodir: true }))).forEach(function (item) { var key = null; var ext = _path2.default.extname(item); if (ext === '.css' || ext === '.less') { key = item.replace(/\.(css|less)$/, '.css'); } else { key = item.replace(new RegExp(ext + '$'), ''); } newEntry[formatName(key)] = item; }); }); } return newEntry; }; module.exports = exports['default'];