johnny-cli
Version:
CLI for Johnny Deps
37 lines (32 loc) • 961 B
JavaScript
// @flow
import {dllWebpackConfig} from 'templates';
import fs from 'fs';
import path from 'path';
import webpack from 'webpack';
export default (DllParams: {
path: string,
}) => ({
create: async function(params: {
packages: Array<string>,
}) {
try {
fs.mkdirSync(DllParams.path);
} catch(error) {
throw 'Dll directory already exists. Please remove the dir or specify another one in --path option.';
}
await this.build({packages: params.packages});
},
// Run webpack in order to build dll
// Compilation starts if only callback function provided
build: (params: {
packages: Array<string>,
}) => new Promise((resolve, reject) => webpack(dllWebpackConfig({
packages: params.packages,
path : path.resolve(DllParams.path),
}), (err, stats) => {
// WARN Get error from webpack properly
if(err || stats.hasErrors())
throw `Dll webpack compilation failed: ${err || stats.toJson().errors.join('\n')}`
resolve();
})),
});