<commit_before>/* global __dirname */
'use strict';
var fs = require('fs');

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var gutil = require('gulp-util');

var handlebars = require('gulp-compile-handlebars');
var tagVersion = require('gulp-tag-version');
var minifyCSS = require('gulp-minify-css');
var scsslint = require('gulp-scss-lint');

var karma = require('karma').server;

var browserSync = require('browser-sync');
var reload = browserSync.reload;

var glob = require('glob');
var runSequence = require('run-sequence');
var changelog = require('conventional-changelog');

var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');

var watchify = require('watchify');
var browserify = require('browserify');

// transforms
var to5ify = require('6to5ify');

var APP_DIR = 'app';
var BUILD_DIR = 'build';

var config = {};

config.app = APP_DIR;
config.build = BUILD_DIR;

config.html = {
    files: [
        APP_DIR + '/**/*.html'
    ]
};

config.js = {
    files: [
        APP_DIR + '/**/*.js',
        '!' + APP_DIR + '/bower_components/**/*.js',
        '!' + APP_DIR + '/templates.js',
        '!' + APP_DIR + '/app.min.js'
    ]
};

config.scss = {
    files: [
        APP_DIR + '/**/*.scss',
        '!' + APP_DIR + '/bower_components/**/*.scss'
    ],
    src: APP_DIR + '/app.scss',
    devDest: APP_DIR + '/app.css',
    buildDest: BUILD_DIR + '/app.css'
};

var release = function(importance) {
    return gulp.src(['./bower.json', './package.json'])
        .pipe($.bump({
            type: importance
        }))
        .pipe(gulp.dest('./'))
        .pipe($.git.commit('bumps package version'))
        .pipe($.filter('bower.json'))
        .pipe(tagVersion());
};

var handlebarOpts = {
    helpers: {
        assetPath: function(path, context) {
            return [context.data.root[path]].join('/');
        }
    }
};

gulp.task('browserify', function() {
    var bundler = watchify(browserify({
        entries: ['./app/app.js'],
        debug: true,
        insertGlobals: true
    }));

    bundler.transform(to5ify);
    bundler.on('error', gutil.log.bind(gutil, 'Browserify Error'));

    bundler.on('update', rebundle);

    function rebundle() {
        return bundler.bundle()
            .pipe($.plumber())
            .on('error', gutil.log.bind(gutil, 'Browserify Error'))
            .pipe(source('app.min.js'))
            .pipe(buffer())
            .pipe($.sourcemaps.init({
                loadMaps: true
            }))
            // Add transformation tasks to the pipeline here.
            // .pipe($.uglify())
            .pipe($.sourcemaps.write('./'))
            .pipe(gulp.dest(config.app));
    }

    return rebundle();
});

gulp.task('cachebust', function() {
    return gulp.src([
            'build/app.css',
            'build/app.js'
        ], {
            base: 'app'
        })
        .pipe(gulp.dest(config.build))
        .pipe($.rev())
        .pipe(gulp.dest(config.build))
        .pipe($.rev.manifest())
        .pipe(gulp.dest(config.build));
});

gulp.task('changelog', function(done) {
    function changeParsed(err, log) {
        if (err) {
            return done(err);
        }
        fs.writeFile('CHANGELOG.md', log, done);
    }
    fs.readFile('./package.json', 'utf8', function(err, data) {
        var ref$ = JSON.parse(data);
        var repository = ref$.repository;
        var version = ref$.version;

        changelog({
            repository: repository.url,
            version: version
        }, changeParsed);
    });
});

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

gulp.task('convert', function() {
    return gulp.src(config.app + 'bower_components/**/*.css')
        .pipe($.rename({
            extname: '.copy.scss'
        }))
        .pipe(gulp.dest(config.app + 'bower_components/'));
});

gulp.task('copy', function() {
    gulp.src(config.appDir + '**/*.html')
        .pipe(gulp.dest(config.build));
});

gulp.task('handlebars:build', function() {
    // read in our manifest file
    var manifest = JSON.parse(fs.readFileSync(config.build + '/rev-manifest.json', 'utf8'));

    // read in our handlebars template, compile it using
    // our manifest, and output it to index.html
    return gulp.src(config.build + '/index.hbs')
        .pipe(handlebars(manifest, handlebarOpts))
        .pipe($.rename(config.build + '/index.html'))
        .pipe(gulp.dest('./'));
});

gulp.task('handlebars:dev', function() {
    var manifest = JSON.parse(fs.readFileSync(config.app + '/rev-manifest.json', 'utf8'));

    return gulp.src(config.app + '/index.hbs')
        .pipe(handlebars(manifest, handlebarOpts))
        .pipe($.rename(config.app + '/index.html'))
        .pipe(gulp.dest('./'));
});

gulp.task('jshint', function() {
    return gulp.src(config.js.files)
        .pipe($.plumber())
        .pipe($.jshint())
        .pipe($.jshint.reporter('jshint-stylish'));
});

gulp.task('serve', function() {
    browserSync({
        server: {
            baseDir: config.app
        }
    });

    gulp.watch([
        '**/*.scss',
        '!bower_components/**'
    ], {
        cwd: config.app
    }, ['scss-dev']);
});

gulp.task('scss-dev', function(cb) {
    gulp.src(config.scss.src)
        .pipe($.plumber())
        .pipe($.sourcemaps.init())
        .pipe($.sass({
            errLogToConsole: true
        }))
        .pipe($.sourcemaps.write({
            includeContent: false,
            sourceRoot: '.'
        }))
        .pipe($.sourcemaps.init({
            loadMaps: true
        }))
        .pipe($.autoprefixer())
        .pipe($.sourcemaps.write('.', {
            includeContent: false,
            sourceRoot: '.'
        }))
        .pipe(gulp.dest(config.app))
        .pipe($.filter(config.app + '/*.css'))
        .pipe(reload({
            stream: true
        }));
    cb();
});

gulp.task('scss-build', function() {
    return gulp.src(config.scss.src)
        .pipe(scsslint({
            config: '.scss-lint.yml'
        }))
        .pipe($.sass())
        .pipe($.autoprefixer())
        .pipe($.uncss({
            html: glob.sync('app/**/*.html')
        }))
        .pipe(minifyCSS({
            keepSpecialComments: 0
        }))
        .pipe(gulp.dest(config.build));
});

gulp.task('test', function(done) {
    karma.start({
        configFile: __dirname + '/karma.conf.js',
        singleRun: true
    }, done);
});

gulp.task('default', [
    'browserify',
    'handlebars:dev',
    'serve',
    'scss-dev',
    'watch'
]);

gulp.task('watch', function() {
    gulp.watch(config.js.files, ['browserify']);
});

gulp.task('build', function() {
    runSequence('test', 'clean', ['scss-build'], 'cachebust', 'changelog');
});

gulp.task('patch', ['build'], function() {
    return release('patch');
});

gulp.task('feature', ['build'], function() {
    return release('minor');
});

gulp.task('release', ['build'], function() {
    return release('major');
});
<commit_msg>chore(karma): Remove config from gulp<commit_after>/* global __dirname */
'use strict';
var fs = require('fs');

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var gutil = require('gulp-util');

var handlebars = require('gulp-compile-handlebars');
var tagVersion = require('gulp-tag-version');
var minifyCSS = require('gulp-minify-css');
var scsslint = require('gulp-scss-lint');

var karma = require('karma').server;

var browserSync = require('browser-sync');
var reload = browserSync.reload;

var glob = require('glob');
var runSequence = require('run-sequence');
var changelog = require('conventional-changelog');

var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');

var watchify = require('watchify');
var browserify = require('browserify');

// transforms
var to5ify = require('6to5ify');

var APP_DIR = 'app';
var BUILD_DIR = 'build';

var config = {};

config.app = APP_DIR;
config.build = BUILD_DIR;

config.html = {
    files: [
        APP_DIR + '/**/*.html'
    ]
};

config.js = {
    files: [
        APP_DIR + '/**/*.js',
        '!' + APP_DIR + '/**/*.spec.js',
        '!' + APP_DIR + '/bower_components/**/*.js',
        '!' + APP_DIR + '/templates.js',
        '!' + APP_DIR + '/app.min.js'
    ]
};

config.scss = {
    files: [
        APP_DIR + '/**/*.scss',
        '!' + APP_DIR + '/bower_components/**/*.scss'
    ],
    src: APP_DIR + '/app.scss',
    devDest: APP_DIR + '/app.css',
    buildDest: BUILD_DIR + '/app.css'
};

var release = function(importance) {
    return gulp.src(['./bower.json', './package.json'])
        .pipe($.bump({
            type: importance
        }))
        .pipe(gulp.dest('./'))
        .pipe($.git.commit('bumps package version'))
        .pipe($.filter('bower.json'))
        .pipe(tagVersion());
};

var handlebarOpts = {
    helpers: {
        assetPath: function(path, context) {
            return [context.data.root[path]].join('/');
        }
    }
};

gulp.task('browserify', function() {
    var bundler = watchify(browserify({
        entries: ['./app/app.js'],
        debug: true,
        insertGlobals: true
    }));

    bundler.transform(to5ify);
    bundler.on('error', gutil.log.bind(gutil, 'Browserify Error'));

    bundler.on('update', rebundle);

    function rebundle() {
        return bundler.bundle()
            .pipe($.plumber())
            .on('error', gutil.log.bind(gutil, 'Browserify Error'))
            .pipe(source('app.min.js'))
            .pipe(buffer())
            .pipe($.sourcemaps.init({
                loadMaps: true
            }))
            // Add transformation tasks to the pipeline here.
            // .pipe($.uglify())
            .pipe($.sourcemaps.write('./'))
            .pipe(gulp.dest(config.app));
    }

    return rebundle();
});

