<commit_before>var pkg         = require('./package.json'),
    fs          = require('fs'),
    path        = require('path'),
    glob        = require('glob'),
    mkdirp      = require('mkdirp'),
    gulp        = require('gulp'),
    gutil       = require('gulp-util'),
    concat      = require('gulp-concat'),
    ignore      = require('gulp-ignore'),
    rename      = require('gulp-rename'),
    rimraf      = require('gulp-rimraf'),
    replace     = require('gulp-replace'),
    header      = require('gulp-header'),
    less        = require('gulp-less'),
    minifycss   = require('gulp-minify-css'),
    uglify      = require('gulp-uglify'),
    watch       = require('gulp-watch'),
    tap         = require('gulp-tap'),
    zip         = require('gulp-zip'),
    runSequence = require('run-sequence'),
    browserSync = require('browser-sync'),
    Promise     = require('promise');

var watchmode    = gutil.env._.length && gutil.env._[0] == 'watch',
    watchCache   = {},
    watchfolders = ['src/**/*', 'themes/**/*.less', 'custom/**/*.less'],
    getThemes    = function(theme, all) {

        var list = [], themefolders = ["themes"];

        if (theme || all) {
            themefolders.push("custom");
        }

        themefolders.forEach(function(f){

            if(!fs.existsSync(f)) return;

            fs.readdirSync(f).forEach(function(t){

                if (theme && t!=theme) return;

                var path = f+'/'+t, uikit = path + '/uikit.less', customizer = path + '/uikit-customizer.less';
                if (!((fs.lstatSync(path).isDirectory() || fs.lstatSync(path).isSymbolicLink()) && fs.existsSync(uikit))) return;
                list.push({"name": t, "path": f+'/'+t, "uikit": uikit});
            });
        });


        return list;
    },

    themes    = (function(){

        var theme = gutil.env.t || gutil.env.theme || false,
            all   = gutil.env.all || gutil.env.a || theme;

        return getThemes(theme, all);
    })(),

    corejs = [
        './src/js/core/core.js',
        './src/js/core/touch.js',
        './src/js/core/utility.js',
        './src/js/core/smooth-scroll.js',
        './src/js/core/scrollspy.js',
        './src/js/core/toggle.js',
        './src/js/core/alert.js',
        './src/js/core/button.js',
        './src/js/core/dropdown.js',
        './src/js/core/grid.js',
        './src/js/core/modal.js',
        './src/js/core/nav.js',
        './src/js/core/offcanvas.js',
        './src/js/core/switcher.js',
        './src/js/core/tab.js',
        './src/js/core/cover.js'
    ];


gulp.task('default', ['dist', 'build-docs', 'indexthemes'], function(done) {

    if(gutil.env.p || gutil.env.prefix) {
        runSequence('prefix', function(){
            done();
        });
    } else {
        done();
    }
});

gulp.task('dist', ['dist-themes-core'], function(done) {

    runSequence('sass', 'dist-core-minify', 'dist-core-header', 'browser-reload', 'dist-bower-file', function(){

        if (gutil.env.m || gutil.env.min) {
            gulp.src(['./dist/**/*.css', './dist/**/*.js', '!./dist/**/*.min.css', '!./dist/**/*.min.js'])
            .pipe(rimraf()).on('end', function(){
                done();
            });
        } else {
            done();
        }

    });
});

/*
 * development related tasks
 * ---------------------------------------------------------*/
gulp.task('browser-sync', function() {
    browserSync({
        server: {
            baseDir: "./",
            startPath: "/tests",
            middleware: function (req, res, next) {

                var m, theme;

                if (m = req.url.match(/dist\/css\/components\/(.*)\.css/)) {
                    theme = m[1].split('.')[1] || 'default';
                } else if (m = req.url.match(/dist\/css\/(.*)\.css/)) {
                    theme = m[1].split('.')[1] || 'default';
                }

                if (theme) {

                    if (!watchCache[theme]) {

                        watchCache[theme] = new Promise(function(resolve){

                            var tmp = themes;

                            themes = getThemes(theme);

                            runSequence('dist-themes-core', function(){
                                themes = tmp;
                                resolve();
                            });
                        });
                    }

                    watchCache[theme].then(function(){
                        next();
                    });

                } else {
                    next();
                }

            }
        }
    });
});

gulp.task('browser-reload', function (done) {
    watchCache = {};
    browserSync.reload();
    done();
});

gulp.task('browsersync', ['browser-sync', 'indexthemes'], function(done) {

    watchfolders = ['src/**/*', 'themes/**/*', 'custom/**/*.less'];

    gulp.watch(watchfolders, function(files) {
        runSequence('browser-reload');
    });
});

gulp.task('watch', ['dist-clean', 'indexthemes'], function(done) {

    gulp.watch(watchfolders, function(files) {
        runSequence('dist');
    });
});


