UNPKG

daizong

Version:

`package.json` script runner for ES Modules

34 lines 1.02 kB
function findTask(config, path) { let obj = config.tasks; for (const arg of path) { obj = obj[arg]; if (!obj) { break; } } if (!obj) { throw new Error(`The task #${path.join('-')} doesn't exist.`); } if (typeof obj === 'string') { return { run: obj }; } if (Array.isArray(obj)) { return { run: obj }; } if (!obj.run) { throw new Error(`A valid task could only be a string, an array of strings, or an object with a "run" field. Got ${JSON.stringify(obj)}`); } return obj; } export default function getTask(config, name, allowPrivate) { const path = name.split('-'); if (!name || !path.length) { throw new Error('No tasks specified'); } const task = findTask(config, path); if (task.__isPrivate && !allowPrivate) { throw new Error(`The task #${path.toString()} is private. It can only be called by other tasks.`); } return task; } //# sourceMappingURL=getTask.js.map