better-scripts
Version:
The next level of npm scripts. An npm scripts runner. A better way to organize your npm scripts. Make redundant NPM scripts easier to read, maintain and use.
19 lines (17 loc) • 453 B
JavaScript
/**
* @param {import('./types').ParsedUserConfig} parsedUserConfig
* @param {string} name
* @returns {import('./types').Script}
*/
export function getScriptByName(parsedUserConfig, name) {
const keys = name.split('.');
return keys.reduce(
(prev, key) => {
if (!prev.scripts[key]) {
throw new Error(`Cannot find "${key}" script in config`);
}
return prev.scripts[key];
},
{scripts: parsedUserConfig}
);
}