// JavaScript Document

// Scripts written by YOURNAME @ YOURCOMPANY

module.exports = function (gulp, plugins) {
    // WIP: init task, initializes the project
    return function () {
        return Promise.all([
            new Promise ((resolve) => {
                // remove any specified optional modules
                gulp.src(global.settings.paths.src + "/**/*")
                    // check if a file is a binary
                    .pipe(plugins.is_binary())
                    // skip file if it's a binary
                    .pipe(plugins.through.obj(function (file, enc, next) {
                        if (file.isBinary()) {
                            next();
                            return;
                        }

                        // go to next file
                        next(null, file);
                    }))
                    // remove login code if --remove login is passed
                    .pipe(plugins.remove_code({login_html: plugins.argv.remove && plugins.argv.remove.includes("login") ? true : false, commentStart: "<!--", commentEnd: "-->"}))
                    .pipe(plugins.remove_code({login_css: plugins.argv.remove && plugins.argv.remove.includes("login") ? true : false, commentStart: "/*", commentEnd: "*/"}))
                    // remove tribe code if --remove tribe is passed
                    .pipe(plugins.remove_code({tribe_html: plugins.argv.remove && plugins.argv.remove.includes("tribe") ? true : false, commentStart: "<!--", commentEnd: "-->"}))
                    .pipe(plugins.remove_code({tribe_css: plugins.argv.remove && plugins.argv.remove.includes("tribe") ? true : false, commentStart: "/*", commentEnd: "*/"}))
                    // output to source directory
                    .pipe(gulp.dest(global.settings.paths.src))
                    .on("end", () => {
                        resolve();
                    });
            })
        ]).then(() => {
            return Promise.all([
                new Promise ((resolve) => {
                    // remove any empty files
                    plugins.glob(global.settings.paths.src + "/**/*", (err, files) => {
                        files.forEach((file) => {
                            if (plugins.fs.statSync(file).size <= 1) {
                                plugins.fs.unlinkSync(file);
                            }
                        });

                        return resolve();
                    });
                })
            ]).then(() => {
                return Promise.all([
                    // remove any empty folders
                    new Promise((resolve) => {
                        plugins.delete_empty(global.settings.paths.src + "/**/*", () => {});
                        return resolve();
                    })
                ]).then(() => {
                    // remove any remaining comments
                    return gulp.src(global.settings.paths.src + "/**/*")
                        .pipe(plugins.replace(/((?:\/\*|<!--)(?:end)?[rR]emoveIf\([^)]+\)(?:\*\/|-->))/g, ""))
                        .pipe(gulp.dest(global.settings.paths.src));
                });
            });
        });
    };
};

@@ -198,34 +198,8 @@
 urn 
-Promise.all(%5B%0A            
 new 
@@ -214,36 +214,32 @@
 ((resolve) =%3E %7B%0A
-    
             // r
@@ -287,20 +287,16 @@
         
-    
 gulp.src
@@ -325,36 +325,32 @@
 .src + %22/**/*%22)%0A
-    
                 
@@ -388,36 +388,32 @@
                 
-    
 .pipe(plugins.is
@@ -439,20 +439,16 @@
         
-   
- 
 // skip 
@@ -461,36 +461,32 @@
 f it's a binary%0A
-    
                 
@@ -556,28 +556,24 @@
             
-  
-  
 if (file.isB
@@ -603,28 +603,24 @@
             
-    
 next();%0A    
@@ -643,20 +643,16 @@
     
- 
-   
 return;%0A
     
@@ -647,20 +647,16 @@
 return;%0A
-    
         
@@ -690,20 +690,16 @@
         
-    
 // go to
@@ -709,20 +709,16 @@
 xt file%0A
-    
         
@@ -767,20 +767,12 @@
     
-    %7D))%0A    
+%7D))%0A
     
@@ -824,36 +824,32 @@
 login is passed%0A
-    
                 
@@ -1015,36 +1015,32 @@
                 
-  
-  
 .pipe(plugins.re
@@ -1186,36 +1186,32 @@
                 
-    
 // remove tribe 
@@ -1251,36 +1251,32 @@
                 
-  
-  
 .pipe(plugins.re
@@ -1426,36 +1426,32 @@
                 
-    
 .pipe(plugins.re
@@ -1605,20 +1605,16 @@
         
- 
-   
 // outpu
@@ -1635,20 +1635,16 @@
 rectory%0A
-    
         
@@ -1695,24 +1695,59 @@
 s.src))%0A    
+            // resolve the promise%0A
             
@@ -1789,20 +1789,16 @@
         
-  
-  
 resolve(
@@ -1792,36 +1792,32 @@
      resolve();%0A
-    
                 
@@ -1832,24 +1832,9 @@
     
-    %7D)%0A        %5D
+%7D
 ).th
@@ -1867,38 +1867,8 @@
 urn 
-Promise.all(%5B%0A                
 new 
@@ -1899,36 +1899,32 @@
                 
-    
 // remove any em
@@ -1941,36 +1941,32 @@
                 
-   
- 
 plugins.glob(glo
@@ -2037,20 +2037,16 @@
         
-    
 files.fo
@@ -2083,28 +2083,24 @@
             
-   
- 
 if (plugins.
@@ -2150,36 +2150,32 @@
                 
-    
 plugins.fs.unlin
@@ -2215,18 +2215,10 @@
     
-  
-  %7D%0A    
+%7D%0A
     
@@ -2254,35 +2254,24 @@
             
-    return 
 resolve();%0A 
@@ -2261,36 +2261,32 @@
      resolve();%0A
-    
                 
@@ -2305,28 +2305,9 @@
     
-    %7D)%0A            %5D
+%7D
 ).th
@@ -2321,49 +2321,8 @@
 %3E %7B%0A
-                return Promise.all(%5B%0A    
     
@@ -2365,63 +2365,8 @@
 ers%0A
-                    new Promise((resolve) =%3E %7B%0A        
     
@@ -2462,78 +2462,9 @@
     
-            return resolve();%0A                    %7D)%0A                %5D
+%7D
 ).th
@@ -2466,36 +2466,32 @@
 %7D).then(() =%3E %7B%0A
-    
                 
@@ -2539,27 +2539,16 @@
         
-    return 
 gulp.src
@@ -2577,36 +2577,32 @@
 .src + %22/**/*%22)%0A
-    
                 
@@ -2704,36 +2704,32 @@
                 
-    
 .pipe(gulp.dest(
@@ -2757,36 +2757,16 @@
 .src));%0A
-                %7D);%0A
         

Simplify init task a bit