<commit_before>var gulp = require('gulp');
var sourcemap = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var copy = require('gulp-copy');
var concat = require('gulp-concat');
var connect = require('gulp-connect');
var sass = require('gulp-sass');
var jshint = require('gulp-jshint');
var ghPages = require('gulp-gh-pages');
var Server = require('karma').Server;

gulp.task('sass', function(){
  return gulp.src('./src/scss/dropchop.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('./dist/static/css'));
});

var vendorCSS = [
  './lib/mapbox.js/mapbox.css',
  './node_modules/font-awesome/css/font-awesome.css'
];

gulp.task('css_vendor', function() {
  return gulp.src(vendorCSS)
    .pipe(concat('vendor.css'))
    .pipe(gulp.dest('./dist/static/css'));
});

gulp.task('mapbox_assets', function() {
  return gulp.src('./node_modules/mapbox.js/dist/images/**.*')
    .pipe(gulp.dest('./dist/static/css/images'));
});

var vendorJS = [
  './node_modules/jquery/dist/jquery.js',
  './node_modules/browser-filesaver/FileSaver.js',
  './node_modules/shp-write/shpwrite.js',
  './src/lib/shp-2-geojson.js',
  './node_modules/osmtogeojson/osmtogeojson.js',
  './node_modules/turf/turf.js',
  './lib/mapbox.js/mapbox.js'
];

gulp.task('lint', function() {
  return gulp.src('./src/js/**/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});

gulp.task('js_dropchop', function() {
  return gulp.src('./src/js/**/*.js')
    .pipe(sourcemap.init())
    .pipe(concat('dropchop.js'))
    .pipe(uglify())
    .pipe(sourcemap.write())
    .pipe(gulp.dest('./dist/static/js'));
});

gulp.task('js_vendor', function() {
  return gulp.src(vendorJS)
    .pipe(sourcemap.init())
    .pipe(concat('vendor.js'))
    .pipe(uglify())
    .pipe(sourcemap.write())
    .pipe(gulp.dest('./dist/static/js'));
});

var testFiles = [
  'dist/static/vendor.js',
  'dist/static/dropchop.js',
  'test/**/*.spec.js'
];

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

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

gulp.task('fa-fonts', function() {
  return gulp.src('./node_modules/font-awesome/fonts/**.*')
    .pipe(gulp.dest('./dist/static/fonts'));
});

gulp.task('cname', function() {
  return gulp.src('./src/CNAME')
    .pipe(gulp.dest('./dist'));
});

gulp.task('ghpages', function() {
  return gulp.src('./dist/**/*')
    .pipe(ghPages());
});

gulp.task('watch', function() {
  gulp.watch('./src/js/**/*.js', ['js']);
  gulp.watch('./src/scss/**/*.scss', ['sass']);
  gulp.watch('./src/html/**.html', ['html']);
});

gulp.task('connect', function() {
  connect.server({
    port: '8888',
    root: 'dist'
  });
});

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

gulp.task('vendor', ['js_vendor', 'css_vendor', 'mapbox_assets', 'fa-fonts']);
gulp.task('js', ['lint', 'js_dropchop']);
gulp.task('build', ['js', 'html', 'sass', 'assets']);
gulp.task('build:prod', ['vendor', 'build']);
gulp.task('deploy', ['build:prod', 'cname', 'gh-pages']);
gulp.task('default', ['build', 'connect', 'watch']);<commit_msg>fix gh-pages gulp<commit_after>var gulp = require('gulp');
var sourcemap = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var copy = require('gulp-copy');
var concat = require('gulp-concat');
var connect = require('gulp-connect');
var sass = require('gulp-sass');
var jshint = require('gulp-jshint');
var ghPages = require('gulp-gh-pages');
var Server = require('karma').Server;

gulp.task('sass', function(){
  return gulp.src('./src/scss/dropchop.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('./dist/static/css'));
});

var vendorCSS = [
  './lib/mapbox.js/mapbox.css',
  './node_modules/font-awesome/css/font-awesome.css'
];

gulp.task('css_vendor', function() {
  return gulp.src(vendorCSS)
    .pipe(concat('vendor.css'))
    .pipe(gulp.dest('./dist/static/css'));
});

gulp.task('mapbox_assets', function() {
  return gulp.src('./node_modules/mapbox.js/dist/images/**.*')
    .pipe(gulp.dest('./dist/static/css/images'));
});

var vendorJS = [
  './node_modules/jquery/dist/jquery.js',
  './node_modules/browser-filesaver/FileSaver.js',
  './node_modules/shp-write/shpwrite.js',
  './src/lib/shp-2-geojson.js',
  './node_modules/osmtogeojson/osmtogeojson.js',
  './node_modules/turf/turf.js',
  './lib/mapbox.js/mapbox.js'
];

gulp.task('lint', function() {
  return gulp.src('./src/js/**/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});

gulp.task('js_dropchop', function() {
  return gulp.src('./src/js/**/*.js')
    .pipe(sourcemap.init())
    .pipe(concat('dropchop.js'))
    .pipe(uglify())
    .pipe(sourcemap.write())
    .pipe(gulp.dest('./dist/static/js'));
});

gulp.task('js_vendor', function() {
  return gulp.src(vendorJS)
    .pipe(sourcemap.init())
    .pipe(concat('vendor.js'))
    .pipe(uglify())
    .pipe(sourcemap.write())
    .pipe(gulp.dest('./dist/static/js'));
});

var testFiles = [
  'dist/static/vendor.js',
  'dist/static/dropchop.js',
  'test/**/*.spec.js'
];

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

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

gulp.task('fa-fonts', function() {
  return gulp.src('./node_modules/font-awesome/fonts/**.*')
    .pipe(gulp.dest('./dist/static/fonts'));
});

gulp.task('cname', function() {
  return gulp.src('./src/CNAME')
    .pipe(gulp.dest('./dist'));
});

gulp.task('ghpages', function() {
  return gulp.src('./dist/**/*')
    .pipe(ghPages());
});

gulp.task('watch', function() {
  gulp.watch('./src/js/**/*.js', ['js']);
  gulp.watch('./src/scss/**/*.scss', ['sass']);
  gulp.watch('./src/html/**.html', ['html']);
});

gulp.task('connect', function() {
  connect.server({
    port: '8888',
    root: 'dist'
  });
});

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

gulp.task('vendor', ['js_vendor', 'css_vendor', 'mapbox_assets', 'fa-fonts']);
gulp.task('js', ['lint', 'js_dropchop']);
gulp.task('build', ['js', 'html', 'sass', 'assets']);
gulp.task('build:prod', ['vendor', 'build']);
gulp.task('deploy', ['build:prod', 'cname', 'ghpages']);
gulp.task('default', ['build', 'connect', 'watch']);<|endoftext|>


<commit_before>var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var less = require('gulp-less');
var clean_css = require('gulp-clean-css');
var environments = require('gulp-environments');
var sourcemaps = require('gulp-sourcemaps');
var eslint = require('gulp-eslint');
var del = require('del');

var development = environments.development;
//var production = environments.production;

var distPath = 'public/assets/';
var elfinderDistPath = 'public/vendor/studio-42/elfinder';
var semanticDistPath = 'public/semantic-ui-css';
var jqueryUiDistPath = 'public/jquery-ui-dist';
var revealDistPath = 'public/reveal.js';
var esLintPaths = [
    'src/Resources/private/js/include/**',
];
var paths = {
    libraryJs: [
        'node_modules/jquery/dist/jquery.js',
        'node_modules/jquery-ui-dist/jquery-ui.js',
        'node_modules/semantic-ui-css/semantic.js',
        'node_modules/moment/min/moment-with-locales.js',
        'node_modules/fullcalendar/dist/fullcalendar.js',
        'node_modules/fullcalendar/dist/locale-all.js',
        'node_modules/codemirror/lib/codemirror.js',
        'node_modules/codemirror/mode/xml/xml.js',
        'node_modules/codemirror/mode/css/css.js',
        'node_modules/codemirror/mode/javascript/javascript.js',
        'node_modules/codemirror/mode/htmlmixed/htmlmixed.js',
        'node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.js',
        'vendor/studio-42/elfinder/js/elfinder.full.js',
        'src/Resources/private/js/lib/**',
    ],
    js: [
        'src/Resources/private/js/include/**',
    ],
    css: [
        'node_modules/reset-css/reset.css',
        'node_modules/semantic-ui-css/semantic.css',
        'node_modules/jquery-ui-dist/jquery-ui.css',
        'node_modules/jquery-ui-dist/jquery-ui.theme.css',
        'node_modules/fullcalendar/dist/fullcalendar.css',
        'node_modules/codemirror/lib/codemirror.css',
        'node_modules/jquery-datetimepicker/build/jquery.datetimepicker.min.css',
        'vendor/studio-42/elfinder/css/elfinder.full.css',
        'vendor/studio-42/elfinder/css/theme.css',
        'src/Resources/private/css/**',
    ],
    lessMain: [
        'src/Resources/private/less/main.less',
    ],
    lessSrc: [
        'src/Resources/private/less/**',
    ],
};
var playerPaths = {
    js: [
        'node_modules/jquery/dist/jquery.js',
        'node_modules/reveal.js/lib/js/head.min.js',
        'node_modules/reveal.js/js/reveal.js',
//        'shinage-client.js',
    ],
    css: [
        'node_modules/reset-css/reset.css',
        'node_modules/reveal.js/css/reveal.css',
        'public/css/reveal_theme_very_black.css',
        'src/Resources/private/player_css/**',
    ],
    less: [
    ],
};

gulp.task('clean', function() {
    return del([
        distPath,
        elfinderDistPath,
        semanticDistPath,
        jqueryUiDistPath,
        revealDistPath,
    ]);
});

gulp.task('copy1', function() {
    return gulp.src('node_modules/semantic-ui-css/themes/**')
        .pipe(gulp.dest(semanticDistPath + '/themes/'));
});
gulp.task('copy2a', function() {
    return gulp.src('vendor/studio-42/elfinder/img/**')
        .pipe(gulp.dest(elfinderDistPath + '/img/'));
});
gulp.task('copy2b', function() {
    return gulp.src('vendor/studio-42/elfinder/js/i18n/**')
        .pipe(gulp.dest(elfinderDistPath + '/js/i18n/'));
});
gulp.task('copy3', function() {
    return gulp.src('node_modules/jquery-ui-dist/images/**')
        .pipe(gulp.dest(jqueryUiDistPath + '/images/'));
});
gulp.task('copy4', function() {
    return gulp.src('node_modules/reveal.js/**')
        .pipe(gulp.dest(revealDistPath + '/'));
});

gulp.task('copy', gulp.parallel('copy1','copy2a','copy2b','copy3','copy4'));

gulp.task('less', function() {
    return gulp.src(paths.lessMain)
        .pipe(development(sourcemaps.init()))
        .pipe(less())
        .pipe(concat('less.css'))
        .pipe(development(sourcemaps.write()))
        .pipe(gulp.dest(distPath));
});

gulp.task('css', gulp.series('less', function() {
    var finalPaths = paths.css;
    finalPaths.push(distPath + '/less.css');
    return gulp.src(finalPaths)
        .pipe(development(sourcemaps.init()))
        .pipe(clean_css({}))
        .pipe(concat('all.min.css'))
        .pipe(development(sourcemaps.write()))
        .pipe(gulp.dest(distPath));
}));

gulp.task('libraryJs', function() {
    return gulp.src(paths.libraryJs)
        .pipe(development(sourcemaps.init()))
        .pipe(uglify())
        .pipe(concat('lib.min.js'))
        .pipe(development(sourcemaps.write()))
        .pipe(gulp.dest(distPath));
});

gulp.task('js', function() {
    return gulp.src(paths.js)
        .pipe(development(sourcemaps.init()))
        .pipe(uglify())
        .pipe(concat('app.min.js'))
        .pipe(development(sourcemaps.write()))
        .pipe(gulp.dest(distPath));
});

gulp.task('player-css', function() {
    return gulp.src(playerPaths.css)
        .pipe(development(sourcemaps.init()))
        .pipe(clean_css({rebaseTo: './public/assets'}))
        .pipe(concat('player.min.css'))
        .pipe(development(sourcemaps.write()))
        .pipe(gulp.dest(distPath));
});

gulp.task('player-js', function() {
    return gulp.src(playerPaths.js)
        .pipe(development(sourcemaps.init()))
        .pipe(uglify())
        .pipe(concat('player.min.js'))
        .pipe(development(sourcemaps.write()))
        .pipe(gulp.dest(distPath));
});

gulp.task('default',
    gulp.series(
        'copy',
        gulp.parallel(
            'css',
            'libraryJs',
            'js',
            'player-css',
            'player-js'
        )
    )
);

gulp.task('eslint', () => {
    return gulp.src(esLintPaths)
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failAfterError());
});

// Rerun the task when a file changes
gulp.task('watch', function() {
  gulp.watch(paths.js, gulp.parallel(['js']));
  gulp.watch(paths.css, gulp.parallel(['css']));
  gulp.watch(paths.lessSrc, gulp.parallel(['less', 'css']));
});

<commit_msg>fix gulp compilation after npm updates<commit_after>var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var less = require('gulp-less');
var clean_css = require('gulp-clean-css');
var environments = require('gulp-environments');
var sourcemaps = require('gulp-sourcemaps');
var eslint = require('gulp-eslint');
var del = require('del');

var development = environments.development;
//var production = environments.production;

var distPath = 'public/assets/';
var elfinderDistPath = 'public/vendor/studio-42/elfinder';
var semanticDistPath = 'public/semantic-ui-css';
var jqueryUiDistPath = 'public/jquery-ui-dist';
var revealDistPath = 'public/reveal.js';
var esLintPaths = [
    'src/Resources/private/js/include/**',
];
var paths = {
    libraryJs: [
        'node_modules/jquery/dist/jquery.js',
        'node_modules/jquery-ui-dist/jquery-ui.js',
        'node_modules/semantic-ui-css/semantic.js',
        'node_modules/moment/min/moment-with-locales.js',
        'node_modules/fullcalendar/dist/fullcalendar.js',
        'node_modules/fullcalendar/dist/locale-all.js',
        'node_modules/codemirror/lib/codemirror.js',
        'node_modules/codemirror/mode/xml/xml.js',
        'node_modules/codemirror/mode/css/css.js',
        'node_modules/codemirror/mode/javascript/javascript.js',
        'node_modules/codemirror/mode/htmlmixed/htmlmixed.js',
        'node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.js',
        'vendor/studio-42/elfinder/js/elfinder.full.js',
        'src/Resources/private/js/lib/**',
    ],
    js: [
        'src/Resources/private/js/include/**',
    ],
    css: [
        'node_modules/reset-css/reset.css',
        'node_modules/semantic-ui-css/semantic.css',
        'node_modules/jquery-ui-dist/jquery-ui.css',
        'node_modules/jquery-ui-dist/jquery-ui.theme.css',
        'node_modules/fullcalendar/dist/fullcalendar.css',
        'node_modules/codemirror/lib/codemirror.css',
        'node_modules/jquery-datetimepicker/build/jquery.datetimepicker.min.css',
        'vendor/studio-42/elfinder/css/elfinder.full.css',
        'vendor/studio-42/elfinder/css/theme.css',
        'src/Resources/private/css/**',
    ],
    lessMain: [
        'src/Resources/private/less/main.less',
    ],
    lessSrc: [
        'src/Resources/private/less/**',
    ],
};
var playerPaths = {
    js: [
        'node_modules/jquery/dist/jquery.js',
        'node_modules/reveal.js/lib/js/html5shiv.js',
        'node_modules/reveal.js/lib/js/promise.js',
        'node_modules/reveal.js/js/reveal.js',
//        'shinage-client.js',
    ],
    css: [
        'node_modules/reset-css/reset.css',
        'node_modules/reveal.js/css/reveal.css',
        'public/css/reveal_theme_very_black.css',
        'src/Resources/private/player_css/**',
    ],
    less: [
    ],
};

gulp.task('clean', function() {
    return del([
        distPath,
        elfinderDistPath,
        semanticDistPath,
        jqueryUiDistPath,
        revealDistPath,
    ]);
});

gulp.task('copy1', function() {
    return gulp.src('node_modules/semantic-ui-css/themes/**')
        .pipe(gulp.dest(semanticDistPath + '/themes/'));
});
gulp.task('copy2a', function() {
    return gulp.src('vendor/studio-42/elfinder/img/**')
        .pipe(gulp.dest(elfinderDistPath + '/img/'));
});
gulp.task('copy2b', function() {
    return gulp.src('vendor/studio-42/elfinder/js/i18n/**')
        .pipe(gulp.dest(elfinderDistPath + '/js/i18n/'));
});
gulp.task('copy3', function() {
    return gulp.src('node_modules/jquery-ui-dist/images/**')
        .pipe(gulp.dest(jqueryUiDistPath + '/images/'));
});
gulp.task('copy4', function() {
    return gulp.src('node_modules/reveal.js/**')
        .pipe(gulp.dest(revealDistPath + '/'));
});

gulp.task('copy', gulp.parallel('copy1','copy2a','copy2b','copy3','copy4'));

gulp.task('less', function() {
    return gulp.src(paths.lessMain)
        .pipe(development(sourcemaps.init()))
        .pipe(less())
        .pipe(concat('less.css'))
        .pipe(development(sourcemaps.write()))
        .pipe(gulp.dest(distPath));
});

gulp.task('css', gulp.series('less', function() {
    var finalPaths = paths.css;
    finalPaths.push(distPath + '/less.css');
    return gulp.src(finalPaths)
        .pipe(development(sourcemaps.init()))
        .pipe(clean_css({}))
        .pipe(concat('all.min.css'))
        .pipe(development(sourcemaps.write()))
        .pipe(gulp.dest(distPath));
}));

gulp.task('libraryJs', function() {
    return gulp.src(paths.libraryJs)
        .pipe(development(sourcemaps.init()))
        .pipe(uglify())
        .pipe(concat('lib.min.js'))
        .pipe(development(sourcemaps.write()))
        .pipe(gulp.dest(distPath));
});

gulp.task('js', function() {
    return gulp.src(paths.js)
        .pipe(development(sourcemaps.init()))
        .pipe(uglify())
        .pipe(concat('app.min.js'))
        .pipe(development(sourcemaps.write()))
        .pipe(gulp.dest(distPath));
});

gulp.task('player-css', function() {
    return gulp.src(playerPaths.css)
        .pipe(development(sourcemaps.init()))
        .pipe(clean_css({rebaseTo: './public/assets'}))
        .pipe(concat('player.min.css'))
        .pipe(development(sourcemaps.write()))
        .pipe(gulp.dest(distPath));
});

gulp.task('player-js', function() {
    return gulp.src(playerPaths.js)
        .pipe(development(sourcemaps.init()))
        .pipe(uglify())
        .pipe(concat('player.min.js'))
        .pipe(development(sourcemaps.write()))
        .pipe(gulp.dest(distPath));
});

gulp.task('default',
    gulp.series(
        'copy',
        gulp.parallel(
            'css',
            'libraryJs',
            'js',
            'player-css',
            'player-js'
        )
    )
);

gulp.task('eslint', () => {
    return gulp.src(esLintPaths)
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failAfterError());
});

// Rerun the task when a file changes
gulp.task('watch', function() {
  gulp.watch(paths.js, gulp.parallel(['js']));
  gulp.watch(paths.css, gulp.parallel(['css']));
  gulp.watch(paths.lessSrc, gulp.parallel(['less', 'css']));
});

<|endoftext|>


<commit_before>var gulp = require('gulp');
var mocha = require('gulp-mocha');
var file = require('gulp-file');
var istanbul = require('gulp-istanbul');
var babel = require("gulp-babel");
var webpack = require('webpack-stream');

// var browserify = require('./support/browserify.js');

gulp.task('webpack', function() {
  return gulp.src('lib/*.js')
    .pipe(webpack({
      entry: './lib/index.js',
      output: {
        filename: 'socket.io.js',
      },
    }))
    .pipe(gulp.dest('./'));
});

// By default, individual js files are transformed by babel and exported to /dist
gulp.task("babel", function () {
  return gulp.src("lib/*.js")
    .pipe(babel())
    .pipe(gulp.dest("dist"));
});

gulp.task('build', function(){
  browserify(function(err, out){
    if(err){
      throw err;
    }else{
      gulp.src('')
        .pipe(file('socket.io.js', out))
        .pipe(gulp.dest('./'));
    }
  });
});

gulp.task('test-node', function(){
  gulp.src(['test/*.js', 'test/support/*.js'])
    .pipe(mocha({
      reporter: 'dot'
    }))
    .once('error', function () {
      process.exit(1);
    })
    .once('end', function () {
      process.exit();
    });
});

gulp.task('istanbul-pre-test', function () {
  return gulp.src(['lib/**/*.js'])
    // Covering files
    .pipe(istanbul())
    // Force `require` to return covered files
    .pipe(istanbul.hookRequire());
});

gulp.task('test-cov', ['istanbul-pre-test'], function(){
  gulp.src(['test/*.js', 'test/support/*.js'])
    .pipe(mocha({
      reporter: 'dot'
    }))
    .pipe(istanbul.writeReports())
    .once('error', function (){
      process.exit(1);
    })
    .once('end', function (){
      process.exit();
    });
});

<commit_msg>Integrate webpack and babel in gulpfile.js and change gulp task to build-webpack<commit_after>var gulp = require('gulp');
var mocha = require('gulp-mocha');
var file = require('gulp-file');
var istanbul = require('gulp-istanbul');
var babel = require("gulp-babel");
var webpack = require('webpack-stream');

// var browserify = require('./support/browserify.js');

gulp.task('build-webpack', function() {
  return gulp.src('lib/*.js')
    .pipe(babel())
    .pipe(webpack({
      entry: './lib/index.js',
      output: {
        filename: 'socket.io.js',
      },
    }))
    .pipe(gulp.dest('./'));
});

// By default, individual js files are transformed by babel and exported to /dist
gulp.task("babel", function () {
  return gulp.src("lib/*.js")
    .pipe(babel())
    .pipe(gulp.dest("dist"));
});

gulp.task('build', function(){
  browserify(function(err, out){
    if(err){
      throw err;
    }else{
      gulp.src('')
        .pipe(file('socket.io.js', out))
        .pipe(gulp.dest('./'));
    }
  });
});

gulp.task('test-node', function(){
  gulp.src(['test/*.js', 'test/support/*.js'])
    .pipe(mocha({
      reporter: 'dot'
    }))
    .once('error', function () {
      process.exit(1);
    })
    .once('end', function () {
      process.exit();
    });
});

gulp.task('istanbul-pre-test', function () {
  return gulp.src(['lib/**/*.js'])
    // Covering files
    .pipe(istanbul())
    // Force `require` to return covered files
    .pipe(istanbul.hookRequire());
});

gulp.task('test-cov', ['istanbul-pre-test'], function(){
  gulp.src(['test/*.js', 'test/support/*.js'])
    .pipe(mocha({
      reporter: 'dot'
    }))
    .pipe(istanbul.writeReports())
    .once('error', function (){
      process.exit(1);
    })
    .once('end', function (){
      process.exit();
    });
});

<|endoftext|>


<commit_before>var gulp       = require("gulp");
var concat     = require("gulp-concat-util");
var wrap       = require("gulp-wrap");

gulp.task("build", () => {
	gulp.src("src/*.js")
		.pipe(concat("ngRestful.js", {sep: "\n\n"}))
		.pipe(wrap("(function(){\n<%= contents %>\n})();"))
		.pipe(gulp.dest("./dist/"));
});<commit_msg>ADDED: gulp watch<commit_after>var gulp       = require("gulp");
var concat     = require("gulp-concat-util");
var wrap       = require("gulp-wrap");

gulp.task("js", () => {
	gulp.src("src/*.js")
		.pipe(concat("ngRestful.js", {sep: "\n\n"}))
		.pipe(wrap("(function(){\n<%= contents %>\n})();"))
		.pipe(gulp.dest("./dist/"));
});

gulp.task("watch", () => {
	gulp.watch("src/*.js", ["js"]);
});<|endoftext|>


<commit_before>var gulp = require('gulp'),
    jshint = require('gulp-jshint'),
    stylish = require('jshint-stylish'),
    gutil = require('gulp-util'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    sass = require('gulp-ruby-sass'),
    sourcemaps = require('gulp-sourcemaps');

gulp.task('js', function() {
    return gulp.src('./js/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter(stylish))
        .pipe(uglify())
        .pipe(concat('app.js'))
        .pipe(gulp.dest('build/js'));
});

gulp.task('sass', function() {
    // need to study the docs for loadpath or search how to use font awesome in gulp
    return sass(['./scss/style.scss', './scss/font-awesome/scss/font-awesome.scss'], {style: 'expanded'})
        .pipe(gulp.dest('build/css'));

});

gulp.task('watch', function() {
  gulp.watch('./js/*.js', ['js']);
  gulp.watch('./scss/*.scss', ['sass']);
 });

gulp.task('default', ['js', 'sass', 'watch']);
<commit_msg>try to fix the font awesome loading problem with gulp<commit_after>var gulp = require('gulp'),
    jshint = require('gulp-jshint'),
    stylish = require('jshint-stylish'),
    gutil = require('gulp-util'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    sass = require('gulp-ruby-sass'),
    sourcemaps = require('gulp-sourcemaps');

gulp.task('js', function() {
    return gulp.src('./js/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter(stylish))
        .pipe(uglify())
        .pipe(concat('app.js'))
        .pipe(gulp.dest('build/js'));
});

gulp.task('sass', function() {
    // need to study the docs for loadpath or search how to use font awesome in gulp
    return sass({
        style: 'expanded',
        loadPath: [
          './scss/style.scss',
          './scss/font-awesome/scss/font-awesome.scss',
        ]
        })
        .pipe(gulp.dest('build/css'));

});

gulp.task('watch', function() {
  gulp.watch('./js/*.js', ['js']);
  gulp.watch('./scss/*.scss', ['sass']);
 });

gulp.task('default', ['js', 'sass', 'watch']);
<|endoftext|>


<commit_before>const gulp = require('gulp')
const rename = require('gulp-rename')
const sketch = require('gulp-sketch')
const iconfont = require('gulp-iconfont')
const consolidate = require('gulp-consolidate')
const bs = require('browser-sync').create()

/**
 * Font settings
 */
const fontName = 'mltrgt-icon' // set name of your symbol font
const className = 'mt' // set class name in your CSS
const template = 'foundation-style' // or 'foundation-style'
const skethcFileName = 'mltrgt-icon-template.sketch' // or 'symbol-font-16px.sketch'

/**
 * Recommended to get consistent builds when watching files
 * See https://github.com/nfroidure/gulp-iconfont
 */
const timestamp = Math.round(Date.now() / 1000)

gulp.task('symbols', () =>
  gulp.src(skethcFileName)
    .pipe(sketch({
      export: 'artboards',
      formats: 'svg'
    }))
    .pipe(iconfont({
      fontName,
      formats: ['ttf', 'eot', 'woff', 'woff2', 'svg'],
      timestamp,
      log: () => {} // suppress unnecessary logging
    }))
    .on('glyphs', (glyphs) => {
      const options = {
        className,
        fontName,
        fontPath: '../fonts/', // set path to font (from your CSS file if relative)
        glyphs: glyphs.map(mapGlyphs)
      }
      gulp.src(`templates/${template}.css`)
        .pipe(consolidate('lodash', options))
        .pipe(rename({ basename: fontName }))
        .pipe(gulp.dest('docs/css/')) // set path to export your CSS

      // if you don't need sample.html, remove next 4 lines
      gulp.src(`templates/${template}.html`)
        .pipe(consolidate('lodash', options))
        .pipe(rename({ basename: 'index' }))
        .pipe(gulp.dest('docs/')) // set path to export your sample HTML
    })
    .pipe(gulp.dest('docs/fonts/')) // set path to export your fonts
)

gulp.task('watch', ['symbols'], () => {
  bs.init({
    files: 'docs/index.html',
    server: 'docs/',
    startPath: '/index.html',
    middleware: cacheControl
  })
  gulp.watch('*.sketch', ['symbols'])
})

/**
 * This is needed for mapping glyphs and codepoints.
 */
function mapGlyphs (glyph) {
  return { name: glyph.name, codepoint: glyph.unicode[0].charCodeAt(0) }
}

/**
 * This keeps browser from caching fonts for your testing environment
 */
function cacheControl (req, res, next) {
  res.setHeader('Cache-control', 'no-store')
  next()
}
<commit_msg>update change filename<commit_after>const gulp = require('gulp')
const rename = require('gulp-rename')
const sketch = require('gulp-sketch')
const iconfont = require('gulp-iconfont')
const consolidate = require('gulp-consolidate')
const bs = require('browser-sync').create()

/**
 * Font settings
 */
const fontName = 'mltrgt-icon' // set name of your symbol font
const className = 'mtg' // set class name in your CSS
const template = 'foundation-style' // or 'foundation-style'
const skethcFileName = 'mltrgt-icon-template.sketch' // or 'symbol-font-16px.sketch'

/**
 * Recommended to get consistent builds when watching files
 * See https://github.com/nfroidure/gulp-iconfont
 */
const timestamp = Math.round(Date.now() / 1000)

gulp.task('symbols', () =>
  gulp.src(skethcFileName)
    .pipe(sketch({
      export: 'artboards',
      formats: 'svg'
    }))
    .pipe(iconfont({
      fontName,
      formats: ['ttf', 'eot', 'woff', 'woff2', 'svg'],
      timestamp,
      log: () => {} // suppress unnecessary logging
    }))
    .on('glyphs', (glyphs) => {
      const options = {
        className,
        fontName,
        fontPath: '../fonts/', // set path to font (from your CSS file if relative)
        glyphs: glyphs.map(mapGlyphs)
      }
      gulp.src(`templates/${template}.css`)
        .pipe(consolidate('lodash', options))
        .pipe(rename({ basename: fontName }))
        .pipe(gulp.dest('docs/css/')) // set path to export your CSS

      // if you don't need sample.html, remove next 4 lines
      gulp.src(`templates/${template}.html`)
        .pipe(consolidate('lodash', options))
        .pipe(rename({ basename: 'index' }))
        .pipe(gulp.dest('docs/')) // set path to export your sample HTML
    })
    .pipe(gulp.dest('docs/fonts/')) // set path to export your fonts
)

gulp.task('watch', ['symbols'], () => {
  bs.init({
    files: 'docs/index.html',
    server: 'docs/',
    startPath: '/index.html',
    middleware: cacheControl
  })
  gulp.watch('*.sketch', ['symbols'])
})

/**
 * This is needed for mapping glyphs and codepoints.
 */
function mapGlyphs (glyph) {
  return { name: glyph.name, codepoint: glyph.unicode[0].charCodeAt(0) }
}

/**
 * This keeps browser from caching fonts for your testing environment
 */
function cacheControl (req, res, next) {
  res.setHeader('Cache-control', 'no-store')
  next()
}
<|endoftext|>


<commit_before>/// <binding BeforeBuild='dist' Clean='clean' />
/*
This file is the main entry point for defining Gulp tasks and using Gulp plugins.
Click here to learn more. https://go.microsoft.com/fwlink/?LinkId=518007
*/

var gulp = require('gulp');
var nunjucksRender = require("gulp-nunjucks-render");
var gulpClean = require("gulp-clean");
var gulpData = require("gulp-data");
var gulpRename = require("gulp-rename");
var merge = require("merge-stream");
var path = require("path");

var libs = './src/lib/';
var dist = './dist/';
var stage = "./dist-stage/";
var distLocal = './dist-local/portfolio';
var nunjucksStage = stage + "/nunjucks/";

gulp.task('default', function () {
    // place code for your default task here
});

gulp.task('restore:bootstrap', function () {
    return gulp.src([
        'node_modules/bootstrap/dist/**/*.*'
    ]).pipe(gulp.dest(libs + 'bootstrap'));
});

gulp.task('restore:font-awesome', function () {
    var css = gulp.src([
        'node_modules/font-awesome/css/*.*'
    ]).pipe(gulp.dest(libs + 'font-awesome/css'));

    var other = gulp.src([
        'node_modules/font-awesome/fonts/*.*'
    ]).pipe(gulp.dest(libs + 'font-awesome/fonts'));

    return merge(css, other);

});

gulp.task('restore', [
    'restore:bootstrap',
    'restore:font-awesome'
]);

function getDataForFile(file) {
    var fileName = file.relative.replace(".njk", ".json");
    try {
        return require("./src/data/" + fileName);
    } catch (ex) {
        return {};
    }
}

function manageNunjucksEnvironment(env) {
    env.addGlobal("contextRoot", "/portfolio/");
}

gulp.task('nunjucks', [
    "nunjucks:stage",
    "nunjucks:render"
]);

gulp.task('nunjucks:render', ["nunjucks:stage"], function () {
    return gulp.src(nunjucksStage + "/**/*.+(html|njk)")
        .pipe(gulpData(getDataForFile))
        .pipe(nunjucksRender({
            path: ["src/templates"],
            manageEnv: manageNunjucksEnvironment
        }))
        .pipe(gulp.dest(dist + "/"));
});

gulp.task("nunjucks:stage", [
    "nunjucks:stage:other",
    "nunjucks:stage:projects"
]);

gulp.task("nunjucks:stage:other", function() {
    return gulp.src(["src/pages/**/*.+(html|njk)", "!src/pages/project.njk"])
        .pipe(gulp.dest(nunjucksStage));
});

gulp.task("nunjucks:stage:projects", function() {
    var projects = [
        "cartracker",
        "showreminder",
        "mirrormirror",
        "mwcaisse",
        "pushfile"
    ];

    var streams = merge();

    for (var i = 0; i < projects.length; i++) {
        var project = projects[i];

        streams.add(gulp.src("src/pages/project.njk")
            .pipe(gulpRename({
                dirname: "projects/",
                basename: project,
                extname: ".njk"
            }))
            .pipe(gulp.dest(nunjucksStage)));
    }
    return streams;
});

gulp.task("stage:clean", function() {
    return gulp.src(stage, { read: false }).pipe(gulpClean());
});

gulp.task("dist:clean",
    function() {
        return gulp.src(dist, { read: false }).pipe(gulpClean());
    });

gulp.task('dist:css',
    function() {
        return gulp.src([
            "src/css/**/*.css"
        ]).pipe(gulp.dest(dist + "/css"));
    });

gulp.task('dist:js',
    function () {
        return gulp.src([
            "src/js/**/*.js"
        ]).pipe(gulp.dest(dist + "/js"));
    });

gulp.task('dist:img',
    function () {
        return gulp.src([
            "src/img-fin/**/*.jpg",
            "src/img-fin/**/*.png"
        ]).pipe(gulp.dest(dist + "/img"));
    });

gulp.task('dist:html', ['nunjucks:render'],
    function () {
        return gulp.src([
            "src/**/*.html"
        ]).pipe(gulp.dest(dist + "/"));
    });

gulp.task('dist:lib', ['restore'],
    function () {
        return gulp.src([
            "src/lib/**/*.*"
        ]).pipe(gulp.dest(dist + "/lib"));
    });

gulp.task('dist-local',
    ['dist'],
    function() {
        return gulp.src(dist + "/**/*.*").pipe(gulp.dest(distLocal));
    });

gulp.task("dist-local:clean",
    function () {
        return gulp.src(distLocal, { read: false }).pipe(gulpClean());
    });

gulp.task('dist', [
    'dist:css',
    'dist:js',
    'dist:img',
    'nunjucks',
    'dist:lib'//,
    //'stage:clean'
]);

gulp.task("clean", [
    "dist:clean",
    "stage:clean",
    "dist-local:clean"
]);<commit_msg>Updated vs bindings in gupl file<commit_after>/// <binding AfterBuild='dist-local' Clean='clean' />
/*
This file is the main entry point for defining Gulp tasks and using Gulp plugins.
Click here to learn more. https://go.microsoft.com/fwlink/?LinkId=518007
*/

var gulp = require('gulp');
var nunjucksRender = require("gulp-nunjucks-render");
var gulpClean = require("gulp-clean");
var gulpData = require("gulp-data");
var gulpRename = require("gulp-rename");
var merge = require("merge-stream");
var path = require("path");

var libs = './src/lib/';
var dist = './dist/';
var stage = "./dist-stage/";
var distLocal = './dist-local/portfolio';
var nunjucksStage = stage + "/nunjucks/";

gulp.task('default', function () {
    // place code for your default task here
});

gulp.task('restore:bootstrap', function () {
    return gulp.src([
        'node_modules/bootstrap/dist/**/*.*'
    ]).pipe(gulp.dest(libs + 'bootstrap'));
});

gulp.task('restore:font-awesome', function () {
    var css = gulp.src([
        'node_modules/font-awesome/css/*.*'
    ]).pipe(gulp.dest(libs + 'font-awesome/css'));

    var other = gulp.src([
        'node_modules/font-awesome/fonts/*.*'
    ]).pipe(gulp.dest(libs + 'font-awesome/fonts'));

    return merge(css, other);

});

gulp.task('restore', [
    'restore:bootstrap',
    'restore:font-awesome'
]);

function getDataForFile(file) {
    var fileName = file.relative.replace(".njk", ".json");
    try {
        return require("./src/data/" + fileName);
    } catch (ex) {
        return {};
    }
}

function manageNunjucksEnvironment(env) {
    env.addGlobal("contextRoot", "/portfolio/");
}

gulp.task('nunjucks', [
    "nunjucks:stage",
    "nunjucks:render"
]);

gulp.task('nunjucks:render', ["nunjucks:stage"], function () {
    return gulp.src(nunjucksStage + "/**/*.+(html|njk)")
        .pipe(gulpData(getDataForFile))
        .pipe(nunjucksRender({
            path: ["src/templates"],
            manageEnv: manageNunjucksEnvironment
        }))
        .pipe(gulp.dest(dist + "/"));
});

gulp.task("nunjucks:stage", [
    "nunjucks:stage:other",
    "nunjucks:stage:projects"
]);

gulp.task("nunjucks:stage:other", function() {
    return gulp.src(["src/pages/**/*.+(html|njk)", "!src/pages/project.njk"])
        .pipe(gulp.dest(nunjucksStage));
});

gulp.task("nunjucks:stage:projects", function() {
    var projects = [
        "cartracker",
        "showreminder",
        "mirrormirror",
        "mwcaisse",
        "pushfile"
    ];

    var streams = merge();

    for (var i = 0; i < projects.length; i++) {
        var project = projects[i];

        streams.add(gulp.src("src/pages/project.njk")
            .pipe(gulpRename({
                dirname: "projects/",
                basename: project,
                extname: ".njk"
            }))
            .pipe(gulp.dest(nunjucksStage)));
    }
    return streams;
});

gulp.task("stage:clean", function() {
    return gulp.src(stage, { read: false }).pipe(gulpClean());
});

gulp.task("dist:clean",
    function() {
        return gulp.src(dist, { read: false }).pipe(gulpClean());
    });

gulp.task('dist:css',
    function() {
        return gulp.src([
            "src/css/**/*.css"
        ]).pipe(gulp.dest(dist + "/css"));
    });

gulp.task('dist:js',
    function () {
        return gulp.src([
            "src/js/**/*.js"
        ]).pipe(gulp.dest(dist + "/js"));
    });

gulp.task('dist:img',
    function () {
        return gulp.src([
            "src/img-fin/**/*.jpg",
            "src/img-fin/**/*.png"
        ]).pipe(gulp.dest(dist + "/img"));
    });

gulp.task('dist:html', ['nunjucks:render'],
    function () {
        return gulp.src([
            "src/**/*.html"
        ]).pipe(gulp.dest(dist + "/"));
    });

gulp.task('dist:lib', ['restore'],
    function () {
        return gulp.src([
            "src/lib/**/*.*"
        ]).pipe(gulp.dest(dist + "/lib"));
    });

gulp.task('dist-local',
    ['dist'],
    function() {
        return gulp.src(dist + "/**/*.*").pipe(gulp.dest(distLocal));
    });

gulp.task("dist-local:clean",
    function () {
        return gulp.src(distLocal, { read: false }).pipe(gulpClean());
    });

gulp.task('dist', [
    'dist:css',
    'dist:js',
    'dist:img',
    'nunjucks',
    'dist:lib'//,
    //'stage:clean'
]);

gulp.task("clean", [
    "dist:clean",
    "stage:clean",
    "dist-local:clean"
]);<|endoftext|>


<commit_before>var gulp = require('gulp'),
    p = require('./package.json'),
    spawn = require('child_process').spawn,
    del = require('del'),
    rename = require("gulp-rename"),
    browserSync = require('browser-sync').create();

gulp.task('css', function (cb) {
    var sass = require('gulp-sass'),
        autoprefixer = require('gulp-autoprefixer');

    // Remove built css file
    del.sync('build/*.css');

    // Compile CSS
    return gulp.src('src/scss/**/*.scss')
        .pipe( sass({ outputStyle: 'compressed' }).on('error', sass.logError) ) // Compile SASS to CSS
        .pipe( autoprefixer() ) // Autoprefix the CSS
        .pipe( rename(p.name + '.css') ) // Rename to package name
        .pipe( gulp.dest('build') ) // Put in build folder
        .pipe( browserSync.stream() );
});

gulp.task('js', [/*'jscs', 'lint'*/], function (cb) {
    // Plugins
    var minifyHTML = require('gulp-minify-html'),
        html2js = require('gulp-html-compile'),
        concat = require('gulp-concat'),
        insert = require('gulp-insert'),
        include = require('gulp-include'),
        replace = require('gulp-replace'),
        tap = require('gulp-tap'),
        uglify = require('gulp-uglify');

    // Variables
    var tpl = '';
    html2js.config = {
        namespace: 'templates',
        name: function(file) {
            // Template names should match file names without extensions
            var filepath = file.relative.split('.')[0],
                parts = filepath.split('/'),
                name = parts[parts.length - 1];

            return name;
        }
    };

    // Remove built js file
    del.sync('build/*.js');

    // Compile HTML to JS
    gulp.src('src/templates/**/*.html')
        .pipe( minifyHTML({ comments: true }) ) // Minify HTML files to 1-liners
        .pipe( html2js(html2js.config) ) // Convert HTML to JS
        .pipe( concat('myTemplates.js') ) // Concatenate all JS templates into one file
        .pipe( insert.prepend('var templates = {};\n') ) // Add a variable declaration to the top
        .pipe( tap(function (file) { tpl = file.contents.toString(); }) ) // Save the file contents to a variable
        .on('end', function () {
            // Build and Minify JS
            gulp.src('src/main.js')
                .pipe( replace(/\/\/= include templates/, tpl) ) // Replace "//= include templates" with templates
                .pipe( include() ) // Include all source files into main.js file
                // .pipe( uglify() ) // Minify final JS file
                .pipe( rename(p.name + '.js') ) // Rename to package name
                .pipe( gulp.dest( 'build') ) // Put in build folder
                .on('end', function () { cb(); }); // Notify the task is complete
        });
});

gulp.task('jscs', function() {
    var jscs = require('gulp-jscs');

    return gulp.src('src/**/*.js')
        .pipe( jscs() );
});

gulp.task('lint', function() {
    var jshint = require('gulp-jshint');

    return gulp.src('src/**/*.js')
        .pipe( jshint() )
        .pipe( jshint.reporter('jshint-stylish') )
        .pipe( jshint.reporter('fail') );
});

gulp.task('test', function(cb) {
    var karma = require('karma').server;

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

gulp.task('watch', ['css', 'js'], function (done) {
    browserSync.init({ server: './', directory: true }, function () {
        gulp.watch(['src/**/*.js', 'src/**/*.html'], ['test', 'js']);
        gulp.watch(['src/scss/**/*.scss'], ['css']);
        gulp.watch(['build/*.js', 'examples/*'], browserSync.reload);
        done();
    });
});

gulp.task('default', ['watch']);<commit_msg>Modifying gulp file to build on windows<commit_after>var gulp = require('gulp'),
    p = require('./package.json'),
    spawn = require('child_process').spawn,
    del = require('del'),
    rename = require("gulp-rename"),
    browserSync = require('browser-sync').create();

gulp.task('css', function (cb) {
    var sass = require('gulp-sass'),
        autoprefixer = require('gulp-autoprefixer');

    // Remove built css file
    del.sync('build/*.css');

    // Compile CSS
    return gulp.src('src/scss/**/*.scss')
        .pipe( sass({ outputStyle: 'compressed' }).on('error', sass.logError) ) // Compile SASS to CSS
        .pipe( autoprefixer() ) // Autoprefix the CSS
        .pipe( rename(p.name + '.css') ) // Rename to package name
        .pipe( gulp.dest('build') ) // Put in build folder
        .pipe( browserSync.stream() );
});

gulp.task('js', [/*'jscs', 'lint'*/], function (cb) {
    // Plugins
    var minifyHTML = require('gulp-minify-html'),
        html2js = require('gulp-html-compile'),
        concat = require('gulp-concat'),
        insert = require('gulp-insert'),
        include = require('gulp-include'),
        replace = require('gulp-replace'),
        tap = require('gulp-tap'),
        uglify = require('gulp-uglify');

    // Variables
    var tpl = '';
    html2js.config = {
        namespace: 'templates',
        name: function(file) {
            var relativeName = file.relative;
            relativeName = relativeName.replace(/\\/g, "/");

            // Template names should match file names without extensions
            var filepath = relativeName.split('.')[0],
                parts = filepath.split('/'),
                name = parts[parts.length - 1];

            return name;
        }
    };

    // Remove built js file
    del.sync('build/*.js');

    // Compile HTML to JS
    gulp.src('src/templates/**/*.html')
        .pipe( minifyHTML({ comments: true }) ) // Minify HTML files to 1-liners
        .pipe( html2js(html2js.config) ) // Convert HTML to JS
        .pipe( concat('myTemplates.js') ) // Concatenate all JS templates into one file
        .pipe( insert.prepend('var templates = {};\n') ) // Add a variable declaration to the top
        .pipe( tap(function (file) { tpl = file.contents.toString(); }) ) // Save the file contents to a variable
        .on('end', function () {
            // Build and Minify JS
            gulp.src('src/main.js')
                .pipe( replace(/\/\/= include templates/, tpl) ) // Replace "//= include templates" with templates
                .pipe( include() ) // Include all source files into main.js file
                // .pipe( uglify() ) // Minify final JS file
                .pipe( rename(p.name + '.js') ) // Rename to package name
                .pipe( gulp.dest( 'build') ) // Put in build folder
                .on('end', function () { cb(); }); // Notify the task is complete
        });
});

gulp.task('jscs', function() {
    var jscs = require('gulp-jscs');

    return gulp.src('src/**/*.js')
        .pipe( jscs() );
});

gulp.task('lint', function() {
    var jshint = require('gulp-jshint');

    return gulp.src('src/**/*.js')
        .pipe( jshint() )
        .pipe( jshint.reporter('jshint-stylish') )
        .pipe( jshint.reporter('fail') );
});

gulp.task('test', function(cb) {
    var karma = require('karma').server;

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

gulp.task('watch', ['css', 'js'], function (done) {
    browserSync.init({ server: './', directory: true }, function () {
        gulp.watch(['src/**/*.js', 'src/**/*.html'], ['test', 'js']);
        gulp.watch(['src/scss/**/*.scss'], ['css']);
        gulp.watch(['build/*.js', 'examples/*'], browserSync.reload);
        done();
    });
});

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


<commit_before>// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2012 Massachusetts Institute of Technology. All rights reserved.

/**
 * @license
 * @fileoverview variables blocks yail generators for Blockly, modified for MIT App Inventor.
 * @author mckinney@mit.edu (Andrew F. McKinney)
 */

'use strict';

goog.provide('Blockly.Yail.variables');

/**
 * Lyn's History:
 * [lyn, 10/27/13] Modified global variable names to begin with YAIL_GLOBAL_VAR_TAG (currently 'g$')
 *     and local variables to begin with YAIL_LOCAL_VAR_TAG (currently '$').
 *     At least on Kawa-legal first character is necessary to ensure AI identifiers
 *     satisfy Kawa's identifier rules. And the global 'g$' tag is necessary to
 *     distinguish globals from procedures (which use the 'g$' tag).
 * [lyn, 12/27/2012] Abstract over handling of param/local/index prefix
 */

// Variable Blocks
/**
 * The identifier rules specified in Blockly.LexicalVariable.checkIdentifier *REQUIRE*
 * a nonempty prefix (here, "tag") whose first character is a legal Kawa identifier character
 * in the character set [a-zA-Z_\!\$%&\?\^\*~\/>\=<]
 * Note this set does not include the characters [@.-\+], which are special in Kawa
 *  and cannot begin identifiers.
 *
 * Why use '$'?  Because $ means money, which is "valuable", and "valuable" sounds like "variable"!
 */
Blockly.Yail.YAIL_GLOBAL_VAR_TAG = 'g$';
Blockly.Yail.YAIL_LOCAL_VAR_TAG = '$';

// Global variable definition block
Blockly.Yail['global_declaration'] = function() {
  var name = Blockly.Yail.YAIL_GLOBAL_VAR_TAG + this.getFieldValue('NAME');
  var argument0 = Blockly.Yail.valueToCode(this, 'VALUE', Blockly.Yail.ORDER_NONE) || '0';
  var code = Blockly.Yail.YAIL_DEFINE +  name + Blockly.Yail.YAIL_SPACER + argument0 + Blockly.Yail.YAIL_CLOSE_COMBINATION;
  return code;
};

// Global variable getter block
Blockly.Yail['lexical_variable_get'] = function() {
  var code = "";
  var name = this.getFieldValue('VAR');
  if (this.eventparam) {        // If this exists, its the english (default) value
    name = this.eventparam;     // which is what we should use in the Yail
  } else {
    Blockly.LexicalVariable.getEventParam(this);
    if (this.eventparam) {
      name = this.eventparam;
    }
  }
  var commandAndName = Blockly.Yail.getVariableCommandAndName(name);
  code += commandAndName[0];
  name = commandAndName[1];

  code += name + Blockly.Yail.YAIL_CLOSE_COMBINATION;
  return [ code, Blockly.Yail.ORDER_ATOMIC ];
};

// Global variable setter block
Blockly.Yail['lexical_variable_set'] = function() {
  var argument0 = Blockly.Yail.valueToCode(this, 'VALUE', Blockly.Yail.ORDER_NONE) || '0';
  var code = "";
  var name = this.getFieldValue('VAR');
  if (this.eventparam) {        // If this exists, its the english (default) value
    name = this.eventparam;     // which is what we should use in the Yail
  } else {
    Blockly.LexicalVariable.getEventParam(this);
    if (this.eventparam) {
      name = this.eventparam;
    }
  }
  var commandAndName = Blockly.Yail.setVariableCommandAndName(name);
  code += commandAndName[0];
  name = commandAndName[1];
  code += name + Blockly.Yail.YAIL_SPACER + argument0
      + Blockly.Yail.YAIL_CLOSE_COMBINATION;
  return code;
};

// [lyn, 12/27/2012] Handle prefixes abstractly
Blockly.Yail['getVariableCommandAndName'] = function(name){
  var command = "";
  var pair = Blockly.unprefixName(name);
  var prefix = pair[0];
  var unprefixedName = pair[1];
  if (prefix === Blockly.globalNamePrefix) {
    name = Blockly.Yail.YAIL_GLOBAL_VAR_TAG + unprefixedName;
    command = Blockly.Yail.YAIL_GET_VARIABLE;
  } else {
    name = Blockly.Yail.YAIL_LOCAL_VAR_TAG + (Blockly.possiblyPrefixYailNameWith(prefix))(unprefixedName);
    command = Blockly.Yail.YAIL_LEXICAL_VALUE;
  }
  return [command,name]
}

// [lyn, 12/27/2012] New
Blockly.Yail['setVariableCommandAndName'] = function(name){
  var command = "";
  var pair = Blockly.unprefixName(name);
  var prefix = pair[0];
  var unprefixedName = pair[1];
  if (prefix === Blockly.globalNamePrefix) {
    name = Blockly.Yail.YAIL_GLOBAL_VAR_TAG + unprefixedName;
    command = Blockly.Yail.YAIL_SET_VARIABLE;
  } else {
    name = Blockly.Yail.YAIL_LOCAL_VAR_TAG + (Blockly.possiblyPrefixYailNameWith(prefix))(unprefixedName);
    command = Blockly.Yail.YAIL_SET_LEXICAL_VALUE;
  }
  return [command,name]
}

Blockly.Yail['local_declaration_statement'] = function() {
  return Blockly.Yail.local_variable(this,false);
}

Blockly.Yail['local_declaration_expression'] = function() {
  return Blockly.Yail.local_variable(this,true);
}

Blockly.Yail['local_variable'] = function(block,isExpression) {
  var code = Blockly.Yail.YAIL_LET;
  code += Blockly.Yail.YAIL_OPEN_COMBINATION + Blockly.Yail.YAIL_SPACER;
  for(var i=0;block.getFieldValue("VAR" + i);i++){
    code += Blockly.Yail.YAIL_OPEN_COMBINATION + Blockly.Yail.YAIL_LOCAL_VAR_TAG + (Blockly.usePrefixInYail ? "local_" : "") + block.getFieldValue("VAR" + i);
    code += Blockly.Yail.YAIL_SPACER + ( Blockly.Yail.valueToCode(block, 'DECL' + i, Blockly.Yail.ORDER_NONE) || '0' );
    code += Blockly.Yail.YAIL_CLOSE_COMBINATION + Blockly.Yail.YAIL_SPACER;
  }
  code += Blockly.Yail.YAIL_SPACER +  Blockly.Yail.YAIL_CLOSE_COMBINATION;
  // [lyn, 01/15/2013] Added to fix bug in local declaration expressions:
  if(isExpression){
    if(!block.getInputTargetBlock("RETURN")){
      code += Blockly.Yail.YAIL_SPACER +  "0";
    } else {
      code += Blockly.Yail.YAIL_SPACER +  Blockly.Yail.valueToCode(block, 'RETURN', Blockly.Yail.ORDER_NONE);
    }
  } else {
    code += Blockly.Yail.YAIL_SPACER +  Blockly.Yail.statementToCode(block, 'STACK', Blockly.Yail.ORDER_NONE);
  }
  code += Blockly.Yail.YAIL_SPACER +  Blockly.Yail.YAIL_CLOSE_COMBINATION;
  if(!isExpression){
    return code;
  } else {
    return [ code, Blockly.Yail.ORDER_ATOMIC ];
  }
};
<commit_msg>Add default statement for empty variable block (#1391)<commit_after>// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2012 Massachusetts Institute of Technology. All rights reserved.

/**
 * @license
 * @fileoverview variables blocks yail generators for Blockly, modified for MIT App Inventor.
 * @author mckinney@mit.edu (Andrew F. McKinney)
 */

'use strict';

goog.provide('Blockly.Yail.variables');

/**
 * Lyn's History:
 * [lyn, 10/27/13] Modified global variable names to begin with YAIL_GLOBAL_VAR_TAG (currently 'g$')
 *     and local variables to begin with YAIL_LOCAL_VAR_TAG (currently '$').
 *     At least on Kawa-legal first character is necessary to ensure AI identifiers
 *     satisfy Kawa's identifier rules. And the global 'g$' tag is necessary to
 *     distinguish globals from procedures (which use the 'g$' tag).
 * [lyn, 12/27/2012] Abstract over handling of param/local/index prefix
 */

// Variable Blocks
/**
 * The identifier rules specified in Blockly.LexicalVariable.checkIdentifier *REQUIRE*
 * a nonempty prefix (here, "tag") whose first character is a legal Kawa identifier character
 * in the character set [a-zA-Z_\!\$%&\?\^\*~\/>\=<]
 * Note this set does not include the characters [@.-\+], which are special in Kawa
 *  and cannot begin identifiers.
 *
 * Why use '$'?  Because $ means money, which is "valuable", and "valuable" sounds like "variable"!
 */
Blockly.Yail.YAIL_GLOBAL_VAR_TAG = 'g$';
Blockly.Yail.YAIL_LOCAL_VAR_TAG = '$';

// Global variable definition block
Blockly.Yail['global_declaration'] = function() {
  var name = Blockly.Yail.YAIL_GLOBAL_VAR_TAG + this.getFieldValue('NAME');
  var argument0 = Blockly.Yail.valueToCode(this, 'VALUE', Blockly.Yail.ORDER_NONE) || '0';
  var code = Blockly.Yail.YAIL_DEFINE +  name + Blockly.Yail.YAIL_SPACER + argument0 + Blockly.Yail.YAIL_CLOSE_COMBINATION;
  return code;
};

// Global variable getter block
Blockly.Yail['lexical_variable_get'] = function() {
  var code = "";
  var name = this.getFieldValue('VAR');
  if (this.eventparam) {        // If this exists, its the english (default) value
    name = this.eventparam;     // which is what we should use in the Yail
  } else {
    Blockly.LexicalVariable.getEventParam(this);
    if (this.eventparam) {
      name = this.eventparam;
    }
  }
  var commandAndName = Blockly.Yail.getVariableCommandAndName(name);
  code += commandAndName[0];
  name = commandAndName[1];

  code += name + Blockly.Yail.YAIL_CLOSE_COMBINATION;
  return [ code, Blockly.Yail.ORDER_ATOMIC ];
};

// Global variable setter block
Blockly.Yail['lexical_variable_set'] = function() {
  var argument0 = Blockly.Yail.valueToCode(this, 'VALUE', Blockly.Yail.ORDER_NONE) || '0';
  var code = "";
  var name = this.getFieldValue('VAR');
  if (this.eventparam) {        // If this exists, its the english (default) value
    name = this.eventparam;     // which is what we should use in the Yail
  } else {
    Blockly.LexicalVariable.getEventParam(this);
    if (this.eventparam) {
      name = this.eventparam;
    }
  }
  var commandAndName = Blockly.Yail.setVariableCommandAndName(name);
  code += commandAndName[0];
  name = commandAndName[1];
  code += name + Blockly.Yail.YAIL_SPACER + argument0
      + Blockly.Yail.YAIL_CLOSE_COMBINATION;
  return code;
};

// [lyn, 12/27/2012] Handle prefixes abstractly
Blockly.Yail['getVariableCommandAndName'] = function(name){
  var command = "";
  var pair = Blockly.unprefixName(name);
  var prefix = pair[0];
  var unprefixedName = pair[1];
  if (prefix === Blockly.globalNamePrefix) {
    name = Blockly.Yail.YAIL_GLOBAL_VAR_TAG + unprefixedName;
    command = Blockly.Yail.YAIL_GET_VARIABLE;
  } else {
    name = Blockly.Yail.YAIL_LOCAL_VAR_TAG + (Blockly.possiblyPrefixYailNameWith(prefix))(unprefixedName);
    command = Blockly.Yail.YAIL_LEXICAL_VALUE;
  }
  return [command,name]
}

// [lyn, 12/27/2012] New
Blockly.Yail['setVariableCommandAndName'] = function(name){
  var command = "";
  var pair = Blockly.unprefixName(name);
  var prefix = pair[0];
  var unprefixedName = pair[1];
  if (prefix === Blockly.globalNamePrefix) {
    name = Blockly.Yail.YAIL_GLOBAL_VAR_TAG + unprefixedName;
    command = Blockly.Yail.YAIL_SET_VARIABLE;
  } else {
    name = Blockly.Yail.YAIL_LOCAL_VAR_TAG + (Blockly.possiblyPrefixYailNameWith(prefix))(unprefixedName);
    command = Blockly.Yail.YAIL_SET_LEXICAL_VALUE;
  }
  return [command,name]
}

Blockly.Yail['local_declaration_statement'] = function() {
  return Blockly.Yail.local_variable(this,false);
}

Blockly.Yail['local_declaration_expression'] = function() {
  return Blockly.Yail.local_variable(this,true);
}

Blockly.Yail['local_variable'] = function(block,isExpression) {
  var code = Blockly.Yail.YAIL_LET;
  code += Blockly.Yail.YAIL_OPEN_COMBINATION + Blockly.Yail.YAIL_SPACER;
  for(var i=0;block.getFieldValue("VAR" + i);i++){
    code += Blockly.Yail.YAIL_OPEN_COMBINATION + Blockly.Yail.YAIL_LOCAL_VAR_TAG + (Blockly.usePrefixInYail ? "local_" : "") + block.getFieldValue("VAR" + i);
    code += Blockly.Yail.YAIL_SPACER + ( Blockly.Yail.valueToCode(block, 'DECL' + i, Blockly.Yail.ORDER_NONE) || '0' );
    code += Blockly.Yail.YAIL_CLOSE_COMBINATION + Blockly.Yail.YAIL_SPACER;
  }
  code += Blockly.Yail.YAIL_SPACER +  Blockly.Yail.YAIL_CLOSE_COMBINATION;
  // [lyn, 01/15/2013] Added to fix bug in local declaration expressions:
  if(isExpression){
    if(!block.getInputTargetBlock("RETURN")){
      code += Blockly.Yail.YAIL_SPACER + "0";
    } else {
      code += Blockly.Yail.YAIL_SPACER + Blockly.Yail.valueToCode(block, 'RETURN', Blockly.Yail.ORDER_NONE);
    }
  } else {
    code += Blockly.Yail.YAIL_SPACER +
      (Blockly.Yail.statementToCode(block, 'STACK', Blockly.Yail.ORDER_NONE) || Blockly.Yail.YAIL_FALSE);
  }
  code += Blockly.Yail.YAIL_SPACER + Blockly.Yail.YAIL_CLOSE_COMBINATION;
  if(!isExpression){
    return code;
  } else {
    return [ code, Blockly.Yail.ORDER_ATOMIC ];
  }
};
<|endoftext|>


<commit_before>'use strict';

var argv = require('yargs').argv;
var browserify = require('browserify');
var browserifyCss = require('browserify-css');
var markedify = require('markedify');
var buffer = require('vinyl-buffer');

// =======================================================================
// Gulp Plugins
// =======================================================================
var gulp = require('gulp'),
    connect = require('gulp-connect'),
    gutil = require('gulp-util'),
    livereload = require('gulp-livereload'),
    merge = require('merge'),
    rename = require('gulp-rename'),
    jshint = require('gulp-jshint'),
    stylish = require('jshint-stylish'),
    jscs = require('gulp-jscs'),
    concat = require('gulp-concat'),
    streamify = require('gulp-streamify'),
    uglify = require('gulp-uglify'),
    less = require('gulp-less'),
    cssnano = require('gulp-cssnano'),
    prefix = require('gulp-autoprefixer'),
    notify = require('gulp-notify'),
    webserver = require('gulp-webserver'),
    watchify = require('watchify'),
    del = require('del'),
    source = require('vinyl-source-stream'),
    sourceMaps = require('gulp-sourcemaps'),
    runSequence = require('run-sequence'),
    Karma = require('karma').Server,
    gulpif = require('gulp-if'),
    envify = require('envify');

// =======================================================================
// File Paths
// =======================================================================
var filePath = require('./gulp.config')();

// =======================================================================
// Error Handling
// =======================================================================
function handleError(err) {
    console.log(err.toString());
    gutil.debug(err);
    // this.emit('end');
}

// =======================================================================
// Server Task
// =======================================================================
var express = require('express'),
    server = express();
// Server settings
server.use(express.static(filePath.build.dest));
// Redirects everything back to our index.html
server.all('/*', function(req, res) {
    res.sendfile('/', {
        root: filePath.build.dest
    });
});
// uncomment the "middleware" section when you are ready to connect to an API
gulp.task('server', function() {
    connect.server({
        root: filePath.build.dest,
        fallback: filePath.build.dest + '/index.html',
        port: 5000,
        livereload: true
        // ,
        // middleware: function(connect, o) {
        //     return [ (function() {
        //         var url = require('url');
        //         var proxy = require('proxy-middleware');
        //         var options = url.parse('http://localhost:3000/'); // path to your dev API
        //         options.route = '/api';
        //         return proxy(options);
        //     })() ];
        // }
    });
});

// =======================================================================
// Clean out dist folder contents on build
// =======================================================================
gulp.task('clean-dev', function() {
    del(['./dist/*.js',
        './dist/css/*.css',
        '!./dist/fonts/**',
        '!./dist/vendor.js',
        '!./dist/vendor.css',
        './dist/*.html',
        './dist/*.png',
        './dist/*.ico',
        './reports/**/*',
        './reports']);
});

gulp.task('clean-full', function() {
    del(['./dist/*',
        './reports/**/*',
        './reports']);
});

// =======================================================================
// JSHint
// =======================================================================
gulp.task('lint', function() {
    return gulp.src(filePath.lint.src)
    .pipe(jshint())
    .pipe(jshint.reporter(stylish));
});

// =======================================================================
// Javascript Checkstyles (JSCS)
// =======================================================================
gulp.task('checkstyle', function() {
    return gulp.src(filePath.lint.src)
    .pipe(jscs())
    .on('error', handleError);
});

// =======================================================================
// Browserify Bundle
// =======================================================================

function bundle(bundler) {
    // Add options to add to "base" bundler passed as parameter
    return bundler
      .transform(browserifyCss, {global: true})
      .transform(markedify)
      .bundle()                                                        // Start bundle
      .pipe(source(filePath.browserify.src))                        // Entry point
      .pipe(buffer())                                               // Convert to gulp pipeline
      .pipe(rename(filePath.browserify.outputFile))          // Rename output from 'app.js'
                                                                              //   to 'bundle.js'
      .pipe(sourceMaps.init({ loadMaps : true }))  // Strip inline source maps
      .pipe(sourceMaps.write(filePath.browserify.mapDir))    // Save source maps to their
                                                                       //   own directory
      .pipe(gulp.dest(filePath.browserify.outputDir))        // Save 'bundle' to build/
      .pipe(connect.reload());                              // Reload browser if relevant

      //TODO: add this code in for bundling dev vs prod
      //
}

gulp.task('bundle', function() {
    var bundler = browserify({
      entries: filePath.browserify.src, // Pass browserify the entry point
      debug: true
    });
    bundle(bundler).pipe(gulpif(!bundle.prod, sourceMaps.init({
                  loadMaps: true
              })))
              .pipe(gulpif(!bundle.prod, sourceMaps.write('./')))
              .pipe(gulpif(bundle.prod, streamify(uglify({
                  mangle: false
              }))))
// ;  // Chain other options -- sourceMaps, rename, etc.
});

// =======================================================================
// Styles Task
// =======================================================================
gulp.task('styles-dev', function() {
    return gulp.src(filePath.styles.src)
    .pipe(sourceMaps.init())
    .pipe(less())
    .on('error', handleError)
    .pipe(sourceMaps.write())
    .pipe(gulp.dest(filePath.build.dest + '/css'))
    .on('error', handleError)
    .pipe(notify({
        message: 'Styles task complete'
    }))
    .pipe(connect.reload());
});

gulp.task('styles-prod', function() {
    return gulp.src(filePath.styles.src)
    .pipe(less())
    .on('error', handleError)
    .pipe(prefix('last 1 version', '> 1%', {
        map: true
    }))
    .pipe(cssnano())
    .pipe(gulp.dest(filePath.build.dest + '/css'))
    .on('error', handleError)
    .pipe(notify({
        message: 'Styles task complete'
    }));
});

// =======================================================================
// Images Task
// =======================================================================
gulp.task('images', function() {
    return gulp.src(filePath.assets.images.src)
    .on('error', handleError)
    .pipe(gulp.dest(filePath.assets.images.dest))
    .pipe(notify({
        message: 'Images copied'
    }))
    .pipe(connect.reload());
});

// =======================================================================
// Fonts Task
// =======================================================================
gulp.task('fonts', function () {
    return gulp.src(filePath.assets.fonts.src)
        .on('error', handleError)
        .pipe(gulp.dest(filePath.assets.fonts.dest))
        .pipe(connect.reload());
});

// =======================================================================
// Vendor CSS Task
// =======================================================================
//gulp.task('vendorCSS', function() {
//    return gulp.src(filePath.vendorCSS.src)
//    .pipe(concat('vendor.css'))
//    .on('error', handleError)
//    .pipe(cssnano())
//    .pipe(gulp.dest(filePath.build.dest))
//    .pipe(notify({
//        message: 'VendorCSS task complete'
//    }))
//    .pipe(connect.reload());
//});

// =======================================================================
// Copy index.html
// =======================================================================
gulp.task('copyIndex', function() {
    return gulp.src(filePath.copyIndex.src)
    .pipe(gulp.dest(filePath.build.dest))
    .pipe(notify({
        message: 'index.html successfully copied'
    }))
    .pipe(connect.reload());
});

// =======================================================================
// Copy Favicon
// =======================================================================
gulp.task('copyFavicon', function() {
    return gulp.src(filePath.copyFavicon.src)
    .pipe(gulp.dest(filePath.build.dest))
    .pipe(notify({
        message: 'favicon successfully copied'
    }));
});

// =======================================================================
// Watch for changes
// =======================================================================
gulp.task('watch', function() {
    gulp.watch(filePath.styles.watch, ['styles-dev']);
    gulp.watch(filePath.assets.images.watch, ['images']);
    gulp.watch(filePath.browserify.watch, ['bundle']);
    // gulp.watch(filePath.vendorJS.src, ['vendorJS']);
    gulp.watch(filePath.copyIndex.watch, ['copyIndex']);
    gulp.watch(filePath.lint.src, ['checkstyle']);
    console.log('Watching...');
});

// =======================================================================
// Start a webserver to serve the assets to developers directly
// =======================================================================
gulp.task('webserver', function() {
  gulp.src('app')
  .pipe(webserver({
    livereload: true,
    directoryListing: true,
    open: true
  }));
});

// =======================================================================
// Karma Configuration
// =======================================================================
gulp.task('karma', function(done) {
  var karma = new Karma({
    configFile: __dirname + '/karma.conf.js',
    singleRun: !argv.watch
  }, done);
  karma.start();
});

// =======================================================================
// Sequential Build Rendering
// =======================================================================

// run "gulp" in terminal to build the DEV app
gulp.task('build-dev', function(callback) {
    runSequence(
        ['clean-dev', 'lint', 'checkstyle'],
        // images and vendor tasks are removed to speed up build time. Use "gulp build" to do a full re-build of the dev app.
        [
          // 'bundle-dev',
          'bundle',
          'styles-dev', 'copyIndex', 'copyFavicon'], ['server', 'watch'],
        callback
    );
});

// run "gulp test" in terminal to build the DEV app
gulp.task('build-test', function(callback) {
    runSequence(
        ['clean-full', 'lint', 'checkstyle'],
        ['karma'],
        callback
    );
});

// run "gulp prod" in terminal to build the PROD-ready app
gulp.task('build-prod', function(callback) {
    runSequence(
        ['clean-full', 'lint', 'checkstyle'],
        [
          // 'bundle-prod',
          'bundle',
          'styles-prod', 'images', 'fonts','copyIndex', 'copyFavicon'],
        callback
    );
});

// run "gulp build" in terminal for a full re-build in DEV
gulp.task('build', function(callback) {
    runSequence(
      ['clean-full'
        // 'lint',
        // 'checkstyle'
      ],
        [
          // 'bundle-dev',
          'bundle',
          'styles-dev', 'images', 'fonts','copyIndex', 'copyFavicon'],
        ['server', 'watch'],
        callback
    );
});

gulp.task('default', ['build-dev']);
gulp.task('test', ['build-test']);
gulp.task('prod', ['build-prod']);
<commit_msg>Remove unsued tasks. Beautify gitfile<commit_after>'use strict';

var argv = require('yargs').argv;
var browserify = require('browserify');
var browserifyCss = require('browserify-css');
var markedify = require('markedify');
var buffer = require('vinyl-buffer');

// =======================================================================
// Gulp Plugins
// =======================================================================
var gulp = require('gulp'),
    connect = require('gulp-connect'),
    gutil = require('gulp-util'),
    livereload = require('gulp-livereload'),
    merge = require('merge'),
    rename = require('gulp-rename'),
    jshint = require('gulp-jshint'),
    stylish = require('jshint-stylish'),
    jscs = require('gulp-jscs'),
    concat = require('gulp-concat'),
    streamify = require('gulp-streamify'),
    uglify = require('gulp-uglify'),
    less = require('gulp-less'),
    cssnano = require('gulp-cssnano'),
    prefix = require('gulp-autoprefixer'),
    notify = require('gulp-notify'),
    webserver = require('gulp-webserver'),
    watchify = require('watchify'),
    del = require('del'),
    source = require('vinyl-source-stream'),
    sourceMaps = require('gulp-sourcemaps'),
    runSequence = require('run-sequence'),
    Karma = require('karma').Server,
    gulpif = require('gulp-if'),
    envify = require('envify');

// =======================================================================
// File Paths
// =======================================================================
var filePath = require('./gulp.config')();

// =======================================================================
// Error Handling
// =======================================================================
function handleError(err) {
    console.log(err.toString());
    gutil.debug(err);
    // this.emit('end');
}

// =======================================================================
// Server Task
// =======================================================================
var express = require('express'),
    server = express();
// Server settings
server.use(express.static(filePath.build.dest));
// Redirects everything back to our index.html
server.all('/*', function (req, res) {
    res.sendfile('/', {
        root: filePath.build.dest
    });
});
// uncomment the "middleware" section when you are ready to connect to an API
gulp.task('server', function () {
    connect.server({
        root: filePath.build.dest,
        fallback: filePath.build.dest + '/index.html',
        port: 5000,
        livereload: true
        // ,
        // middleware: function(connect, o) {
        //     return [ (function() {
        //         var url = require('url');
        //         var proxy = require('proxy-middleware');
        //         var options = url.parse('http://localhost:3000/'); // path to your dev API
        //         options.route = '/api';
        //         return proxy(options);
        //     })() ];
        // }
    });
});

// =======================================================================
// Clean out dist folder contents on build
// =======================================================================
gulp.task('clean-dev', function () {
    del(['./dist/*.js',
        './dist/css/*.css',
        '!./dist/fonts/**',
        '!./dist/vendor.js',
        '!./dist/vendor.css',
        './dist/*.html',
        './dist/*.png',
        './dist/*.ico',
        './reports/**/*',
        './reports'
    ]);
});

gulp.task('clean-full', function () {
    del(['./dist/*',
        './reports/**/*',
        './reports'
    ]);
});

// =======================================================================
// JSHint
// =======================================================================
gulp.task('lint', function () {
    return gulp.src(filePath.lint.src)
        .pipe(jshint())
        .pipe(jshint.reporter(stylish));
});

// =======================================================================
// Javascript Checkstyles (JSCS)
// =======================================================================
gulp.task('checkstyle', function () {
    return gulp.src(filePath.lint.src)
        .pipe(jscs())
        .on('error', handleError);
});

// =======================================================================
// Browserify Bundle
// =======================================================================

function bundle() {
    return browserify({
        entries: filePath.browserify.src, // Pass browserify the entry point
        debug: true
    })
    .transform(browserifyCss, {
            global: true
        })
        .transform(markedify)
        .bundle() // Start bundle
        .pipe(source(filePath.browserify.src)) // Entry point
        .pipe(buffer()) // Convert to gulp pipeline
        .pipe(rename(filePath.browserify.outputFile)) // Rename output from 'app.js' to 'bundle.js'
        .pipe(sourceMaps.init({
            loadMaps: true
        })) // Strip inline source maps
        .pipe(sourceMaps.write(filePath.browserify.mapDir)) // Save source maps to their own directory
        .pipe(gulp.dest(filePath.browserify.outputDir)) // Save 'bundle' to build/
        .pipe(connect.reload()); // Reload browser if relevant
}

gulp.task('bundle', function () {
    bundle().pipe(
            gulpif(!bundle.prod, sourceMaps.init({
                loadMaps: true
            }))
        )
        .pipe(gulpif(!bundle.prod, sourceMaps.write('./')))
        .pipe(gulpif(bundle.prod, streamify(uglify({
            mangle: false
        }))))
});

// =======================================================================
// Styles Task
// =======================================================================
gulp.task('styles-dev', function () {
    return gulp.src(filePath.styles.src)
        .pipe(sourceMaps.init())
        .pipe(less())
        .on('error', handleError)
        .pipe(sourceMaps.write())
        .pipe(gulp.dest(filePath.build.dest + '/css'))
        .on('error', handleError)
        .pipe(notify({
            message: 'Styles task complete'
        }))
        .pipe(connect.reload());
});

gulp.task('styles-prod', function () {
    return gulp.src(filePath.styles.src)
        .pipe(less())
        .on('error', handleError)
        .pipe(prefix('last 1 version', '> 1%', {
            map: true
        }))
        .pipe(cssnano())
        .pipe(gulp.dest(filePath.build.dest + '/css'))
        .on('error', handleError)
        .pipe(notify({
            message: 'Styles task complete'
        }));
});

// =======================================================================
// Images Task
// =======================================================================
gulp.task('images', function () {
    return gulp.src(filePath.assets.images.src)
        .on('error', handleError)
        .pipe(gulp.dest(filePath.assets.images.dest))
        .pipe(notify({
            message: 'Images copied'
        }))
        .pipe(connect.reload());
});

// =======================================================================
// Fonts Task
// =======================================================================
gulp.task('fonts', function () {
    return gulp.src(filePath.assets.fonts.src)
        .on('error', handleError)
        .pipe(gulp.dest(filePath.assets.fonts.dest))
        .pipe(connect.reload());
});

// =======================================================================
// Vendor CSS Task
// =======================================================================
//gulp.task('vendorCSS', function() {
//    return gulp.src(filePath.vendorCSS.src)
//    .pipe(concat('vendor.css'))
//    .on('error', handleError)
//    .pipe(cssnano())
//    .pipe(gulp.dest(filePath.build.dest))
//    .pipe(notify({
//        message: 'VendorCSS task complete'
//    }))
//    .pipe(connect.reload());
//});

// =======================================================================
// Copy index.html
// =======================================================================
gulp.task('copyIndex', function () {
    return gulp.src(filePath.copyIndex.src)
        .pipe(gulp.dest(filePath.build.dest))
        .pipe(notify({
            message: 'index.html successfully copied'
        }))
        .pipe(connect.reload());
});

// =======================================================================
// Copy Favicon
// =======================================================================
gulp.task('copyFavicon', function () {
    return gulp.src(filePath.copyFavicon.src)
        .pipe(gulp.dest(filePath.build.dest))
        .pipe(notify({
            message: 'favicon successfully copied'
        }));
});

// =======================================================================
// Watch for changes
// =======================================================================
gulp.task('watch', function () {
    gulp.watch(filePath.styles.watch, ['styles-dev']);
    gulp.watch(filePath.assets.images.watch, ['images']);
    gulp.watch(filePath.browserify.watch, ['bundle']);
    // gulp.watch(filePath.vendorJS.src, ['vendorJS']);
    gulp.watch(filePath.copyIndex.watch, ['copyIndex']);
    gulp.watch(filePath.lint.src, ['checkstyle']);
    console.log('Watching...');
});

// =======================================================================
// Start a webserver to serve the assets to developers directly
// =======================================================================
gulp.task('webserver', function () {
    gulp.src('app')
        .pipe(webserver({
            livereload: true,
            directoryListing: true,
            open: true
        }));
});

// =======================================================================
// Karma Configuration
// =======================================================================
gulp.task('karma', function (done) {
    var karma = new Karma({
        configFile: __dirname + '/karma.conf.js',
        singleRun: !argv.watch
    }, done);
    karma.start();
});

// =======================================================================
// Sequential Build Rendering
// =======================================================================

// run "gulp" in terminal to build the DEV app
gulp.task('build-dev', function (callback) {
    runSequence(
        ['clean-dev', 'lint', 'checkstyle'],
        // images and vendor tasks are removed to speed up build time. Use "gulp build" to do a full re-build of the dev app.
        [
            'bundle',
            'styles-dev', 'copyIndex', 'copyFavicon'
        ], ['server', 'watch'],
        callback
    );
});

// run "gulp test" in terminal to build the DEV app
gulp.task('build-test', function (callback) {
    runSequence(
        ['clean-full', 'lint', 'checkstyle'], ['karma'],
        callback
    );
});

// run "gulp prod" in terminal to build the PROD-ready app
gulp.task('build-prod', function (callback) {
    runSequence(
        ['clean-full', 'lint', 'checkstyle'], [
            'bundle',
            'styles-prod', 'images', 'fonts', 'copyIndex', 'copyFavicon'
        ],
        callback
    );
});

// run "gulp build" in terminal for a full re-build in DEV
gulp.task('build', function (callback) {
    runSequence(
        ['clean-full', 'lint','checkstyle'],
        ['bundle','styles-dev', 'images', 'fonts', 'copyIndex', 'copyFavicon'],
        ['server', 'watch'],
        callback
    );
});

gulp.task('default', ['build-dev']);
gulp.task('test', ['build-test']);
gulp.task('prod', ['build-prod']);<|endoftext|>


<commit_before>/* jshint node: true */
var gulp = require('gulp');
var gulpif = require('gulp-if');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var header = require('gulp-header');
var imagemin = require('gulp-imagemin');
var minifyCss = require('gulp-minify-css');
var minifyHtml = require('gulp-minify-html');
var argv = require('yargs').argv;
var shell = require('gulp-shell');
var uglify = require('gulp-uglify');
var runSequence = require('run-sequence');
var del = require('del');
var ngAnnotate = require('gulp-ng-annotate');

// allows for watch to continue after errors
function handleError(error) {
  console.error(error);
  this.emit('end');
};

var basePaths = {
  dev: './toc/',
  app: './toc/app/',
  prod: './www/',
  prodApp: './www/app/',
  mobile: './mobile/',
  platforms: './platforms/'
};

var paths = {
  sass: {
    app: [
      basePaths.app + 'components/**/*.scss',
      basePaths.app + 'libraries/**/*.scss',
      basePaths.app + 'views/**/*.scss',
      basePaths.app + 'app.scss'
    ],
    init: [
      basePaths.app + 'initialize.scss'
    ],
    landing: [
      basePaths.dev + 'landing.scss'
    ]
  },
  js: [
    basePaths.app + 'components/**/*.js',
    basePaths.app + 'libraries/**/*.js',
    basePaths.app + 'services/**/*.js',
    basePaths.app + 'views/**/*.js',
    basePaths.app + '*.js',
    basePaths.dev + '*.js',
    './*.js'
  ],
  html: [
    basePaths.app + 'components/**/*.html',
    basePaths.app + 'views/**/*.html',
    basePaths.app + '*.html',
    basePaths.dev + '*.html'
  ],
  asset: [
    basePaths.app + 'assets/**'
  ]
};

gulp.task('watch', function watch() {
  gulp.watch(paths.sass.app, ['bundle-sass-app']);
  gulp.watch(paths.sass.init, ['bundle-sass-init']);
  gulp.watch(paths.sass.landing, ['bundle-sass-landing']);
});

gulp.task('serve', function serve() {
  var serveCommand = argv.prod ?
    'http-server www -p 8100' :
    // 'cd app && jspm-server --no-browser --port=8100 --ignore-exts=".scss"';
    'ionic serve --lab --address=$(hostname -i) -i 8101 --nobrowser';
  return gulp.src('')
    .pipe(shell(serveCommand));
});

gulp.task('clean', ['clean-build', 'clean-package']);

gulp.task('clean-build', function clean(done) {
  return del([
    basePaths.prod + '**'
  ], done);
});

gulp.task('build', function build(done) {
  return runSequence(
    'clean-build',
    'uncache-jspm',
    ['build-js', 'build-html', 'build-sass', 'build-asset'],
    ['inject-js', 'rename-js'],
    // 'cache-jspm',
    done
  );
});

gulp.task('package', ['build'], function package() {
  //FIXME: doesn't work yet due to
  // https://github.com/driftyco/ionic-cli/issues/620
  return gulp.src('')
    .pipe(shell(
      'ionic package build android'
    ));
});

gulp.task('run', function run() {
  return gulp.src('')
    .pipe(shell(
      'ionic run --device --livereload --livereload-port 8101 ' +
      '--external-address $TOC_HOST_IP android'
    ));
});

gulp.task('build-js', ['build-jspm'], function buildJs() {
  return gulp.src([
      basePaths.app + 'dependencies/system-csp-production.src.js',
      basePaths.app + 'dependencies/system-polyfills.js',
      basePaths.app + 'jspm-config.js',
      basePaths.app + 'initialize.js',
      basePaths.dev + 'landing.js',
    ], {
      base: basePaths.dev
    })
    .pipe(gulpif(argv.prod, uglify()))
    .pipe(gulp.dest(basePaths.prod));
});

gulp.task('rename-js', function injectJs() {
  return gulp.src([
      basePaths.prodApp + 'dependencies/system-csp-production.src.js',
    ], {
      base: basePaths.prodApp
    })
    .pipe(rename('dependencies/system.src.js'))
    .pipe(gulp.dest(basePaths.prodApp));
});

gulp.task('inject-js', function injectJs() {
  var tocVersion = require('package.json').version;
  return gulp.src([
      basePaths.prodApp + 'initialize.js',
    ], {
      base: basePaths.prodApp
    })
    .pipe(header('window.tocVersion="' + tocVersion + '";'))
    .pipe(gulpif(argv.prod, header('window.tocProd=true;')))
    .pipe(gulp.dest(basePaths.prodApp));
});

gulp.task('build-jspm', ['bundle-jspm'], function buildJspm() {
  return gulp.src(basePaths.prodApp + 'app.js')
    .pipe(gulpif(argv.prod, ngAnnotate()))
    .pipe(gulpif(argv.prod, uglify()))
    .pipe(gulp.dest(basePaths.prodApp));
});

gulp.task('bundle-jspm', function bundleJspm() {
  return gulp.src('')
    .pipe(shell([
      //clear depcache config first
      'jspm bundle app ' + basePaths.prodApp +
        'app.js --skip-source-maps'
    ]));
});

gulp.task('uncache-jspm', function uncacheJspm() {
  return gulp.src('')
    .pipe(shell([
      'jspm unbundle'
    ]));
});

gulp.task('cache-jspm', function cacheJspm() {
  return gulp.src('')
    .pipe(shell([
      'jspm depcache app'
    ]));
});

gulp.task('build-html', function buildHtml() {
  return gulp.src([
      basePaths.app + 'index.html',
      basePaths.dev + 'index.html',
    ], {
      base: basePaths.dev
    })
    .pipe(gulpif(argv.prod, minifyHtml()))
    .pipe(gulp.dest(basePaths.prod));
});

gulp.task('build-asset', function buildAsset() {
  return gulp.src([
      basePaths.app + 'assets/**'
    ], {
      base: basePaths.dev
    })
    .pipe(gulp.dest(basePaths.prod));
});

//not part of build because this only needs to run occassionaly for new images
gulp.task('build-image', function buildImage() {
  return gulp.src([
      basePaths.app + 'assets/images/**'
    ], {
      base: basePaths.dev
    })
    .pipe(imagemin({
      optimizationLevel: 7,
      multipass: true
    }))
    .pipe(gulp.dest(basePaths.dev));
});

gulp.task('build-sass', ['bundle-sass'], function buildSass() {
  return gulp.src([
      basePaths.app + 'app.css',
      basePaths.app + 'initialize.css',
      basePaths.dev + 'landing.css'
    ], {
      base: basePaths.dev
    })
    .pipe(gulp.dest(basePaths.prod))
    .on('error', handleError);
});

gulp.task('bundle-sass', [
  'bundle-sass-app',
  'bundle-sass-init',
  'bundle-sass-landing'
]);

var makeSassTask = function makeSassTask(sassPath) {
  return gulp.src(sassPath, { base: basePaths.dev })
    .pipe(gulpif(!argv.prod, sourcemaps.init()))
    .pipe(sass())
    .on('error', handleError)
    .pipe(gulpif(!argv.prod, sourcemaps.write()))
    .pipe(gulpif(argv.prod, minifyCss()))
    .pipe(gulp.dest(basePaths.dev))
    .on('error', handleError);
};

gulp.task('bundle-sass-app', function bundleSass() {
  return makeSassTask(basePaths.app + 'app.scss');
});

gulp.task('bundle-sass-init', function bundleSass() {
  return makeSassTask(basePaths.app + 'initialize.scss');
});

gulp.task('bundle-sass-landing', function bundleSass() {
  return makeSassTask(basePaths.dev + 'landing.scss');
});
<commit_msg>Fixed gulp build always exiting with 0<commit_after>/* jshint node: true */
var gulp = require('gulp');
var gulpif = require('gulp-if');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var header = require('gulp-header');
var imagemin = require('gulp-imagemin');
var minifyCss = require('gulp-minify-css');
var minifyHtml = require('gulp-minify-html');
var argv = require('yargs').argv;
var shell = require('gulp-shell');
var uglify = require('gulp-uglify');
var runSequence = require('run-sequence');
var del = require('del');
var ngAnnotate = require('gulp-ng-annotate');

// allows for watch to continue after errors
function handleError(error) {
  console.error(error);
  this.emit('end');
};

var basePaths = {
  dev: './toc/',
  app: './toc/app/',
  prod: './www/',
  prodApp: './www/app/',
  mobile: './mobile/',
  platforms: './platforms/'
};

var paths = {
  sass: {
    app: [
      basePaths.app + 'components/**/*.scss',
      basePaths.app + 'libraries/**/*.scss',
      basePaths.app + 'views/**/*.scss',
      basePaths.app + 'app.scss'
    ],
    init: [
      basePaths.app + 'initialize.scss'
    ],
    landing: [
      basePaths.dev + 'landing.scss'
    ]
  },
  js: [
    basePaths.app + 'components/**/*.js',
    basePaths.app + 'libraries/**/*.js',
    basePaths.app + 'services/**/*.js',
    basePaths.app + 'views/**/*.js',
    basePaths.app + '*.js',
    basePaths.dev + '*.js',
    './*.js'
  ],
  html: [
    basePaths.app + 'components/**/*.html',
    basePaths.app + 'views/**/*.html',
    basePaths.app + '*.html',
    basePaths.dev + '*.html'
  ],
  asset: [
    basePaths.app + 'assets/**'
  ]
};

gulp.task('watch', function watch() {
  gulp.watch(paths.sass.app, ['bundle-sass-app']);
  gulp.watch(paths.sass.init, ['bundle-sass-init']);
  gulp.watch(paths.sass.landing, ['bundle-sass-landing']);
});

gulp.task('serve', function serve() {
  var serveCommand = argv.prod ?
    'http-server www -p 8100' :
    // 'cd app && jspm-server --no-browser --port=8100 --ignore-exts=".scss"';
    'ionic serve --lab --address=$(hostname -i) -i 8101 --nobrowser';
  return gulp.src('')
    .pipe(shell(serveCommand));
});

gulp.task('clean', ['clean-build', 'clean-package']);

gulp.task('clean-build', function clean(done) {
  return del([
    basePaths.prod + '**'
  ], done);
});

gulp.task('build', function build(done) {
  // fixes runsequence always exiting with 0 even on errors
  // http://dev.topheman.com/gulp-fail-run-sequence-with-a-correct-exit-code/
  var handleBuildError = function (error) {
    //if any error happened in the previous tasks, exit with a code > 0
    if (error) {
      var exitCode = 2;
      console.log('[ERROR] gulp build task failed', error);
      console.log('[FAIL] gulp build task failed - exiting with code ' + exitCode);
      return process.exit(exitCode);
    }
    else {
      return done();
    }
  };

  return runSequence(
    'clean-build',
    'uncache-jspm',
    ['build-js', 'build-html', 'build-sass', 'build-asset'],
    ['inject-js', 'rename-js'],
    // 'cache-jspm',
    handleBuildError
  );
});

gulp.task('package', ['build'], function package() {
  //FIXME: doesn't work yet due to
  // https://github.com/driftyco/ionic-cli/issues/620
  return gulp.src('')
    .pipe(shell(
      'ionic package build android'
    ));
});

gulp.task('run', function run() {
  return gulp.src('')
    .pipe(shell(
      'ionic run --device --livereload --livereload-port 8101 ' +
      '--external-address $TOC_HOST_IP android'
    ));
});

gulp.task('build-js', ['build-jspm'], function buildJs() {
  return gulp.src([
      basePaths.app + 'dependencies/system-csp-production.src.js',
      basePaths.app + 'dependencies/system-polyfills.js',
      basePaths.app + 'jspm-config.js',
      basePaths.app + 'initialize.js',
      basePaths.dev + 'landing.js',
    ], {
      base: basePaths.dev
    })
    .pipe(gulpif(argv.prod, uglify()))
    .pipe(gulp.dest(basePaths.prod));
});

gulp.task('rename-js', function injectJs() {
  return gulp.src([
      basePaths.prodApp + 'dependencies/system-csp-production.src.js',
    ], {
      base: basePaths.prodApp
    })
    .pipe(rename('dependencies/system.src.js'))
    .pipe(gulp.dest(basePaths.prodApp));
});

gulp.task('inject-js', function injectJs() {
  var tocVersion = require('package.json').version;
  return gulp.src([
      basePaths.prodApp + 'initialize.js',
    ], {
      base: basePaths.prodApp
    })
    .pipe(header('window.tocVersion="' + tocVersion + '";'))
    .pipe(gulpif(argv.prod, header('window.tocProd=true;')))
    .pipe(gulp.dest(basePaths.prodApp));
});

gulp.task('build-jspm', ['bundle-jspm'], function buildJspm() {
  return gulp.src(basePaths.prodApp + 'app.js')
    .pipe(gulpif(argv.prod, ngAnnotate()))
    .pipe(gulpif(argv.prod, uglify()))
    .pipe(gulp.dest(basePaths.prodApp));
});

gulp.task('bundle-jspm', function bundleJspm() {
  return gulp.src('')
    .pipe(shell([
      //clear depcache config first
      'jspm bundle app ' + basePaths.prodApp +
        'app.js --skip-source-maps'
    ]));
});

gulp.task('uncache-jspm', function uncacheJspm() {
  return gulp.src('')
    .pipe(shell([
      'jspm unbundle'
    ]));
});

gulp.task('cache-jspm', function cacheJspm() {
  return gulp.src('')
    .pipe(shell([
      'jspm depcache app'
    ]));
});

gulp.task('build-html', function buildHtml() {
  return gulp.src([
      basePaths.app + 'index.html',
      basePaths.dev + 'index.html',
    ], {
      base: basePaths.dev
    })
    .pipe(gulpif(argv.prod, minifyHtml()))
    .pipe(gulp.dest(basePaths.prod));
});

gulp.task('build-asset', function buildAsset() {
  return gulp.src([
      basePaths.app + 'assets/**'
    ], {
      base: basePaths.dev
    })
    .pipe(gulp.dest(basePaths.prod));
});

//not part of build because this only needs to run occassionaly for new images
gulp.task('build-image', function buildImage() {
  return gulp.src([
      basePaths.app + 'assets/images/**'
    ], {
      base: basePaths.dev
    })
    .pipe(imagemin({
      optimizationLevel: 7,
      multipass: true
    }))
    .pipe(gulp.dest(basePaths.dev));
});

gulp.task('build-sass', ['bundle-sass'], function buildSass() {
  return gulp.src([
      basePaths.app + 'app.css',
      basePaths.app + 'initialize.css',
      basePaths.dev + 'landing.css'
    ], {
      base: basePaths.dev
    })
    .pipe(gulp.dest(basePaths.prod))
    .on('error', handleError);
});

gulp.task('bundle-sass', [
  'bundle-sass-app',
  'bundle-sass-init',
  'bundle-sass-landing'
]);

var makeSassTask = function makeSassTask(sassPath) {
  return gulp.src(sassPath, { base: basePaths.dev })
    .pipe(gulpif(!argv.prod, sourcemaps.init()))
    .pipe(sass())
    .on('error', handleError)
    .pipe(gulpif(!argv.prod, sourcemaps.write()))
    .pipe(gulpif(argv.prod, minifyCss()))
    .pipe(gulp.dest(basePaths.dev))
    .on('error', handleError);
};

gulp.task('bundle-sass-app', function bundleSass() {
  return makeSassTask(basePaths.app + 'app.scss');
});

gulp.task('bundle-sass-init', function bundleSass() {
  return makeSassTask(basePaths.app + 'initialize.scss');
});

gulp.task('bundle-sass-landing', function bundleSass() {
  return makeSassTask(basePaths.dev + 'landing.scss');
});
<|endoftext|>