<commit_before>var gulp = require('gulp');
var concat = require('gulp-concat');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var gulpDebug = require('gulp-debug');
var mainNpmFiles = require('npmfiles');
var del = require('del');
var path = require('path');
var cached = require('gulp-cached');
var remember = require('gulp-remember');
var inject = require('gulp-inject');
var gulpif = require('gulp-if');
var gutil = require('gulp-util');
var zip = require('gulp-zip');
var bump = require('gulp-bump');
var semver = require('semver');
var git = require('gulp-git');
var replace = require('gulp-replace');
var release = require('gulp-github-release');
var cleanCSS = require('gulp-clean-css');
var modifyCssUrls = require('gulp-modify-css-urls');
var sort = require('gulp-sort');
var scanner = require('i18next-scanner');
var jsonConcat = require('gulp-json-concat');
var rename = require('gulp-rename');
var browserSync = require('browser-sync');
var merge = require('merge-stream');

const server = browserSync.create();

var debug = false;

var paths = {
    // see overrides in package.json
    scriptsConfig: mainNpmFiles().filter(f => RegExp('url-search-params/.*\\.js', 'i').test(f)),
    scripts: [
        'node_modules/jquery/dist/jquery.js',
        'node_modules/tether/dist/js/tether.js',
        'node_modules/async/lib/async.js',
        'node_modules/leaflet/dist/leaflet-src.js'
    ]
        .concat(
            mainNpmFiles().filter(
                f =>
                    RegExp('.*\\.js', 'i').test(f) &&
                    !RegExp('.*\\.min\\.js', 'i').test(f) &&
                    !RegExp('url-search-params/.*\\.js', 'i').test(f)
            )
        )
        .concat([
            'js/Browser.js',
            'js/Util.js',
            'js/Map.js',
            'js/LayersConfig.js',
            'js/router/BRouter.js',
            'js/plugin/*.js',
            'js/control/*.js',
            'js/index.js'
        ]),
    styles: mainNpmFiles()
        .filter(f => RegExp('.*\\.css', 'i').test(f) && !RegExp('.*\\.min\\.css', 'i').test(f))
        .concat('css/*.css'),
    images: mainNpmFiles().filter(f => RegExp('.*.+(png|gif|svg)', 'i').test(f)),
    fonts: mainNpmFiles().filter(f => RegExp('font-awesome/fonts/.*', 'i').test(f)),
    locales: 'locales/*.json',
    layers: 'layers/**/*.geojson',
    layersDestName: 'layers.js',
    layersConfig: [
        'layers/config/config.js',
        'layers/config/tree.js',
        'layers/config/overrides.js',
        'layers/config/geometry.js'
    ],
    layersConfigDestName: 'layersConf.js',
    zip: ['dist/**', 'index.html', 'config.template.js', 'keys.template.js'],
    dest: 'dist',
    destName: 'brouter-web'
};

gulp.task('clean', function(cb) {
    del(paths.dest + '/**/*', cb);
});

// libs that require loading before config.js
gulp.task('scripts_config', function() {
    // just copy for now
    return gulp.src(paths.scriptsConfig).pipe(gulp.dest(paths.dest));
});

gulp.task('scripts', function() {
    if (debug) gutil.log(gutil.colors.yellow('Running in Debug mode'));
    else gutil.log(gutil.colors.green('Running in Release mode'));

    return gulp
        .src(paths.scripts, { base: '.' })
        .pipe(sourcemaps.init())
        .pipe(cached('scripts'))
        .pipe(gulpif(!debug, uglify()))
        .pipe(remember('scripts'))
        .pipe(concat(paths.destName + '.js'))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(paths.dest));
});

// separate, fallback task for debugging (switch manually in index.html)
gulp.task('concat', function() {
    return gulp
        .src(paths.scripts)
        .pipe(concat(paths.destName + '.src.js'))
        .pipe(gulp.dest(paths.dest));
});

gulp.task('styles', function() {
    return gulp
        .src(paths.styles)
        .pipe(
            modifyCssUrls({
                modify(url, filePath) {
                    var distUrl = url;
                    var imageExt = ['.png', '.gif', '.svg'];

                    if (imageExt.indexOf(path.extname(url)) !== -1) {
                        distUrl = 'images/' + path.basename(url);
                    } else if (url.indexOf('font') !== -1) {
                        distUrl = 'fonts/' + path.basename(url);
                    }

                    return distUrl;
                }
            })
        )
        .pipe(concat(paths.destName + '.css'))
        .pipe(
            cleanCSS({
                rebase: false
            })
        )
        .pipe(postcss([autoprefixer({ remove: false })]))
        .pipe(gulp.dest(paths.dest));
});

gulp.task('images', function() {
    return gulp.src(paths.images).pipe(gulp.dest(paths.dest + '/images'));
});

gulp.task('fonts', function() {
    return gulp.src(paths.fonts).pipe(gulp.dest(paths.dest + '/fonts'));
});

gulp.task('locales', function() {
    return gulp.src(paths.locales).pipe(gulp.dest(paths.dest + '/locales'));
});

gulp.task('reload', function(done) {
    server.reload();
    done();
});

gulp.task('watch', function() {
    debug = true;
    var watcher = gulp.watch(paths.scripts, gulp.series('scripts', 'reload'));
    watcher.on('change', function(event) {
        if (event.type === 'deleted') {
            delete cached.caches.scripts[event.path];
            remember.forget('scripts', event.path);
        }
    });
    gulp.watch(paths.locales, gulp.series('locales', 'reload'));
    gulp.watch(paths.styles, gulp.series('styles', 'reload'));
    gulp.watch(paths.layersConfig, gulp.series('layers_config', 'reload'));
    gulp.watch(
        ['./index.html']
            .concat(paths.images)
            .concat(paths.fonts)
            .concat(paths.locales),
        gulp.series('reload')
    );
});

// Print paths to console, for manually debugging the gulp build
// (comment out corresponding line of paths to print)
gulp.task('log', function() {
    // var src = paths.scripts
    // var src = paths.styles
    // var src = paths.images
    // var src = paths.locales
    var src = paths.scripts
        .concat(paths.styles)
        .concat(paths.images)
        .concat(paths.locales);

    return gulp.src(src).pipe(gulpDebug());
});

gulp.task('inject', function() {
    var target = gulp.src('index.html');
    var sources = gulp.src(paths.scripts.concat(paths.styles), {
        base: '.',
        read: false
    });

    return target.pipe(inject(sources, { relative: true })).pipe(gulp.dest('.'));
});

var pkg = require('./package.json');
var tags = { patch: 'patch', minor: 'minor', major: 'major' };
var nextVersion;
var ghToken;

gulp.task('release:init', function(cb) {
    var tag = gutil.env.tag;
    if (!tag) {
        return cb(new Error('--tag is required'));
    }
    if (['major', 'minor', 'patch'].indexOf(tag) < 0) {
        return cb(new Error('--tag must be major, minor or patch'));
    }
    ghToken = gutil.env.token;
    if (!ghToken) {
        return cb(new Error('--token is required (github personnal access token'));
    }
    if (ghToken.length != 40) {
        return cb(new Error('--token length must be 40'));
    }

    nextVersion = semver.inc(pkg.version, tag);

    git.status({ args: '--porcelain', quiet: true }, function(err, stdout) {
        if (err) return cb(err);
        if (stdout.length > 0) {
            return cb(new Error('Repository is not clean. Please commit or stash your pending modification'));
        }

        cb();
    });
});

gulp.task('bump:json', function() {
    gutil.log(gutil.colors.green('Bump to ' + nextVersion));
    return gulp
        .src(['./package.json'])
        .pipe(bump({ version: nextVersion }))
        .pipe(gulp.dest('./'));
});

gulp.task('bump:html', function() {
    return gulp
        .src('./index.html')
        .pipe(replace(/(.*)<\/sup>/, '' + nextVersion + ''))
        .pipe(gulp.dest('.'));
});

gulp.task('bump', gulp.series('bump:json', 'bump:html'));

gulp.task('release:commit', function() {
    return gulp.src(['./index.html', './package.json']).pipe(git.commit('release: ' + nextVersion));
});

gulp.task('release:tag', function(cb) {
    return git.tag(nextVersion, '', cb);
});

gulp.task('release:push', function(cb) {
    git.push('origin', 'master', { args: '--tags' }, cb);
});

gulp.task('i18next', function() {
    return gulp
        .src(['index.html', 'locales/keys.js', 'layers/config/overrides.js', 'js/**/*.js'])
        .pipe(sort())
        .pipe(
            scanner({
                lngs: ['en'], // we only generate English version, other languages are handled by transifex via yarn transifex-pull/push
                removeUnusedKeys: true,
                sort: true,
                resource: {
                    // the source path is relative to current working directory
                    loadPath: 'locales/{{lng}}.json',

                    // the destination path is relative to your `gulp.dest()` path
                    savePath: 'locales/{{lng}}.json'
                }
            })
        )
        .pipe(gulp.dest('.'));
});

gulp.task('layers_config', function() {
    return gulp
        .src(paths.layersConfig)
        .pipe(concat(paths.layersConfigDestName))
        .pipe(gulp.dest(paths.dest));
});

// Bundles layer files. To download and extract run "yarn layers"
gulp.task('layers', function() {
    return (
        gulp
            .src(paths.layers)
            // Workaround to get file extension removed from the dictionary key
            .pipe(rename({ extname: '.json' }))
            .pipe(
                jsonConcat(paths.layersDestName, function(data) {
                    var header =
                        '// Licensed under the MIT License (https://github.com/nrenner/brouter-web#license + Credits and Licenses),\n' +
                        '// except JOSM imagery database (dataSource=JOSM) is licensed under Creative Commons (CC-BY-SA),\n' +
                        '// see https://josm.openstreetmap.de/wiki/Maps#Otherimportantinformation\n';
                    return Buffer.from(header + 'BR.layerIndex = ' + JSON.stringify(data, null, 2) + ';');
                })
            )
            .pipe(gulp.dest(paths.dest))
    );
});