gulp.task('cachebust', function() {
    return gulp.src([
            'build/app.css',
            'build/app.js'
        ], {
            base: 'app'
        })
        .pipe(gulp.dest(config.build))
        .pipe($.rev())
        .pipe(gulp.dest(config.build))
        .pipe($.rev.manifest())
        .pipe(gulp.dest(config.build));
});

gulp.task('changelog', function(done) {
    function changeParsed(err, log) {
        if (err) {
            return done(err);
        }
        fs.writeFile('CHANGELOG.md', log, done);
    }
    fs.readFile('./package.json', 'utf8', function(err, data) {
        var ref$ = JSON.parse(data);
        var repository = ref$.repository;
        var version = ref$.version;

        changelog({
            repository: repository.url,
            version: version
        }, changeParsed);
    });
});

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

gulp.task('convert', function() {
    return gulp.src(config.app + 'bower_components/**/*.css')
        .pipe($.rename({
            extname: '.copy.scss'
        }))
        .pipe(gulp.dest(config.app + 'bower_components/'));
});

gulp.task('copy', function() {
    gulp.src(config.appDir + '**/*.html')
        .pipe(gulp.dest(config.build));
});

gulp.task('handlebars:build', function() {
    // read in our manifest file
    var manifest = JSON.parse(fs.readFileSync(config.build + '/rev-manifest.json', 'utf8'));

    // read in our handlebars template, compile it using
    // our manifest, and output it to index.html
    return gulp.src(config.build + '/index.hbs')
        .pipe(handlebars(manifest, handlebarOpts))
        .pipe($.rename(config.build + '/index.html'))
        .pipe(gulp.dest('./'));
});

gulp.task('handlebars:dev', function() {
    var manifest = JSON.parse(fs.readFileSync(config.app + '/rev-manifest.json', 'utf8'));

    return gulp.src(config.app + '/index.hbs')
        .pipe(handlebars(manifest, handlebarOpts))
        .pipe($.rename(config.app + '/index.html'))
        .pipe(gulp.dest('./'));
});

gulp.task('jshint', function() {
    return gulp.src(config.js.files)
        .pipe($.plumber())
        .pipe($.jshint())
        .pipe($.jshint.reporter('jshint-stylish'));
});

gulp.task('serve', function() {
    browserSync({
        server: {
            baseDir: config.app
        }
    });

    gulp.watch([
        '**/*.scss',
        '!bower_components/**'
    ], {
        cwd: config.app
    }, ['scss-dev']);
});

gulp.task('scss-dev', function(cb) {
    gulp.src(config.scss.src)
        .pipe($.plumber())
        .pipe($.sourcemaps.init())
        .pipe($.sass({
            errLogToConsole: true
        }))
        .pipe($.sourcemaps.write({
            includeContent: false,
            sourceRoot: '.'
        }))
        .pipe($.sourcemaps.init({
            loadMaps: true
        }))
        .pipe($.autoprefixer())
        .pipe($.sourcemaps.write('.', {
            includeContent: false,
            sourceRoot: '.'
        }))
        .pipe(gulp.dest(config.app))
        .pipe($.filter(config.app + '/*.css'))
        .pipe(reload({
            stream: true
        }));
    cb();
});

gulp.task('scss-build', function() {
    return gulp.src(config.scss.src)
        .pipe(scsslint({
            config: '.scss-lint.yml'
        }))
        .pipe($.sass())
        .pipe($.autoprefixer())
        .pipe($.uncss({
            html: glob.sync('app/**/*.html')
        }))
        .pipe(minifyCSS({
            keepSpecialComments: 0
        }))
        .pipe(gulp.dest(config.build));
});

gulp.task('test', function(done) {
    karma.start({
        configFile: __dirname + '/karma.conf.js'
    }, done);
});

gulp.task('default', [
    'browserify',
    'handlebars:dev',
    'serve',
    'scss-dev',
    'watch'
]);

gulp.task('watch', function() {
    gulp.watch(config.js.files, ['browserify']);
});

gulp.task('build', function() {
    runSequence('test', 'clean', ['scss-build'], 'cachebust', 'changelog');
});

gulp.task('patch', ['build'], function() {
    return release('patch');
});

gulp.task('feature', ['build'], function() {
    return release('minor');
});

gulp.task('release', ['build'], function() {
    return release('major');
});
<|endoftext|>


<commit_before>const gulp = require('gulp');
const path = require('path');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config');
const webpackStream = require('webpack-stream');
const babel = require('gulp-babel');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-babel-istanbul');
const coveralls = require('gulp-coveralls');
const eslint = require('gulp-eslint');

function build() {
  return gulp.src('./src/formwood.js')
    .pipe(webpackStream(webpackConfig, webpack));
}

function sendToCoveralls() {
  gulp.src('coverage/**/lcov.info')
    .pipe(coveralls());
}

function runMochaTests() {
  return gulp.src('test/unit/**/*.js', {read: false})
    .pipe(mocha({
      reporter: 'dot',
      ignoreLeaks: false
    }));
}

function test() {
  require('babel-core/register');
  return gulp.src('src/**/*.js')
    .pipe(istanbul())
    .pipe(istanbul.hookRequire())
    .on('finish', function() {
      runMochaTests()
        .pipe(istanbul.writeReports())
    });
}

function lint() {
  return gulp.src('src/**/*')
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
}

gulp.task('build', build);
gulp.task('test', test);
gulp.task('coveralls', sendToCoveralls);
gulp.task('lint', lint);
gulp.task('default', ['build']);
<commit_msg>Fix issue with missing dist output<commit_after>const gulp = require('gulp');
const path = require('path');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config');
const webpackStream = require('webpack-stream');
const babel = require('gulp-babel');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-babel-istanbul');
const coveralls = require('gulp-coveralls');
const eslint = require('gulp-eslint');
const manifest = require('./package.json');

const mainFile = manifest.main
const destinationDirectory = path.dirname(mainFile);

function build() {
  return gulp.src('./src/formwood.js')
    .pipe(webpackStream(webpackConfig, webpack))
    .pipe(gulp.dest(destinationDirectory));
}

function sendToCoveralls() {
  gulp.src('coverage/**/lcov.info')
    .pipe(coveralls());
}

function runMochaTests() {
  return gulp.src('test/unit/**/*.js', {read: false})
    .pipe(mocha({
      reporter: 'dot',
      ignoreLeaks: false
    }));
}

function test() {
  require('babel-core/register');
  return gulp.src('src/**/*.js')
    .pipe(istanbul())
    .pipe(istanbul.hookRequire())
    .on('finish', function() {
      runMochaTests()
        .pipe(istanbul.writeReports())
    });
}

function lint() {
  return gulp.src('src/**/*')
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
}

gulp.task('build', build);
gulp.task('test', test);
gulp.task('coveralls', sendToCoveralls);
gulp.task('lint', lint);
gulp.task('default', ['build']);
<|endoftext|>


<commit_before>var Fs = require('fire-fs');
var Path = require('path');
var Del = require('del');
var Chalk = require('chalk');
var Npmconf = require('npmconf');

var gulp = require('gulp');
var gulpSequence = require('gulp-sequence');

var git = require('./utils/libs/git.js');
var pjson = require('./package.json');
var spawn = require('child_process').spawn;

// require tasks
require('./utils/gulp-tasks/electron-tasks');
require('./utils/gulp-tasks/setup-tasks');

// init and update
// =====================================

gulp.task('bootstrap',
    gulpSequence([
        'install-builtin',
        'install-shared-packages'
    ],'update-electron')
);

gulp.task('update',
    gulpSequence(
        'setup-branch',
        'update-editor-framework',
        'update-builtin',
        'remove-builtin-bin',
        'update-shared-packages',
        'update-electron',
        'check-dependencies'
    )
);

gulp.task('pre-install-npm', ['setup-mirror'], function(cb) {
    var mirror = JSON.parse(Fs.readFileSync('local-setting.json')).mirror;
    Npmconf.load(function(_, conf) {
        var registry = Npmconf.defaults.registry;
        if (mirror === 'china') {
            registry = 'http://registry.npm.taobao.org/';
        }
        conf.set('registry', registry, 'user');
        conf.save('user', cb);
    });
});

gulp.task('post-install-npm', function(cb) {
    // resume the default config when being installed
    Npmconf.load(function(_, conf) {
        conf.set('registry', Npmconf.defaults.registry, 'user');
        conf.save('user', cb);
    });
});

// run
// =====================================

gulp.task('run', function(cb) {
    var cmdStr = '';
    var optArr = [];
    if (process.platform === 'win32') {
        cmdStr = 'bin\\electron\\electron.exe';
        optArr = ['.\\', '--debug=3030', '--dev', '--show-devtools'];
    }
    else if (process.platform === 'darwin') {
        cmdStr = 'bin/electron/Electron.app/Contents/MacOS/Electron';
        optArr = ['./', '--debug=3030', '--dev', '--show-devtools'];
    }
    else {
        cmdStr = 'bin/electron/electron';
        optArr = ['./', '--debug=3030', '--dev', '--show-devtools'];
    }
    var child = spawn(cmdStr, optArr, {
        stdio: 'inherit'
    });
    child.on('exit', function() {
        cb();
    });
});

// self
// =====================================

gulp.task('update-editor-framework', function(cb) {
    var Async = require('async');

    Async.series([
        function ( next ) {
            git.exec(['pull', 'https://github.com/fireball-x/editor-framework.git', 'master'], './', next);
        },

        function ( next ) {
            console.log('editor-framework update complete!');
            git.exec(['fetch', '--all'], './', next);
        },

        function ( next ) {
            // NOTE: when we update the main project, we should reload its package.json
            pjson = JSON.parse(Fs.readFileSync('./package.json'));
            next();
        },

    ], function ( err ) {
        if ( err ) throw err;
        cb ();
    });
});

// builtin
// =====================================

