Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp task does not finish even when the process terminates with code 0

I have added a gulp task to remove directories in the given paths. The paths are read from an array. My gulp task runs properly and does the required job. The Task Runner explorer give the message of starting the task as well as the process terminating successfully with code 0. The problem is that it doesn't state that the task has finished. Due to this, my other tasks that are dependent on this task, cannot execute during build process automation.

const rmr = require('rmr');

// array containing the list of all paths of the folders to be deleted
const removeFoldersArr = [ 
    {
        Path: "wwww/scripts"
    },
    {
        Path: "www/styles"
    }
];

// Gulp Task to remove all files in a folder
gulp.task('cleanFolders', function () {
    return removeFoldersArr.map(function (folder) {
        rmr.sync(folder.Path);
    });
});

Inside Task Runner Explorer, the task starts but doesn't finish, though it terminates with code 0, as shown below:

cmd.exe /c gulp -b "D:\My Projects\Solution1" --color --gulpfile "D:\My Projects\Solution1\Gulpfile.js" cleanFolders
[18:04:23] Using gulpfile D:\My Projects\Solution1\Gulpfile.js
[18:04:23] Starting 'cleanFolders'...
Process terminated with code 0.
like image 970
Srishti Avatar asked Jan 11 '18 12:01

Srishti


2 Answers

The correct way is to return a promise.

Given an iterable (array or string), or a promise of an iterable, promise.all iterates over all the values in the iterable into an array and returns a promise that is fulfilled when all the item(s) in the array is(are) fulfilled.

Following is the code snippet of the solution:

gulp.task('cleanFolders', function () {
    return Promise.all([
        removeFoldersArr.map(function (folder) {
            rmr.sync(folder.Path);
        })
    ]);
});

Now, the process first finishes and then gets terminated.

Following is the output as shown in Task Runner Explorer:

cmd.exe /c gulp -b "D:\My Projects\Solution1" --color --gulpfile "D:\My Projects\Solution1\Gulpfile.js" cleanFolders
[12:25:01] Using gulpfile D:\My Projects\Solution1\Gulpfile.js
[12:45:01] Starting 'cleanFolders'...
[12:45:01] Finished 'cleanFolders' after 3.18 ms
Process terminated with code 0.
like image 189
Srishti Avatar answered Oct 13 '22 00:10

Srishti


After having this issue on VS2017, we looked to see that the issue we were having was related to version numbers 15.8.X, in which they shipped a new version of Node.js, version 10.6, and that basically broke gulp. It was terminating the process early with a code 0, but few if any of the processes were even allowed to finish.

Rearranging the web package management list to put $(PATH) before $(VSInstalledExternalTools) and having LTS version of Node on your path is what fixed it for us.

See: https://developercommunity.visualstudio.com/content/problem/311553/task-runner-cant-load-gruntfilejs.html

like image 36
Ty Crawford Avatar answered Oct 12 '22 23:10

Ty Crawford