gulp.task(
    'default',
    gulp.series('clean', 'scripts_config', 'layers_config', 'layers', 'scripts', 'styles', 'images', 'fonts', 'locales')
);

gulp.task(
    'debug',
    gulp.series(function(cb) {
        debug = true;
        cb();
    }, 'default')
);

gulp.task(
    'serve',
    gulp.series('debug', function(cb) {
        server.init({
            server: {
                baseDir: './'
            }
        });
        cb();
    })
);

gulp.task('release:zip', function() {
    gutil.log(gutil.colors.green('Build brouter-web.' + nextVersion + '.zip'));
    return gulp
        .src(paths.zip, {
            base: '.'
        })
        .pipe(zip('brouter-web.' + nextVersion + '.zip'))
        .pipe(gulp.dest('.'));
});

gulp.task('release:zip_standalone', function() {
    var version = pkg.version;
    var destName = 'brouter-web-standalone.' + version + '.zip';

    gutil.log(gutil.colors.green('Build ' + destName));

    var brouterWeb = gulp
        .src(paths.zip, {
            base: '.'
        })
        .pipe(
            rename(function(path) {
                path.dirname = 'brouter-web/' + path.dirname;
            })
        );

    var root = gulp.src(['resources/standalone/run.sh', 'resources/standalone/segments4']);

    var serverRoot = gulp
        .src(
            [
                'misc/readmes/profile_developers_guide.txt',
                'brouter-server/target/brouter-server-*-jar-with-dependencies.jar'
            ],
            {
                cwd: path.join(process.cwd(), '../brouter')
            }
        )
        .pipe(
            rename(function(path) {
                if (path.basename.startsWith('brouter-server-')) {
                    path.basename = 'brouter';
                }
            })
        );

    var serverProfiles = gulp.src(
        [
            'profiles2/**',
            '!profiles2/all.brf',
            '!profiles2/car-eco-suspect_scan.brf',
            '!profiles2/car-traffic_analysis.brf',
            '!profiles2/softaccess.brf'
        ],
        {
            cwd: path.join(process.cwd(), '../brouter/misc/'),
            base: '../brouter/misc/'
        }
    );

    var serverScripts = gulp.src(['standalone/**'], {
        cwd: path.join(process.cwd(), '../brouter/misc/scripts/'),
        base: '../brouter/misc/scripts/'
    });

    return merge(brouterWeb, root, serverRoot, serverProfiles, serverScripts)
        .pipe(zip(destName))
        .pipe(gulp.dest('.'));
});

gulp.task('release:publish', function() {
    return gulp.src('./brouter-web.' + nextVersion + '.zip').pipe(
        release({
            tag: nextVersion,
            token: ghToken,
            manifest: pkg
        })
    );
});

gulp.task(
    'release',
    gulp.series(
        'release:init',
        'bump',
        'release:commit',
        'release:tag',
        'release:push',
        'default',
        'release:zip',
        'release:publish'
    )
);
<commit_msg>Disable opening browser on gulp serve<commit_after>var gulp = require('gulp');
var concat = require('gulp-concat');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var gulpDebug = require('gulp-debug');
var mainNpmFiles = require('npmfiles');
var del = require('del');
var path = require('path');
var cached = require('gulp-cached');
var remember = require('gulp-remember');
var inject = require('gulp-inject');
var gulpif = require('gulp-if');
var gutil = require('gulp-util');
var zip = require('gulp-zip');
var bump = require('gulp-bump');
var semver = require('semver');
var git = require('gulp-git');
var replace = require('gulp-replace');
var release = require('gulp-github-release');
var cleanCSS = require('gulp-clean-css');
var modifyCssUrls = require('gulp-modify-css-urls');
var sort = require('gulp-sort');
var scanner = require('i18next-scanner');
var jsonConcat = require('gulp-json-concat');
var rename = require('gulp-rename');
var browserSync = require('browser-sync');
var merge = require('merge-stream');

const server = browserSync.create();

var debug = false;

var paths = {
    // see overrides in package.json
    scriptsConfig: mainNpmFiles().filter(f => RegExp('url-search-params/.*\\.js', 'i').test(f)),
    scripts: [
        'node_modules/jquery/dist/jquery.js',
        'node_modules/tether/dist/js/tether.js',
        'node_modules/async/lib/async.js',
        'node_modules/leaflet/dist/leaflet-src.js'
    ]
        .concat(
            mainNpmFiles().filter(
                f =>
                    RegExp('.*\\.js', 'i').test(f) &&
                    !RegExp('.*\\.min\\.js', 'i').test(f) &&
                    !RegExp('url-search-params/.*\\.js', 'i').test(f)
            )
        )
        .concat([
            'js/Browser.js',
            'js/Util.js',
            'js/Map.js',
            'js/LayersConfig.js',
            'js/router/BRouter.js',
            'js/plugin/*.js',
            'js/control/*.js',
            'js/index.js'
        ]),
    styles: mainNpmFiles()
        .filter(f => RegExp('.*\\.css', 'i').test(f) && !RegExp('.*\\.min\\.css', 'i').test(f))
        .concat('css/*.css'),
    images: mainNpmFiles().filter(f => RegExp('.*.+(png|gif|svg)', 'i').test(f)),
    fonts: mainNpmFiles().filter(f => RegExp('font-awesome/fonts/.*', 'i').test(f)),
    locales: 'locales/*.json',
    layers: 'layers/**/*.geojson',
    layersDestName: 'layers.js',
    layersConfig: [
        'layers/config/config.js',
        'layers/config/tree.js',
        'layers/config/overrides.js',
        'layers/config/geometry.js'
    ],
    layersConfigDestName: 'layersConf.js',
    zip: ['dist/**', 'index.html', 'config.template.js', 'keys.template.js'],
    dest: 'dist',
    destName: 'brouter-web'
};

gulp.task('clean', function(cb) {
    del(paths.dest + '/**/*', cb);
});

// libs that require loading before config.js
gulp.task('scripts_config', function() {
    // just copy for now
    return gulp.src(paths.scriptsConfig).pipe(gulp.dest(paths.dest));
});

gulp.task('scripts', function() {
    if (debug) gutil.log(gutil.colors.yellow('Running in Debug mode'));
    else gutil.log(gutil.colors.green('Running in Release mode'));

    return gulp
        .src(paths.scripts, { base: '.' })
        .pipe(sourcemaps.init())
        .pipe(cached('scripts'))
        .pipe(gulpif(!debug, uglify()))
        .pipe(remember('scripts'))
        .pipe(concat(paths.destName + '.js'))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(paths.dest));
});

// separate, fallback task for debugging (switch manually in index.html)
gulp.task('concat', function() {
    return gulp
        .src(paths.scripts)
        .pipe(concat(paths.destName + '.src.js'))
        .pipe(gulp.dest(paths.dest));
});

gulp.task('styles', function() {
    return gulp
        .src(paths.styles)
        .pipe(
            modifyCssUrls({
                modify(url, filePath) {
                    var distUrl = url;
                    var imageExt = ['.png', '.gif', '.svg'];

                    if (imageExt.indexOf(path.extname(url)) !== -1) {
                        distUrl = 'images/' + path.basename(url);
                    } else if (url.indexOf('font') !== -1) {
                        distUrl = 'fonts/' + path.basename(url);
                    }

                    return distUrl;
                }
            })
        )
        .pipe(concat(paths.destName + '.css'))
        .pipe(
            cleanCSS({
                rebase: false
            })
        )
        .pipe(postcss([autoprefixer({ remove: false })]))
        .pipe(gulp.dest(paths.dest));
});

gulp.task('images', function() {
    return gulp.src(paths.images).pipe(gulp.dest(paths.dest + '/images'));
});

gulp.task('fonts', function() {
    return gulp.src(paths.fonts).pipe(gulp.dest(paths.dest + '/fonts'));
});

gulp.task('locales', function() {
    return gulp.src(paths.locales).pipe(gulp.dest(paths.dest + '/locales'));
});

gulp.task('reload', function(done) {
    server.reload();
    done();
});

gulp.task('watch', function() {
    debug = true;
    var watcher = gulp.watch(paths.scripts, gulp.series('scripts', 'reload'));
    watcher.on('change', function(event) {
        if (event.type === 'deleted') {
            delete cached.caches.scripts[event.path];
            remember.forget('scripts', event.path);
        }
    });
    gulp.watch(paths.locales, gulp.series('locales', 'reload'));
    gulp.watch(paths.styles, gulp.series('styles', 'reload'));
    gulp.watch(paths.layersConfig, gulp.series('layers_config', 'reload'));
    gulp.watch(
        ['./index.html']
            .concat(paths.images)
            .concat(paths.fonts)
            .concat(paths.locales),
        gulp.series('reload')
    );
});

// Print paths to console, for manually debugging the gulp build
// (comment out corresponding line of paths to print)
gulp.task('log', function() {
    // var src = paths.scripts
    // var src = paths.styles
    // var src = paths.images
    // var src = paths.locales
    var src = paths.scripts
        .concat(paths.styles)
        .concat(paths.images)
        .concat(paths.locales);

    return gulp.src(src).pipe(gulpDebug());
});

gulp.task('inject', function() {
    var target = gulp.src('index.html');
    var sources = gulp.src(paths.scripts.concat(paths.styles), {
        base: '.',
        read: false
    });

    return target.pipe(inject(sources, { relative: true })).pipe(gulp.dest('.'));
});

var pkg = require('./package.json');
var tags = { patch: 'patch', minor: 'minor', major: 'major' };
var nextVersion;
var ghToken;