gulp.task('install-builtin', function(cb) {
    Fs.ensureDirSync('builtin');

    var Async = require('async');
    Async.eachLimit( pjson.builtins, 5, function ( name, done ) {
        git.clone('https://github.com/fireball-packages/' + name,
                  Path.join('builtin', name),
                  done);
    }, function ( err ) {
        console.log('Builtin packages installation complete!');
        cb();
    });
});

gulp.task('update-builtin', function(cb) {
    var setting = JSON.parse(Fs.readFileSync('local-setting.json'));

    if ( !Fs.isDirSync('builtin') ) {
        console.error(Chalk.red('Builtin folder not initialized, please run "gulp install-builtin" first!'));
        return cb();
    }

    var Async = require('async');
    Async.eachLimit( pjson.builtins, 5, function ( name, done ) {
        if ( !Fs.existsSync(Path.join('builtin', name, '.git')) ) {
            console.error(Chalk.red('Builtin package ' + name + ' not initialized, please run "gulp install-builtin" first!'));
            process.exit(1);
            return;
        }

        var branch = 'master';
        if ( setting.branch.builtins ) {
            branch = setting.branch.builtins.name || 'master';
        }

        git.pull(Path.join('builtin', name),
                 'https://github.com/fireball-packages/' + name,
                 branch,
                 done);
    }, function ( err ) {
        if ( err ) {
            process.exit(1);
            return;
        }

        console.log('Builtin packages update complete!');
        return cb();
    });
});

gulp.task('remove-builtin-bin', function(cb) {
    var bins = pjson.builtins.filter(function(name) {
        var json = JSON.parse(Fs.readFileSync(Path.join('builtin', name, 'package.json')));
        return json.build;
    }).map(function (name) {
        return Path.join('builtin', name, 'bin');
    });

    console.log('Clean built files for ' + bins);
    Del(bins, function(err) {
        if (err) {
            throw err;
        }

        console.log('Builtin Packages Cleaned! Will be rebuilt when Icebolt launches.');
        cb();
    });
});

gulp.task('prune-builtin', function(cb) {
    var results = Fs.readdirSync('builtin').filter(function ( name ) {
        return pjson.builtins.indexOf(name) === -1;
    });

    results = results.map(function ( name ) {
        return Path.join( 'builtin', name );
    });

    Del( results, function ( err ) {
        if (err) {
            throw err;
        }

        results.forEach( function (name) {
            console.log( 'Prune builtin package ' + name );
        });

        cb();
    });
});

// shared-packages
// =====================================

gulp.task('install-shared-packages', function(cb) {
    var Async = require('async');
    Async.eachLimit( pjson.sharedPackages, 5, function ( name, done ) {
        git.clone('https://github.com/fireball-packages/' + name,
                  name,
                  done);
    }, function ( err ) {
        console.log('Shared packages installation complete!');
        cb();
    });
});

gulp.task('update-shared-packages', function(cb) {
    var setting = JSON.parse(Fs.readFileSync('local-setting.json'));

    var Async = require('async');
    Async.eachLimit( pjson.sharedPackages, 5, function ( name, done ) {
        if ( !Fs.existsSync(Path.join(name, '.git')) ) {
            console.error(Chalk.red('Shared package ' + name + ' not initialized, please run "gulp install-shared-packages" first!'));
            process.exit(1);
            return;
        }

        var branch = 'master';
        if ( setting.branch.sharedPackages ) {
            branch = setting.branch.sharedPackages.name || 'master';
        }

        git.pull(name,
                 'https://github.com/fireball-packages/' + name,
                 branch,
                 done);
    }, function ( err ) {
        if ( err ) {
            process.exit(1);
            return;
        }

        console.log('Shared packages update complete!');
        return cb();
    });
});

// native rebuild
// =====================================

function findNativeModulePathRecursive(path) {
    var nativePaths = [];
    if (Fs.existsSync(Path.join(path, 'binding.gyp'))) {
        nativePaths.push(path);
    } else {
        if (Fs.isDirSync(Path.join(path, 'node_modules'))) {
            var subPaths = Fs.readdirSync(Path.join(path, 'node_modules'));
            subPaths.forEach(function(subpath) {
                var subCollect = findNativeModulePathRecursive(Path.join(path, 'node_modules', subpath));
                if (subCollect.length > 0) {
                    nativePaths = nativePaths.concat(subCollect);
                }
            });
        }
    }
    return nativePaths;
}

gulp.task('npm-rebuild', function(cb) {
    var cmdstr;
    var tmpenv = process.env;
    var arch;
    if (process.platform === 'win32') {
        cmdstr = 'node-gyp.cmd';
        tmpenv.HOME = Path.join(tmpenv.HOMEPATH, '.electron-gyp');
        arch = 'ia32';
    } else {
        cmdstr = 'node-gyp';
        tmpenv.HOME = Path.join(tmpenv.HOME, '.electron-gyp');
        var os = require('os');
        arch = os.arch();
    }
    var disturl = 'https://atom.io/download/atom-shell';
    var target = pjson.electronVersion;
    // var arch = process.platform === 'win32' ? 'ia32' : 'x64';
    var nativePaths = findNativeModulePathRecursive('.');
    console.log('rebuilding native modules: \n' + nativePaths);
    var count = nativePaths.length;
    if (count === 0) {
        console.log('no native module found!');
        return cb();
    }
    nativePaths.forEach(function(path) {
        var child = spawn(cmdstr, [
            'rebuild', '--target='+target,
            '--arch='+arch, '--dist-url='+disturl
            ], {
            stdio: 'inherit',
            env: tmpenv,
            cwd: path
        });
        child.on('exit', function() {
            if (--count <= 0) {
                cb();
            }
        });
    });
});

// deps
// =====================================

gulp.task('check-dependencies', function(cb) {
    var checkdeps = require('check-dependencies');
    console.log(Chalk.cyan('====Checking Dependencies===='));
    var count = 2;
    checkdeps({
        packageManager: 'npm',
        verbose: true,
        checkGitUrls: true
    }, function() {
        if (--count<=0) {
            console.log('If you see any version number in ' + Chalk.red('red') + '. Please run ' + Chalk.cyan('"npm install && bower install"') + 'to install missing dependencies');
            cb();
        }
    });
    checkdeps({
        packageManager: 'bower',
        verbose: true,
        checkGitUrls: true
    }, function() {
        if (--count<=0) {
            console.log('If you see any version number in ' + Chalk.red('red') + '. Please run ' + Chalk.cyan('"npm install && bower install"') + 'to install missing dependencies');
            cb();
        }
    });
});
<commit_msg>fix gulpfile can not checkout to correct branch<commit_after>var Fs = require('fire-fs');
var Path = require('path');
var Del = require('del');
var Chalk = require('chalk');
var Npmconf = require('npmconf');

var gulp = require('gulp');
var gulpSequence = require('gulp-sequence');

var git = require('./utils/libs/git.js');
var pjson = require('./package.json');
var spawn = require('child_process').spawn;

// require tasks
require('./utils/gulp-tasks/electron-tasks');
require('./utils/gulp-tasks/setup-tasks');

// init and update
// =====================================

gulp.task('bootstrap',
    gulpSequence([
        'install-builtin',
        'install-shared-packages'
    ],'update-electron')
);

gulp.task('update',
    gulpSequence(
        'setup-branch',
        'update-editor-framework',
        'update-builtin',
        'remove-builtin-bin',
        'update-shared-packages',
        'update-electron',
        'check-dependencies'
    )
);

gulp.task('pre-install-npm', ['setup-mirror'], function(cb) {
    var mirror = JSON.parse(Fs.readFileSync('local-setting.json')).mirror;
    Npmconf.load(function(_, conf) {
        var registry = Npmconf.defaults.registry;
        if (mirror === 'china') {
            registry = 'http://registry.npm.taobao.org/';
        }
        conf.set('registry', registry, 'user');
        conf.save('user', cb);
    });
});

gulp.task('post-install-npm', function(cb) {
    // resume the default config when being installed
    Npmconf.load(function(_, conf) {
        conf.set('registry', Npmconf.defaults.registry, 'user');
        conf.save('user', cb);
    });
});

// run
// =====================================

gulp.task('run', function(cb) {
    var cmdStr = '';
    var optArr = [];
    if (process.platform === 'win32') {
        cmdStr = 'bin\\electron\\electron.exe';
        optArr = ['.\\', '--debug=3030', '--dev', '--show-devtools'];
    }
    else if (process.platform === 'darwin') {
        cmdStr = 'bin/electron/Electron.app/Contents/MacOS/Electron';
        optArr = ['./', '--debug=3030', '--dev', '--show-devtools'];
    }
    else {
        cmdStr = 'bin/electron/electron';
        optArr = ['./', '--debug=3030', '--dev', '--show-devtools'];
    }
    var child = spawn(cmdStr, optArr, {
        stdio: 'inherit'
    });
    child.on('exit', function() {
        cb();
    });
});

// self
// =====================================

gulp.task('update-editor-framework', function(cb) {
    var Async = require('async');

    Async.series([
        function ( next ) {
            git.exec(['pull', 'https://github.com/fireball-x/editor-framework.git', 'master'], './', next);
        },

        function ( next ) {
            console.log('editor-framework update complete!');
            git.exec(['fetch', '--all'], './', next);
        },

        function ( next ) {
            // NOTE: when we update the main project, we should reload its package.json
            pjson = JSON.parse(Fs.readFileSync('./package.json'));
            next();
        },

    ], function ( err ) {
        if ( err ) throw err;
        cb ();
    });
});

// builtin
// =====================================

gulp.task('install-builtin', function(cb) {
    Fs.ensureDirSync('builtin');

    var Async = require('async');
    Async.eachLimit( pjson.builtins, 5, function ( name, done ) {
        git.clone('https://github.com/fireball-packages/' + name,
                  Path.join('builtin', name),
                  done);
    }, function ( err ) {
        console.log('Builtin packages installation complete!');
        cb();
    });
});