gulp.task('help', function(done) {

    for(var p in {
        '-c, --clean': '',
        '-m, --min': '',
        '-a, --all': '',
        '-t, --theme': '',
        '-p, --prefix': ''
    }) {<commit_msg>watchfolders updated<commit_after>var pkg         = require('./package.json'),
    fs          = require('fs'),
    path        = require('path'),
    glob        = require('glob'),
    mkdirp      = require('mkdirp'),
    gulp        = require('gulp'),
    gutil       = require('gulp-util'),
    concat      = require('gulp-concat'),
    ignore      = require('gulp-ignore'),
    rename      = require('gulp-rename'),
    rimraf      = require('gulp-rimraf'),
    replace     = require('gulp-replace'),
    header      = require('gulp-header'),
    less        = require('gulp-less'),
    minifycss   = require('gulp-minify-css'),
    uglify      = require('gulp-uglify'),
    watch       = require('gulp-watch'),
    tap         = require('gulp-tap'),
    zip         = require('gulp-zip'),
    runSequence = require('run-sequence'),
    browserSync = require('browser-sync'),
    Promise     = require('promise');

var watchmode    = gutil.env._.length && gutil.env._[0] == 'watch',
    watchCache   = {},
    watchfolders = ['src/**/*', 'themes/**/*.less', 'custom/**/*.less'],
    getThemes    = function(theme, all) {

        var list = [], themefolders = ["themes"];

        if (theme || all) {
            themefolders.push("custom");
        }

        themefolders.forEach(function(f){

            if(!fs.existsSync(f)) return;

            fs.readdirSync(f).forEach(function(t){

                if (theme && t!=theme) return;

                var path = f+'/'+t, uikit = path + '/uikit.less', customizer = path + '/uikit-customizer.less';
                if (!((fs.lstatSync(path).isDirectory() || fs.lstatSync(path).isSymbolicLink()) && fs.existsSync(uikit))) return;
                list.push({"name": t, "path": f+'/'+t, "uikit": uikit});
            });
        });


        return list;
    },

    themes    = (function(){

        var theme = gutil.env.t || gutil.env.theme || false,
            all   = gutil.env.all || gutil.env.a || theme;

        return getThemes(theme, all);
    })(),

    corejs = [
        './src/js/core/core.js',
        './src/js/core/touch.js',
        './src/js/core/utility.js',
        './src/js/core/smooth-scroll.js',
        './src/js/core/scrollspy.js',
        './src/js/core/toggle.js',
        './src/js/core/alert.js',
        './src/js/core/button.js',
        './src/js/core/dropdown.js',
        './src/js/core/grid.js',
        './src/js/core/modal.js',
        './src/js/core/nav.js',
        './src/js/core/offcanvas.js',
        './src/js/core/switcher.js',
        './src/js/core/tab.js',
        './src/js/core/cover.js'
    ];


gulp.task('default', ['dist', 'build-docs', 'indexthemes'], function(done) {

    if(gutil.env.p || gutil.env.prefix) {
        runSequence('prefix', function(){
            done();
        });
    } else {
        done();
    }
});

gulp.task('dist', ['dist-themes-core'], function(done) {

    runSequence('sass', 'dist-core-minify', 'dist-core-header', 'browser-reload', 'dist-bower-file', function(){

        if (gutil.env.m || gutil.env.min) {
            gulp.src(['./dist/**/*.css', './dist/**/*.js', '!./dist/**/*.min.css', '!./dist/**/*.min.js'])
            .pipe(rimraf()).on('end', function(){
                done();
            });
        } else {
            done();
        }

    });
});

/*
 * development related tasks
 * ---------------------------------------------------------*/
gulp.task('browser-sync', function() {
    browserSync({
        server: {
            baseDir: "./",
            startPath: "/tests",
            middleware: function (req, res, next) {

                var m, theme;

                if (m = req.url.match(/dist\/css\/components\/(.*)\.css/)) {
                    theme = m[1].split('.')[1] || 'default';
                } else if (m = req.url.match(/dist\/css\/(.*)\.css/)) {
                    theme = m[1].split('.')[1] || 'default';
                }

                if (theme) {

                    if (!watchCache[theme]) {

                        watchCache[theme] = new Promise(function(resolve){

                            var tmp = themes;

                            themes = getThemes(theme);

                            runSequence('dist-themes-core', function(){
                                themes = tmp;
                                resolve();
                            });
                        });
                    }

                    watchCache[theme].then(function(){
                        next();
                    });

                } else {
                    next();
                }

            }
        }
    });
});

gulp.task('browser-reload', function (done) {
    watchCache = {};
    browserSync.reload();
    done();
});

gulp.task('browsersync', ['browser-sync', 'indexthemes'], function(done) {

    watchfolders = ['src/**/*', 'themes/**/*.less', 'custom/**/*.less'];

    gulp.watch(watchfolders, function(files) {
        runSequence('browser-reload');
    });
});

gulp.task('watch', ['dist-clean', 'indexthemes'], function(done) {

    gulp.watch(watchfolders, function(files) {
        runSequence('dist');
    });
});


gulp.task('help', function(done) {

    for(var p in {
        '-c, --clean': '',
        '-m, --min': '',
        '-a, --all': '',
        '-t, --theme': '',
        '-p, --prefix': ''
    }) {
{'fraction_non_alphanumeric': 0.21068888056907525, 'fraction_numerical': 0.0009359790340696368, 'mean_word_length': 1.507627317531096, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '444608', 'n_tokens_mistral': 3370, 'n_tokens_neox': 3265, 'n_words': 503}