gulp.task('release:init', function(cb) {
    var tag = gutil.env.tag;
    if (!tag) {
        return cb(new Error('--tag is required'));
    }
    if (['major', 'minor', 'patch'].indexOf(tag) < 0) {
        return cb(new Error('--tag must be major, minor or patch'));
    }
    ghToken = gutil.env.token;
    if (!ghToken) {
        return cb(new Error('--token is required (github personnal access token'));
    }
    if (ghToken.length != 40) {
        return cb(new Error('--token length must be 40'));
    }

    nextVersion = semver.inc(pkg.version, tag);

    git.status({ args: '--porcelain', quiet: true }, function(err, stdout) {
        if (err) return cb(err);
        if (stdout.length > 0) {
            return cb(new Error('Repository is not clean. Please commit or stash your pending modification'));
        }

        cb();
    });
});

gulp.task('bump:json', function() {
    gutil.log(gutil.colors.green('Bump to ' + nextVersion));
    return gulp
        .src(['./package.json'])
        .pipe(bump({ version: nextVersion }))
        .pipe(gulp.dest('./'));
});

gulp.task('bump:html', function() {
    return gulp
        .src('./index.html')
        .pipe(replace(/(.*)<\/sup>/, '' + nextVersion + ''))
        .pipe(gulp.dest('.'));
});

gulp.task('bump', gulp.series('bump:json', 'bump:html'));

gulp.task('release:commit', function() {
    return gulp.src(['./index.html', './package.json']).pipe(git.commit('release: ' + nextVersion));
});

gulp.task('release:tag', function(cb) {
    return git.tag(nextVersion, '', cb);
});

gulp.task('release:push', function(cb) {
    git.push('origin', 'master', { args: '--tags' }, cb);
});

gulp.task('i18next', function() {
    return gulp
        .src(['index.html', 'locales/keys.js', 'layers/config/overrides.js', 'js/**/*.js'])
        .pipe(sort())
        .pipe(
            scanner({
                lngs: ['en'], // we only generate English version, other languages are handled by transifex via yarn transifex-pull/push
                removeUnusedKeys: true,
                sort: true,
                resource: {
                    // the source path is relative to current working directory
                    loadPath: 'locales/{{lng}}.json',

                    // the destination path is relative to your `gulp.dest()` path
                    savePath: 'locales/{{lng}}.json'
                }
            })
        )
        .pipe(gulp.dest('.'));
});

gulp.task('layers_config', function() {
    return gulp
        .src(paths.layersConfig)
        .pipe(concat(paths.layersConfigDestName))
        .pipe(gulp.dest(paths.dest));
});

// Bundles layer files. To download and extract run "yarn layers"
gulp.task('layers', function() {
    return (
        gulp
            .src(paths.layers)
            // Workaround to get file extension removed from the dictionary key
            .pipe(rename({ extname: '.json' }))
            .pipe(
                jsonConcat(paths.layersDestName, function(data) {
                    var header =
                        '// Licensed under the MIT License (https://github.com/nrenner/brouter-web#license + Credits and Licenses),\n' +
                        '// except JOSM imagery database (dataSource=JOSM) is licensed under Creative Commons (CC-BY-SA),\n' +
                        '// see https://josm.openstreetmap.de/wiki/Maps#Otherimportantinformation\n';
                    return Buffer.from(header + 'BR.layerIndex = ' + JSON.stringify(data, null, 2) + ';');
                })
            )
            .pipe(gulp.dest(paths.dest))
    );
});

gulp.task(
    'default',
    gulp.series('clean', 'scripts_config', 'layers_config', 'layers', 'scripts', 'styles', 'images', 'fonts', 'locales')
);

gulp.task(
    'debug',
    gulp.series(function(cb) {
        debug = true;
        cb();
    }, 'default')
);

gulp.task(
    'serve',
    gulp.series('debug', function(cb) {
        server.init({
            server: {
                baseDir: './'
            },
            open: false
        });
        cb();
    })
);

gulp.task('release:zip', function() {
    gutil.log(gutil.colors.green('Build brouter-web.' + nextVersion + '.zip'));
    return gulp
        .src(paths.zip, {
            base: '.'
        })
        .pipe(zip('brouter-web.' + nextVersion + '.zip'))
        .pipe(gulp.dest('.'));
});

gulp.task('release:zip_standalone', function() {
    var version = pkg.version;
    var destName = 'brouter-web-standalone.' + version + '.zip';

    gutil.log(gutil.colors.green('Build ' + destName));

    var brouterWeb = gulp
        .src(paths.zip, {
            base: '.'
        })
        .pipe(
            rename(function(path) {
                path.dirname = 'brouter-web/' + path.dirname;
            })
        );

    var root = gulp.src(['resources/standalone/run.sh', 'resources/standalone/segments4']);

    var serverRoot = gulp
        .src(
            [
                'misc/readmes/profile_developers_guide.txt',
                'brouter-server/target/brouter-server-*-jar-with-dependencies.jar'
            ],
            {
                cwd: path.join(process.cwd(), '../brouter')
            }
        )
        .pipe(
            rename(function(path) {
                if (path.basename.startsWith('brouter-server-')) {
                    path.basename = 'brouter';
                }
            })
        );

    var serverProfiles = gulp.src(
        [
            'profiles2/**',
            '!profiles2/all.brf',
            '!profiles2/car-eco-suspect_scan.brf',
            '!profiles2/car-traffic_analysis.brf',
            '!profiles2/softaccess.brf'
        ],
        {
            cwd: path.join(process.cwd(), '../brouter/misc/'),
            base: '../brouter/misc/'
        }
    );

    var serverScripts = gulp.src(['standalone/**'], {
        cwd: path.join(process.cwd(), '../brouter/misc/scripts/'),
        base: '../brouter/misc/scripts/'
    });

    return merge(brouterWeb, root, serverRoot, serverProfiles, serverScripts)
        .pipe(zip(destName))
        .pipe(gulp.dest('.'));
});

gulp.task('release:publish', function() {
    return gulp.src('./brouter-web.' + nextVersion + '.zip').pipe(
        release({
            tag: nextVersion,
            token: ghToken,
            manifest: pkg
        })
    );
});

gulp.task(
    'release',
    gulp.series(
        'release:init',
        'bump',
        'release:commit',
        'release:tag',
        'release:push',
        'default',
        'release:zip',
        'release:publish'
    )
);
<|endoftext|>


<commit_before>var gulp = require('gulp');
var _ = require('lodash');
var path = require('path');
var mkdirp = require('mkdirp');
var Rsync = require('rsync');
var Promise = require('bluebird');
var eslint = require('gulp-eslint');
var rimraf = require('rimraf');
var zip = require('gulp-zip');
var fs = require('fs');
var spawn = require('child_process').spawn;
var minimist = require('minimist');

var pkg = require('./package.json');
var packageName = pkg.name;

// in their own sub-directory to not interfere with Gradle
var buildDir = path.resolve(__dirname, 'build/gulp');
var targetDir = path.resolve(__dirname, 'target/gulp');
var buildTarget = path.resolve(buildDir, packageName);

var include = [
  '*.json',
  'LICENSE',
  'README.md',
  'index.js',
  'init.js',
  'server',
  'public'
];

var knownOptions = {
  string: 'kibanahomepath',
  default: { kibanahomepath: '../kibi-internal' }
};
var options = minimist(process.argv.slice(2), knownOptions);
var kibanaPluginDir = path.resolve(__dirname, options.kibanahomepath + '/plugins/' + packageName);

function syncPluginTo(dest, done) {
  mkdirp(dest, function (err) {
    if (err) return done(err);
    Promise.all(include.map(function (name) {
      var source = path.resolve(__dirname, name);
      return new Promise(function (resolve, reject) {
        var rsync = new Rsync();
        rsync
          .source(source)
          .destination(dest)
          .flags('uav')
          .recursive(true)
          .set('delete')
          .output(function (data) {
            process.stdout.write(data.toString('utf8'));
          });
        rsync.execute(function (err) {
          if (err) {
            console.log(err);
            return reject(err);
          }
          resolve();
        });
      });
    }))
    .then(function () {
      return new Promise(function (resolve, reject) {
        mkdirp(path.join(buildTarget, 'node_modules'), function (err) {
          if (err) return reject(err);
          resolve();
        });
      });
    })
    .then(function () {
      spawn('npm', ['install', '--production'], {
        cwd: dest,
        stdio: 'inherit'
      })
      .on('close', done);
    })
    .catch(done);
  });
}

gulp.task('sync', function (done) {
  syncPluginTo(kibanaPluginDir, done);
});

gulp.task('lint', function (done) {
  return gulp.src([
    'index.js',
    'init.js',
    'public/**/*.js',
    'server/**/*.js',
    '!**/webpackShims/**'
  ]).pipe(eslint())
  .pipe(eslint.formatEach())
  .pipe(eslint.failOnError());
});

gulp.task('clean', function (done) {
  Promise.each([buildDir, targetDir], function (dir) {
    return new Promise(function (resolve, reject) {
      rimraf(dir, function (err) {
        if (err) return reject(err);
        resolve();
      });
    });
  }).nodeify(done);
});

gulp.task('build', ['clean'], function (done) {
  syncPluginTo(buildTarget, done);
});

gulp.task('package', ['build'], function (done) {
  return gulp.src([
    path.join(buildDir, '**', '*')
  ])
  .pipe(zip(packageName + '.zip'))
  .pipe(gulp.dest(targetDir));
});

gulp.task('dev', ['sync'], function (done) {
  gulp.watch([
    'index.js',
    'init.js',
    '*.json',
    'public/**/*',
    'server/**/*'
  ], ['sync', 'lint']);
});

gulp.task('test', ['sync'], function(done) {
  spawn('grunt', ['test:server', '--grep=Sentinl'], {
    cwd: options.kibanahomepath,
    stdio: 'inherit'
  }).on('close', done);
});

gulp.task('testdev', ['sync'], function(done) {
  spawn('grunt', ['test:dev', '--browser=Chrome'], {
    cwd: options.kibanahomepath,
    stdio: 'inherit'
  }).on('close', done);
});