gulp.task('update-builtin', function(cb) {
    var setting = JSON.parse(Fs.readFileSync('local-setting.json'));

    if ( !Fs.isDirSync('builtin') ) {
        console.error(Chalk.red('Builtin folder not initialized, please run "gulp install-builtin" first!'));
        return cb();
    }

    var Async = require('async');
    Async.eachLimit( pjson.builtins, 5, function ( name, done ) {
        if ( !Fs.existsSync(Path.join('builtin', name, '.git')) ) {
            console.error(Chalk.red('Builtin package ' + name + ' not initialized, please run "gulp install-builtin" first!'));
            process.exit(1);
            return;
        }

        var branch = 'master';
        if ( setting.branch.builtins ) {
            branch = setting.branch.builtins[name] || 'master';
        }

        git.pull(Path.join('builtin', name),
                 'https://github.com/fireball-packages/' + name,
                 branch,
                 done);
    }, function ( err ) {
        if ( err ) {
            process.exit(1);
            return;
        }

        console.log('Builtin packages update complete!');
        return cb();
    });
});

gulp.task('remove-builtin-bin', function(cb) {
    var bins = pjson.builtins.filter(function(name) {
        var json = JSON.parse(Fs.readFileSync(Path.join('builtin', name, 'package.json')));
        return json.build;
    }).map(function (name) {
        return Path.join('builtin', name, 'bin');
    });

    console.log('Clean built files for ' + bins);
    Del(bins, function(err) {
        if (err) {
            throw err;
        }

        console.log('Builtin Packages Cleaned! Will be rebuilt when Icebolt launches.');
        cb();
    });
});

gulp.task('prune-builtin', function(cb) {
    var results = Fs.readdirSync('builtin').filter(function ( name ) {
        return pjson.builtins.indexOf(name) === -1;
    });

    results = results.map(function ( name ) {
        return Path.join( 'builtin', name );
    });

    Del( results, function ( err ) {
        if (err) {
            throw err;
        }

        results.forEach( function (name) {
            console.log( 'Prune builtin package ' + name );
        });

        cb();
    });
});

// shared-packages
// =====================================

gulp.task('install-shared-packages', function(cb) {
    var Async = require('async');
    Async.eachLimit( pjson.sharedPackages, 5, function ( name, done ) {
        git.clone('https://github.com/fireball-packages/' + name,
                  name,
                  done);
    }, function ( err ) {
        console.log('Shared packages installation complete!');
        cb();
    });
});

gulp.task('update-shared-packages', function(cb) {
    var setting = JSON.parse(Fs.readFileSync('local-setting.json'));

    var Async = require('async');
    Async.eachLimit( pjson.sharedPackages, 5, function ( name, done ) {
        if ( !Fs.existsSync(Path.join(name, '.git')) ) {
            console.error(Chalk.red('Shared package ' + name + ' not initialized, please run "gulp install-shared-packages" first!'));
            process.exit(1);
            return;
        }

        var branch = 'master';
        if ( setting.branch.sharedPackages ) {
            branch = setting.branch.sharedPackages[name] || 'master';
        }

        git.pull(name,
                 'https://github.com/fireball-packages/' + name,
                 branch,
                 done);
    }, function ( err ) {
        if ( err ) {
            process.exit(1);
            return;
        }

        console.log('Shared packages update complete!');
        return cb();
    });
});

// native rebuild
// =====================================

function findNativeModulePathRecursive(path) {
    var nativePaths = [];
    if (Fs.existsSync(Path.join(path, 'binding.gyp'))) {
        nativePaths.push(path);
    } else {
        if (Fs.isDirSync(Path.join(path, 'node_modules'))) {
            var subPaths = Fs.readdirSync(Path.join(path, 'node_modules'));
            subPaths.forEach(function(subpath) {
                var subCollect = findNativeModulePathRecursive(Path.join(path, 'node_modules', subpath));
                if (subCollect.length > 0) {
                    nativePaths = nativePaths.concat(subCollect);
                }
            });
        }
    }
    return nativePaths;
}

gulp.task('npm-rebuild', function(cb) {
    var cmdstr;
    var tmpenv = process.env;
    var arch;
    if (process.platform === 'win32') {
        cmdstr = 'node-gyp.cmd';
        tmpenv.HOME = Path.join(tmpenv.HOMEPATH, '.electron-gyp');
        arch = 'ia32';
    } else {
        cmdstr = 'node-gyp';
        tmpenv.HOME = Path.join(tmpenv.HOME, '.electron-gyp');
        var os = require('os');
        arch = os.arch();
    }
    var disturl = 'https://atom.io/download/atom-shell';
    var target = pjson.electronVersion;
    // var arch = process.platform === 'win32' ? 'ia32' : 'x64';
    var nativePaths = findNativeModulePathRecursive('.');
    console.log('rebuilding native modules: \n' + nativePaths);
    var count = nativePaths.length;
    if (count === 0) {
        console.log('no native module found!');
        return cb();
    }
    nativePaths.forEach(function(path) {
        var child = spawn(cmdstr, [
            'rebuild', '--target='+target,
            '--arch='+arch, '--dist-url='+disturl
            ], {
            stdio: 'inherit',
            env: tmpenv,
            cwd: path
        });
        child.on('exit', function() {
            if (--count <= 0) {
                cb();
            }
        });
    });
});

// deps
// =====================================

gulp.task('check-dependencies', function(cb) {
    var checkdeps = require('check-dependencies');
    console.log(Chalk.cyan('====Checking Dependencies===='));
    var count = 2;
    checkdeps({
        packageManager: 'npm',
        verbose: true,
        checkGitUrls: true
    }, function() {
        if (--count<=0) {
            console.log('If you see any version number in ' + Chalk.red('red') + '. Please run ' + Chalk.cyan('"npm install && bower install"') + 'to install missing dependencies');
            cb();
        }
    });
    checkdeps({
        packageManager: 'bower',
        verbose: true,
        checkGitUrls: true
    }, function() {
        if (--count<=0) {
            console.log('If you see any version number in ' + Chalk.red('red') + '. Please run ' + Chalk.cyan('"npm install && bower install"') + 'to install missing dependencies');
            cb();
        }
    });
});
<|endoftext|>


<commit_before>/* global require */

var gulp = require('gulp');
var eslint = require('gulp-eslint');
var gulpIf = require('gulp-if');
var jshint = require('gulp-jshint');
var prettify = require('gulp-jsbeautifier');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var del = require('del');
var fs = require('fs');
var pkg = require('./package.json');

// Assets for the project
var Assets = {
    css: {
        main: './example.scss',
        compiled: './example.css',
        source: './',
    },
    js: {
        main: './jquery.creep.js',
        minified: './jquery.creep.min.js',
        source: './',
    },
    package: './package.json',
};

// See the sass documentation for more details
var _sassSettings = {
    // Options are 'nested', 'compact', 'compressed', 'expanded'
    outputStyle: 'compressed',
};

// See the uglify documentation for more details
var _uglifySettings = {
    compress: {
        comparisons: true,
        conditionals: true,
        /* jscs: disable */
        dead_code: true,
        drop_console: true,
        /* jscs: enable */
        unsafe: true,
        unused: true,
    },
};

// Clean the current directory
gulp.task('clean', function clesnTask(cb) {
    del([Assets.js.minified], cb);
});

// Check the main js file meets the following standards outlined in .eslintrc
gulp.task('eslint', function esLintTask() {
    // Has ESLint fixed the file contents?
    function isFixed(file) {
        return file.eslint !== undefined && file.eslint !== null && file.eslint.fixed;
    }

    return gulp.src(Assets.js.main)
        .pipe(eslint({
            fix: true,
            useEslintrc: '.eslintrc',
        }))
        .pipe(eslint.format())
        .pipe(gulpIf(isFixed, gulp.dest(Assets.js.source)));
});

// Prettify the main js file
gulp.task('prettify-js', function prettifyJSTask() {
    gulp.src(Assets.js.main)
        .pipe(prettify({
            config: '.jsbeautifyrc',
            mode: 'VERIFY_AND_WRITE',
        }))
        .pipe(gulp.dest(Assets.js.source));
});

// Compile the main scss (sass) stylesheet
gulp.task('sass', function sassTask() {
    return gulp.src(Assets.css.main)
        .pipe(sass(_sassSettings))
        .pipe(rename(Assets.css.compiled))
        .pipe(gulp.dest(Assets.css.source));
});

// Uglify aka minify the main js file
gulp.task('uglify', function uglifyTask() {
    return gulp.src(Assets.js.main)
        .pipe(uglify(_uglifySettings))
        .pipe(rename(Assets.js.minified))
        .pipe(gulp.dest(Assets.js.source));
});

// Update version numbers based on the main file version comment
gulp.task('version', function versionTask() {
    // SemVer matching is done using (?:\d+\.){2}\d+

    var reVersion = /(?:(\n\s*\*\s+Version:\s+)(?:\d+\.){2}\d+)/;

    // Update the main js file version number
    return gulp.src(Assets.js.main)
        .pipe(replace(reVersion, '$1' + pkg.version))
        .pipe(gulp.dest(Assets.js.source));
});

// Register the default task
gulp.task('build', ['eslint', 'sass', 'version', 'clean', 'uglify']);

// Watch for changes to the js and scss files
gulp.task('default', function defaultTask() {
    gulp.watch(Assets.css.main, ['sass']);
    gulp.watch(Assets.js.main, ['version', 'eslint', 'clean', 'uglify']);
});

// 'gulp build' to invoke all tasks above
// 'gulp eslint' to check the syntax of the main js file
// 'gulp prettify-js' to prettify the main js file
// 'gulp sass' to compile the main scss (sass) file
// 'gulp uglify' to uglify the main js file
// 'gulp version' to update the version numbers based on the main js file version comment
<commit_msg>Removed unused requires<commit_after>/* global require */

var gulp = require('gulp');
var eslint = require('gulp-eslint');
var gulpIf = require('gulp-if');
var prettify = require('gulp-jsbeautifier');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var del = require('del');
var pkg = require('./package.json');

