{"size": 6709, "ext": "js", "max_stars_repo_path": "Gulpfile.js", "max_stars_repo_name": "finagin/Gulpfile.js", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Gulpfile.js", "max_issues_repo_name": "finagin/Gulpfile.js", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Gulpfile.js", "max_forks_repo_name": "finagin/Gulpfile.js", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.3169811321, "max_line_length": 79, "alphanum_fraction": 0.4645997913}
"use strict";

var fs = require("fs"),
    gulp = require("gulp"),
    csso = require("gulp-csso"),
    file = require('gulp-file'),
    rimraf = require("gulp-rimraf"),
    uglify = require("gulp-uglify"),
    stylus = require("gulp-stylus"),
    concat = require("gulp-concat"),
    browserSync = require("browser-sync"),
    sourcemaps = require("gulp-sourcemaps"),
    autoprefixer = require("gulp-autoprefixer"),

    defaults = function defaults(obj, def) {
        function req(obj, def) {
            for (var key in def) {
                if (obj[key] !== undefined) {
                    if (typeof obj[key] == "object") {
                        req(obj[key], def[key]);
                    }
                } else {
                    obj[key] = def[key];
                }
            }
        }

        req(obj, def);

        return obj;
    },

    settings = defaults(
        JSON.parse(fs.readFileSync("Gulpfile.json", "utf8")),
        {
            "path": {
                "src": "./src",
                "root": "./",
                "dist": "./assets/"
            },
            "proxy": {
                "protocol": "http://",
                "path": "localhost",
                "port": 8888
            },
            "gitignore": true
        }
    ),
    path = {
        src: settings.path.src,
        root: settings.path.root,
        dist: settings.path.dist,

        include: function include() {
            var a = Array.from(arguments);
            return a.join("/").replace(/\/+/g, "/");
        },
        exclude: function exclude() {
            return "!" + path.include.apply(this, arguments);
        }
    },
    proxy = {
        "protocol": settings.proxy.protocol,
        "path": settings.proxy.path,
        "port": settings.proxy.port,
        get url() {
            var url = "";

            url += this.protocol;
            url += this.path;
            url += (this.port != "80" ? (":" + this.port) : "");

            return url;
        }
    },
    buildTasks;


gulp.task("stylus:clear", function () {
    return gulp
        .src([
            path.include(path.dist, "css")
        ], {read: false})
        .pipe(rimraf({force: true}));
});
gulp.task("stylus:main", ["stylus:clear"], function () {
    return gulp
        .src([
            path.include(path.src, "stylus/**/**.{styl,css}"),

            path.exclude(path.src, "stylus/separate/**/**.{styl,css}"),
            path.exclude(path.src, "stylus/imports/**/**.{styl,css}")
        ])
        .pipe(sourcemaps.init())
        .pipe(stylus({
            compress: true
        }))
        .pipe(csso({
            sourceMap: true
        }))
        .pipe(concat("style.css"))
        .pipe(sourcemaps.write("./"))
        .pipe(gulp.dest(path.include(path.dist, "css")))
        .pipe(browserSync.stream());
});
gulp.task("stylus:separate", ["stylus:clear"], function () {
    return gulp
        .src([
            path.include(path.src, "stylus/separate/**/**.{styl,css}")
        ])
        .pipe(sourcemaps.init())
        .pipe(stylus({
            compress: true
        }))
        .pipe(sourcemaps.write("./"))
        .pipe(gulp.dest(path.include(path.dist, "css")))
        .pipe(browserSync.stream());
});


gulp.task("js:clear", function () {
    return gulp
        .src([
            path.include(path.dist, "js")
        ], {read: false})
        .pipe(rimraf({force: true}));
});
gulp.task("js:main", ["js:clear"], function () {
    return gulp
        .src([
            path.include(path.src, "js/**/**.js"),

            path.exclude(path.src, "js/separate/**/**.js")
        ])
        .pipe(sourcemaps.init())
        .pipe(uglify({
            compress: true
        }))
        .pipe(concat("main.js"))
        .pipe(sourcemaps.write("./"))
        .pipe(gulp.dest(path.include(path.dist, "js")));
});
gulp.task("js:separate", ["js:clear"], function () {
    return gulp
        .src([
            path.include(path.src, "js/separate/**/**.js")
        ])
        .pipe(sourcemaps.init())
        .pipe(uglify({
            compress: true
        }))
        .pipe(sourcemaps.write("./"))
        .pipe(gulp.dest(path.include(path.dist, "js")));
});
gulp.task("js:reload", ["js:main", "js:separate"], function () {
    return gulp
        .src([
            path.include(path.src + "js/**/**.js")
        ])
        .pipe(browserSync.stream());
});


gulp.task("other:clear", function () {
    return gulp
        .src([
            path.include(path.dist, "**/**.*"),

            path.exclude(path.dist, "css/**/**.*"),
            path.exclude(path.dist, "js/**/**.*")
        ], {read: false})
        .pipe(rimraf({force: true}));
});
gulp.task("other:copy", ["other:clear"], function () {
    return gulp
        .src([
            path.include(path.src, "**/**.*"),

            path.exclude(path.src, "stylus/**/**.*"),
            path.exclude(path.src, "js/**/**.*")
        ])
        .pipe(gulp.dest(path.include(path.dist)))
        .pipe(browserSync.stream());
});


gulp.task("git-ignore", function () {
    return file(".gitignore", "*", {src: true})
        .pipe(gulp.dest(path.dist));
});


gulp.task("php-html", function () {
    return gulp
        .src([
            path.include(path.root, "**/**.{php,html}")
        ])
        .pipe(browserSync.stream());
});


gulp.task("stylus", [
    "stylus:clear",
    "stylus:main",
    "stylus:separate"
]);
gulp.task("js", [
    "js:clear",
    "js:main",
    "js:separate",
    "js:reload"
]);
gulp.task("other", [
    "other:clear",
    "other:copy"
]);


gulp.task("watch", function (cb) {
    if (settings.proxy !== false) {
        browserSync.init({
            notify: true,
            https: false,
            open: true,
            proxy: {
                target: proxy.url,
                ws: true
            },

            serveStatic: [
                settings.path.dist
            ],
            localOnly: true
        }, cb);

        process.on("exit", function () {
            browserSync.exit();
        });
    }

    gulp.watch([
        path.include(path.src, "stylus/**/**.{styl,css}")
    ], ["stylus"]);
    gulp.watch([
        path.include(path.src, "js/**/**.js")
    ], ["js"]);
    gulp.watch([
        path.include(path.src, "**/**.*"),

        path.exclude(path.src, "stylus/**/**.*"),
        path.exclude(path.src, "js/**/**.*")
    ], ["other"]);
    gulp.watch([
        path.include(path.root, "**/**.{php,html}")
    ], ["php-html"]);

});

buildTasks = ["stylus", "js", "other"];
buildTasks.unshift.apply(buildTasks, settings.gitignore ? ["git-ignore"] : []);
gulp.task("build", buildTasks);


gulp.task("default", ["build", "watch"]);