gulp.task('coverage', ['sync'], function(done) {
  spawn('grunt', ['test:coverage', '--grep=Sentinl'], {
    cwd: options.kibanahomepath,
    stdio: 'inherit'
  }).on('close', done);
});
<commit_msg>Fix gulp file to correctly package plugin<commit_after>var gulp = require('gulp');
var _ = require('lodash');
var path = require('path');
var mkdirp = require('mkdirp');
var Rsync = require('rsync');
var Promise = require('bluebird');
var eslint = require('gulp-eslint');
var rimraf = require('rimraf');
var zip = require('gulp-zip');
var fs = require('fs');
var spawn = require('child_process').spawn;
var minimist = require('minimist');

var pkg = require('./package.json');
var packageName = pkg.name;

// in their own sub-directory to not interfere with Gradle
var buildDir = path.resolve(__dirname, 'build/gulp');
var targetDir = path.resolve(__dirname, 'target/gulp');
var buildTarget = path.resolve(buildDir, 'kibana', packageName);

var include = [
  '*.json',
  'LICENSE',
  'README.md',
  'index.js',
  'init.js',
  'server',
  'public'
];

var knownOptions = {
  string: 'kibanahomepath',
  default: { kibanahomepath: '../kibi-internal' }
};
var options = minimist(process.argv.slice(2), knownOptions);
var kibanaPluginDir = path.resolve(__dirname, options.kibanahomepath + '/plugins/' + packageName);

function syncPluginTo(dest, done) {
  mkdirp(dest, function (err) {
    if (err) return done(err);
    Promise.all(include.map(function (name) {
      var source = path.resolve(__dirname, name);
      return new Promise(function (resolve, reject) {
        var rsync = new Rsync();
        rsync
          .source(source)
          .destination(dest)
          .flags('uav')
          .recursive(true)
          .set('delete')
          .output(function (data) {
            process.stdout.write(data.toString('utf8'));
          });
        rsync.execute(function (err) {
          if (err) {
            console.log(err);
            return reject(err);
          }
          resolve();
        });
      });
    }))
    .then(function () {
      return new Promise(function (resolve, reject) {
        mkdirp(path.join(buildTarget, 'node_modules'), function (err) {
          if (err) return reject(err);
          resolve();
        });
      });
    })
    .then(function () {
      spawn('npm', ['install', '--production'], {
        cwd: dest,
        stdio: 'inherit'
      })
      .on('close', done);
    })
    .catch(done);
  });
}

gulp.task('sync', function (done) {
  syncPluginTo(kibanaPluginDir, done);
});

gulp.task('lint', function (done) {
  return gulp.src([
    'index.js',
    'init.js',
    'public/**/*.js',
    'server/**/*.js',
    '!**/webpackShims/**'
  ]).pipe(eslint())
  .pipe(eslint.formatEach())
  .pipe(eslint.failOnError());
});

gulp.task('clean', function (done) {
  Promise.each([buildDir, targetDir], function (dir) {
    return new Promise(function (resolve, reject) {
      rimraf(dir, function (err) {
        if (err) return reject(err);
        resolve();
      });
    });
  }).nodeify(done);
});

gulp.task('build', ['clean'], function (done) {
  syncPluginTo(buildTarget, done);
});

gulp.task('package', ['build'], function (done) {
  return gulp.src([
    path.join(buildDir, '**', '*')
  ])
  .pipe(zip(packageName + '.zip'))
  .pipe(gulp.dest(targetDir));
});

gulp.task('dev', ['sync'], function (done) {
  gulp.watch([
    'index.js',
    'init.js',
    '*.json',
    'public/**/*',
    'server/**/*'
  ], ['sync', 'lint']);
});

gulp.task('test', ['sync'], function(done) {
  spawn('grunt', ['test:server', '--grep=Sentinl'], {
    cwd: options.kibanahomepath,
    stdio: 'inherit'
  }).on('close', done);
});

gulp.task('testdev', ['sync'], function(done) {
  spawn('grunt', ['test:dev', '--browser=Chrome'], {
    cwd: options.kibanahomepath,
    stdio: 'inherit'
  }).on('close', done);
});

gulp.task('coverage', ['sync'], function(done) {
  spawn('grunt', ['test:coverage', '--grep=Sentinl'], {
    cwd: options.kibanahomepath,
    stdio: 'inherit'
  }).on('close', done);
});
<|endoftext|>


<commit_before>// Load in all the plugins ----------------------------------------------------
//
// Note: Plumber fixes an issue with Node Stream piping
//		 -> https://gist.github.com/floatdrop/8269868

var gulp 			= require('gulp'),

    plumber 		= require('gulp-plumber'),
    connect			= require('connect'),
    http			= require('http'),
    open			= require('open'),
    rimraf 			= require('gulp-rimraf'),
    jshint 			= require('gulp-jshint'),
    concat 			= require('gulp-concat'),
    uglify 			= require('gulp-uglify'),
    sass 			= require('gulp-ruby-sass'),
    autoprefixer 	= require('gulp-autoprefixer'),
    minifycss 		= require('gulp-minify-css'),
    imagemin 		= require('gulp-imagemin'),
    rename 			= require('gulp-rename'),
    cache 			= require('gulp-cache'),
    refresh 		= require('gulp-livereload'),
    useref	 		= require('gulp-useref'),
    tinylr			= require('tiny-lr'),
    livereload		= tinylr(),
    server 			= lr(),

    config			= {
				    	app: 	'app',
				    	dist: 	'dist',
				    	port:	9000,
				    	lr:		35729
				    };

// Clean up -------------------------------------------------------------------
//
// This task does the following things:
// - Clean out the dist folder before rebuilding

gulp.task('clean', function()
{
	return gulp.src(['dist'], {read: false})
		.pipe(plumber())
		.pipe(rimraf());
});

// Styles ---------------------------------------------------------------------
//
// This task does the following things:
// - Grab and compile all main .scss files
// - Auto-prefix results
// - Save and minify results to .css files
// - Reload browser

gulp.task('styles', function()
{
	return gulp.src('assets/sass/*.scss')
		.pipe(plumber())
		.pipe(sass({ style: 'nested', compass: true }))
		.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
		.pipe(rename({suffix: '.min'}))
		.pipe(minifycss())
		.pipe(gulp.dest('dist/assets/css'))
		.pipe(livereload(server));
});

// Scripts --------------------------------------------------------------------
//

gulp.task('lint-main', function()
{
	return gulp.src(['assets/js/app.js', 'assets/js/core/*.js'])
		.pipe(jshint())
		.pipe(jshint.reporter('default'));
});

gulp.task('scripts-main', ['lint-main'], function()
{
	return gulp.src(['assets/js/libs/jquery*.js', 'assets/js/libs/*.js', 'assets/js/core/*.js', 'assets/js/app.js'])
		.pipe(plumber())
		.pipe(concat('core-libs.min.js'))
		.pipe(uglify())
		.pipe(gulp.dest('dist/assets/js'))
		.pipe(livereload(server));
});

gulp.task('scripts-view', function()
{
	return gulp.src('assets/js/view/*.js')
		.pipe(jshint())
		.pipe(jshint.reporter('default'))
		.pipe(rename({suffix: '.min'}))
		.pipe(uglify())
		.pipe(gulp.dest('dist/assets/js/view'))
		.pipe(livereload(server));
});

gulp.task('scripts-ie', function()
{
	return gulp.src(['**/html5shiv.js', '**/nwmatcher-1.2.5.js', '**/selectivizr.js', '**/matchmedia.polyfill.js', '**/matchmedia.addListener.js', '**/respond.js'])
		.pipe(plumber())
		.pipe(concat('ie.min.js'))
		.pipe(uglify())
		.pipe(gulp.dest('dist/assets/js'))
		.pipe(livereload(server));
});

// Images ---------------------------------------------------------------------
//
// This task does the following things:
// - Grab all images
// - Optimize them
// - Reload browser

gulp.task('images', function()
{
	return gulp.src('assets/images/**/*')
		.pipe(plumber())
		.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
		.pipe(gulp.dest('dist/assets/images'))
		.pipe(livereload(server));
});

// Watch ----------------------------------------------------------------------
//
// Watch files for changes and run appropriate task

gulp.task('watch', function(cb)
{
	server.listen(35729, function(err)
	{
		if (err) { return console.log(err) };

		console.log('Started watching assets folder..')

		gulp.watch('assets/sass/*.scss', ['styles'], function(event)
		{
      		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
    	});

		gulp.watch('assets/**/*.js', ['scripts, ie-scripts'], function(event)
		{
      		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
      	});

		gulp.watch('assets/images/**/*', ['images'], function(event)
		{
      		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
      	});
	});

	cb();
});

// The default task -----------------------------------------------------------
//
// Runs tasks in order when you call 'gulp' from the CLI

// TODO:
// Use dependencies instead of gulp.run()
// Not as easy as it seems though

gulp.task('default', ['clean'], function(cb)
{
	gulp.run('styles', 'scripts-main', 'scripts-view', 'scripts-ie', /*'images',*/ 'watch');
});

<commit_msg>Cleaned up, started implementing dev/prod run<commit_after>// Load in all the plugins ----------------------------------------------------
//
// Note: Plumber fixes an issue with Node Stream piping
//		 -> https://gist.github.com/floatdrop/8269868

var gulp 			= require('gulp'),

    plumber 		= require('gulp-plumber'),
    connect			= require('connect'),
    http			= require('http'),
    open			= require('open'),
    gulpif			= require('gulp-if'),
    inject			= require('gulp-inject'),
    rimraf 			= require('gulp-rimraf'),
    jshint 			= require('gulp-jshint'),
    concat 			= require('gulp-concat'),
    uglify 			= require('gulp-uglify'),
    sass 			= require('gulp-ruby-sass'),
    autoprefixer 	= require('gulp-autoprefixer'),
    minifycss 		= require('gulp-minify-css'),
    imagemin 		= require('gulp-imagemin'),
    rename 			= require('gulp-rename'),
    cache 			= require('gulp-cache'),
    refresh 		= require('gulp-livereload'),
    tinylr			= require('tiny-lr'),
    livereload		= tinylr(),
    server 			= lr(),

    config			= {
				    	app: 	'app',
				    	dev:	'dev',
				    	dist: 	'dist',
				    	port:	9000,
				    	lr:		35729
				    };