// Assets for the project
var Assets = {
    css: {
        main: './example.scss',
        compiled: './example.css',
        source: './',
    },
    js: {
        main: './jquery.creep.js',
        minified: './jquery.creep.min.js',
        source: './',
    },
    package: './package.json',
};

// See the sass documentation for more details
var _sassSettings = {
    // Options are 'nested', 'compact', 'compressed', 'expanded'
    outputStyle: 'compressed',
};

// See the uglify documentation for more details
var _uglifySettings = {
    compress: {
        comparisons: true,
        conditionals: true,
        /* jscs: disable */
        dead_code: true,
        drop_console: true,
        /* jscs: enable */
        unsafe: true,
        unused: true,
    },
};

// Clean the current directory
gulp.task('clean', function clesnTask(cb) {
    del([Assets.js.minified], cb);
});

// Check the main js file meets the following standards outlined in .eslintrc
gulp.task('eslint', function esLintTask() {
    // Has ESLint fixed the file contents?
    function isFixed(file) {
        return file.eslint !== undefined && file.eslint !== null && file.eslint.fixed;
    }

    return gulp.src(Assets.js.main)
        .pipe(eslint({
            fix: true,
            useEslintrc: '.eslintrc',
        }))
        .pipe(eslint.format())
        .pipe(gulpIf(isFixed, gulp.dest(Assets.js.source)));
});

// Prettify the main js file
gulp.task('prettify-js', function prettifyJSTask() {
    gulp.src(Assets.js.main)
        .pipe(prettify({
            config: '.jsbeautifyrc',
            mode: 'VERIFY_AND_WRITE',
        }))
        .pipe(gulp.dest(Assets.js.source));
});

// Compile the main scss (sass) stylesheet
gulp.task('sass', function sassTask() {
    return gulp.src(Assets.css.main)
        .pipe(sass(_sassSettings))
        .pipe(rename(Assets.css.compiled))
        .pipe(gulp.dest(Assets.css.source));
});

// Uglify aka minify the main js file
gulp.task('uglify', function uglifyTask() {
    return gulp.src(Assets.js.main)
        .pipe(uglify(_uglifySettings))
        .pipe(rename(Assets.js.minified))
        .pipe(gulp.dest(Assets.js.source));
});

// Update version numbers based on the main file version comment
gulp.task('version', function versionTask() {
    // SemVer matching is done using (?:\d+\.){2}\d+

    var reVersion = /(?:(\n\s*\*\s+Version:\s+)(?:\d+\.){2}\d+)/;

    // Update the main js file version number
    return gulp.src(Assets.js.main)
        .pipe(replace(reVersion, '$1' + pkg.version))
        .pipe(gulp.dest(Assets.js.source));
});

// Register the default task
gulp.task('build', ['eslint', 'sass', 'version', 'clean', 'uglify']);

// Watch for changes to the js and scss files
gulp.task('default', function defaultTask() {
    gulp.watch(Assets.css.main, ['sass']);
    gulp.watch(Assets.js.main, ['version', 'eslint', 'clean', 'uglify']);
});

// 'gulp build' to invoke all tasks above
// 'gulp eslint' to check the syntax of the main js file
// 'gulp prettify-js' to prettify the main js file
// 'gulp sass' to compile the main scss (sass) file
// 'gulp uglify' to uglify the main js file
// 'gulp version' to update the version numbers based on the main js file version comment
<|endoftext|>


<commit_before>var rootDestPath = "dist/";
var jsSrcPath = "lib/";
var jsDestPath = rootDestPath + "lib/";
var cssSrcPath = "assets/";
var cssDestPath = rootDestPath + "assets/";

var gulp = require("gulp");
var del = require("del");
var vinylpaths = require("vinyl-paths");
var concat = require("gulp-concat");
var uglify = require("gulp-uglify");
var rename = require("gulp-rename");
var sourcemaps = require("gulp-sourcemaps");
var babel = require("gulp-babel");
var cssnano = require("gulp-cssnano");
var htmlreplace = require("gulp-html-replace")
var browserSync = require('browser-sync').create();
var mainBowerFiles = require('gulp-main-bower-files');

gulp.task('serve', ['build'], function(){
    browserSync.init({
        server:{
            baseDir: 'dist'
        }
    });

    gulp.watch('index.html', browserSync.reload);
    gulp.watch('pages/**/*.html', browserSync.reload);
    gulp.watch('assets/**/*.css', browserSync.reload);
    gulp.watch('lib/**/*.js', ['build-js', browserSync.reload]);
});

gulp.task("default", ["build"]);
gulp.task("build", ["build-js", "build-bower-files", "build-html-templates", "build-css", "build-index-html"]);
gulp.task("clean", function(){
    return del("dist/*");
});

gulp.task("build-bower-files", ["clean-bower-files"], function(){
    return gulp.src("bower.json")
        .pipe(mainBowerFiles())
        .pipe(sourcemaps.init())
        .pipe(concat("extlibs.js"))
        .pipe(gulp.dest(jsDestPath))
        .pipe(uglify())
        .pipe(rename("extlibs.min.js"))
        .pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../../lib"}))
        .pipe(gulp.dest(jsDestPath));
});

gulp.task("clean-bower-files", function(){
    return del([jsDestPath + "extlibs.js"]);
});

gulp.task("build-js", ["clean-js"], function(){
    return gulp.src(jsSrcPath + "**/*.js")
        .pipe(sourcemaps.init())
        .pipe(concat("app.js"))
        .pipe(babel())
        .pipe(gulp.dest(jsDestPath))
        .pipe(uglify())
        .pipe(rename("app.min.js"))
        .pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../../lib"}))
        .pipe(gulp.dest(jsDestPath));
});

gulp.task("clean-js", function(){
    return del([jsDestPath + "app.js", jsDestPath + "app.min.js", jsDestPath + "app.min.js.map"]);
});

gulp.task("build-html-templates", ["clean-html-templates"], function(){
    return gulp.src(jsSrcPath + "**/*.html")
        .pipe(gulp.dest(jsDestPath));
});

gulp.task("clean-html-templates", function(){
    return del([jsDestPath + "**/*", "!**/*.js"]);
});

gulp.task("build-css", ["clean-css"], function(){
    return gulp.src(cssSrcPath + "**/*.css")
        .pipe(concat("styles.css"))
        .pipe(gulp.dest(cssDestPath))
        .pipe(sourcemaps.init())
        .pipe(cssnano({safe: true}))
        .pipe(rename("styles.min.css"))
        .pipe(sourcemaps.write("."))
        .pipe(gulp.dest(cssDestPath));
});

gulp.task("clean-css", function(){
    return del([cssDestPath]);
});

gulp.task("build-index-html", ["clean-index-html"], function(){
    return gulp.src("*.html")
        .pipe(htmlreplace({
            js: [jsDestPath + "extlibs.min.js", jsDestPath + "app.min.js"],
            css: [cssDestPath + "styles.min.css"]
        }))
        .pipe(gulp.dest(rootDestPath));
});

gulp.task("clean-index-html", function(){
    return del([rootDestPath + "*.html"]);
});<commit_msg>Fixed error where too many files were deleted on clean-html-templates<commit_after>var rootDestPath = "dist/";
var jsSrcPath = "lib/";
var jsDestPath = rootDestPath + "lib/";
var cssSrcPath = "assets/";
var cssDestPath = rootDestPath + "assets/";

var gulp = require("gulp");
var del = require("del");
var vinylpaths = require("vinyl-paths");
var concat = require("gulp-concat");
var uglify = require("gulp-uglify");
var rename = require("gulp-rename");
var sourcemaps = require("gulp-sourcemaps");
var babel = require("gulp-babel");
var cssnano = require("gulp-cssnano");
var htmlreplace = require("gulp-html-replace")
var browserSync = require('browser-sync').create();
var mainBowerFiles = require('gulp-main-bower-files');

gulp.task('serve', ['build'], function(){
    browserSync.init({
        server:{
            baseDir: 'dist'
        }
    });

    gulp.watch('index.html', browserSync.reload);
    gulp.watch('pages/**/*.html', browserSync.reload);
    gulp.watch('assets/**/*.css', browserSync.reload);
    gulp.watch('lib/**/*.js', ['build-js', browserSync.reload]);
});

gulp.task("default", ["build"]);
gulp.task("build", ["build-js", "build-bower-files", "build-html-templates", "build-css", "build-index-html"]);
gulp.task("clean", function(){
    return del("dist/*");
});

gulp.task("build-bower-files", ["clean-bower-files"], function(){
    return gulp.src("bower.json")
        .pipe(mainBowerFiles())
        .pipe(sourcemaps.init())
        .pipe(concat("extlibs.js"))
        .pipe(gulp.dest(jsDestPath))
        .pipe(uglify())
        .pipe(rename("extlibs.min.js"))
        .pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../../lib"}))
        .pipe(gulp.dest(jsDestPath));
});

gulp.task("clean-bower-files", function(){
    return del([jsDestPath + "extlibs.js"]);
});

gulp.task("build-js", ["clean-js"], function(){
    return gulp.src(jsSrcPath + "**/*.js")
        .pipe(sourcemaps.init())
        .pipe(concat("app.js"))
        .pipe(babel())
        .pipe(gulp.dest(jsDestPath))
        .pipe(uglify())
        .pipe(rename("app.min.js"))
        .pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../../lib"}))
        .pipe(gulp.dest(jsDestPath));
});

gulp.task("clean-js", function(){
    return del([jsDestPath + "app.js", jsDestPath + "app.min.js", jsDestPath + "app.min.js.map"]);
});

gulp.task("build-html-templates", ["clean-html-templates"], function(){
    return gulp.src(jsSrcPath + "**/*.html")
        .pipe(gulp.dest(jsDestPath));
});

