import { taskMaker } from '../taskMaker';

import runSequence from 'run-sequence';
import gutil from 'gulp-util';
import conventionalRecommendedBump from 'conventional-recommended-bump';
import conventionalChangelog from 'conventional-changelog';


function releaseTasks(gulp) {
    taskMaker(gulp)
        .createTask({
            name: 'release',
            desc: 'Run a series of tasks to build, commit and tag your project',
            fn: release,
        })
        .createTask({
            name: 'release:changelog',
            desc: 'Generate a changelog for a new release',
            fn: releaseChangelog,
        })
        .createTask({
            name: 'release:suggestion',
            desc: 'Suggest what kind of version bump to perform',
            fn: releaseSuggestion,
            help: {
                aliases: ['suggestion'],
            },
        });


    function release(done) {
        runSequence.use(gulp)(
            'clean:dist',
            'eslint:fail',
            'test:fail',
            [ 'copy:dist', 'stylus:dist' ],
            'commit:dist',
            'version:branch',
            'commit:version',
            error => {
                if (error) {
                    gutil.log(error.message);
                } else {
                    gutil.log('RELEASE FINISHED SUCCESSFULLY');
                }
                done(error);
            }
        );
    }

    function releaseChangelog() {
        conventionalChangelog({ preset: 'angular'})
            .pipe(process.stdout);
    }

    function releaseSuggestion(done) {
        conventionalRecommendedBump({preset: 'angular'}, (n, releaseAs) => {
            gutil.log(gutil.colors.inverse('Recommended bump:', releaseAs));
            done();
        });
    }
}

export { releaseTasks };

@@ -36,16 +36,38 @@
 aker';%0A%0A
+import fs from 'fs';%0A%0A
 import r
@@ -1317,49 +1317,1189 @@
     
-gutil.log('RELEASE FINISHED SUCCESSFULLY'
+const pkg = JSON.parse(fs.readFileSync(process.cwd() + '/package.json', 'utf8'));%0A%0A                    gutil.log(gutil.colors.inverse(%60Release $%7Bpkg.version%7D finished successfully! :D%60));%0A                    gutil.log(gutil.colors.blue('Operations performed:'));%0A                    gutil.log(gutil.colors.blue(' %E2%80%A2 Linted all JS'));%0A                    gutil.log(gutil.colors.blue(' %E2%80%A2 Ran all unit tests'));%0A                    gutil.log(gutil.colors.blue(' %E2%80%A2 Copied JS files to dist/'));%0A                    gutil.log(gutil.colors.blue(' %E2%80%A2 Compiled Stylus files to dist/'));%0A                    gutil.log(gutil.colors.blue(' %E2%80%A2 Committed dist files'));%0A                    gutil.log(gutil.colors.blue(%60 %E2%80%A2 Bumped version to $%7Bpkg.version%7D%60));%0A                    gutil.log(gutil.colors.blue(' %E2%80%A2 Committed new version'));%0A                    gutil.log(gutil.colors.blue('============================='));%0A                    gutil.log(gutil.colors.inverse('What to do next:'));%0A                    gutil.log(gutil.colors.blue(%60 %E2%80%A2 Finish the release by running git flow release finish $%7Bpkg.version%7D%60));%0A                    gutil.log(gutil.colors.blue('=============================')
 );%0A 
@@ -2507,32 +2507,33 @@
               %7D%0A
+%0A
                 
@@ -2545,16 +2545,53 @@
 error);%0A
+                process.exit(error);%0A
         

add more verbose output after release sequence is done