// Catch CLI parameter

var isProduction = gulp.env.type === 'production';
console.log('isProduction: ' + isProduction);

// Clean up -------------------------------------------------------------------
//

gulp.task('clean', function()
{
	return gulp.src([config.dev, config.dist], {read: false})
		.pipe(plumber())
		.pipe(rimraf());
});

// Styles ---------------------------------------------------------------------
//

gulp.task('sass', function()
{
	return gulp.src(config.app + '/sass/*.scss')
		.pipe(plumber())
		.pipe(sass({ style: 'nested', compass: true }))
		.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
		.pipe(rename({suffix: '.min'}))
		.pipe(minifycss())
		.pipe(gulpif(isProduction, gulp.dest(config.dist + '/assets/css')))
		.pipe(gulpif(!isProduction, gulp.dest(config.dev + 'dist/assets/css')))
		.pipe(gulpif(isProduction, refresh(livereload)));
});

// Scripts --------------------------------------------------------------------
//

gulp.task('lint-main', function()
{
	return gulp.src([
			config.app + '/js/app.js',
			config.app + '/js/core/*.js'
		])
		.pipe(jshint())
		.pipe(jshint.reporter('default'));
});

gulp.task('scripts-main', ['lint-main'], function()
{
	return gulp.src([
			config.app + '/js/libs/jquery*.js',
			config.app + '/js/libs/*.js',
			config.app + '/js/core/*.js',
			config.app + '/js/app.js'
		])
		.pipe(plumber())
		.pipe(gulpif(isProduction, concat('core-libs.min.js')))
		.pipe(gulpif(isProduction, uglify()))
		.pipe(gulpif(isProduction, gulp.dest(config.dist + '/assets/js')))
		.pipe(gulpif(!isProduction, gulp.dest(config.dev + '/assets/js')))
		.pipe(gulpif(isProduction, refresh(livereload)));
});

gulp.task('lint-view', function()
{
	return gulp.src(config.app + '/js/view/*.js')
		.pipe(plumber())
		.pipe(jshint())
		.pipe(jshint.reporter('default'));
});

gulp.task('scripts-view', ['lint-view'], function()
{
	return gulp.src(config.app + '/js/view/*.js')
		.pipe(rename({suffix: '.min'}))
		.pipe(uglify())
		.pipe(gulpif(isProduction, gulp.dest(config.dist + '/assets/js/view')))
		.pipe(gulpif(!isProduction, gulp.dest(config.dev + '/assets/js/view')))
		.pipe(gulpif(isProduction, refresh(livereload)));
});

gulp.task('scripts-ie', function()
{
	return gulp.src([
			'**/html5shiv.js',
			'**/nwmatcher-1.2.5.js',
			'**/selectivizr.js',
			'**/matchmedia.polyfill.js',
			'**/matchmedia.addListener.js',
			'**/respond.js'
		])
		.pipe(plumber())
		.pipe(concat('ie.min.js'))
		.pipe(uglify())
		.pipe(gulpif(isProduction, gulp.dest(config.dist + '/assets/js')))
		.pipe(gulpif(!isProduction, gulp.dest(config.dev + '/assets/js')))
		.pipe(gulpif(isProduction, refresh(livereload)));
});

// Images ---------------------------------------------------------------------
//

gulp.task('images', function()
{
	return gulp.src(config.app + '/images/**/*')
		.pipe(plumber())
		.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
		.pipe(gulpif(isProduction, gulp.dest(config.dist + '/assets/images')))
		.pipe(gulpif(!isProduction, gulp.dest(config.dev + 'dist/assets/images')))
		.pipe(gulpif(isProduction, refresh(livereload)));
});

// Fonts ----------------------------------------------------------------------
//

gulp.task('fonts', function()
{
    return gulp.src(config.app + '/fonts/*')
        .pipe(gulpif(isProduction, gulp.dest(config.dist + 'assets/fonts')))
        .pipe(gulpif(!isProduction, gulp.dest(config.dev + 'assets/fonts')));
});

// Misc -----------------------------------------------------------------------
//

gulp.task('misc', function()
{
    return gulp.src(config.app + '/misc/*')
        .pipe(gulpif(isProduction, gulp.dest(config.dist)))
        .pipe(gulpif(!isProduction, gulp.dest(config.dev)));
});

// HTML -----------------------------------------------------------------------
//

gulp.task('html', function()
{
    return gulp.src(config.app + '/html/*')
        .pipe(gulpif(isProduction, gulp.dest(config.dist)))
        .pipe(gulpif(!isProduction, gulp.dest(config.dev)));
});

// LiveReload -----------------------------------------------------------------
//

gulp.task('connect-livereload', function()
{
    var middleware = [
        require('connect-livereload')({ port: config.lr }),
        connect.static(config.app),
        connect.directory(config.app)
    ];

    var app = connect.apply(null, middleware);

    var server = http.createServer(app);

    server
        .listen(config.port)
        .on('listening', function() {
            console.log('Started connect web server on http://localhost:' + config.port + '.');

            open('http://localhost:' + config.port);
        });
});

gulp.task('tinylr', function()
{
    livereload.listen(config.lr, function(err){
        if (err) {
            return console.log(err);
        }
    });
});

gulp.task('server', ['sass', 'connect-livereload', 'tinylr'], function()
{
    console.log('Started watching assets folder..')

	gulp.watch(config.app + '/sass/*.scss', ['sass'], function(event)
	{
  		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
	});

	gulp.watch(config.app + '/**/*.js', ['scripts', 'scripts-view', 'scripts-ie'], function(event)
	{
  		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
  	});

	gulp.watch(config.app + '/images/**/*', ['images'], function(event)
	{
  		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
  	});
	/*
	gulp.watch(config.app + '/html/*', ['html'], function(event)
	{
  		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
  	});*/
});

// The default task -----------------------------------------------------------
//
// Runs when you call 'gulp' from the CLI

gulp.task('default', ['clean'], function()
{
	gulp.run('html', 'sass', 'fonts', 'misc', 'scripts-main', 'scripts-view', 'scripts-ie', 'images', 'server');
});

<|endoftext|>


<commit_before>var gulp = require('gulp');
var path = require('path');
var fs = require('fs');
var glob = require("glob");
var through2 = require('through2');
var runSequence = require('run-sequence');
var tarbz2 = require('decompress-tarbz2');
var vinylAssign = require('vinyl-assign');
var exec = require('child_process').exec;
var uiIndex = require('./lib/findBy/tagname/searchIndex/build-stream');
var codeIndex = require('./lib/findBy/code/searchIndex/build-stream');
var Promise = require("bluebird");
var config = require("config");
var mongo = require('./lib/db/connection');
var DATASET_ROOT = config.get('dataset.root');

gulp.task('index:ui', function () {
    gulp.src(path.join(DATASET_ROOT, 'ui', '*.xml'))
        .pipe(uiIndex())
        .pipe(gulp.dest('indexes/tagname'));
})

gulp.task('solr:indexCode', function (callback) {
    glob(path.join(DATASET_ROOT, 'code', '*.txt'), function (er, files) {
        codeIndex.index(files);
        callback();
    });
})

gulp.task('solr:commit', function () {
    codeIndex.commit();
})

gulp.task('extract:archives', function () {
    // Extract listing details JSON files
    gulp.src(path.join(DATASET_ROOT, 'listing', 'listing.tar.bz2'))
        .pipe(vinylAssign({extract: true}))
        .pipe(tarbz2({strip: 1}))
        .pipe(gulp.dest(path.join(DATASET_ROOT, 'listing')));
    // Extract UI xml files
    gulp.src(path.join(DATASET_ROOT, 'ui', 'ui-xml.tar.bz2'))
        .pipe(vinylAssign({extract: true}))
        .pipe(tarbz2({strip: 1}))
        .pipe(gulp.dest(path.join(DATASET_ROOT, 'ui')));
    // Extract smali code text files
    gulp.src(path.join(DATASET_ROOT, 'code', 'smali-invoked-methods.tar.bz2'))
        .pipe(vinylAssign({extract: true}))
        .pipe(tarbz2({strip: 1}))
        .pipe(gulp.dest(path.join(DATASET_ROOT, 'code')));
})

gulp.task('start:db', function (callback) {
    try {
        fs.mkdirSync(path.join(DATASET_ROOT, 'db'));
    } catch (error) {
        if (error.code != 'EEXIST') callback(error);
    }
    // start Solr in SolrCloud mode as a daemon
    var solr = 'solr start -cloud -V -h ' + config.get('dbConfig.solr.host') +
        ' -p ' + config.get('dbConfig.solr.port')
    console.log("Starting Solr server in SolrCloud mode. " + solr);
    exec(solr,
        function (error, stdout, stderr) {
            console.log(stdout);
            console.log(stderr);
            callback(stderr);
        });
    // start MongoDB
    var mongod = 'mongod --port ' + config.get('dbConfig.mongo.port') +
        ' --config ' + config.get('dbConfig.mongo.config') +
        ' --dbpath ' + path.join(DATASET_ROOT, 'db')
    console.log("Starting MongoDB server: " + mongod);
    exec(mongod,
        function (error, stdout, stderr) {
            console.log(stdout);
            console.log(stderr);
            callback(stderr);
        });
})

gulp.task('mongo:insertListing', function (done) {
    gulp.src(path.join(DATASET_ROOT, 'listing', '*.json'))
        .pipe(new through2.obj(function (file, enc, cb) {
            var doc = JSON.parse(file.contents);
            doc.id = doc.n + '-' + doc.verc;
            mongo.upsertOne('listings', doc, doc)
                .then(function () {
                    cb();
                })
                .error(function (e) {
                    console.error('Error in insert:listing task: ' + e.message);
                });
            ;
        }, function () {
            done();
        }));

})