gulp.task("clean-html-templates", function(){
    return del([jsDestPath + "**/*", "!**/*.js", !"**/*.js.map"]);
});

gulp.task("build-css", ["clean-css"], function(){
    return gulp.src(cssSrcPath + "**/*.css")
        .pipe(concat("styles.css"))
        .pipe(gulp.dest(cssDestPath))
        .pipe(sourcemaps.init())
        .pipe(cssnano({safe: true}))
        .pipe(rename("styles.min.css"))
        .pipe(sourcemaps.write("."))
        .pipe(gulp.dest(cssDestPath));
});

gulp.task("clean-css", function(){
    return del([cssDestPath]);
});

gulp.task("build-index-html", ["clean-index-html"], function(){
    return gulp.src("*.html")
        .pipe(htmlreplace({
            js: [jsDestPath + "extlibs.min.js", jsDestPath + "app.min.js"],
            css: [cssDestPath + "styles.min.css"]
        }))
        .pipe(gulp.dest(rootDestPath));
});

gulp.task("clean-index-html", function(){
    return del([rootDestPath + "*.html"]);
});
<|endoftext|>


<commit_before>'use strict'

const { dest, parallel, series, src, watch } = require('gulp')

const bsync = require('browser-sync').create()
const cssnano = require('cssnano')
const filter = require('gulp-filter')
const focus = require('postcss-focus')
const newer = require('gulp-newer')
const postcss = require('gulp-postcss')
const rename = require('gulp-rename')
const rollup = require('gulp-better-rollup')
const rtlcss = require('gulp-rtlcss')
const sass = require('gulp-sass')
const sh = require('shelljs')
const uglify = require('gulp-uglify')

const bsConfig = require('./bs-config')
const roConfig = require('./rollup.config')

const uglifyOpts = {output: {comments: /(^!|\@license|\@preserve)/i}}

const paths = {
    scripts: {
        dest: roConfig.output.dir,
        mapDest: '.',
        src: roConfig.input,
        watchSrc: ['./assets/scripts/**/*.ts']
    },
    serve: {
        src: bsConfig.files
    },
    styles: {
        dest: './dist/styles',
        mapDest: '.',
        src: ['./assets/styles/*.scss'],
        watchSrc: ['./assets/styles/**/*.scss']
    },
    vendor: {
        dest: {
            assets: './assets/vendor',
            dist: './dist/vendor'
        }
    }
}

function _chmod(done)
{
    sh.chmod('-R', 'a+x', './bin', './vendor/bin', './node_modules/.bin')

    done()
}

function _clean(done)
{
    sh.rm(
        '-rf',
        paths.styles.dest,
        paths.scripts.dest,
        paths.vendor.dest.dist,
        paths.vendor.dest.assets
    )

    done()
}

function _scripts(done)
{
    src(paths.scripts.src, {sourcemaps: true})
        .pipe(newer(paths.scripts.dest))
        .pipe(rollup({plugins: roConfig.plugins}, roConfig.output))
        .pipe(rename({'suffix': '.min', 'extname': '.js'}))
        .pipe(uglify(uglifyOpts))
        .pipe(dest(paths.scripts.dest, {sourcemaps: paths.scripts.mapDest}))

    done()
}

function _serve(done)
{
    bsync.init(bsConfig)

    done()
}

function _styles(done)
{
    src(paths.styles.src, {sourcemaps: true})
        .pipe(newer(paths.styles.dest))
        .pipe(sass().on('error', sass.logError))
        .pipe(postcss([focus(), cssnano()]))
        .pipe(rename({'suffix': '.min'}))
        .pipe(dest(paths.styles.dest, {sourcemaps: paths.styles.mapDest}))
        .pipe(filter(['**/*.css']))
        .pipe(rtlcss())
        .pipe(rename(path => {
            path.basename = path.basename.replace('.min', '-rtl.min')
        }))
        .pipe(dest(paths.styles.dest, {sourcemaps: paths.styles.mapDest}))

    done()
}

function _vendor(done)
{
    src([
        './node_modules/html5shiv/dist/html5shiv.min.js',
        './node_modules/respond.js/dest/respond.min.js',
        './node_modules/what-input/dist/what-input.min.js',
        './node_modules/jquery/dist/jquery.min.js',
        './node_modules/jquery-migrate/dist/jquery-migrate.min.js'
    ])
        .pipe(newer(paths.vendor.dest.dist))
        .pipe(uglify(uglifyOpts))
        .pipe(dest(paths.vendor.dest.dist))

    src(['./node_modules/normalize.css/normalize.css'])
        .pipe(newer(paths.vendor.dest.dist))
        .pipe(postcss([cssnano()]))
        .pipe(rename({'suffix': '.min'}))
        .pipe(dest(paths.vendor.dest.dist))

    src(['./node_modules/@fortawesome/fontawesome-free/js/all.min.js'])
        .pipe(newer(paths.vendor.dest.dist))
        .pipe(uglify(uglifyOpts))
        .pipe(rename({'basename': 'font-awesome.min'}))
        .pipe(dest(paths.vendor.dest.dist))

    src(['./node_modules/@fortawesome/fontawesome-free/js/v4-shims.min.js'])
        .pipe(newer(paths.vendor.dest.dist))
        .pipe(uglify(uglifyOpts))
        .pipe(rename({'basename': 'font-awesome-v4-shims.min'}))
        .pipe(dest(paths.vendor.dest.dist))

    src(['./node_modules/@grottopress/scss/**'])
        .pipe(newer(paths.vendor.dest.assets))
        .pipe(dest(`${paths.vendor.dest.assets}/@grottopress/scss`))

    done()
}

function _watch(done)
{
    watch(paths.scripts.watchSrc, {ignoreInitial: false}, _scripts)
    watch(paths.styles.watchSrc, {ignoreInitial: false}, _styles)

    done()
}

exports.chmod = _chmod
exports.clean = _clean
exports.scripts = _scripts
exports.serve = _serve
exports.styles = _styles
exports.vendor = _vendor
exports.watch = _watch

exports.default = series(parallel(_styles, _scripts), _serve, _watch)
<commit_msg>Run `serve` and `watch` tasks in parallel<commit_after>'use strict'

const { dest, parallel, series, src, watch } = require('gulp')

const bsync = require('browser-sync').create()
const cssnano = require('cssnano')
const filter = require('gulp-filter')
const focus = require('postcss-focus')
const newer = require('gulp-newer')
const postcss = require('gulp-postcss')
const rename = require('gulp-rename')
const rollup = require('gulp-better-rollup')
const rtlcss = require('gulp-rtlcss')
const sass = require('gulp-sass')
const sh = require('shelljs')
const uglify = require('gulp-uglify')

const bsConfig = require('./bs-config')
const roConfig = require('./rollup.config')

const uglifyOpts = {output: {comments: /(^!|\@license|\@preserve)/i}}

const paths = {
    scripts: {
        dest: roConfig.output.dir,
        mapDest: '.',
        src: roConfig.input,
        watchSrc: ['./assets/scripts/**/*.ts']
    },
    serve: {
        src: bsConfig.files
    },
    styles: {
        dest: './dist/styles',
        mapDest: '.',
        src: ['./assets/styles/*.scss'],
        watchSrc: ['./assets/styles/**/*.scss']
    },
    vendor: {
        dest: {
            assets: './assets/vendor',
            dist: './dist/vendor'
        }
    }
}

function _chmod(done)
{
    sh.chmod('-R', 'a+x', './bin', './vendor/bin', './node_modules/.bin')

    done()
}

function _clean(done)
{
    sh.rm(
        '-rf',
        paths.styles.dest,
        paths.scripts.dest,
        paths.vendor.dest.dist,
        paths.vendor.dest.assets
    )

    done()
}

function _scripts(done)
{
    src(paths.scripts.src, {sourcemaps: true})
        .pipe(newer(paths.scripts.dest))
        .pipe(rollup({plugins: roConfig.plugins}, roConfig.output))
        .pipe(rename({'suffix': '.min', 'extname': '.js'}))
        .pipe(uglify(uglifyOpts))
        .pipe(dest(paths.scripts.dest, {sourcemaps: paths.scripts.mapDest}))

    done()
}

function _serve(done)
{
    bsync.init(bsConfig)

    done()
}

function _styles(done)
{
    src(paths.styles.src, {sourcemaps: true})
        .pipe(newer(paths.styles.dest))
        .pipe(sass().on('error', sass.logError))
        .pipe(postcss([focus(), cssnano()]))
        .pipe(rename({'suffix': '.min'}))
        .pipe(dest(paths.styles.dest, {sourcemaps: paths.styles.mapDest}))
        .pipe(filter(['**/*.css']))
        .pipe(rtlcss())
        .pipe(rename(path => {
            path.basename = path.basename.replace('.min', '-rtl.min')
        }))
        .pipe(dest(paths.styles.dest, {sourcemaps: paths.styles.mapDest}))

    done()
}

function _vendor(done)
{
    src([
        './node_modules/html5shiv/dist/html5shiv.min.js',
        './node_modules/respond.js/dest/respond.min.js',
        './node_modules/what-input/dist/what-input.min.js',
        './node_modules/jquery/dist/jquery.min.js',
        './node_modules/jquery-migrate/dist/jquery-migrate.min.js'
    ])
        .pipe(newer(paths.vendor.dest.dist))
        .pipe(uglify(uglifyOpts))
        .pipe(dest(paths.vendor.dest.dist))

    src(['./node_modules/normalize.css/normalize.css'])
        .pipe(newer(paths.vendor.dest.dist))
        .pipe(postcss([cssnano()]))
        .pipe(rename({'suffix': '.min'}))
        .pipe(dest(paths.vendor.dest.dist))

    src(['./node_modules/@fortawesome/fontawesome-free/js/all.min.js'])
        .pipe(newer(paths.vendor.dest.dist))
        .pipe(uglify(uglifyOpts))
        .pipe(rename({'basename': 'font-awesome.min'}))
        .pipe(dest(paths.vendor.dest.dist))

    src(['./node_modules/@fortawesome/fontawesome-free/js/v4-shims.min.js'])
        .pipe(newer(paths.vendor.dest.dist))
        .pipe(uglify(uglifyOpts))
        .pipe(rename({'basename': 'font-awesome-v4-shims.min'}))
        .pipe(dest(paths.vendor.dest.dist))

    src(['./node_modules/@grottopress/scss/**'])
        .pipe(newer(paths.vendor.dest.assets))
        .pipe(dest(`${paths.vendor.dest.assets}/@grottopress/scss`))

    done()
}

