Skip to content

Commit

Permalink
fix: Display proper error when no config was found.
Browse files Browse the repository at this point in the history
Fixes #164
  • Loading branch information
danez committed Sep 1, 2018
1 parent 526a7ec commit 6326a10
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
13 changes: 12 additions & 1 deletion tasks/webpack-dev-server.js
Expand Up @@ -57,10 +57,21 @@ npm install --save-dev webpack-dev-server
grunt.registerTask('webpack-dev-server', 'Start a webpack-dev-server.', function webpackDevServerTask(cliTarget) {
const done = this.async();

const targets = cliTarget ? [cliTarget] : Object.keys(grunt.config([this.name]));
const config = grunt.config([this.name]);
const targets = cliTarget
? [cliTarget]
: config
? Object.keys(config)
: [];

let runningTargetCount = targets.length;
let keepalive = false;

if (runningTargetCount === 0) {
done(new Error('No configuration was found for webpack-dev-server. For further assistance on how to create the config refer to https://github.com/webpack-contrib/grunt-webpack/blob/master/README.md#grunt-webpack'));
return;
}

targets.forEach((target) => {
if (target === 'options') {
runningTargetCount--;
Expand Down
12 changes: 11 additions & 1 deletion tasks/webpack.js
Expand Up @@ -12,10 +12,20 @@ module.exports = (grunt) => {
grunt.registerTask('webpack', 'Run webpack.', function webpackTask(cliTarget) {
const done = this.async();

const targets = cliTarget ? [cliTarget] : Object.keys(grunt.config([this.name]));
const config = grunt.config([this.name]);
const targets = cliTarget
? [cliTarget]
: config
? Object.keys(config)
: [];
let runningTargetCount = targets.length;
let keepalive = false;

if (runningTargetCount === 0) {
done(new Error('No configuration was found for webpack. For further assistance on how to create the config refer to https://github.com/webpack-contrib/grunt-webpack/blob/master/README.md#grunt-webpack'));
return;
}

targets.forEach((target) => {
if (target === 'options') {
runningTargetCount--;
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/webpack/no-config/Gruntfile.js
@@ -0,0 +1,8 @@
const path = require('path');
const loadGruntWebpackTasks = require('../../../utils/loadGruntWebpackTasks');

module.exports = function (grunt) {
grunt.initConfig({});

loadGruntWebpackTasks(grunt);
};
1 change: 1 addition & 0 deletions tests/fixtures/webpack/no-config/entry.js
@@ -0,0 +1 @@
console.log(okey);
3 changes: 3 additions & 0 deletions tests/fixtures/webpack/no-config/exec.js
@@ -0,0 +1,3 @@
assertGrunt.failed();

t.regex(stdout, /No configuration was found for webpack./);

0 comments on commit 6326a10

Please sign in to comment.