Merge branch 'feature/webpack-cli-task' of git://github.com/anikethsaha/just into anikethsaha-feature/webpack-cli-task

This commit is contained in:
Ken 2019-09-16 16:43:18 -07:00
Родитель d7982d10be e469e884e3
Коммит b7be70942e
3 изменённых файлов: 51 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,8 @@
{
"comment": "feat: added webpack-cli tasks init, more to come",
"type": "minor",
"packageName": "just-scripts",
"email": "anik220798@gmail.com",
"commit": "912936dffcb2680426283c8f2a1560a957fb5f0c",
"date": "2019-07-07T13:52:24.824Z"
}

Просмотреть файл

@ -12,3 +12,4 @@ export * from './upgradeStackTask';
export * from './copyInstructionsTask';
export * from './prettierTask';
export * from './eslintTask';
export * from './webpackCLITask';

Просмотреть файл

@ -0,0 +1,42 @@
import { logger, TaskFunction } from 'just-task';
import { tryRequire } from '../tryRequire';
/**
* webpackCliInitTask - task for webpack-cli init command
*
* @param {string} customScaffold? - to pass any webpack-scaffold
* @param {Boolean=false} auto - to pass the --auto flag, which will generate a default webpack.config.js
* @returns TaskFunction
*/
export function webpackCliInitTask(customScaffold?: string, auto: Boolean = false): TaskFunction {
return async function webpackCli() {
const init = tryRequire('@webpack-cli/init').default;
if (!init) {
logger.warn('webpack-cli init requires three dependencies: @webpack-cli/init (preferred - as a devDependency)');
return;
}
logger.info(`Running Webpack-cli init `);
if (typeof customScaffold === 'undefined') {
if (auto) {
try {
init(null, null, null, '--auto');
} catch (error) {
throw `Webpack-cli init failed with ${error.length} error(s).`;
}
} else {
try {
init();
} catch (error) {
throw `Webpack-cli init failed with ${error.length} error(s).`;
}
}
} else {
logger.info(`Running the Scaffold ${customScaffold}`);
try {
init(null, null, customScaffold);
} catch (error) {
throw `Webpack-cli init failed with ${error.length} error(s).`;
}
}
};
}