gulp.task('mongo:indexListing', function (done) {
    mongo.createIndex('listings', {id: 1}, {unique: true})
        .then(function () {
            done();
        })
        .error(function (e) {
            console.error('Error in mongoIndex task: ' + e.message);
        })
});

gulp.task('mongo:close', function () {
    mongo.close();
});

gulp.task('load:db', function (callback) {
    runSequence('mongo:insertListing', 'mongo:indexListing', 'mongo:close', callback)
});

gulp.task('default', function (callback) {
    runSequence('extract:archives', 'index:ui', 'solr:indexCode', 'solr:commit',
        'load:db', callback);
});<commit_msg>fix extract:arvhives task<commit_after>var gulp = require('gulp');
var path = require('path');
var fs = require('fs');
var glob = require("glob");
var through2 = require('through2');
var runSequence = require('run-sequence');
var exec = require('child_process').exec;
var uiIndex = require('./lib/findBy/tagname/searchIndex/build-stream');
var codeIndex = require('./lib/findBy/code/searchIndex/build-stream');
var Promise = require("bluebird");
var execAsync = Promise.promisify(exec);
var config = require("config");
var mongo = require('./lib/db/connection');
var DATASET_ROOT = config.get('dataset.root');

gulp.task('index:ui', function () {
    gulp.src(path.join(DATASET_ROOT, 'ui', '*.xml'))
        .pipe(uiIndex())
        .pipe(gulp.dest('indexes/tagname'));
});

gulp.task('solr:indexCode', function (callback) {
    glob(path.join(DATASET_ROOT, 'code', '*.txt'), function (er, files) {
        codeIndex.index(files);
        callback();
    });
});

gulp.task('solr:commit', function () {
    codeIndex.commit();
});

gulp.task('extract:archives', function (done) {
    var untarListings = 'tar xvjf ' + path.join(DATASET_ROOT, 'listing',
            'listing.tar.bz2') + ' -C ' + path.join(DATASET_ROOT, 'listing');
    var untarUI = 'tar xvjf ' + path.join(DATASET_ROOT, 'ui', 'ui-xml.tar.bz2') +
        ' -C ' + path.join(DATASET_ROOT, 'ui');
    var untarCode = 'tar xvjf ' + path.join(DATASET_ROOT, 'code',
            'smali-invoked-methods.tar.bz2') + ' -C ' + path.join(DATASET_ROOT,
            'code');
    console.log("Extracting listing details json files...");
    execAsync(untarListings)
        .then(function () {
            console.log("Extracting UI xml files...");
            return execAsync(untarUI);
        })
        .then(function () {
            console.log("Extracting code text files...");
            return execAsync(untarCode);
        })
        .then(function () {
            console.log("All archives have been extracted.");
            done();
        })
        .error(function (error) {
            console.error(error);
            done(error);
        });
});

gulp.task('start:db', function (callback) {
    try {
        fs.mkdirSync(path.join(DATASET_ROOT, 'db'));
    } catch (error) {
        if (error.code != 'EEXIST') callback(error);
    }
    // start Solr in SolrCloud mode as a daemon
    var solr = 'solr start -cloud -V -h ' + config.get('dbConfig.solr.host') +
        ' -p ' + config.get('dbConfig.solr.port');
    console.log("Starting Solr server in SolrCloud mode. " + solr);
    exec(solr,
        function (error, stdout, stderr) {
            console.log(stdout);
            console.log(stderr);
            callback(stderr);
        });
    // start MongoDB
    var mongod = 'mongod --port ' + config.get('dbConfig.mongo.port') +
        ' --config ' + config.get('dbConfig.mongo.config') +
        ' --dbpath ' + path.join(DATASET_ROOT, 'db');
    console.log("Starting MongoDB server: " + mongod);
    exec(mongod,
        function (error, stdout, stderr) {
            console.log(stdout);
            console.log(stderr);
            callback(stderr);
        });
});

gulp.task('mongo:insertListing', function (done) {
    gulp.src(path.join(DATASET_ROOT, 'listing', '*.json'))
        .pipe(new through2.obj(function (file, enc, cb) {
            var doc = JSON.parse(file.contents);
            doc['id'] = doc['n'] + '-' + doc['verc'];
            mongo.upsertOne('listings', doc, doc)
                .then(function () {
                    cb();
                })
                .error(function (e) {
                    console.error('Error in insert:listing task: ' + e.message);
                });
        }, function () {
            done();
        }));

});

gulp.task('mongo:indexListing', function (done) {
    mongo.createIndex('listings', {id: 1}, {unique: true})
        .then(function () {
            done();
        })
        .error(function (e) {
            console.error('Error in mongoIndex task: ' + e.message);
        })
});

gulp.task('mongo:close', function () {
    mongo.close();
});

gulp.task('load:db', function (callback) {
    runSequence('mongo:insertListing', 'mongo:indexListing', 'mongo:close', callback)
});

gulp.task('default', function (callback) {
    runSequence('extract:archives', 'index:ui', 'solr:indexCode', 'solr:commit',
        'load:db', callback);
});<|endoftext|>


<commit_before>var gulp = require("gulp"),
    del = require("del"),
    concat = require("gulp-concat"),
    sourcemaps = require("gulp-sourcemaps"),
    uglify = require("gulp-uglify"),
    babel = require("gulp-babel"),
    eslint = require("gulp-eslint"),
    karma = require("gulp-karma");

var fileName = "angular-autowrap.js",
    minFileName = "angular-autowrap.min.js";

var sourceLocations = [
    "./src/app.js",
    "./src/**/*.js"
];

var getSourceFiles = function(lint){
    var stream = gulp.src(sourceLocations);
    if(!lint){
        return stream;
    }

    return stream
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failOnError())
    .pipe(eslint.formatEach('compact', process.stderr));
};

gulp.task('lint', function(){
   return getSourceFiles(true);
});

gulp.task("clean", function(cb){
    return del("./build/*", cb);
});

gulp.task("build", ["clean"], function(){
    return getSourceFiles(true)
    .pipe(sourcemaps.init())
    .pipe(concat(fileName))
    .pipe(babel())
    .pipe(sourcemaps.write("./", {includeContent: false, sourceRoot: "../src/"}))
    .pipe(gulp.dest("./build/"));
});

gulp.task("release", ["clean"], function(){
    return getSourceFiles()
    .pipe(concat(fileName))
    .pipe(babel())
    .pipe(gulp.dest("./build/"))
    .pipe(sourcemaps.init())
    .pipe(concat(minFileName))
    .pipe(uglify())
    .pipe(sourcemaps.write("./", {includeContent: false, sourceRoot: "./"}))
    .pipe(gulp.dest("./build/"));
});

gulp.task("test", function(){
    var testFiles = [
        "test/**/*.js"
    ];
    var testDependecies = [
        'node_modules/angular/angular.js',
        'node_modules/angular-mocks/angular-mocks.js'
    ];

    var testSuite = [];
    testSuite.concat(testDependecies, sourceLocations, testFiles);

    return gulp.src(testSuite)
    .pipe(karma({
        configFile: "karma.conf.js",
        action: "run",
        reporters: ["spec"]
    }))
    .on("error", function(err){
        throw err;
    });
});

gulp.task('default', ["build"]);<commit_msg>[ci skip] added linting as a part of "gulp test"<commit_after>var gulp = require("gulp"),
    del = require("del"),
    concat = require("gulp-concat"),
    sourcemaps = require("gulp-sourcemaps"),
    uglify = require("gulp-uglify"),
    babel = require("gulp-babel"),
    eslint = require("gulp-eslint"),
    karma = require("gulp-karma");

var fileName = "angular-autowrap.js",
    minFileName = "angular-autowrap.min.js";

var sourceLocations = [
    "./src/app.js",
    "./src/**/*.js"
];

var getSourceFiles = function(lint){
    var stream = gulp.src(sourceLocations);
    if(!lint){
        return stream;
    }

    return stream
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failOnError())
    .pipe(eslint.formatEach('compact', process.stderr));
};

gulp.task('lint', function(){
   return getSourceFiles(true);
});

gulp.task("clean", function(cb){
    return del("./build/*", cb);
});

gulp.task("build", ["clean"], function(){
    return getSourceFiles(true)
    .pipe(sourcemaps.init())
    .pipe(concat(fileName))
    .pipe(babel())
    .pipe(sourcemaps.write("./", {includeContent: false, sourceRoot: "../src/"}))
    .pipe(gulp.dest("./build/"));
});

gulp.task("release", ["clean"], function(){
    return getSourceFiles()
    .pipe(concat(fileName))
    .pipe(babel())
    .pipe(gulp.dest("./build/"))
    .pipe(sourcemaps.init())
    .pipe(concat(minFileName))
    .pipe(uglify())
    .pipe(sourcemaps.write("./", {includeContent: false, sourceRoot: "./"}))
    .pipe(gulp.dest("./build/"));
});

gulp.task("test", ["lint"], function(){
    var testFiles = [
        "test/**/*.js"
    ];
    var testDependecies = [
        'node_modules/angular/angular.js',
        'node_modules/angular-mocks/angular-mocks.js'
    ];

    var testSuite = [];
    testSuite.concat(testDependecies, sourceLocations, testFiles);

    return gulp.src(testSuite)
    .pipe(karma({
        configFile: "karma.conf.js",
        action: "run",
        reporters: ["spec"]
    }))
    .on("error", function(err){
        throw err;
    });
});

gulp.task('default', ["build"]);<|endoftext|>


<commit_before>var gulp = require('gulp');
var sass = require('gulp-sass');
var sassdoc = require('sassdoc');
var mocha = require('gulp-mocha');
var _ = require('lodash');

var pkg = require('./package.json');