function _watch(done)
{
    watch(paths.scripts.watchSrc, {ignoreInitial: false}, _scripts)
    watch(paths.styles.watchSrc, {ignoreInitial: false}, _styles)

    done()
}

exports.chmod = _chmod
exports.clean = _clean
exports.scripts = _scripts
exports.serve = _serve
exports.styles = _styles
exports.vendor = _vendor
exports.watch = _watch

exports.default = series(parallel(_styles, _scripts), parallel(_serve, _watch))
<|endoftext|>


<commit_before>var gulp = require('gulp');
var rjs = require('gulp-requirejs');
var compass = require('gulp-compass');
var babel = require('gulp-babel');
var uglify = require('gulp-uglify');
var clean = require('gulp-clean');
var sequence = require('gulp-sequence');
var through2 = require('through2');

const SCSS_FILES = './src/frontend/scss/**/*.scss';
const FRONTEND_JS_FILES = './src/frontend/js/**/*.js';
const BACKEND_JS_FILES = './src/backend/**/*.js';
const VENDOR_FILES = './src/frontend/vendor/**/*';
const COMPONENTS_FILES = './src/frontend/js/components/**/*.js';
const DIST_FILES = './dist/**/*.js';

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

gulp.task('6to5:frontend', function() {
  return gulp
    .src(FRONTEND_JS_FILES)
    .pipe(babel({
      // we only process react here
      whitelist: ['react']
    }))
    .pipe(gulp.dest('./dist/frontend'));
});

gulp.task('6to5:backend', function() {
  // we just want to move all files to the right place
  return gulp
    .src(BACKEND_JS_FILES)
    .pipe(gulp.dest('./dist/backend'));
});

gulp.task('copy:vendor', function() {
  return gulp
    .src(VENDOR_FILES)
    .pipe(gulp.dest('./dist/vendor'));
});

gulp.task('rjs', function() {
  // all frontend + backend js -> main.js
  return rjs({
    name: 'main',
    baseUrl: './dist/frontend',
    out: 'main.js',
    paths: {
      react: '../vendor/react/react',
      backend: '../backend',
    }
  })
  .pipe(through2.obj(function (file, enc, next) {
    this.push(file);
    this.end();
    next();
  }))
  .pipe(gulp.dest('dist/'));
});

gulp.task('compass', function() {
  return gulp
    .src(SCSS_FILES)
    .pipe(compass({
      config_file: './config.rb',
      css: 'src/frontend/css',
      sass: 'src/frontend/scss'
    }))
    .pipe(gulp.dest('./src/frontend/css'));
});

gulp.task('watch', function() {
  gulp.watch(SCSS_FILES, ['compass']);
  gulp.watch([
    FRONTEND_JS_FILES,
    BACKEND_JS_FILES,
    '!' + COMPONENTS_FILES
  ], ['default']);
});

gulp.task('default', sequence(
  'cleanup',
  '6to5:frontend',
  '6to5:backend',
  'copy:vendor',
  'rjs'
));
<commit_msg>fix sequence tasks problems<commit_after>var gulp = require('gulp');
var rjs = require('gulp-requirejs');
var compass = require('gulp-compass');
var babel = require('gulp-babel');
var uglify = require('gulp-uglify');
var clean = require('gulp-clean');
var sequence = require('gulp-sequence');
var through2 = require('through2');

const SCSS_FILES = './src/frontend/scss/**/*.scss';
const FRONTEND_JS_FILES = './src/frontend/js/**/*.js';
const BACKEND_JS_FILES = './src/backend/**/*.js';
const VENDOR_FILES = './src/frontend/vendor/**/*';
const COMPONENTS_FILES = './src/frontend/js/components/**/*.js';
const DIST_FILES = './dist/**/*.js';

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

gulp.task('6to5:frontend', function() {
  return gulp
    .src(FRONTEND_JS_FILES)
    .pipe(babel({
      // we only process react here
      whitelist: ['react']
    }))
    .pipe(gulp.dest('./dist/frontend'));
});

gulp.task('6to5:backend', function() {
  // we just want to move all files to the right place
  return gulp
    .src(BACKEND_JS_FILES)
    .pipe(gulp.dest('./dist/backend'));
});

gulp.task('copy:vendor', function() {
  return gulp
    .src(VENDOR_FILES)
    .pipe(gulp.dest('./dist/vendor'));
});

gulp.task('rjs', function() {
  // all frontend + backend js -> main.js
  return rjs({
    name: 'main',
    baseUrl: './dist/frontend',
    out: 'main.js',
    paths: {
      react: '../vendor/react/react',
      backend: '../backend',
    }
  })
  .pipe(through2.obj(function (file, enc, next) {
    this.push(file);
    this.end();
    next();
  }))
  .pipe(gulp.dest('dist/'));
});

gulp.task('compass', function() {
  return gulp
    .src(SCSS_FILES)
    .pipe(compass({
      config_file: './config.rb',
      css: 'src/frontend/css',
      sass: 'src/frontend/scss'
    }))
    .pipe(gulp.dest('./src/frontend/css'));
});

gulp.task('watch', function() {
  gulp.watch(SCSS_FILES, ['compass']);
  gulp.watch([
    FRONTEND_JS_FILES,
    BACKEND_JS_FILES,
    '!' + COMPONENTS_FILES
  ], ['default']);
});

gulp.task('default', function(callback) {
  sequence(
    'cleanup',
    '6to5:frontend',
    '6to5:backend',
    'copy:vendor',
    'rjs'
  )(callback);
});
<|endoftext|>


<commit_before>'use strict';

var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var moduleName = (function () {
      var args = process.argv;
      var length = args.length;
      var i = 0;
      var matched;
      var name;

      while (i++ < length) {
        matched = String(args[i]).match(/^--+(\w+)$/i);

        if (matched) {
          name = matched[1];
          break;
        }
      }

      return name;
    })();

// Admin
// Command: gulp [task]
// -----------------------------------------------------------------------------