var documentOptions = {
    dest: 'docs',
    verbose: true,
    package: 'package.json',
    theme: './node_modules/sassdoc-theme-winter/',
    groups: {
        'undefined': 'General',
        'add-ons': 'Add-ons',
        'helpers': 'Helpers',
        'list': 'List',
        'map': 'Map',
        'elements': 'Elements',
        'elements-extend': 'Elements Extend',
        'scaffolding': 'Scaffolding',
        'variables': 'Variables',
        'debug': 'Debug'
    },
    display: {
        access: ['public'],
        require: false,
        tagline: false,
        sort: {
            group: [
                'undefined',
                'variables',
                'helpers',
                'add-ons',
                'list',
                'map',
                'elements',
                'scaffolding',
                'debug'
            ],
            type: [
                'variable',
                'function',
                'mixin',
                'placeholder'
            ]
        }
    },
    fragments: {
        document: __dirname + '/README.md',
        group: {
            'variables': __dirname + '/docs-fragments/group-variables.md',
            'helpers': __dirname + '/docs-fragments/group-helpers.md',
            'add-ons': __dirname + '/docs-fragments/group-add-ons.md',
            'list': __dirname + '/docs-fragments/group-list.md',
            'map': __dirname + '/docs-fragments/group-map.md',
            'elements': __dirname + '/docs-fragments/group-elements.md',
            'scaffolding': __dirname + '/docs-fragments/group-scaffolding.md',
            'debug': __dirname + '/docs-fragments/debug.md'
        }
    },
    basePath: 'http://biossun.org/nojiko',
    sourceLinkPrefix: 'sass/'
};

gulp.task('docs', function() {
    return gulp.src('./sass/**/*.scss')
        .pipe( sassdoc(_.cloneDeep(documentOptions)) );
});

gulp.task('test.sass', function() {
    gulp.src('./test/sass/index.js', { read: false })
        .pipe( mocha() );
});

gulp.task('test.css', function() {
    gulp.src('./test/css/**/*.scss')
        .pipe(sass({
            outputStyle: 'expanded',
            precision: 10
        }))
        .pipe(gulp.dest('./test/css'));
});

// watch
gulp.task('develop', ['docs', 'test.sass', 'test.css'], function() {
    gulp.watch('./sass/**/*', ['test.sass', 'test.css', 'docs']);
    gulp.watch('./test/**/*', ['test.sass', 'test.css']);
    gulp.watch('./docs-fragments/**/*', ['docs']);
    gulp.watch('./README.md', ['docs']);
});

gulp.task('default', ['docs', 'test.sass', 'test.css']);
<commit_msg>确保在单元测试失败时强制退出<commit_after>var gulp = require('gulp');
var sass = require('gulp-sass');
var sassdoc = require('sassdoc');
var mocha = require('gulp-mocha');
var _ = require('lodash');

var pkg = require('./package.json');

var documentOptions = {
    dest: 'docs',
    verbose: true,
    package: 'package.json',
    theme: './node_modules/sassdoc-theme-winter/',
    groups: {
        'undefined': 'General',
        'add-ons': 'Add-ons',
        'helpers': 'Helpers',
        'list': 'List',
        'map': 'Map',
        'elements': 'Elements',
        'elements-extend': 'Elements Extend',
        'scaffolding': 'Scaffolding',
        'variables': 'Variables',
        'debug': 'Debug'
    },
    display: {
        access: ['public'],
        require: false,
        tagline: false,
        sort: {
            group: [
                'undefined',
                'variables',
                'helpers',
                'add-ons',
                'list',
                'map',
                'elements',
                'scaffolding',
                'debug'
            ],
            type: [
                'variable',
                'function',
                'mixin',
                'placeholder'
            ]
        }
    },
    fragments: {
        document: __dirname + '/README.md',
        group: {
            'variables': __dirname + '/docs-fragments/group-variables.md',
            'helpers': __dirname + '/docs-fragments/group-helpers.md',
            'add-ons': __dirname + '/docs-fragments/group-add-ons.md',
            'list': __dirname + '/docs-fragments/group-list.md',
            'map': __dirname + '/docs-fragments/group-map.md',
            'elements': __dirname + '/docs-fragments/group-elements.md',
            'scaffolding': __dirname + '/docs-fragments/group-scaffolding.md',
            'debug': __dirname + '/docs-fragments/debug.md'
        }
    },
    basePath: 'http://biossun.org/nojiko',
    sourceLinkPrefix: 'sass/'
};

gulp.task('docs', function() {
    return gulp.src('./sass/**/*.scss')
        .pipe( sassdoc(_.cloneDeep(documentOptions)) );
});

gulp.task('test.sass', function() {
    return gulp.src('./test/sass/index.js', { read: false })
        .pipe( mocha() );
});

gulp.task('test.css', function() {
    return gulp.src('./test/css/**/*.scss')
        .pipe(sass({
            outputStyle: 'expanded',
            precision: 10
        }))
        .pipe(gulp.dest('./test/css'));
});

// watch
gulp.task('develop', ['docs', 'test.sass', 'test.css'], function() {
    gulp.watch('./sass/**/*', ['test.sass', 'test.css', 'docs']);
    gulp.watch('./test/**/*', ['test.sass', 'test.css']);
    gulp.watch('./docs-fragments/**/*', ['docs']);
    gulp.watch('./README.md', ['docs']);
});

gulp.task('default', ['docs', 'test.sass', 'test.css']);
<|endoftext|>


<commit_before>var gulp = require('gulp');
var path = require('path');
var replace = require('gulp-replace');
var child_process = require('child_process');
var fs = require('fs');
var shell = require('gulp-shell');
var jshint = require('gulp-jshint');
var jshStylish = require('jshint-stylish');
var exec = require('child_process').exec;
var runSequence = require('run-sequence');
var prompt = require('gulp-prompt');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var gutil = require('gulp-util');
var notifier = require('node-notifier');
var derequire = require('gulp-derequire');
var version;

var browserifyOpts = {
  entries: './src/index.js',
  debug: true
};

var logError = function( err ){
  notifier.notify({ title: 'cose-bilkent', message: 'Error: ' + err.message });
  gutil.log( gutil.colors.red('Error in watch:'), gutil.colors.red(err) );
};

gulp.task('build', function(){
  return browserify( browserifyOpts )
    .bundle()
    .on( 'error', logError )
    .pipe( source('cytoscape-cose-bilkent.js') )
    .pipe( buffer() )
    .pipe( derequire() )
    .pipe( gulp.dest('.') )
});

gulp.task('default', ['build'], function( next ){
  next();
});

gulp.task('publish', [], function( next ){
  runSequence('confver', 'lint', 'build', 'pkgver', 'push', 'tag', 'npm', 'spm', 'meteor', next);
});

gulp.task('confver', ['version'], function(){
  return gulp.src('.')
    .pipe( prompt.confirm({ message: 'Are you sure version `' + version + '` is OK to publish?' }) )
  ;
});

gulp.task('version', function( next ){
  var now = new Date();
  version = process.env['VERSION'];

  if( version ){
    done();
  } else {
    exec('git rev-parse HEAD', function( error, stdout, stderr ){
      var sha = stdout.substring(0, 10); // shorten so not huge filename

      version = [ 'snapshot', sha, +now ].join('-');
      done();
    });
  }

  function done(){
    console.log('Using version number `%s` for building', version);
    next();
  }

});