function adminTasks() {
  var pathto = function (file) {
        return ('admin/views/assets/' + file);
      };
  var scripts = {
        src: pathto('javascripts/app/*.js'),
        dest: pathto('javascripts'),
        qor: pathto('javascripts/qor/*.js'),
        all: [
          'gulpfile.js',
          pathto('javascripts/qor/*.js')
        ]
      };
  var styles = {
        src: pathto('stylesheets/scss/{app,qor}.scss'),
        dest: pathto('stylesheets'),
        main: pathto('stylesheets/{qor,app}.css'),
        scss: pathto('stylesheets/scss/**/*.scss')
      };
  var fonts = {
        dest: pathto('fonts'),
      };

  gulp.task('jshint', function () {
    return gulp.src(scripts.all)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'));
  });

  gulp.task('jscs', function () {
    return gulp.src(scripts.all)
    .pipe(plugins.jscs());
  });

  gulp.task('qor', ['jshint', 'jscs'], function () {
    return gulp.src(scripts.qor)
    .pipe(plugins.concat('qor.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('js', ['qor'], function () {
    return gulp.src(scripts.src)
    .pipe(plugins.concat('app.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('qor+', function () {
    return gulp.src(scripts.qor)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat('qor.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('js+', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat('app.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('jslib', function () {
    return gulp.src([
      'bower_components/jquery/dist/jquery.min.js',
      'bower_components/jquery/dist/jquery.min.map',
      'bower_components/material-design-lite/material.min.js',
      'bower_components/material-design-lite/material.min.js.map',
      'bower_components/cropper/dist/cropper.min.js',
      'bower_components/chosen/chosen.jquery.min.js'
    ])
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('sass', function () {
    return gulp.src(styles.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.sass())
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('csslint', ['sass'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.csslint('.csslintrc'))
    .pipe(plugins.csslint.reporter());
  });

  gulp.task('css', ['csslint'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.autoprefixer())
    .pipe(plugins.csscomb())
    .pipe(plugins.minifyCss())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('fonts', function () {
    return gulp.src([
      'bower_components/material-design-icons/iconfont/codepoints',
      'bower_components/material-design-icons/iconfont/MaterialIcons*'
    ])
    .pipe(gulp.dest(fonts.dest));
  });

  gulp.task('csslib', ['fonts'], function () {
    return gulp.src([
      'bower_components/material-design-lite/material.min.css',
      'bower_components/material-design-lite/material.min.css.map',
      'bower_components/cropper/dist/cropper.min.css',
      'bower_components/chosen/chosen-sprite.png',
      'bower_components/chosen/chosen-sprite@2x.png',
      'bower_components/chosen/chosen.min.css'
    ])
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('watch', function () {
    gulp.watch(scripts.qor, ['qor+']);
    gulp.watch(scripts.src, ['js+']);
    gulp.watch(styles.scss, ['sass']);
  });

  gulp.task('lib', ['jslib', 'csslib']);
  gulp.task('release', ['js', 'css']);

  gulp.task('default', ['watch']);
}

// Modules
// Command: gulp [task] --moduleName
// -----------------------------------------------------------------------------

function moduleTasks(moduleName) {
  var pathto = function (file) {
        return (moduleName + '/views/themes/' + moduleName + '/assets/' + file);
      };
  var scripts = {
        src: pathto('javascripts/app/*.js'),
        dest: pathto('javascripts/')
      };
  var styles = {
        src: pathto('stylesheets/scss/*.scss'),
        dest: pathto('stylesheets/'),
        main: pathto('stylesheets/' + moduleName + '.css'),
        scss: pathto('stylesheets/scss/**/*.scss')
      };

  gulp.task('jshint', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'));
  });

  gulp.task('jscs', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jscs());
  });

  gulp.task('js', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.concat(moduleName + '.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('concat', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat(moduleName + '.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('sass', function () {
    return gulp.src(styles.src)
    .pipe(plugins.sass())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('csslint', ['sass'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.csslint('.csslintrc'))
    .pipe(plugins.csslint.reporter());
  });

  gulp.task('css', ['csslint'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.autoprefixer())
    .pipe(plugins.csscomb())
    .pipe(plugins.minifyCss())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('watch', function () {
    gulp.watch(scripts.src, ['concat']);
    gulp.watch(styles.scss, ['sass']);
  });

  gulp.task('release', ['js', 'css']);

  gulp.task('default', ['watch']);
}

// Init
// -----------------------------------------------------------------------------

if (moduleName) {
  console.log('Running "' + moduleName + '" task...');
  moduleTasks(moduleName);
} else {
  console.log('Running "admin" task...');
  adminTasks();
}
<commit_msg>Add "mdl" task<commit_after>'use strict';

var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var moduleName = (function () {
      var args = process.argv;
      var length = args.length;
      var i = 0;
      var matched;
      var name;

      while (i++ < length) {
        matched = String(args[i]).match(/^--+(\w+)$/i);

        if (matched) {
          name = matched[1];
          break;
        }
      }

      return name;
    })();

// Admin
// Command: gulp [task]
// -----------------------------------------------------------------------------

function adminTasks() {
  var pathto = function (file) {
        return ('admin/views/assets/' + file);
      };
  var scripts = {
        src: pathto('javascripts/app/*.js'),
        dest: pathto('javascripts'),
        qor: pathto('javascripts/qor/*.js'),
        all: [
          'gulpfile.js',
          pathto('javascripts/qor/*.js')
        ]
      };
  var styles = {
        src: pathto('stylesheets/scss/{app,qor}.scss'),
        dest: pathto('stylesheets'),
        main: pathto('stylesheets/{qor,app}.css'),
        scss: pathto('stylesheets/scss/**/*.scss')
      };
  var fonts = {
        dest: pathto('fonts'),
      };

  gulp.task('jshint', function () {
    return gulp.src(scripts.all)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'));
  });

  gulp.task('jscs', function () {
    return gulp.src(scripts.all)
    .pipe(plugins.jscs());
  });

  gulp.task('qor', ['jshint', 'jscs'], function () {
    return gulp.src(scripts.qor)
    .pipe(plugins.concat('qor.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('js', ['qor'], function () {
    return gulp.src(scripts.src)
    .pipe(plugins.concat('app.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('qor+', function () {
    return gulp.src(scripts.qor)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat('qor.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('js+', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat('app.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('jslib', function () {
    return gulp.src([
      'bower_components/jquery/dist/jquery.min.js',
      'bower_components/jquery/dist/jquery.min.map',
      'bower_components/material-design-lite/material.min.js',
      'bower_components/material-design-lite/material.min.js.map',
      'bower_components/cropper/dist/cropper.min.js',
      'bower_components/chosen/chosen.jquery.min.js'
    ])
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('sass', function () {
    return gulp.src(styles.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.sass())
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('csslint', ['sass'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.csslint('.csslintrc'))
    .pipe(plugins.csslint.reporter());
  });

  gulp.task('css', ['csslint'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.autoprefixer())
    .pipe(plugins.csscomb())
    .pipe(plugins.minifyCss())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('mdl', function () {
    return gulp.src([
      'bower_components/material-design-lite/src/_*',
    ])
    .pipe(gulp.dest(pathto('stylesheets/scss/mdl')));
  });

  gulp.task('fonts', function () {
    return gulp.src([
      'bower_components/material-design-icons/iconfont/codepoints',
      'bower_components/material-design-icons/iconfont/MaterialIcons*'
    ])
    .pipe(gulp.dest(fonts.dest));
  });

  gulp.task('csslib', ['mdl', 'fonts'], function () {
    return gulp.src([
      'bower_components/material-design-lite/material.min.css',
      'bower_components/material-design-lite/material.min.css.map',
      'bower_components/cropper/dist/cropper.min.css',
      'bower_components/chosen/chosen-sprite.png',
      'bower_components/chosen/chosen-sprite@2x.png',
      'bower_components/chosen/chosen.min.css'
    ])
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('watch', function () {
    gulp.watch(scripts.qor, ['qor+']);
    gulp.watch(scripts.src, ['js+']);
    gulp.watch(styles.scss, ['sass']);
  });

  gulp.task('lib', ['jslib', 'csslib']);
  gulp.task('release', ['js', 'css']);

  gulp.task('default', ['watch']);
}

// Modules
// Command: gulp [task] --moduleName
// -----------------------------------------------------------------------------

function moduleTasks(moduleName) {
  var pathto = function (file) {
        return (moduleName + '/views/themes/' + moduleName + '/assets/' + file);
      };
  var scripts = {
        src: pathto('javascripts/app/*.js'),
        dest: pathto('javascripts/')
      };
  var styles = {
        src: pathto('stylesheets/scss/*.scss'),
        dest: pathto('stylesheets/'),
        main: pathto('stylesheets/' + moduleName + '.css'),
        scss: pathto('stylesheets/scss/**/*.scss')
      };

  gulp.task('jshint', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'));
  });

  gulp.task('jscs', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jscs());
  });

  gulp.task('js', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.concat(moduleName + '.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('concat', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat(moduleName + '.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('sass', function () {
    return gulp.src(styles.src)
    .pipe(plugins.sass())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('csslint', ['sass'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.csslint('.csslintrc'))
    .pipe(plugins.csslint.reporter());
  });

  gulp.task('css', ['csslint'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.autoprefixer())
    .pipe(plugins.csscomb())
    .pipe(plugins.minifyCss())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('watch', function () {
    gulp.watch(scripts.src, ['concat']);
    gulp.watch(styles.scss, ['sass']);
  });

  gulp.task('release', ['js', 'css']);

  gulp.task('default', ['watch']);
}

// Init
// -----------------------------------------------------------------------------

if (moduleName) {
  console.log('Running "' + moduleName + '" task...');
  moduleTasks(moduleName);
} else {
  console.log('Running "admin" task...');
  adminTasks();
}
<|endoftext|>


<commit_before>'use strict';

let gulp = require('gulp');
let requireDir = require('require-dir');
let gulpLoadPlugin = require('gulp-load-plugins');
let $ = gulpLoadPlugin();
let runSequence = require('run-sequence');
let config = require('./gulp/config');
let exec = require('child_process').exec;

requireDir('./gulp/task', {recurse: true});

gulp.task('watch', () => {
  $.watch(config.style.src, () => {
    gulp.start(['style', 'lint:style', 'minify:style']);
  });
  $.watch(config.script.src, () => {
    gulp.start(['script', 'lint:script']);
  });
});

gulp.task('serve', (cb) => {
  exec('./node_modules/.bin/harp server test --port 5000', (err, stdout, stderr) => {
    console.log(stdout);
    console.log(stderr);
    cb(err);
  });
});

gulp.task('develop', ['watch', 'serve']);

gulp.task('default', () => {
  return runSequence(
    'lint',
    'style',
    'minify',
    'watch'
  );
});
<commit_msg>Change a port number of harp<commit_after>'use strict';

let gulp = require('gulp');
let requireDir = require('require-dir');
let gulpLoadPlugin = require('gulp-load-plugins');
let $ = gulpLoadPlugin();
let runSequence = require('run-sequence');
let config = require('./gulp/config');
let exec = require('child_process').exec;

requireDir('./gulp/task', {recurse: true});

gulp.task('watch', () => {
  $.watch(config.style.src, () => {
    gulp.start(['style', 'lint:style', 'minify:style']);
  });
  $.watch(config.script.src, () => {
    gulp.start(['script', 'lint:script']);
  });
});

gulp.task('serve', (cb) => {
  exec('./node_modules/.bin/harp server test --port 3000', (err, stdout, stderr) => {
    console.log(stdout);
    console.log(stderr);
    cb(err);
  });
});

gulp.task('develop', ['watch', 'serve']);

gulp.task('default', () => {
  return runSequence(
    'lint',
    'style',
    'minify',
    'watch'
  );
});
<|endoftext|>


<commit_before>/*
  gulpfile.js
  ===========
  Rather than manage one giant configuration file responsible
  for creating multiple tasks, each task has been broken out into
  its own file in gulp/tasks. Any files in that directory get
  automatically required below.

  To add a new task, simply add a new task file that directory.
  gulp/tasks/default.js specifies the default set of tasks to run
  when you run `gulp`.
*/

var requireDir = require('require-dir');

// Require all tasks in gulp/tasks, including subfolders
requireDir('./gulp/tasks', { recurse: true });

if(process.argv.length > 2 && process.argv[2] == "-s"){
	console.log("STAGE")
	requireDir('./gulp/deployTasks', { recurse: true });
}<commit_msg>fixing stage after windows fix<commit_after>/*
  gulpfile.js
  ===========
  Rather than manage one giant configuration file responsible
  for creating multiple tasks, each task has been broken out into
  its own file in gulp/tasks. Any files in that directory get
  automatically required below.

  To add a new task, simply add a new task file that directory.
  gulp/tasks/default.js specifies the default set of tasks to run
  when you run `gulp`.
*/

var requireDir = require('require-dir');

// Require all tasks in gulp/tasks, including subfolders
requireDir('./gulp/tasks', { recurse: true });

if(process.argv.length > 3 && process.argv[3] == "-s"){
	console.log("STAGE")
	requireDir('./gulp/deployTasks', { recurse: true });
}<|endoftext|>