gulp.task('pkgver', ['version'], function(){
  return gulp.src([
    'package.json',
    'bower.json'
  ])
    .pipe( replace(/\"version\"\:\s*\".*?\"/, '"version": "' + version + '"') )

    .pipe( gulp.dest('./') )
  ;
});

gulp.task('push', shell.task([
  'git add -A',
  'git commit -m "pushing changes for v$VERSION release"',
  'git push'
]));

gulp.task('tag', shell.task([
  'git tag -a $VERSION -m "tagging v$VERSION"',
  'git push origin $VERSION'
]));

gulp.task('npm', shell.task([
  'npm publish .'
]));

gulp.task('spm', shell.task([
  'spm publish'
]));

gulp.task('meteor', shell.task([
  'meteor publish'
]));

// http://www.jshint.com/docs/options/
gulp.task('lint', function(){
  return gulp.src( './src/**' )
    .pipe( jshint({
      funcscope: true,
      laxbreak: true,
      loopfunc: true,
      strict: true,
      unused: 'vars',
      eqnull: true,
      sub: true,
      shadow: true,
      laxcomma: true
    }) )

    .pipe( jshint.reporter(jshStylish) )

    // TODO clean up via linting
    //.pipe( jshint.reporter('fail') )
  ;
});
<commit_msg>add commit fallback<commit_after>var gulp = require('gulp');
var path = require('path');
var replace = require('gulp-replace');
var child_process = require('child_process');
var fs = require('fs');
var shell = require('gulp-shell');
var jshint = require('gulp-jshint');
var jshStylish = require('jshint-stylish');
var exec = require('child_process').exec;
var runSequence = require('run-sequence');
var prompt = require('gulp-prompt');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var gutil = require('gulp-util');
var notifier = require('node-notifier');
var derequire = require('gulp-derequire');
var version;

var browserifyOpts = {
  entries: './src/index.js',
  debug: true
};

var logError = function( err ){
  notifier.notify({ title: 'cose-bilkent', message: 'Error: ' + err.message });
  gutil.log( gutil.colors.red('Error in watch:'), gutil.colors.red(err) );
};

gulp.task('build', function(){
  return browserify( browserifyOpts )
    .bundle()
    .on( 'error', logError )
    .pipe( source('cytoscape-cose-bilkent.js') )
    .pipe( buffer() )
    .pipe( derequire() )
    .pipe( gulp.dest('.') )
});

gulp.task('default', ['build'], function( next ){
  next();
});

gulp.task('publish', [], function( next ){
  runSequence('confver', 'lint', 'build', 'pkgver', 'push', 'tag', 'npm', 'spm', 'meteor', next);
});

gulp.task('confver', ['version'], function(){
  return gulp.src('.')
    .pipe( prompt.confirm({ message: 'Are you sure version `' + version + '` is OK to publish?' }) )
  ;
});

gulp.task('version', function( next ){
  var now = new Date();
  version = process.env['VERSION'];

  if( version ){
    done();
  } else {
    exec('git rev-parse HEAD', function( error, stdout, stderr ){
      var sha = stdout.substring(0, 10); // shorten so not huge filename

      version = [ 'snapshot', sha, +now ].join('-');
      done();
    });
  }

  function done(){
    console.log('Using version number `%s` for building', version);
    next();
  }

});

gulp.task('pkgver', ['version'], function(){
  return gulp.src([
    'package.json',
    'bower.json'
  ])
    .pipe( replace(/\"version\"\:\s*\".*?\"/, '"version": "' + version + '"') )

    .pipe( gulp.dest('./') )
  ;
});

gulp.task('push', shell.task([
  'git add -A',
  'git commit -m "pushing changes for v$VERSION release" || echo Nothing to commit',
  'git push || echo Nothing to push'
]));

gulp.task('tag', shell.task([
  'git tag -a $VERSION -m "tagging v$VERSION"',
  'git push origin $VERSION'
]));

gulp.task('npm', shell.task([
  'npm publish .'
]));

gulp.task('spm', shell.task([
  'spm publish'
]));

gulp.task('meteor', shell.task([
  'meteor publish'
]));

// http://www.jshint.com/docs/options/
gulp.task('lint', function(){
  return gulp.src( './src/**' )
    .pipe( jshint({
      funcscope: true,
      laxbreak: true,
      loopfunc: true,
      strict: true,
      unused: 'vars',
      eqnull: true,
      sub: true,
      shadow: true,
      laxcomma: true
    }) )

    .pipe( jshint.reporter(jshStylish) )

    // TODO clean up via linting
    //.pipe( jshint.reporter('fail') )
  ;
});
<|endoftext|>


<commit_before>var fs = require('fs');
var gulp = require('gulp');
var gutil = require('gulp-util');
var del = require('del');
var NwBuilder = require('nw-builder');

gulp.task('sync', function() {
  var package = JSON.parse(fs.readFileSync('package.json', 'utf8'));
  var srcPackage = JSON.parse(fs.readFileSync('src/package.json', 'utf8'));
  srcPackage.name = package.name;
  srcPackage.version = package.version;
  srcPackage.description = package.description;
  srcPackage.repository = package.repository;
  srcPackage.homepage = package.homepage;
  try {
    fs.writeFileSync('src/package.json', JSON.stringify(srcPackage, null, "  "), 'utf8');
  } catch(e) {
    console.error("Failed to sync package.json");
  }
});

gulp.task('clean:build', function(cb) {
  del(['build'], cb);
});

var nw = function(cb, platforms) {
  var nw = new NwBuilder({
    files: 'src/**',
    version: '0.12.1',
    platforms: platforms,
    build: 'build',
    cacheDir: 'cache',
    macCredits: 'Credits.html',
    macIcns: 'src/images/jikkyo.icns',
    macZip: true,
    winIco: 'src/images/jikkyo.ico',
    winZip: false
  });
  nw.on('log', function(msg) {
    gutil.log('node-webkit-builder', msg);
  });
  nw.build(cb);
};

gulp.task('nw:release', ['clean', 'sync'], function(cb) {
  nw(cb, ['win', 'osx', 'linux']);
});

gulp.task('nw:win32', function(cb) {
  nw(cb, ['win32']);
});

gulp.task('nw:win64', function(cb) {
  nw(cb, ['win64']);
});

gulp.task('nw:osx32', function(cb) {
  nw(cb, ['osx32']);
});

gulp.task('nw:osx64', function(cb) {
  nw(cb, ['osx64']);
});

gulp.task('nw:linux', function(cb) {
  nw(cb, ['linux']);
});

gulp.task('clean', ['clean:build']);
gulp.task('release', ['clean', 'sync', 'nw:release']);
gulp.task('default', ['build']);
<commit_msg>Disable macZip on nw-builder<commit_after>var fs = require('fs');
var gulp = require('gulp');
var gutil = require('gulp-util');
var del = require('del');
var NwBuilder = require('nw-builder');

gulp.task('sync', function() {
  var package = JSON.parse(fs.readFileSync('package.json', 'utf8'));
  var srcPackage = JSON.parse(fs.readFileSync('src/package.json', 'utf8'));
  srcPackage.name = package.name;
  srcPackage.version = package.version;
  srcPackage.description = package.description;
  srcPackage.repository = package.repository;
  srcPackage.homepage = package.homepage;
  try {
    fs.writeFileSync('src/package.json', JSON.stringify(srcPackage, null, "  "), 'utf8');
  } catch(e) {
    console.error("Failed to sync package.json");
  }
});

gulp.task('clean:build', function(cb) {
  del(['build'], cb);
});

var nw = function(cb, platforms) {
  var nw = new NwBuilder({
    files: 'src/**',
    version: '0.12.1',
    platforms: platforms,
    build: 'build',
    cacheDir: 'cache',
    macCredits: 'Credits.html',
    macIcns: 'src/images/jikkyo.icns',
    macZip: false,
    winIco: 'src/images/jikkyo.ico',
    winZip: false
  });
  nw.on('log', function(msg) {
    gutil.log('node-webkit-builder', msg);
  });
  nw.build(cb);
};

gulp.task('nw:release', ['clean', 'sync'], function(cb) {
  nw(cb, ['win', 'osx', 'linux']);
});

gulp.task('nw:win32', function(cb) {
  nw(cb, ['win32']);
});

gulp.task('nw:win64', function(cb) {
  nw(cb, ['win64']);
});

gulp.task('nw:osx32', function(cb) {
  nw(cb, ['osx32']);
});

gulp.task('nw:osx64', function(cb) {
  nw(cb, ['osx64']);
});

gulp.task('nw:linux', function(cb) {
  nw(cb, ['linux']);
});

gulp.task('clean', ['clean:build']);
gulp.task('release', ['clean', 'sync', 'nw:release']);
gulp.task('default', ['build']);
<|endoftext|>


<commit_before>/**
* Dependencies.
*/
var gulp = require('gulp'),
    merge = require('merge-stream'),
    util = require('gulp-util'),
    concat = require('gulp-concat'),
    minifycss = require('gulp-minify-css'),
    uglify = require('gulp-uglify'),
    imagemin = require('gulp-imagemin'),
    htmlmin = require('gulp-htmlmin'),
    pkg = require('./package.json'),
    assets = require('./assets');

var gulpFileCwd = __dirname + '/public';
process.chdir(gulpFileCwd);
util.log('Working directory changed to', gulpFileCwd);

gulp.task('html', function() {
  return gulp.src('../server/views/**/*.html')
	.pipe(htmlmin({collapseWhitespace: true, removeComments: true}))
	.pipe(gulp.dest('../dist/server/views/'));
});

gulp.task('scripts', function() {
  return gulp.src(assets.development.js)
        .pipe(concat('bundle-scripts.js'))
        .pipe(uglify())
        .pipe(gulp.dest('../dist/public/js/'));
});

gulp.task('styles', function() {
  return gulp.src(assets.development.css)
        .pipe(concat('bundle-styles.css'))
        .pipe(minifycss())
        .pipe(gulp.dest('../dist/public/css/'));
});

gulp.task('copy', function() {
  var server_assets = gulp.src('../server/assets/**/*')
		.pipe(gulp.dest('../dist/server/assets/'));

  var server_base = gulp.src('../server/base/**/*')
		.pipe(gulp.dest('../dist/server/base/'));

  var server_locales = gulp.src('../server/locales/**/*')
		.pipe(gulp.dest('../dist/server/locales/'));

  var server_config = gulp.src(['../assets.js', '../package.json', '../server.js'])
		.pipe(gulp.dest('../dist/'));

  return merge(server_assets, server_base, server_locales, server_config);

});

gulp.task('images', function() {
  return gulp.src('./images/*')
        .pipe(imagemin())
        .pipe(gulp.dest('../dist/public/images/'));
});

gulp.task('default', function() {
    gulp.start('html', 'scripts', 'styles', 'copy', 'images');
});
<commit_msg>adding new project<commit_after>/**
* Dependencies.
*/
var gulp = require('gulp'),
    merge = require('merge-stream'),
    util = require('gulp-util'),
    concat = require('gulp-concat'),
    minifycss = require('gulp-minify-css'),
    uglify = require('gulp-uglify'),
    imagemin = require('gulp-imagemin'),
    htmlmin = require('gulp-htmlmin'),
    pkg = require('./package.json'),
    assets = require('./assets');

var gulpFileCwd = __dirname + '/public';
process.chdir(gulpFileCwd);
util.log('Working directory changed to', gulpFileCwd);

gulp.task('html', function() {
  return gulp.src('../server/views/**/*.html')
	.pipe(htmlmin({collapseWhitespace: true, removeComments: true}))
	.pipe(gulp.dest('../dist/server/views/'));
});

gulp.task('scripts', function() {
  return gulp.src(assets.development.js)
        .pipe(concat('bundle-scripts.js'))
        .pipe(uglify())
        .pipe(gulp.dest('../dist/public/js/'));
});

gulp.task('styles', function() {
  return gulp.src(assets.development.css)
        .pipe(concat('bundle-styles.css'))
        .pipe(minifycss({processImport: false}))
        .pipe(gulp.dest('../dist/public/css/'));
});

gulp.task('copy', function() {
  var server_assets = gulp.src('../server/assets/**/*')
		.pipe(gulp.dest('../dist/server/assets/'));

  var server_base = gulp.src('../server/base/**/*')
		.pipe(gulp.dest('../dist/server/base/'));

  var server_locales = gulp.src('../server/locales/**/*')
		.pipe(gulp.dest('../dist/server/locales/'));

  var server_config = gulp.src(['../assets.js', '../package.json', '../server.js'])
		.pipe(gulp.dest('../dist/'));

  return merge(server_assets, server_base, server_locales, server_config);

});

gulp.task('images', function() {
  return gulp.src('./images/*')
        .pipe(imagemin())
        .pipe(gulp.dest('../dist/public/images/'));
});

gulp.task('default', function() {
    gulp.start('html', 'scripts', 'styles', 'copy', 'images');
});
<|endoftext|>