<commit_before>// Copyright 2015 The Oppia Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview node module that automate tasks.
 */

var fs = require('fs');
var yargs = require('yargs');
var argv = yargs
  .usage('Usage: $0 <command> [<options>]')
  .example('$0 build --minify=True')
  .command('build', 'generate optimimized third party library for production',
    function(yargs) {
      argv = yargs
        .usage('Usage: $0 build [--minify] [--output_directory]')
        .option('minify', {
          describe: 'Whether to minify third-party dependencies'
        })
        .option('output_directory', {
          describe: 'A path to the directory where the files will be generated'
        }).argv;
    })
  .command('start_devserver', 'start GAE development server',
    function(yargs) {
      argv = yargs
        .usage('Usage: $0 start_devserver [--gae_devserver_path]' +
         '[--clear_datastore] [--enable_sendmail] [--use_minification]' +
         '[--prod_env]')
        .option('gae_devserver_path', {
          describe: 'A path to app engine'
        })
        .option('enable_sendmail', {
          describe: 'Whether to send emails'
        })
        .option('clear_datastore', {
          describe: 'Whether to clear all data storage'
        })
        .option('use_minification', {
          describe: 'Whether to build with minification'
        })
        .option('prod_env', {
          describe: 'Whether to run server in prod mode'
        })
        .demand(['gae_devserver_path'])
        .argv;
    }).argv;
var concat = require('gulp-concat');
var gulp = require('gulp');
var gulpStartGae = require('./scripts/gulp-start-gae-devserver');
var gulpUtil = require('gulp-util');
var manifest = require('./manifest.json');
var cleanCss = require('gulp-clean-css');
var path = require('path');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');

var gaeDevserverPath = argv.gae_devserver_path;
var params = {
  admin_host: '0.0.0.0',
  admin_port: 8000,
  host: '0.0.0.0',
  port: 8181,
  skip_sdk_update_check: true
};
if (argv.clear_datastore) {
  params.clear_datastore = true;
}

if (argv.enable_sendmail) {
  params.enable_sendmail = argv.enable_sendmail;
}

// Check if path to the file to be minified and/or concatenated does exist.
// If not, raise a warning and terminate the program.
// This will help to check spelling errors in manifest.json.
var requireFilesExist = function(filePaths) {
  filePaths.forEach(function(filePath) {
    if (!fs.lstatSync(filePath).isFile()) {
      console.log(filePath + ' is not a valid filepath, check spelling');
      process.exit();
    }
  });
};

// Check if there are enough commands/actions/tasks to run gulp.
var checkCommands = function(yargs, argv, numRequired) {
  if (argv._.length < numRequired) {
    // Display help(usage) message.
    console.log(yargs.help());
    // Stop gulp and exit.
    process.exit();
  }
};
// There should atleast be minimum of one defined task.
checkCommands(yargs, argv, 1);

var isMinificationNeeded = (
  argv.minify === 'True' || argv.use_minification === 'True');
var frontendDependencies = manifest.dependencies.frontend;
var cssFilePaths = [];
var jsFilePaths = [];
var fontFolderPaths = [];
var cssBackgroundFilepaths = [];

// TODO(gvishal): Issue: https://github.com/oppia/oppia/issues/2324
// This code needs refactoring, reasons for which are documented in the above
// issue. The issue also contains a complete description of the build process
// for clarity.

// If output_directory argument is specified we generate files there, otherwise
// we generate files in /third_party/generated.
// In non-dev mode (prod mode), we serve files from a separate build directory
// specified by the output_directory argument.
// And for dev mode without minification, we do it from /third_party/generated.
var generatedTargetDir = path.join('third_party', 'generated');
if ('output_directory' in argv && argv.output_directory !== undefined) {
  generatedTargetDir = argv.output_directory;
}
var generatedCssTargetDir = path.join(generatedTargetDir, 'css');
var generatedJsTargetDir = path.join(generatedTargetDir, 'js');

gulp.task('collectDependencyFilepaths', function() {
  for (var dependencyId in frontendDependencies) {
    var dependency = frontendDependencies[dependencyId];
    var dependencyDir = (
      dependency.targetDir ? dependency.targetDir :
      dependency.targetDirPrefix + dependency.version);
    if (dependency.hasOwnProperty('bundle')) {
      if (dependency.bundle.hasOwnProperty('css')) {
        dependency.bundle.css.forEach(function(cssFiles) {
          cssFilePaths.push(path.join(
            'third_party', 'static', dependencyDir, cssFiles));
        });
      }
      if (dependency.bundle.hasOwnProperty('js')) {
        dependency.bundle.js.forEach(function(jsFiles) {
          jsFilePaths.push(path.join(
            'third_party', 'static', dependencyDir, jsFiles));
        });
      }
      if (dependency.bundle.hasOwnProperty('fontsPath')) {
        var fontPrefix = '*.{eot,woff2,ttf,woff,eof,svg}';
        fontFolderPaths.push(path.join('third_party', 'static', dependencyDir,
          dependency.bundle.fontsPath, fontPrefix));
      }
      if (dependency.bundle.hasOwnProperty('cssBackgroundImage')) {
        dependency.bundle.cssBackgroundImage.forEach(function(imagePath) {
          cssBackgroundFilepaths.push(path.join(
            'third_party', 'static', dependencyDir, imagePath));
        });
      }
    }
  }
});

gulp.task('generateCss', function() {
  requireFilesExist(cssFilePaths);
  gulp.src(cssFilePaths)
    .pipe(isMinificationNeeded ? sourcemaps.init() : gulpUtil.noop())
    .pipe(isMinificationNeeded ? concat('third_party.min.css') :
        concat('third_party.css'))
    .pipe(isMinificationNeeded ? cleanCss({}) : gulpUtil.noop())
    .pipe(isMinificationNeeded ? sourcemaps.write() : gulpUtil.noop())
    .pipe(gulp.dest(generatedCssTargetDir));
});

gulp.task('generateJs', function() {
  requireFilesExist(jsFilePaths);
  gulp.src(jsFilePaths)
    .pipe(isMinificationNeeded ? sourcemaps.init() : gulpUtil.noop())
    .pipe(isMinificationNeeded ? concat('third_party.min.js') :
        concat('third_party.js'))
    .pipe(isMinificationNeeded ? uglify() : gulpUtil.noop())
    // This maps a combined/minified file back to an unbuilt state by holding
    // information about original files. When you query a certain line and
    // column number in your generated JavaScript, you can do a lookup in the
    // source map which returns the original location.
    // http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/
    .pipe(isMinificationNeeded ? sourcemaps.write() : gulpUtil.noop())
    .pipe(gulp.dest(generatedJsTargetDir));
});
// This task is used to copy all fonts which are used by
// Bootstrap and font-Awesome to one folder
var generatedFontsTargetDir = path.join(generatedTargetDir, 'fonts');
gulp.task('copyFonts', function() {
  gulp.src(fontFolderPaths)
    .pipe(gulp.dest(path.join(generatedFontsTargetDir)));
});

// This is a task which copies background image used by css.
// TODO(Barnabas) find a way of removing this task. It is a bit of a hack,
// because it depends on the relative location of the CSS background images
// of a third-party library with respect to the CSS file that uses them.
// The currently-affected libraries include select2.css.
gulp.task('copyCssBackgroundImages', function() {
  requireFilesExist(cssBackgroundFilepaths);
  gulp.src(cssBackgroundFilepaths)
    .pipe(gulp.dest(generatedCssTargetDir));
});

gulp.task('gulpStartGae', function() {
  gulp.src('app.yaml')
    .pipe(gulpStartGae(gaeDevserverPath, [], params));
});

// This takes all functions  that are required for the build
// e.g css, Js and Images
gulp.task('build', [
  'collectDependencyFilepaths', 'generateCss', 'copyFonts',
  'copyCssBackgroundImages', 'generateJs']);

gulp.slurped = false;
gulp.task('watch', function() {
  if (!gulp.slurped) {
    gulp.watch('gulpfile.js', ['build']);
    gulp.watch(cssFilePaths, ['generateCss']);
    gulp.watch(jsFilePaths, ['generateJs']);
    gulp.watch('manifest.json', ['build']);
    gulp.slurped = true;
  }
});

// This task starts google app engine development server.
// TODO(Barnabas Makonda): check if files are already generated and if so
// do not build.
var isProdMode = argv.prod_env === 'True';
if (isProdMode) {
  gulp.task('start_devserver', ['gulpStartGae', 'watch']);
} else {
  gulp.task('start_devserver', ['build', 'gulpStartGae', 'watch']);
}
<commit_msg>generate source maps into separate files<commit_after>// Copyright 2015 The Oppia Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview node module that automate tasks.
 */

var fs = require('fs');
var yargs = require('yargs');
var argv = yargs
  .usage('Usage: $0 <command> [<options>]')
  .example('$0 build --minify=True')
  .command('build', 'generate optimimized third party library for production',
    function(yargs) {
      argv = yargs
        .usage('Usage: $0 build [--minify] [--output_directory]')
        .option('minify', {
          describe: 'Whether to minify third-party dependencies'
        })
        .option('output_directory', {
          describe: 'A path to the directory where the files will be generated'
        }).argv;
    })
  .command('start_devserver', 'start GAE development server',
    function(yargs) {
      argv = yargs
        .usage('Usage: $0 start_devserver [--gae_devserver_path]' +
         '[--clear_datastore] [--enable_sendmail] [--use_minification]' +
         '[--prod_env]')
        .option('gae_devserver_path', {
          describe: 'A path to app engine'
        })
        .option('enable_sendmail', {
          describe: 'Whether to send emails'
        })
        .option('clear_datastore', {
          describe: 'Whether to clear all data storage'
        })
        .option('use_minification', {
          describe: 'Whether to build with minification'
        })
        .option('prod_env', {
          describe: 'Whether to run server in prod mode'
        })
        .demand(['gae_devserver_path'])
        .argv;
    }).argv;
var concat = require('gulp-concat');
var gulp = require('gulp');
var gulpStartGae = require('./scripts/gulp-start-gae-devserver');
var gulpUtil = require('gulp-util');
var manifest = require('./manifest.json');
var cleanCss = require('gulp-clean-css');
var path = require('path');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');

var gaeDevserverPath = argv.gae_devserver_path;
var params = {
  admin_host: '0.0.0.0',
  admin_port: 8000,
  host: '0.0.0.0',
  port: 8181,
  skip_sdk_update_check: true
};
if (argv.clear_datastore) {
  params.clear_datastore = true;
}

if (argv.enable_sendmail) {
  params.enable_sendmail = argv.enable_sendmail;
}

// Check if path to the file to be minified and/or concatenated does exist.
// If not, raise a warning and terminate the program.
// This will help to check spelling errors in manifest.json.
var requireFilesExist = function(filePaths) {
  filePaths.forEach(function(filePath) {
    if (!fs.lstatSync(filePath).isFile()) {
      console.log(filePath + ' is not a valid filepath, check spelling');
      process.exit();
    }
  });
};

// Check if there are enough commands/actions/tasks to run gulp.
var checkCommands = function(yargs, argv, numRequired) {
  if (argv._.length < numRequired) {
    // Display help(usage) message.
    console.log(yargs.help());
    // Stop gulp and exit.
    process.exit();
  }
};
// There should atleast be minimum of one defined task.
checkCommands(yargs, argv, 1);

var isMinificationNeeded = (
  argv.minify === 'True' || argv.use_minification === 'True');
var frontendDependencies = manifest.dependencies.frontend;
var cssFilePaths = [];
var jsFilePaths = [];
var fontFolderPaths = [];
var cssBackgroundFilepaths = [];

// TODO(gvishal): Issue: https://github.com/oppia/oppia/issues/2324
// This code needs refactoring, reasons for which are documented in the above
// issue. The issue also contains a complete description of the build process
// for clarity.

// If output_directory argument is specified we generate files there, otherwise
// we generate files in /third_party/generated.
// In non-dev mode (prod mode), we serve files from a separate build directory
// specified by the output_directory argument.
// And for dev mode without minification, we do it from /third_party/generated.
var generatedTargetDir = path.join('third_party', 'generated');
if ('output_directory' in argv && argv.output_directory !== undefined) {
  generatedTargetDir = argv.output_directory;
}
var generatedCssTargetDir = path.join(generatedTargetDir, 'css');
var generatedJsTargetDir = path.join(generatedTargetDir, 'js');

gulp.task('collectDependencyFilepaths', function() {
  for (var dependencyId in frontendDependencies) {
    var dependency = frontendDependencies[dependencyId];
    var dependencyDir = (
      dependency.targetDir ? dependency.targetDir :
      dependency.targetDirPrefix + dependency.version);
    if (dependency.hasOwnProperty('bundle')) {
      if (dependency.bundle.hasOwnProperty('css')) {
        dependency.bundle.css.forEach(function(cssFiles) {
          cssFilePaths.push(path.join(
            'third_party', 'static', dependencyDir, cssFiles));
        });
      }
      if (dependency.bundle.hasOwnProperty('js')) {
        dependency.bundle.js.forEach(function(jsFiles) {
          jsFilePaths.push(path.join(
            'third_party', 'static', dependencyDir, jsFiles));
        });
      }
      if (dependency.bundle.hasOwnProperty('fontsPath')) {
        var fontPrefix = '*.{eot,woff2,ttf,woff,eof,svg}';
        fontFolderPaths.push(path.join('third_party', 'static', dependencyDir,
          dependency.bundle.fontsPath, fontPrefix));
      }
      if (dependency.bundle.hasOwnProperty('cssBackgroundImage')) {
        dependency.bundle.cssBackgroundImage.forEach(function(imagePath) {
          cssBackgroundFilepaths.push(path.join(
            'third_party', 'static', dependencyDir, imagePath));
        });
      }
    }
  }
});

gulp.task('generateCss', function() {
  requireFilesExist(cssFilePaths);
  gulp.src(cssFilePaths)
    .pipe(isMinificationNeeded ? sourcemaps.init() : gulpUtil.noop())
    .pipe(isMinificationNeeded ? concat('third_party.min.css') :
        concat('third_party.css'))
    .pipe(isMinificationNeeded ? cleanCss({}) : gulpUtil.noop())
    .pipe(isMinificationNeeded ? sourcemaps.write('.') : gulpUtil.noop())
    .pipe(gulp.dest(generatedCssTargetDir));
});

gulp.task('generateJs', function() {
  requireFilesExist(jsFilePaths);
  gulp.src(jsFilePaths)
    .pipe(isMinificationNeeded ? sourcemaps.init() : gulpUtil.noop())
    .pipe(isMinificationNeeded ? concat('third_party.min.js') :
        concat('third_party.js'))
    .pipe(isMinificationNeeded ? uglify() : gulpUtil.noop())
    // This maps a combined/minified file back to an unbuilt state by holding
    // information about original files. When you query a certain line and
    // column number in your generated JavaScript, you can do a lookup in the
    // source map which returns the original location.
    // http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/
    .pipe(isMinificationNeeded ? sourcemaps.write('.') : gulpUtil.noop())
    .pipe(gulp.dest(generatedJsTargetDir));
});
// This task is used to copy all fonts which are used by
// Bootstrap and font-Awesome to one folder
var generatedFontsTargetDir = path.join(generatedTargetDir, 'fonts');
gulp.task('copyFonts', function() {
  gulp.src(fontFolderPaths)
    .pipe(gulp.dest(path.join(generatedFontsTargetDir)));
});

// This is a task which copies background image used by css.
// TODO(Barnabas) find a way of removing this task. It is a bit of a hack,
// because it depends on the relative location of the CSS background images
// of a third-party library with respect to the CSS file that uses them.
// The currently-affected libraries include select2.css.
gulp.task('copyCssBackgroundImages', function() {
  requireFilesExist(cssBackgroundFilepaths);
  gulp.src(cssBackgroundFilepaths)
    .pipe(gulp.dest(generatedCssTargetDir));
});

gulp.task('gulpStartGae', function() {
  gulp.src('app.yaml')
    .pipe(gulpStartGae(gaeDevserverPath, [], params));
});

// This takes all functions  that are required for the build
// e.g css, Js and Images
gulp.task('build', [
  'collectDependencyFilepaths', 'generateCss', 'copyFonts',
  'copyCssBackgroundImages', 'generateJs']);

gulp.slurped = false;
gulp.task('watch', function() {
  if (!gulp.slurped) {
    gulp.watch('gulpfile.js', ['build']);
    gulp.watch(cssFilePaths, ['generateCss']);
    gulp.watch(jsFilePaths, ['generateJs']);
    gulp.watch('manifest.json', ['build']);
    gulp.slurped = true;
  }
});

// This task starts google app engine development server.
// TODO(Barnabas Makonda): check if files are already generated and if so
// do not build.
var isProdMode = argv.prod_env === 'True';
if (isProdMode) {
  gulp.task('start_devserver', ['gulpStartGae', 'watch']);
} else {
  gulp.task('start_devserver', ['build', 'gulpStartGae', 'watch']);
}
<|endoftext|>


<commit_before>
var gulp = require("gulp");
var jscs = require('gulp-jscs');
var webserver = require('gulp-webserver');
var browserify = require("gulp-browserify");
var url = require('url');
var proxy = require('proxy-middleware');
var zip = require("gulp-zip");
var clean = require('gulp-clean');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var karma = require('karma').server;
var replace = require('gulp-replace');
var mocha = require('gulp-mocha');

gulp.task("default", ["clean","bundle-uglify"]);
gulp.task("sdk", ["bundle", "sdk-zip"]);

gulp.task('clean', function() {
    return gulp.src('build')
               .pipe(clean());
});

gulp.task("test", ["test-build", "test-watch", "test-run"]);
gulp.task("test-run", ["test-run-node", "test-run-browser"]);
gulp.task("test-ci", ["test-build", "test-run-browser-ci", "test-run-node"]);

gulp.task("test-run-node", function() {
    return gulp.src('test-node/*.js', {read: false})
            .pipe(mocha({reporter:"progress", bail:false}));
});

gulp.task("test-run-browser", function(done) {
    console.log("\n* Running browser tests");
    karma.start({
        configFile: __dirname + '/karma.conf.js'
    }, done);
});

gulp.task("test-run-browser-ci", function(done) {
    console.log("\n* Running browser tests");
    karma.start({
        configFile: __dirname + '/karma.ci.conf.js'
    }, done);
});

gulp.task("test-build", ["jscs"], function(done) {
    gulp.src("test-browser/index.js")
        .pipe(browserify({exclude: "./http-node"}))
        .pipe(rename("appstax-test.js"))
        .pipe(gulp.dest("./build/"))
        .on("end", done);
});

gulp.task("test-watch", function (done) {
    gulp.watch("build/appstax-test.js", ["test-run"]);
    gulp.watch("src/**/*.js", ["test-build"]);
    gulp.watch("test-browser/**/*.js", ["test-build"]);
    gulp.watch("test-node/**/*.js", ["test-build"]);
});

gulp.task("jscs", function() {
    return gulp.src(["src/**/*.js", "test-*/**/*.js"])
               .pipe(jscs());
})

gulp.task("bundle", ["jscs"], function() {
    return gulp.src("src/appstax.js")
               .pipe(browserify({
                   standalone: "appstax",
                   exclude: "./http-node"
               }))
               .pipe(replace(" "," ")) // replace non-breaking space with space
               .pipe(gulp.dest("./build/"));
});

gulp.task("bundle-uglify", ["bundle"], function() {
    return gulp.src("build/appstax.js")
               .pipe(uglify())
               .pipe(rename("appstax.min.js"))
               .pipe(gulp.dest("./build/"));
})

gulp.task("sdk-assemble-bundle", ["bundle", "bundle-uglify"], function() {
    return gulp.src(["build/appstax.js","build/appstax.min.js"])
               .pipe(gulp.dest("build/appstax-js"))
               .pipe(gulp.dest("build/appstax-js/examples/notes/app/vendor"))
               .pipe(gulp.dest("build/appstax-js/starterprojects/angular/app/vendor"))
               .pipe(gulp.dest("build/appstax-js/starterprojects/basic/"));
});

gulp.task("sdk-assemble-examples", ["bundle"], function() {
    return gulp.src(["examples/**/*",
                     "!examples/notes/{bower_components,bower_components/**}",
                     "!examples/notes/{node_modules,node_modules/**}",
                     "!examples/notes/{dist,dist/**}",
                     "!examples/mybox/{bower_components,bower_components/**}",
                     "!examples/mybox/{node_modules,node_modules/**}",
                     "!examples/mybox/{dist,dist/**}"])
               .pipe(gulp.dest("build/appstax-js/examples"));
});

gulp.task("sdk-assemble-starterprojects", ["bundle"], function() {
    return gulp.src(["starterprojects/**/*",
                     "!starterprojects/{angular,angular-full}/{public,public/**,bower_components,bower_components/**,node_modules,node_modules/**}"])
               .pipe(gulp.dest("build/appstax-js/starterprojects"));
});

gulp.task("sdk-zip", ["sdk-assemble-examples", "sdk-assemble-starterprojects", "sdk-assemble-bundle"], function() {
    return gulp.src("build/appstax-js/**/*", {base: "build"})
               .pipe(zip("appstax-js.zip"))
               .pipe(gulp.dest("build"));
});

<commit_msg>Fix gulp task dependencies.<commit_after>
var gulp = require("gulp");
var jscs = require('gulp-jscs');
var webserver = require('gulp-webserver');
var browserify = require("gulp-browserify");
var url = require('url');
var proxy = require('proxy-middleware');
var zip = require("gulp-zip");
var clean = require('gulp-clean');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var karma = require('karma').server;
var replace = require('gulp-replace');
var mocha = require('gulp-mocha');

gulp.task("default", ["clean","bundle-uglify"]);
gulp.task("sdk", ["bundle", "sdk-zip"]);

gulp.task('clean', function() {
    return gulp.src('build')
               .pipe(clean());
});

gulp.task("test", ["test-build", "test-watch", "test-run"]);
gulp.task("test-run", ["test-run-node", "test-run-browser"]);
gulp.task("test-ci", ["test-run-browser-ci", "test-run-node"]);

gulp.task("test-run-node", function() {
    return gulp.src('test-node/*.js', {read: false})
            .pipe(mocha({reporter:"progress", bail:false}));
});

gulp.task("test-run-browser", ["test-build"], function(done) {
    console.log("\n* Running browser tests");
    karma.start({
        configFile: __dirname + '/karma.conf.js'
    }, done);
});

gulp.task("test-run-browser-ci", ["test-build"], function(done) {
    console.log("\n* Running browser tests");
    karma.start({
        configFile: __dirname + '/karma.ci.conf.js'
    }, done);
});

gulp.task("test-build", ["jscs"], function(done) {
    gulp.src("test-browser/index.js")
        .pipe(browserify({exclude: "./http-node"}))
        .pipe(rename("appstax-test.js"))
        .pipe(gulp.dest("./build/"))
        .on("end", done);
});

gulp.task("test-watch", function (done) {
    gulp.watch("build/appstax-test.js", ["test-run"]);
    gulp.watch("src/**/*.js", ["test-build"]);
    gulp.watch("test-browser/**/*.js", ["test-build"]);
    gulp.watch("test-node/**/*.js", ["test-build"]);
});

gulp.task("jscs", function() {
    return gulp.src(["src/**/*.js", "test-*/**/*.js"])
               .pipe(jscs());
})

gulp.task("bundle", ["jscs"], function() {
    return gulp.src("src/appstax.js")
               .pipe(browserify({
                   standalone: "appstax",
                   exclude: "./http-node"
               }))
               .pipe(replace(" "," ")) // replace non-breaking space with space
               .pipe(gulp.dest("./build/"));
});

gulp.task("bundle-uglify", ["bundle"], function() {
    return gulp.src("build/appstax.js")
               .pipe(uglify())
               .pipe(rename("appstax.min.js"))
               .pipe(gulp.dest("./build/"));
})

gulp.task("sdk-assemble-bundle", ["bundle", "bundle-uglify"], function() {
    return gulp.src(["build/appstax.js","build/appstax.min.js"])
               .pipe(gulp.dest("build/appstax-js"))
               .pipe(gulp.dest("build/appstax-js/examples/notes/app/vendor"))
               .pipe(gulp.dest("build/appstax-js/starterprojects/angular/app/vendor"))
               .pipe(gulp.dest("build/appstax-js/starterprojects/basic/"));
});

gulp.task("sdk-assemble-examples", ["bundle"], function() {
    return gulp.src(["examples/**/*",
                     "!examples/notes/{bower_components,bower_components/**}",
                     "!examples/notes/{node_modules,node_modules/**}",
                     "!examples/notes/{dist,dist/**}",
                     "!examples/mybox/{bower_components,bower_components/**}",
                     "!examples/mybox/{node_modules,node_modules/**}",
                     "!examples/mybox/{dist,dist/**}"])
               .pipe(gulp.dest("build/appstax-js/examples"));
});

gulp.task("sdk-assemble-starterprojects", ["bundle"], function() {
    return gulp.src(["starterprojects/**/*",
                     "!starterprojects/{angular,angular-full}/{public,public/**,bower_components,bower_components/**,node_modules,node_modules/**}"])
               .pipe(gulp.dest("build/appstax-js/starterprojects"));
});

gulp.task("sdk-zip", ["sdk-assemble-examples", "sdk-assemble-starterprojects", "sdk-assemble-bundle"], function() {
    return gulp.src("build/appstax-js/**/*", {base: "build"})
               .pipe(zip("appstax-js.zip"))
               .pipe(gulp.dest("build"));
});

<|endoftext|>


<commit_before>'use strict';

var gulp = require('gulp');
var ghPages = require('gulp-gh-pages');

var babelify = require('babelify');
var browserify = require('browserify');
var watchify = require('watchify');
var uglify = require('gulp-uglify');
var beautify = require('gulp-beautify');

var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var gulpif = require('gulp-if');
var runSequence = require('run-sequence');

var argv = require('yargs').argv;

gulp.task('default', function() {
    gulp.start('build');
});

gulp.task('build', function(callback) {
    runSequence(['browserify', 'copy-css', 'copy-html'],
                'deploy');
});

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

gulp.task('copy-css', function () {
    return gulp.src('./examples/**/*.css')
        .pipe(gulp.dest('./examples/dist/css'));
});

gulp.task('copy-html', function () {
    return gulp.src('./examples/index.html')
        .pipe(gulp.dest('./examples/dist/'));
});

gulp.task('browserify', function() {
    var bundle = watchify(browserify('./examples/app.js', {
        extensions: ['.js', '.jsx'],
    }));
    bundle.transform(babelify, {'presets': ['es2015', 'react']});
    bundle.on('update', function() {
        rebundle(bundle);
    });

    function rebundle(bundle) {
        return bundle.bundle()
            .on('error', function(error) {
                console.log(error.stack, error.message);
                this.emit('end');
            })
            .pipe(gulpif(argv.production, source('bundle.min.js'), source('bundle.js')))
            .pipe(buffer())
            .pipe(gulpif(argv.production, uglify(), beautify()))
            .pipe(gulp.dest('examples/dist/js'));
    }
    return rebundle(bundle);
});
<commit_msg>added gulp-clean for umm, cleaning<commit_after>'use strict';

var gulp = require('gulp');
var ghPages = require('gulp-gh-pages');

var babelify = require('babelify');
var browserify = require('browserify');
var watchify = require('watchify');
var uglify = require('gulp-uglify');
var beautify = require('gulp-beautify');

var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var gulpif = require('gulp-if');
var runSequence = require('run-sequence');
var clean = require('gulp-clean');

var argv = require('yargs').argv;

gulp.task('default', function() {
    gulp.start('build');
});

gulp.task('build', function(callback) {
    runSequence(
        'clean',
        ['browserify', 'copy-css', 'copy-html'],
        'deploy');
});

gulp.task('clean', function () {
    return gulp.src('./examples/dist', {read: false})
        .pipe(clean());
});

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

gulp.task('copy-css', function () {
    return gulp.src('./examples/**/*.css')
        .pipe(gulp.dest('./examples/dist/css'));
});

gulp.task('copy-html', function () {
    return gulp.src('./examples/index.html')
        .pipe(gulp.dest('./examples/dist/'));
});

gulp.task('browserify', function() {
    var bundle = watchify(browserify('./examples/app.js', {
        extensions: ['.js', '.jsx'],
    }));
    bundle.transform(babelify, {'presets': ['es2015', 'react']});
    bundle.on('update', function() {
        rebundle(bundle);
    });

    function rebundle(bundle) {
        return bundle.bundle()
            .on('error', function(error) {
                console.log(error.stack, error.message);
                this.emit('end');
            })
            .pipe(gulpif(argv.production, source('bundle.min.js'), source('bundle.js')))
            .pipe(buffer())
            .pipe(gulpif(argv.production, uglify(), beautify()))
            .pipe(gulp.dest('examples/dist/js'));
    }
    return rebundle(bundle);
});
<|endoftext|>


<commit_before>var gulp = require('gulp');
var sass = require('gulp-sass');
var bower = require('gulp-bower');
var minifyCSS = require('gulp-minify-css');

var paths = {
  css: 'src/styles/**/*.scss',
  fonts: 'bower_components/font-awesome/fonts/**/*'
};

gulp.task('bower', function() {
  return bower();
});

gulp.task('css', ['bower'], function() {
  return gulp.src(paths.css)
    .pipe(sass())
    .pipe(minifyCSS())
    .pipe(gulp.dest('public/css'));
});

gulp.task('fonts', ['bower'], function() {
  return gulp.src(paths.fonts)
    .pipe(gulp.dest('public/fonts'));
});

gulp.task('watch', function() {
  gulp.watch(paths.css, ['css']);
});

gulp.task('default', ['css', 'fonts']);
<commit_msg>Build the full project before gulp watch.<commit_after>var gulp = require('gulp');
var sass = require('gulp-sass');
var bower = require('gulp-bower');
var minifyCSS = require('gulp-minify-css');

var paths = {
  css: 'src/styles/**/*.scss',
  fonts: 'bower_components/font-awesome/fonts/**/*'
};

gulp.task('bower', function() {
  return bower();
});

gulp.task('css', ['bower'], function() {
  return gulp.src(paths.css)
    .pipe(sass())
    .pipe(minifyCSS())
    .pipe(gulp.dest('public/css'));
});

gulp.task('fonts', ['bower'], function() {
  return gulp.src(paths.fonts)
    .pipe(gulp.dest('public/fonts'));
});

gulp.task('watch', ['default'], function() {
  gulp.watch(paths.css, ['css']);
});

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


<commit_before>var gulp = require('gulp'),
    replace = require('gulp-replace'),
    bump = require("gulp-bump"),
    rename = require("gulp-rename"),
    del = require('del'),
    css = require('gulp-clean-css');
    js = require('gulp-uglify');

gulp.task('css', ['clean'], function () {
    return gulp.src('./src/stable/css/tableexport.css')
        .pipe(gulp.dest('./dist/css/'))
        .pipe(css())
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(gulp.dest('./dist/css/'))
        .pipe(gulp.dest('./src/stable/css/'));
});

gulp.task('js', ['clean'], function () {
    return gulp.src('./src/stable/js/tableexport.js')
        .pipe(gulp.dest('./dist/js/'))
        .pipe(js({output: {comments: /^!|@preserve|@license|@cc_on/i}}))
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(gulp.dest('./dist/js/'))
        .pipe(gulp.dest('./src/stable/js/'));
});

gulp.task('typings', ['clean'], function () {
    return gulp.src('./src/stable/typings/*.ts')
        .pipe(gulp.dest('./dist/typings/'));
});

gulp.task('bump', ['bump-js', 'bump-css'], function(){
    return gulp.src(['./bower.json', './package.json', './src/stable/tableexport.js'])
        .pipe(bump())
        .pipe(gulp.dest('./'));
});

gulp.task('bump-js', function () {
    return gulp.src(['src/stable/js/tableexport.js'])
        .pipe(replace(/(v\d\.\d\.)(\d+)/g, function (matches, match1, match2) {
            return match1 + (Number(match2)+1);
        }))
        .pipe(gulp.dest('src/stable/js/'))
        .on('end', function () {
            gulp.start('js');
        });
});

gulp.task('bump-css', function () {
    gulp.src(['src/stable/css/tableexport.css'])
        .pipe(replace(/(v\d\.\d\.)(\d+)/g, function (matches, match1, match2) {
            return match1 + (Number(match2) + 1);
        }))
        .pipe(gulp.dest('src/stable/css/'))
        .on('end', function () {
            gulp.start('css');
        });
});

gulp.task('clean', function () {
    return del(['dist/js']);
});

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

gulp.task('default', ['build']);

<commit_msg>Improve version bump logic<commit_after>var gulp = require('gulp'),
    replace = require('gulp-replace'),
    bump = require("gulp-bump"),
    rename = require("gulp-rename"),
    del = require('del'),
    css = require('gulp-clean-css');
    js = require('gulp-uglify');

gulp.task('css', ['clean'], function () {
    return gulp.src('./src/stable/css/tableexport.css')
        .pipe(gulp.dest('./dist/css/'))
        .pipe(css())
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(gulp.dest('./dist/css/'))
        .pipe(gulp.dest('./src/stable/css/'));
});

gulp.task('js', ['clean'], function () {
    return gulp.src('./src/stable/js/tableexport.js')
        .pipe(gulp.dest('./dist/js/'))
        .pipe(js({output: {comments: /^!|@preserve|@license|@cc_on/i}}))
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(gulp.dest('./dist/js/'))
        .pipe(gulp.dest('./src/stable/js/'));
});

gulp.task('typings', ['clean'], function () {
    return gulp.src('./src/stable/typings/*.ts')
        .pipe(gulp.dest('./dist/typings/'));
});

gulp.task('bump', ['bump-js', 'bump-css'], function(){
    return gulp.src(['./bower.json', './package.json'])
        .pipe(bump())
        .pipe(gulp.dest('./'));
});

gulp.task('bump-js', function () {
    return gulp.src(['src/stable/js/tableexport.js'])
        .pipe(replace(/(v\d+\.\d+\.)(\d+)/g, function (matches, match1, match2) {
            return match1 + (Number(match2)+1);
        }))
        .pipe(replace(/(version: "\d+\.\d+\.)(\d+)/g, function (matches, match1, match2) {
            return match1 + (Number(match2)+1);
        }))
        .pipe(gulp.dest('src/stable/js/'))
        .on('end', function () {
            gulp.start('js');
        });
});

gulp.task('bump-css', function () {
    gulp.src(['src/stable/css/tableexport.css'])
        .pipe(replace(/(v\d+\.\d+\.)(\d+)/g, function (matches, match1, match2) {
            return match1 + (Number(match2) + 1);
        }))
        .pipe(gulp.dest('src/stable/css/'))
        .on('end', function () {
            gulp.start('css');
        });
});

gulp.task('clean', function () {
    return del(['dist/js']);
});

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

gulp.task('default', ['build']);

<|endoftext|>


<commit_before>// Include gulp.
var gulp = require('gulp');
var browserSync = require('browser-sync').create();

// Include plugins.
var sass = require('gulp-sass');
var imagemin = require('gulp-imagemin');
var pngcrush = require('imagemin-pngcrush');
var shell = require('gulp-shell');
var plumber = require('gulp-plumber');
var notify = require('gulp-notify');
var autoprefix = require('gulp-autoprefixer');
var glob = require('gulp-sass-glob');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var scssLint = require('gulp-scss-lint');
var jshint = require('gulp-jshint');

// Load config
var YAML = require('yamljs');
var config = YAML.load('gulp-config.yml');

// CSS.
gulp.task('css', function() {
  return gulp.src(config.themeDir + '/' + config.css.src)
    .pipe(glob())
    .pipe(plumber({
      errorHandler: function (error) {
        notify.onError({
          title:    "Gulp",
          subtitle: "Failure!",
          message:  "Error: <%= error.message %>",
          sound:    "Beep"
        }) (error);
        this.emit('end');
      }}))
    .pipe(sourcemaps.init())
    .pipe(sass({
      style: 'compressed',
      errLogToConsole: true,
      includePaths: config.css.includePaths
    }))
    .pipe(autoprefix('last 2 versions', '> 1%', 'ie 9', 'ie 10'))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest(config.themeDir + '/' + config.css.dest))
    .pipe(browserSync.reload({ stream: true, match: '**/*.css' }));
});

// Compress images.
gulp.task('images', function () {
  return gulp.src(config.themeDir + '/' + config.images.src)
    .pipe(imagemin({
      progressive: true,
      svgoPlugins: [{ removeViewBox: false }],
      use: [pngcrush()]
    }))
    .pipe(gulp.dest(config.themeDir + '/' + config.images.dest));
});

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

// Watch task.
gulp.task('watch', function() {
  gulp.watch(config.themeDir + '/' + config.css.src, ['css']);
  gulp.watch(config.themeDir + '/' + config.images.src, ['images']);
});

// Static Server + Watch
gulp.task('serve', ['css', 'fonts', 'watch'], function() {
  browserSync.init({
    proxy: config.browserSyncProxy
  });
});

// Run drush to clear the theme registry.
gulp.task('drush', shell.task([
  'drush ' + config.drushAlias + ' cache-clear theme-registry'
]));

// SCSS Linting.
gulp.task('scss-lint', function() {
  return gulp.src([config.themeDir + '/' + config.css.src])
    .pipe(scssLint())
    .pipe(scssLint.format())
    .pipe(scssLint.failOnError());
});

// JS Linting.
gulp.task('js-lint', function() {
  return gulp.src(config.themeDir + '/' + config.js.src)
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});

// Default Task
gulp.task('default', ['serve']);
<commit_msg>fix sass outputStyle option<commit_after>// Include gulp.
var gulp = require('gulp');
var browserSync = require('browser-sync').create();

// Include plugins.
var sass = require('gulp-sass');
var imagemin = require('gulp-imagemin');
var pngcrush = require('imagemin-pngcrush');
var shell = require('gulp-shell');
var plumber = require('gulp-plumber');
var notify = require('gulp-notify');
var autoprefix = require('gulp-autoprefixer');
var glob = require('gulp-sass-glob');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var scssLint = require('gulp-scss-lint');
var jshint = require('gulp-jshint');

// Load config
var YAML = require('yamljs');
var config = YAML.load('gulp-config.yml');

// CSS.
gulp.task('css', function() {
  return gulp.src(config.themeDir + '/' + config.css.src)
    .pipe(glob())
    .pipe(plumber({
      errorHandler: function (error) {
        notify.onError({
          title:    "Gulp",
          subtitle: "Failure!",
          message:  "Error: <%= error.message %>",
          sound:    "Beep"
        }) (error);
        this.emit('end');
      }}))
    .pipe(sourcemaps.init())
    .pipe(sass({
      outputStyle: 'compressed,
      errLogToConsole: true,
      includePaths: config.css.includePaths
    }))
    .pipe(autoprefix('last 2 versions', '> 1%', 'ie 9', 'ie 10'))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest(config.themeDir + '/' + config.css.dest))
    .pipe(browserSync.reload({ stream: true, match: '**/*.css' }));
});

// Compress images.
gulp.task('images', function () {
  return gulp.src(config.themeDir + '/' + config.images.src)
    .pipe(imagemin({
      progressive: true,
      svgoPlugins: [{ removeViewBox: false }],
      use: [pngcrush()]
    }))
    .pipe(gulp.dest(config.themeDir + '/' + config.images.dest));
});

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

// Watch task.
gulp.task('watch', function() {
  gulp.watch(config.themeDir + '/' + config.css.src, ['css']);
  gulp.watch(config.themeDir + '/' + config.images.src, ['images']);
});

// Static Server + Watch
gulp.task('serve', ['css', 'fonts', 'watch'], function() {
  browserSync.init({
    proxy: config.browserSyncProxy
  });
});

// Run drush to clear the theme registry.
gulp.task('drush', shell.task([
  'drush ' + config.drushAlias + ' cache-clear theme-registry'
]));

// SCSS Linting.
gulp.task('scss-lint', function() {
  return gulp.src([config.themeDir + '/' + config.css.src])
    .pipe(scssLint())
    .pipe(scssLint.format())
    .pipe(scssLint.failOnError());
});

// JS Linting.
gulp.task('js-lint', function() {
  return gulp.src(config.themeDir + '/' + config.js.src)
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});

// Default Task
gulp.task('default', ['serve']);
<|endoftext|>


<commit_before>require('shelljs/global');
var argv = process.argv;
var projectNameFromArgv = argv[4];

//当为开发环境时需要做些配置
if(argv[2] == 'serve') {
    require('./setting/setting')(projectNameFromArgv);
}

var gulp = require('gulp');
var nodemon = require('gulp-nodemon');
var sass = require('gulp-ruby-sass');
var autoprefixer = require('gulp-autoprefixer');
var livereload = require('gulp-livereload');
var uglify = require('gulp-uglify');
var cssmin = require('gulp-cssmin');
var imagemin = require('gulp-imagemin');
var del = require('del');
var replace = require('gulp-replace');
var md5 = require("gulp-md5-plus");
var copy = require('gulp-copy');
var sequence = require('gulp-sequence');

var path = require('path');

var projectConfig = require('./config/projectConfig');
var baseConfig = require('./config/baseConfig');
var projectName = projectNameFromArgv || projectConfig.currentProject;
var CDN_PATH = baseConfig.CDN_PATH;

var filePath = {
	srcName: 'src',
	destName: 'dest',
	srcSass: 'public/' + projectName + '/sass/*.scss',
	srcJS: 'public/' + projectName + '/js/*.js',
	srcEjs: 'views/' + projectName + 'View/*.ejs',
	srcTpl: 'views/' + projectName + 'View/template/*.ejs',
	srcImg: 'public/' + projectName + '/img/*',
	srcCss: 'public/' + projectName + '/css/*.css',
	srcCssDir: 'public/' + projectName + '/css',
	destCss: 'dest/' + projectName + '/css',
	destJS: 'dest/' + projectName + '/js',
	destImg: 'dest/' + projectName + '/img',
	configPath: 'config/projectConfig.js'
};

var md5TargetPath = filePath.destName + '/' + projectName + 'View/**/*.ejs';

gulp.task('styles', function() {
  return sass(filePath.srcSass)
    .pipe(autoprefixer('last 2 version'))
    .pipe(gulp.dest(filePath.srcCssDir))
    .pipe(livereload());
});

gulp.task('scripts', function() {
  return gulp.src(filePath.srcJS)
    .pipe(livereload());
});

gulp.task('ejs',function(){
    return gulp.src(filePath.srcEjs)
    .pipe(livereload());
});

gulp.task('watch', function() {
    livereload.listen();
    gulp.watch(filePath.srcSass, ['styles']);
    gulp.watch(filePath.srcJS, ['scripts']);
    gulp.watch(filePath.srcEjs, ['ejs']);
});

gulp.task('server',function(){
    nodemon({
        'script': './bin/www',
        'ignore': filePath.srcJS
    });
});

//将页面中的相对路径替换为绝对路径
gulp.task('replace', function(){
    return gulp.src([path.join(__dirname, 'views/' + projectName + 'View/**/*.ejs')])
    .pipe(replace(/\.\.\/\.\.\//g, CDN_PATH))
    .pipe(gulp.dest(filePath.destName + '/' + projectName + 'View/'));
});

gulp.task('build_js', function () {
  	return gulp.src(filePath.srcJS)
  		.pipe(md5(6,md5TargetPath))
        .pipe(uglify())
        .pipe(gulp.dest(filePath.destJS))
});

gulp.task('build_css', function () {
    return gulp.src(filePath.srcCss)
    	.pipe(md5(6,md5TargetPath))
        .pipe(cssmin())
        .pipe(gulp.dest(filePath.destCss));
});

gulp.task('build_img', function () {
    return gulp.src(filePath.srcImg)
    	// .pipe(md5(6,md5TargetPath))
        .pipe(imagemin())
        .pipe(gulp.dest(filePath.destImg))
});

gulp.task('copy', function () {
    return gulp.src([filePath.configPath])
        .pipe(copy(filePath.destName + '/' + projectName +  'View/', { prefix: 1 }));
});

gulp.task('clean', function () {
    del.sync([filePath.destName + '/**']);
});

gulp.task('serve', ['server','watch']);
// gulp.task('build', ['clean','replace','build_js','build_css','build_img','copy']);

gulp.task('build', function(cb) {
    sequence(
        ['clean','replace'],
        ['build_js','build_css','build_img','copy'],
        cb);
});
<commit_msg>update gulpfile.<commit_after>require('shelljs/global');
var argv = process.argv;
var projectNameFromArgv = argv[4];

//当为开发环境时需要做些配置
if(argv[2] == 'serve') {
    require('./setting/setting')(projectNameFromArgv);
}

var gulp = require('gulp');
var nodemon = require('gulp-nodemon');
var sass = require('gulp-ruby-sass');
var autoprefixer = require('gulp-autoprefixer');
var livereload = require('gulp-livereload');
var uglify = require('gulp-uglify');
var cssmin = require('gulp-cssmin');
var imagemin = require('gulp-imagemin');
var del = require('del');
var replace = require('gulp-replace');
var md5 = require("gulp-md5-plus");
var copy = require('gulp-copy');
var sequence = require('gulp-sequence');

var path = require('path');

var projectConfig = require('./config/projectConfig');
var baseConfig = require('./config/baseConfig');
var projectName = projectNameFromArgv || projectConfig.currentProject;
var CDN_PATH = baseConfig.CDN_PATH;

var filePath = {
	srcName: 'src',
	destName: 'dest',
	srcSass: 'public/' + projectName + '/sass/*.scss',
	srcJS: 'public/' + projectName + '/js/**/*.js',
	srcEjs: 'views/' + projectName + 'View/*.ejs',
	srcTpl: 'views/' + projectName + 'View/template/*.ejs',
	srcImg: 'public/' + projectName + '/img/*',
	srcCss: 'public/' + projectName + '/css/**/*.css',
	srcCssDir: 'public/' + projectName + '/css',
	destCss: 'dest/' + projectName + '/css',
	destJS: 'dest/' + projectName + '/js',
	destImg: 'dest/' + projectName + '/img',
	configPath: 'config/projectConfig.js'
};

var md5TargetPath = filePath.destName + '/' + projectName + 'View/**/*.ejs';

gulp.task('styles', function() {
  return sass(filePath.srcSass)
    .pipe(autoprefixer('last 2 version'))
    .pipe(gulp.dest(filePath.srcCssDir))
    .pipe(livereload());
});

gulp.task('scripts', function() {
  return gulp.src(filePath.srcJS)
    .pipe(livereload());
});

gulp.task('ejs',function(){
    return gulp.src(filePath.srcEjs)
    .pipe(livereload());
});

gulp.task('watch', function() {
    livereload.listen();
    gulp.watch(filePath.srcSass, ['styles']);
    gulp.watch(filePath.srcJS, ['scripts']);
    gulp.watch(filePath.srcEjs, ['ejs']);
});

gulp.task('server',function(){
    nodemon({
        'script': './bin/www',
        'ignore': filePath.srcJS
    });
});

//将页面中的相对路径替换为绝对路径
gulp.task('replace', function(){
    return gulp.src([path.join(__dirname, 'views/' + projectName + 'View/**/*.ejs')])
    .pipe(replace(/\.\.\/\.\.\//g, CDN_PATH))
    .pipe(gulp.dest(filePath.destName + '/' + projectName + 'View/'));
});

gulp.task('build_js', function () {
  	return gulp.src(filePath.srcJS)
  		.pipe(md5(6,md5TargetPath))
        .pipe(uglify())
        .pipe(gulp.dest(filePath.destJS))
});

gulp.task('build_css', function () {
    return gulp.src(filePath.srcCss)
        .pipe(replace(/\.\.\//g, CDN_PATH + projectName + '/'))
    	.pipe(md5(6,md5TargetPath))
        .pipe(cssmin())
        .pipe(gulp.dest(filePath.destCss));
});

gulp.task('build_img', function () {
    return gulp.src(filePath.srcImg)
    	// .pipe(md5(6,md5TargetPath))
        .pipe(imagemin())
        .pipe(gulp.dest(filePath.destImg))
});

gulp.task('copy', function () {
    return gulp.src([filePath.configPath])
        .pipe(copy(filePath.destName + '/' + projectName +  'View/', { prefix: 1 }));
});

gulp.task('clean', function () {
    del.sync([filePath.destName + '/**']);
});

gulp.task('serve', ['server','watch']);
// gulp.task('build', ['clean','replace','build_js','build_css','build_img','copy']);

gulp.task('build', function(cb) {
    sequence(
        ['clean','replace'],
        ['build_js','build_css','build_img','copy'],
        cb);
});
<|endoftext|>


<commit_before>var gulp = require('gulp'),
    sass = require('gulp-sass'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    minifyCSS = require('gulp-minify-css')

gulp.task('sass', function () {
    gulp.src('./public/src/*.scss')
        .pipe(sass())
        .pipe(gulp.dest('./public/css'));
});

var cssPath = [
    './public/src/vendor/foundation/css/normalize.css',
    './public/css/my-foundation.css',
    './public/css/template.css'
];

gulp.task('css', function () {
    gulp.src(cssPath)
        .pipe(minifyCSS({keepBreaks:true}))
        .pipe(concat('all.css'))
        .pipe(gulp.dest('./public/dist/'))
});

var jsPath = [
    './public/src/vendor/angular/angular.min.js',
    './public/src/vendor/angular-route/angular-route.js',
    './public/src/app.js'
];

gulp.task('js', function() {
    gulp.src(jsPath)
        .pipe(uglify())
        .pipe(concat('app.js'))
        .pipe(gulp.dest('./public/dist/'))
});

gulp.task('default', ['sass', 'css', 'js']);<commit_msg>Minify js<commit_after>var gulp = require('gulp'),
    sass = require('gulp-sass'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    minifyCSS = require('gulp-minify-css')

gulp.task('sass', function () {
    gulp.src('./public/src/*.scss')
        .pipe(sass())
        .pipe(gulp.dest('./public/css'));
});

var cssPath = [
    './public/src/vendor/foundation/css/normalize.css',
    './public/css/my-foundation.css',
    './public/css/template.css'
];

gulp.task('css', function () {
    gulp.src(cssPath)
        .pipe(minifyCSS({keepBreaks:true}))
        .pipe(concat('all.css'))
        .pipe(gulp.dest('./public/dist/'))
});

var jsPath = [
    './public/src/vendor/angular/angular.js',
    './public/src/vendor/angular-route/angular-route.js',
    './public/src/app.js'
];

gulp.task('js', function() {
    gulp.src(jsPath)
        //.pipe(uglify())
        .pipe(concat('app.js'))
        .pipe(gulp.dest('./public/dist/'))
});

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


<commit_before>var gulp = require('gulp');
    jshint = require('gulp-jshint'),
    stylish = require('jshint-stylish'),
    watch = require('gulp-watch'),
    cssnano = require('gulp-cssnano'),
    rtlcss = require('gulp-rtlcss'),
    del = require('del'),
    uglify = require('gulp-uglify'),
    rename = require('gulp-rename');

require('gulp-stats')(gulp);

gulp.task('clean', function() {
    return del(['dist']);
});

gulp.task('watch', function() {
  watch("src/js/**/*.js")
    .pipe(jshint())
    .pipe(jshint.reporter(stylish));
});

gulp.task('js', ['clean'], function() {
  return gulp.src('./src/js/**/*.js')
    .pipe(jshint())
    .pipe(uglify())
    .pipe(gulp.dest('dist/js'));
});

gulp.task('css', ['clean'], function() {
   return gulp.src('src/css/**/*.css')
    .pipe(cssnano())
    .pipe(gulp.dest('dist/css'))
	// Till this point, we've only managed to minimize the css.

	// Now, take the minimized css and also generate an rtl version of it.
    .pipe(rtlcss())
    .pipe(rename({ suffix: '-rtl' }))
    .pipe(gulp.dest('dist/css'));
});

// 'js' and 'css' will run concurrently, but only after 'clean' is done.
gulp.task('default', ['js', 'css']);<commit_msg>Added jsHintSummary module<commit_after>var gulp = require('gulp');
    jshint = require('gulp-jshint'),
    stylish = require('jshint-stylish'),
    watch = require('gulp-watch'),
    cssnano = require('gulp-cssnano'),
    rtlcss = require('gulp-rtlcss'),
    del = require('del'),
    uglify = require('gulp-uglify'),
    rename = require('gulp-rename'),
	jshintSummary = require('jshint-stylish-summary');

require('gulp-stats')(gulp);

gulp.task('clean', function() {
    return del(['dist']);
});

gulp.task('watch', function() {
  watch("src/js/**/*.js")
    .pipe(jshint())
    .pipe(jshint.reporter(stylish));
});

gulp.task('js', ['clean'], function() {
  return gulp.src('./src/js/**/*.js')
    .pipe(jshint())
	.pipe(jshint.reporter(stylish))
	.pipe(jshintSummary.collect())
    .on('end', jshintSummary.summarize())
    .pipe(uglify())
    .pipe(gulp.dest('dist/js'));
});

gulp.task('css', ['clean'], function() {
   return gulp.src('src/css/**/*.css')
    .pipe(cssnano())
    .pipe(gulp.dest('dist/css'))
	// Till this point, we've only managed to minimize the css.

	// Now, take the minimized css and also generate an rtl version of it.
    .pipe(rtlcss())
    .pipe(rename({ suffix: '-rtl' }))
    .pipe(gulp.dest('dist/css'));
});

// 'js' and 'css' will run concurrently, but only after 'clean' is done.
gulp.task('default', ['js', 'css']);<|endoftext|>


<commit_before>var	gulp = require('gulp'),
	plugins = require('gulp-load-plugins')();

gulp.task('styles', function () {

	gulp.src('./src/styles/main.scss')
		.pipe(plugins.sass())
		.pipe(plugins.concat('basicModal.min.css', {newLine: "\n"}))
		.pipe(plugins.autoprefixer('last 2 version', '> 1%'))
		.pipe(plugins.minifyCss())
		.pipe(gulp.dest('./dist'));

});

gulp.task('scripts', function () {

	gulp.src('./src/scripts/*.js')
		.pipe(plugins.babel())
		.pipe(plugins.concat('basicModal.min.js', {newLine: "\n"}))
		.pipe(plugins.uglify())
		.pipe(gulp.dest('./dist'));

});

gulp.task('default', ['styles', 'scripts']);<commit_msg>Added watch task to gulpfile<commit_after>var	gulp = require('gulp'),
	plugins = require('gulp-load-plugins')();

gulp.task('styles', function () {

	gulp.src('./src/styles/main.scss')
		.pipe(plugins.sass())
		.pipe(plugins.concat('basicModal.min.css', {newLine: "\n"}))
		.pipe(plugins.autoprefixer('last 2 version', '> 1%'))
		.pipe(plugins.minifyCss())
		.pipe(gulp.dest('./dist'));

});

gulp.task('scripts', function () {

	gulp.src('./src/scripts/*.js')
		.pipe(plugins.babel())
		.pipe(plugins.concat('basicModal.min.js', {newLine: "\n"}))
		.pipe(plugins.uglify())
		.pipe(gulp.dest('./dist'));

});

gulp.task('default', ['styles', 'scripts']);

gulp.task('watch', function() {
	gulp.watch('./src/styles/*.scss', ['styles']);
	gulp.watch('./src/scripts/*.js', ['scripts']);
});<|endoftext|>


<commit_before>var gulp = require('gulp');

var clean = require('gulp-clean');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');

var paths = {
    scripts: ['app/scripts/model/task.js', 'app/scripts/collection/tasks.js', 'app/scripts/view/sandbox.js', 'app/scripts/view/task.js', 'app/scripts/app.js'],
    styles: ['app/styles/**/*.css'],
    html: ['app/index.html', 'app/404.html'],
    bower: ['bower_components/jquery/dist/jquery.js', 'bower_components/underscore/underscore.js', 'bower_components/backbone/backbone.js', 'bower_components/backbone.localStorage/backbone.localStorage-min.js'],
    extras: ['app/crossdomain.xml', 'app/humans.txt', 'app/manifest.appcache', 'app/robots.txt', 'app/favicon.ico'],
    app: 'app/',
    dist: 'dist/'
};

gulp.task('clean', function() {
    return gulp.src(paths.dist)
        .pipe(clean());
});

gulp.task('scripts', function() {
    return gulp.src(paths.scripts)
        .pipe(jshint())
        .pipe(jshint.reporter('default'))
        .pipe(uglify())
        .pipe(concat('multitasq.min.js'))
        .pipe(gulp.dest(paths.dist + 'scripts/'));
});

/* Not needed for favicon
gulp.task('imagemin', function() {
    return gulp.src(paths.images)
        .pipe(imagemin())
        .pipe(gulp.dest(paths.dist));
});
*/

gulp.task('copy', function() {
    // copy html
    gulp.src(paths.html)
        .pipe(gulp.dest(paths.dist));

    // copy styles
    gulp.src(paths.styles)
        .pipe(gulp.dest(paths.dist + 'styles'));

    // copy bower scripts
    gulp.src(paths.bower, {cwd: 'app/**'})
        .pipe(gulp.dest(paths.dist));

    // copy extra html5bp files
    gulp.src(paths.extras)
        .pipe(gulp.dest(paths.dist));
});

gulp.task('watch', function() {
    gulp.watch('app/**/*', ['scripts', 'copy']);
});

gulp.task('default', ['clean', 'scripts', 'copy']);

<commit_msg>cleaned up gulpfile with cwd<commit_after>var gulp = require('gulp');

var clean = require('gulp-clean');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');

var bases = {
    app: 'app/',
    dist: 'dist/',
};

var paths = {
    scripts: ['scripts/model/task.js', 'scripts/collection/tasks.js', 'scripts/view/sandbox.js', 'scripts/view/task.js', 'scripts/app.js'],
    styles: ['styles/**/*.css'],
    html: ['index.html', '404.html'],
    bower: ['bower_components/jquery/dist/jquery.js', 'bower_components/underscore/underscore.js', 'bower_components/backbone/backbone.js', 'bower_components/backbone.localStorage/backbone.localStorage-min.js'],
    extras: ['crossdomain.xml', 'humans.txt', 'manifest.appcache', 'robots.txt', 'favicon.ico'],
};

gulp.task('clean', function() {
    return gulp.src(bases.dist)
        .pipe(clean());
});

gulp.task('scripts', function() {
    return gulp.src(paths.scripts, {cwd: bases.app})
        .pipe(jshint())
        .pipe(jshint.reporter('default'))
        .pipe(uglify())
        .pipe(concat('multitasq.min.js'))
        .pipe(gulp.dest(bases.dist + 'scripts/'));
});

/* Not needed for favicon
gulp.task('imagemin', function() {
    return gulp.src(paths.images)
        .pipe(imagemin())
        .pipe(gulp.dest(bases.dist));
});
*/

gulp.task('copy', function() {
    // copy html
    gulp.src(paths.html, {cwd: bases.app})
        .pipe(gulp.dest(bases.dist));

    // copy styles
    gulp.src(paths.styles, {cwd: bases.app})
        .pipe(gulp.dest(bases.dist + 'styles'));

    // copy bower scripts
    gulp.src(paths.bower, {cwd: 'app/**'})
        .pipe(gulp.dest(bases.dist));

    // copy extra html5bp files
    gulp.src(paths.extras, {cwd: bases.app})
        .pipe(gulp.dest(bases.dist));
});

gulp.task('watch', function() {
    gulp.watch('app/**/*', ['scripts', 'copy']);
});

gulp.task('default', ['clean', 'scripts', 'copy']);

<|endoftext|>


<commit_before>"use strict";

var path = require("path");
var express = require("express");
var httpProxy = require("http-proxy");
var gitSubtree = require('gulp-gh-pages');
var gulp = require("gulp");
var gutil = require("gulp-util");
var webpack = require("webpack");
var webpackStream = require("webpack-stream");
var webpackDevMiddleware = require("webpack-dev-middleware");
var webpackHotMiddleware = require("webpack-hot-middleware");
var webpackConfig = process.env.NODE_ENV === "production" ?
  require("./webpack.config.prod")
: require("./webpack.config.dev");

// The development server (the recommended option for development)
gulp.task("default", ["webpack-dev-server"]);

// Production build
gulp.task("build", ["webpack:build"]);

/*
 * Build. One and done.
 */
gulp.task("webpack:build", function() {
  return gulp.src("src/index.js")
    .pipe(webpackStream(webpackConfig, null, function(err, stats) {
      if (err) throw new gutil.PluginError("webpack:build", err);
      gutil.log("[webpack:build]", stats.toString({
        // output options
        colors: true,
        chunkModules: true
      }));
      // callback();
    }))
    .pipe(gulp.dest("dist/"));
});

/*
 * A customized webpack-dev-server setup.
 * Integrates hot-module-reloading and proxying.
 */
gulp.task("webpack-dev-server", function(callback) {
  var app = express();
  var apiProxy = httpProxy.createProxyServer();

  // Start a webpack-dev-server
  var compiler = webpack(webpackConfig);

  app.use(webpackDevMiddleware(compiler, {
    // server and middleware options
    open: true,
    publicPath: webpackConfig.output.publicPath,
    stats: {
      colors: true,
      chunkModules: true
    }
  }));

  // Enables HMR
  app.use(webpackHotMiddleware(compiler));

  // Proxy api requests
  app.use("*", function(req, res) {
    req.url = req.baseUrl; // Janky hack... wtf WRITE SOME FUCKING DOCUMENTATION FUCKING CHRIST.
    apiProxy.web(req, res, {
      target: {
        port: 5000, // TODO put this in config
        host: "localhost"
      }
    });
  });

  app.listen(8080, "localhost", function(err) {
    if (err) throw new gutil.PluginError("webpack-dev-server", err);
    // Server listening
    gutil.log("[webpack-dev-server]", "http://localhost:8080");

    // keep the server alive or continue?
    // callback();
    console.log("Listening at http://localhost:8080");
    console.log("Compiling ... please wait for \"bundle is VALID\"");
  });
});

/*
 * Deployment.
 */
gulp.task("deploy", function() {
  return gulp.src('./dist/**/*')
    .pipe(gitSubtree({
      branch: "production"
    }));
});

<commit_msg>Whitespacing.<commit_after>"use strict";

var path = require("path");
var express = require("express");
var httpProxy = require("http-proxy");
var gitSubtree = require('gulp-gh-pages');
var gulp = require("gulp");
var gutil = require("gulp-util");
var webpack = require("webpack");
var webpackStream = require("webpack-stream");
var webpackDevMiddleware = require("webpack-dev-middleware");
var webpackHotMiddleware = require("webpack-hot-middleware");
var webpackConfig = process.env.NODE_ENV === "production" ?
  require("./webpack.config.prod")
: require("./webpack.config.dev");

// The development server (the recommended option for development)
gulp.task("default", ["webpack-dev-server"]);

// Production build
gulp.task("build", ["webpack:build"]);

/*
 * Build. One and done.
 */
gulp.task("webpack:build", function() {
  return gulp.src("src/index.js")
    .pipe(webpackStream(webpackConfig, null, function(err, stats) {
      if (err) throw new gutil.PluginError("webpack:build", err);
      gutil.log("[webpack:build]", stats.toString({
        // output options
        colors: true,
        chunkModules: true
      }));
      // callback();
    }))
    .pipe(gulp.dest("dist/"));
});

/*
 * A customized webpack-dev-server setup.
 * Integrates hot-module-reloading and proxying.
 */
gulp.task("webpack-dev-server", function(callback) {
  var app = express();
  var apiProxy = httpProxy.createProxyServer();

  // Start a webpack-dev-server
  var compiler = webpack(webpackConfig);

  app.use(webpackDevMiddleware(compiler, {
    // server and middleware options
    open: true,
    publicPath: webpackConfig.output.publicPath,
    stats: {
      colors: true,
      chunkModules: true
    }
  }));

  // Enables HMR
  app.use(webpackHotMiddleware(compiler));

  // Proxy api requests
  app.use("*", function(req, res) {
    req.url = req.baseUrl; // Janky hack... wtf WRITE SOME FUCKING DOCUMENTATION FUCKING CHRIST.
    apiProxy.web(req, res, {
      target: {
        port: 5000, // TODO put this in config
        host: "localhost"
      }
    });
  });

  app.listen(8080, "localhost", function(err) {
    if (err) throw new gutil.PluginError("webpack-dev-server", err);
    // Server listening
    gutil.log("[webpack-dev-server]", "http://localhost:8080");

    // keep the server alive or continue?
    // callback();
    console.log("Listening at http://localhost:8080");
    console.log("Compiling ... please wait for \"bundle is VALID\"");
  });
});

/*
 * Deployment.
 */
gulp.task("deploy", function() {
  return gulp.src('./dist/**/*')
    .pipe(gitSubtree({
      branch: "production"
    }));
});
<|endoftext|>


<commit_before>var gulp = require('gulp');
var jshint = require('gulp-jshint');
var less = require('gulp-less');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var react = require('gulp-react');
var flowtype = require('gulp-flowtype');

// Lint Task
gulp.task('lint', function() {
    return gulp.src('build/**/*.js')
        .pipe(jshint({
            esnext: true
        }))
        .pipe(jshint.reporter('default'));
});

gulp.task('typecheck', function() {
    return gulp.src('js/**/*.js')
        .pipe(flowtype({
            declarations: './flowtypes',
        }))
        .pipe(jshint.reporter('default'));
});

// Compile Our LESS
gulp.task('less', function() {
    return gulp.src('./style/**/*.less')
        .pipe(less({
            paths: ['./style']
        }))
        .pipe(gulp.dest('./build/css'));
});

gulp.task('react', function() {
    return gulp.src('./js/**/*.js')
        .pipe(react({
            harmony: true,
            // Skip Flow type annotations!
            stripTypes: true
        }))
        .pipe(gulp.dest('./build'));

});

// Concatenate & Minify JS
gulp.task('releasify', function() {
    return gulp.src('build/**/*.js')
        .pipe(concat('all.js'))
        .pipe(gulp.dest('dist'))
        .pipe(rename('all.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('dist'));
});

// Watch Files For Changes
gulp.task('watch', function() {
    gulp.watch('js/**/*.js', ['react']);
    gulp.watch('build/**/*.js', ['lint']);
    gulp.watch('style/**/*.less', ['less']);
});

// Default Task
// Not including Flow typechecking by default because it takes so painfully long.
// Maybe because of my code layout or otheriwse, needto figure it out before enabling by default.
gulp.task('default', ['react', 'less', 'lint', 'watch']);
<commit_msg>Tweak Flow typecheck gulp rule<commit_after>var gulp = require('gulp');
var jshint = require('gulp-jshint');
var less = require('gulp-less');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var react = require('gulp-react');
var flowtype = require('gulp-flowtype');

// Lint Task
gulp.task('lint', function() {
    return gulp.src('build/**/*.js')
        .pipe(jshint({
            esnext: true
        }))
        .pipe(jshint.reporter('default'));
});

gulp.task('typecheck', function() {
    return gulp.src('js/**/*.js')
        .pipe(flowtype({
            declarations: './flowtypes',
            background: false,    // Watch/Server mode
            all: false,           // Check all files regardless
            lib: '',              // Library directory
            module: '',           // Module mode
            stripRoot: false,     // Relative vs Absolute paths
            weak: false,          // Force weak check
            showAllErrors: false, // Show more than 50 errors
            killFlow: false,
        }))
        .pipe(jshint.reporter('default'));
});

// Compile Our LESS
gulp.task('less', function() {
    return gulp.src('./style/**/*.less')
        .pipe(less({
            paths: ['./style']
        }))
        .pipe(gulp.dest('./build/css'));
});

gulp.task('react', function() {
    return gulp.src('./js/**/*.js')
        .pipe(react({
            harmony: true,
            // Skip Flow type annotations!
            stripTypes: true
        }))
        .pipe(gulp.dest('./build'));

});

// Concatenate & Minify JS
gulp.task('releasify', function() {
    return gulp.src('build/**/*.js')
        .pipe(concat('all.js'))
        .pipe(gulp.dest('dist'))
        .pipe(rename('all.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('dist'));
});

// Watch Files For Changes
gulp.task('watch', function() {
    gulp.watch('js/**/*.js', ['react']);
    gulp.watch('build/**/*.js', ['lint']);
    gulp.watch('style/**/*.less', ['less']);
});

// Default Task
// Not including Flow typechecking by default because it takes so painfully long.
// Maybe because of my code layout or otheriwse, needto figure it out before enabling by default.
gulp.task('default', ['react', 'less', 'lint', 'watch']);
<|endoftext|>


<commit_before>"use strict";

var babelify = require("babelify");
var browserify = require("browserify");
var browserSync = require('browser-sync').create();
var changed = require("gulp-changed");
var compass = require("gulp-compass");
var ejs = require("gulp-ejs");
var fs = require("fs");
var gulp = require("gulp");
var gutil = require("gulp-util");
var KarmaServer = require("karma").Server;
var notify = require("gulp-notify");
var path = require("path");
var plumber = require("gulp-plumber");
var rename = require("gulp-rename");
var source = require("vinyl-source-stream");
var watchify = require("watchify");

// Parameters
var SRC_DIR = "src";
var DEST_DIR = "build";
var DIRS = {
    fonts: {src: "fonts"},
    html: {src: "html", dest: "", srcPattern: "*.ejs"},
    js: {src: "js"},
    css: {src: "scss", dest: "css", srcPattern: "*.scss"},
    resources: {src: "../node_modules/vivliostyle/resources", dest: "resources"},
    mathjax: {src: "../node_modules/mathjax", dest: "mathjax"}
};
var JS_ENTRIES = {
    production: "main.js",
    development: "main-dev.js"
};
var VIVLIOSTYLE_JS_SRC_DIR = "node_modules/vivliostyle/src";
var HTML_FILENAMES = {
    production: "vivliostyle-viewer.html",
    development: "vivliostyle-viewer-dev.html"
};
var SERVER_START_PATH = "/vivliostyle-ui/build/%viewer-html%#x=/vivliostyle.js/samples/gon/index.html";

function getVersion(basePath) {
    var version = JSON.parse(fs.readFileSync(basePath + "package.json", "utf8")).version;
    return version.replace(/\.0$/, "");
}
var versions = {
    core: getVersion("node_modules/vivliostyle/"),
    ui: getVersion("")
};

// Utility functions
function srcDir(type) {
    return SRC_DIR + "/" + DIRS[type].src;
}
function destDir(type) {
    var dirs = DIRS[type];
    return DEST_DIR + "/" + (typeof dirs.dest === "string" ? dirs.dest : dirs.src);
}
function srcPattern(type) {
    return SRC_DIR + "/" + DIRS[type].src + "/" + (DIRS[type].srcPattern || "**/*");
}
function serverStartPath(development) {
    var name = development ? HTML_FILENAMES.development : HTML_FILENAMES.production;
    return SERVER_START_PATH.replace("%viewer-html%", name);
}

// JS build
function getBrowserify(development, watch) {
    var b = browserify({
        cache: {},
        packageCache: {},
        entries: [srcDir("js") + "/" + (development ? JS_ENTRIES.development : JS_ENTRIES.production)],
        transform: [babelify],
        debug: development
    });
    if (watch) {
        b = watchify(b);
    }
    b.on("log", gutil.log);
    return b;
}
function bundleJs(b, name) {
    return b.bundle()
            .on("error", gutil.log.bind(gutil, "Browserify Error"))
            .pipe(source(name))
            .pipe(gulp.dest(destDir("js")));
}
var b;
var watching = false;
function bundleJsProd() {
    var name = JS_ENTRIES.production;
    return bundleJs(b, name);
}
function bundleJsDev() {
    var name = JS_ENTRIES.development;
    return bundleJs(b, name);
}
gulp.task("build:js", function() {
    b = getBrowserify(false, watching);
    bundleJsProd();
});
gulp.task("build:js-dev", function() {
    b = getBrowserify(true, watching);
    bundleJsDev();
});

// create a task simply copying files
function copyTask(type) {
    var dest = destDir(type);
    return gulp.task("build:" + type, function() {
        return gulp.src(srcPattern(type))
            .pipe(changed(dest))
            .pipe(gulp.dest(dest));
    });
}
copyTask("fonts");
copyTask("resources");
copyTask("mathjax");

// HTML build
function buildHtml(development) {
    return gulp.src(srcPattern("html"))
        .pipe(ejs({development: development, versions: versions}))
        .pipe(plumber({
            errorHandler: notify.onError("Error: <%= error.message %>")
        }))
        .pipe(rename(development ? HTML_FILENAMES.development : HTML_FILENAMES.production))
        .pipe(gulp.dest(destDir("html")));
}
gulp.task("build:html", function() {
    return buildHtml(false);
});
gulp.task("build:html-dev", function() {
    return buildHtml(true);
});

// CSS build
function buildCss(development) {
    return gulp.src(srcPattern("css"))
        .pipe(plumber({
            errorHandler: notify.onError("Error: <%= error.message %>")
        }))
        .pipe(compass({
            config_file: SRC_DIR + "/config.rb",
            css: path.resolve(destDir("css")),
            sass: path.resolve(srcDir("css")),
            environment: development ? "development" : "production"
        }));
}
gulp.task("build:css", function() {
    return buildCss(false);
});
gulp.task("build:css-dev", function() {
    return buildCss(true);
});

// build all
gulp.task("build", [
    "build:js",
    "build:html",
    "build:fonts",
    "build:resources",
//    "build:mathjax",
    "build:css"
]);
gulp.task("build-dev", [
    "build:js-dev",
    "build:html-dev",
    "build:fonts",
    "build:resources",
    "build:css-dev"
]);

// watch
gulp.task("start-watching", function() {
    watching = true;
});
gulp.task("watch", ["start-watching", "build"], function() {
    b.on("update", bundleJsProd);
    gulp.watch(srcPattern("html"), ["build:html"]);
    gulp.watch(srcPattern("fonts"), ["build:fonts"]);
    gulp.watch(srcPattern("resources"), ["build:resources"]);
    gulp.watch(srcPattern("css"), ["build:css"]);
});
gulp.task("watch-dev", ["start-watching", "build-dev"], function() {
    b.on("update", bundleJsDev);
    gulp.watch(srcPattern("html"), ["build:html-dev"]);
    gulp.watch(srcPattern("fonts"), ["build:fonts"]);
    gulp.watch(srcPattern("resources"), ["build:resources"]);
    gulp.watch(srcPattern("css"), ["build:css-dev"]);
});

// serve
function serve(development) {
    browserSync.init({
        browser: process.platform === "darwin" ? "google chrome": "chromium-browser",
        server: {
            baseDir: "../"
        },
        startPath: "/vivliostyle.js/test/files/"
    });
    var target = [DEST_DIR + "/**/*"];
    if (development) {
        target.push(VIVLIOSTYLE_JS_SRC_DIR + "/**/*");
    }
    gulp.watch(target).on("change", browserSync.reload);
}
gulp.task("serve", ["watch"], function() {
    serve(false);
});
gulp.task("serve-dev", ["watch-dev"], function() {
    serve(true);
});

gulp.task("default", ["serve-dev"]);

// test
gulp.task("test-local", function(done) {
    var server = new KarmaServer({
        configFile: process.cwd() + "/test/conf/karma-local.conf"
    }, function(exitStatus) {
        done(exitStatus ? "Some tests failed" : undefined);
    });
    server.start();
});
gulp.task("test-sauce", function(done) {
    var server = new KarmaServer({
        configFile: process.cwd() + "/test/conf/karma-sauce.conf"
    }, function(exitStatus) {
        done(exitStatus ? "Some tests failed" : undefined);
    });
    server.start();
});
<commit_msg>Create `build:plugin_resources` gulp task that copies `<core>/plugins/*/resources/*` to `build` directory<commit_after>"use strict";

var babelify = require("babelify");
var browserify = require("browserify");
var browserSync = require('browser-sync').create();
var changed = require("gulp-changed");
var compass = require("gulp-compass");
var ejs = require("gulp-ejs");
var fs = require("fs");
var gulp = require("gulp");
var gutil = require("gulp-util");
var KarmaServer = require("karma").Server;
var notify = require("gulp-notify");
var path = require("path");
var plumber = require("gulp-plumber");
var rename = require("gulp-rename");
var source = require("vinyl-source-stream");
var watchify = require("watchify");

// Parameters
var SRC_DIR = "src";
var DEST_DIR = "build";
var DIRS = {
    fonts: {src: "fonts"},
    html: {src: "html", dest: "", srcPattern: "*.ejs"},
    js: {src: "js"},
    css: {src: "scss", dest: "css", srcPattern: "*.scss"},
    resources: {src: "../node_modules/vivliostyle/resources", dest: "resources"},
    mathjax: {src: "../node_modules/mathjax", dest: "mathjax"},
    plugin_resources: {src: "../node_modules/vivliostyle/plugins/*/resources", dest: "plugins"}
};
var JS_ENTRIES = {
    production: "main.js",
    development: "main-dev.js"
};
var VIVLIOSTYLE_JS_SRC_DIR = "node_modules/vivliostyle/src";
var HTML_FILENAMES = {
    production: "vivliostyle-viewer.html",
    development: "vivliostyle-viewer-dev.html"
};
var SERVER_START_PATH = "/vivliostyle-ui/build/%viewer-html%#x=/vivliostyle.js/samples/gon/index.html";

function getVersion(basePath) {
    var version = JSON.parse(fs.readFileSync(basePath + "package.json", "utf8")).version;
    return version.replace(/\.0$/, "");
}
var versions = {
    core: getVersion("node_modules/vivliostyle/"),
    ui: getVersion("")
};

// Utility functions
function srcDir(type) {
    return SRC_DIR + "/" + DIRS[type].src;
}
function destDir(type) {
    var dirs = DIRS[type];
    return DEST_DIR + "/" + (typeof dirs.dest === "string" ? dirs.dest : dirs.src);
}
function srcPattern(type) {
    return SRC_DIR + "/" + DIRS[type].src + "/" + (DIRS[type].srcPattern || "**/*");
}
function serverStartPath(development) {
    var name = development ? HTML_FILENAMES.development : HTML_FILENAMES.production;
    return SERVER_START_PATH.replace("%viewer-html%", name);
}

// JS build
function getBrowserify(development, watch) {
    var b = browserify({
        cache: {},
        packageCache: {},
        entries: [srcDir("js") + "/" + (development ? JS_ENTRIES.development : JS_ENTRIES.production)],
        transform: [babelify],
        debug: development
    });
    if (watch) {
        b = watchify(b);
    }
    b.on("log", gutil.log);
    return b;
}
function bundleJs(b, name) {
    return b.bundle()
            .on("error", gutil.log.bind(gutil, "Browserify Error"))
            .pipe(source(name))
            .pipe(gulp.dest(destDir("js")));
}
var b;
var watching = false;
function bundleJsProd() {
    var name = JS_ENTRIES.production;
    return bundleJs(b, name);
}
function bundleJsDev() {
    var name = JS_ENTRIES.development;
    return bundleJs(b, name);
}
gulp.task("build:js", function() {
    b = getBrowserify(false, watching);
    bundleJsProd();
});
gulp.task("build:js-dev", function() {
    b = getBrowserify(true, watching);
    bundleJsDev();
});

// create a task simply copying files
function copyTask(type) {
    var dest = destDir(type);
    return gulp.task("build:" + type, function() {
        return gulp.src(srcPattern(type))
            .pipe(changed(dest))
            .pipe(gulp.dest(dest));
    });
}
copyTask("fonts");
copyTask("resources");
copyTask("mathjax");
copyTask("plugin_resources");

// HTML build
function buildHtml(development) {
    return gulp.src(srcPattern("html"))
        .pipe(ejs({development: development, versions: versions}))
        .pipe(plumber({
            errorHandler: notify.onError("Error: <%= error.message %>")
        }))
        .pipe(rename(development ? HTML_FILENAMES.development : HTML_FILENAMES.production))
        .pipe(gulp.dest(destDir("html")));
}
gulp.task("build:html", function() {
    return buildHtml(false);
});
gulp.task("build:html-dev", function() {
    return buildHtml(true);
});

// CSS build
function buildCss(development) {
    return gulp.src(srcPattern("css"))
        .pipe(plumber({
            errorHandler: notify.onError("Error: <%= error.message %>")
        }))
        .pipe(compass({
            config_file: SRC_DIR + "/config.rb",
            css: path.resolve(destDir("css")),
            sass: path.resolve(srcDir("css")),
            environment: development ? "development" : "production"
        }));
}
gulp.task("build:css", function() {
    return buildCss(false);
});
gulp.task("build:css-dev", function() {
    return buildCss(true);
});

// build all
gulp.task("build", [
    "build:js",
    "build:html",
    "build:fonts",
    "build:resources",
//    "build:mathjax",
    "build:plugin_resources",
    "build:css"
]);
gulp.task("build-dev", [
    "build:js-dev",
    "build:html-dev",
    "build:fonts",
    "build:resources",
    "build:plugin_resources",
    "build:css-dev"
]);

// watch
gulp.task("start-watching", function() {
    watching = true;
});
gulp.task("watch", ["start-watching", "build"], function() {
    b.on("update", bundleJsProd);
    gulp.watch(srcPattern("html"), ["build:html"]);
    gulp.watch(srcPattern("fonts"), ["build:fonts"]);
    gulp.watch(srcPattern("resources"), ["build:resources"]);
    gulp.watch(srcPattern("plugin_resources"), ["build:plugin_resources"]);
    gulp.watch(srcPattern("css"), ["build:css"]);
});
gulp.task("watch-dev", ["start-watching", "build-dev"], function() {
    b.on("update", bundleJsDev);
    gulp.watch(srcPattern("html"), ["build:html-dev"]);
    gulp.watch(srcPattern("fonts"), ["build:fonts"]);
    gulp.watch(srcPattern("resources"), ["build:resources"]);
    gulp.watch(srcPattern("plugin_resources"), ["build:plugin_resources"]);
    gulp.watch(srcPattern("css"), ["build:css-dev"]);
});

// serve
function serve(development) {
    browserSync.init({
        browser: process.platform === "darwin" ? "google chrome": "chromium-browser",
        server: {
            baseDir: "../"
        },
        startPath: "/vivliostyle.js/test/files/"
    });
    var target = [DEST_DIR + "/**/*"];
    if (development) {
        target.push(VIVLIOSTYLE_JS_SRC_DIR + "/**/*");
    }
    gulp.watch(target).on("change", browserSync.reload);
}
gulp.task("serve", ["watch"], function() {
    serve(false);
});
gulp.task("serve-dev", ["watch-dev"], function() {
    serve(true);
});

gulp.task("default", ["serve-dev"]);

// test
gulp.task("test-local", function(done) {
    var server = new KarmaServer({
        configFile: process.cwd() + "/test/conf/karma-local.conf"
    }, function(exitStatus) {
        done(exitStatus ? "Some tests failed" : undefined);
    });
    server.start();
});
gulp.task("test-sauce", function(done) {
    var server = new KarmaServer({
        configFile: process.cwd() + "/test/conf/karma-sauce.conf"
    }, function(exitStatus) {
        done(exitStatus ? "Some tests failed" : undefined);
    });
    server.start();
});
<|endoftext|>


<commit_before>
var gulp         = require('gulp'),
    sass         = require('gulp-sass'),
    autoprefixer = require('gulp-autoprefixer'),
    cssmin       = require('gulp-cssmin'),
    rename       = require('gulp-rename'),
    concat       = require('gulp-concat'),
    uglify       = require('gulp-uglify'),
    notify       = require('gulp-notify'),
    watch        = require('gulp-watch'),
    livereload   = require('gulp-livereload');

gulp.task('sass', function() {
    return gulp.src('./scss/style.scss')
        // sass, notify
        .pipe(sass({
            errLogToConsole: false,
            onError: function(err) {
                return notify().write(err);
            }
        }))
        .pipe(gulp.dest('./dist'))
        // autoprefixer
        .pipe(rename('style.prefixed.css'))
        .pipe(autoprefixer('last 2 version', 'ie 9'))
        .pipe(gulp.dest('./dist'))
        // cssmin
        .pipe(rename('style.min.css'))
        .pipe(cssmin())
        .pipe(gulp.dest('./dist'));
});

gulp.task('js', function() {
    gulp.src(['./js/scripts.js', './js/*/*.js'])
        // concat
        .pipe(concat('scripts.concat.js'))
        .pipe(gulp.dest('./dist'))
        // uglify
        .pipe(rename('scripts.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./dist'));
});

gulp.task('watch', function() {
    livereload.listen();

    gulp.watch('./scss/**/*.scss', ['sass']).on('change', livereload.changed);
    gulp.watch('./js/**/*.js', ['js']).on('change', livereload.changed);;
    gulp.watch('./**/*.php').on('change', livereload.changed);
});
<commit_msg>gulp js fix<commit_after>
var gulp         = require('gulp'),
    sass         = require('gulp-sass'),
    autoprefixer = require('gulp-autoprefixer'),
    cssmin       = require('gulp-cssmin'),
    rename       = require('gulp-rename'),
    concat       = require('gulp-concat'),
    uglify       = require('gulp-uglify'),
    notify       = require('gulp-notify'),
    watch        = require('gulp-watch'),
    livereload   = require('gulp-livereload');

gulp.task('sass', function() {
    return gulp.src('./scss/style.scss')
        // sass, notify
        .pipe(sass({
            errLogToConsole: false,
            onError: function(err) {
                return notify().write(err);
            }
        }))
        .pipe(gulp.dest('./dist'))
        // autoprefixer
        .pipe(rename('style.prefixed.css'))
        .pipe(autoprefixer('last 2 version', 'ie 9'))
        .pipe(gulp.dest('./dist'))
        // cssmin
        .pipe(rename('style.min.css'))
        .pipe(cssmin())
        .pipe(gulp.dest('./dist'));
});

gulp.task('js', function() {
    gulp.src(['./js/*/*.js', './js/scripts.js'])
        // concat
        .pipe(concat('scripts.concat.js'))
        .pipe(gulp.dest('./dist'))
        // uglify
        .pipe(rename('scripts.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./dist'));
});

gulp.task('watch', function() {
    livereload.listen();

    gulp.watch('./scss/**/*.scss', ['sass']).on('change', livereload.changed);
    gulp.watch('./js/**/*.js', ['js']).on('change', livereload.changed);;
    gulp.watch('./**/*.php').on('change', livereload.changed);
});
<|endoftext|>


<commit_before>var elixir = require('laravel-elixir'),
    path   = require('./tasks/app.components.js');

require('./tasks/angular.task.js');
require('./tasks/bower.task.js');
require('./tasks/ngHtml2Js.task.js');
require('laravel-elixir-livereload');

/*
 |--------------------------------------------------------------------------
 | Elixir Asset Management
 |--------------------------------------------------------------------------
 |
 | Elixir provides a clean, fluent API for defining some basic Gulp tasks
 | for your Laravel application. By default, we are compiling the Less
 | file for our application, as well as publishing vendor resources.
 |
 */

elixir(function(mix) {
    'use strict';

    mix
        .bower()
        .angular(path.angularDirectory())
        .ngHtml2Js(path.htmlDirectory())
        .sass(path.sassDirectory(), 'public/css')
        //.copy(path.copyDirectory(), 'public/views/')
        .livereload([
            'public/js/vendor.js',
            'public/js/partials.js',
            'public/js/app.js',
            'public/css/vendor.css',
            'public/css/app.css'
        ], {liveCSS: true});
        //.phpUnit();
});

require('gulp').task('generate', require('./tasks/generators/tasks/generate.js').generate);

<commit_msg>Modified gulpfile<commit_after>var elixir = require('laravel-elixir'),
    path   = require('./tasks/app.components.js');

require('./tasks/angular.task.js');
require('./tasks/bower.task.js');
require('./tasks/ngHtml2Js.task.js');
require('laravel-elixir-livereload');

/*
 |--------------------------------------------------------------------------
 | Elixir Asset Management
 |--------------------------------------------------------------------------
 |
 | Elixir provides a clean, fluent API for defining some basic Gulp tasks
 | for your Laravel application. By default, we are compiling the Less
 | file for our application, as well as publishing vendor resources.
 |
 */

elixir(function(mix) {
    'use strict';

    mix
        //.bower()
        .angular(path.angularDirectory())
        .ngHtml2Js(path.htmlDirectory())
        .sass(path.sassDirectory(), 'public/css');
    //.copy(path.copyDirectory(), 'public/views/')
    //.livereload([
    //    'public/js/vendor.js',
    //    'public/js/partials.js',
    //    'public/js/app.js',
    //    'public/css/vendor.css',
    //    'public/css/app.css'
    //], {liveCSS: true});
    //.phpUnit();
});

require('gulp').task('generate', require('./tasks/generators/tasks/generate.js').generate);

<|endoftext|>


<commit_before>var app = angular.module('NarrativeRoulette', [
  'ngRoute',
  'contenteditable',
  'LocalStorageModule',
  'ngProgress',
  'ngFacebook',
]);

app.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/write', {
        templateUrl: 'partials/write.html',
        controller: 'WriteCtrl'
      }).
      when('/write/:perspectiveId', {
        templateUrl: 'partials/write.html',
        controller: 'WriteCtrl'
      }).
      when('/display', {
        templateUrl: 'partials/display.html',
        controller: 'DisplayCtrl'
      }).
      when('/round/:roundId', {
        templateUrl: 'partials/submissionList.html',
        controller: 'SubmissionListCtrl'
      }).
      when('/read', {
        templateUrl: 'partials/submissionList.html',
        controller: 'SubmissionListCtrl'
      }).
      when('/submissions', {
        templateUrl: 'partials/submissions.html',
        controller: 'SubmissionsCtrl'
      }).
      when('/submission/:submissionId', {
        templateUrl: 'partials/submission.html',
        controller: 'SubmissionCtrl'
      }).
      otherwise({
        redirectTo: '/write'
      });
  }])
  .config(['localStorageServiceProvider',
    function(localStorageServiceProvider) {
      localStorageServiceProvider.setPrefix('narrativeRoulette');
    }]
  )
  .config( function( $facebookProvider ) {
    $facebookProvider.setAppId('629563240412158');
    console.log("Set Facebook AppID");
  });

app.run( function( $rootScope ) {
  // Cut and paste the "Load the SDK" code from the facebook javascript sdk page.
  (function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=629563240412158";
  fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));

  console.log("Loaded Facebook JS SDK");
});

app.factory('interceptorNgProgress', function ($injector) {
  var complete_progress, getNgProgress, ng_progress, working;
  ng_progress = null;
  working = false;

  getNgProgress = function() {
    ng_progress = ng_progress || $injector.get("ngProgress");
    ng_progress.color("rgb(207,181,150)");
    return ng_progress;
  };

  complete_progress = function() {
    var ngProgress;
    if (working) {
      ngProgress = getNgProgress();
      ngProgress.complete();
      return working = false;
    }
  };

  return {
    request: function(request) {
      var ngProgress;
      ngProgress = getNgProgress();
      if (request.url.indexOf('.html') > 0) {
        return request;
      }
      if (!working) {
        ngProgress.reset();
        ngProgress.start();
        working = true;
      }
      return request;
    },
    requestError: function(request) {
      complete_progress();
      return request;
    },
    response: function(response) {
      complete_progress();
      return response;
    },
    responseError: function(response) {
      complete_progress();
      return response;
    }
  }
});

app.config(function ($httpProvider) {
  $httpProvider.interceptors.push('interceptorNgProgress');
});
<commit_msg>Changed name of rounds link<commit_after>var app = angular.module('NarrativeRoulette', [
  'ngRoute',
  'contenteditable',
  'LocalStorageModule',
  'ngProgress',
  'ngFacebook',
]);

app.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/write', {
        templateUrl: 'partials/write.html',
        controller: 'WriteCtrl'
      }).
      when('/write/:perspectiveId', {
        templateUrl: 'partials/write.html',
        controller: 'WriteCtrl'
      }).
      when('/display', {
        templateUrl: 'partials/display.html',
        controller: 'DisplayCtrl'
      }).
      when('/round/:roundId', {
        templateUrl: 'partials/submissionList.html',
        controller: 'SubmissionListCtrl'
      }).
      when('/read', {
        templateUrl: 'partials/submissionList.html',
        controller: 'SubmissionListCtrl'
      }).
      when('/rounds', {
        templateUrl: 'partials/submissions.html',
        controller: 'SubmissionsCtrl'
      }).
      when('/submission/:submissionId', {
        templateUrl: 'partials/submission.html',
        controller: 'SubmissionCtrl'
      }).
      otherwise({
        redirectTo: '/write'
      });
  }])
  .config(['localStorageServiceProvider',
    function(localStorageServiceProvider) {
      localStorageServiceProvider.setPrefix('narrativeRoulette');
    }]
  )
  .config( function( $facebookProvider ) {
    $facebookProvider.setAppId('629563240412158');
    console.log("Set Facebook AppID");
  });

app.run( function( $rootScope ) {
  // Cut and paste the "Load the SDK" code from the facebook javascript sdk page.
  (function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=629563240412158";
  fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));

  console.log("Loaded Facebook JS SDK");
});

app.factory('interceptorNgProgress', function ($injector) {
  var complete_progress, getNgProgress, ng_progress, working;
  ng_progress = null;
  working = false;

  getNgProgress = function() {
    ng_progress = ng_progress || $injector.get("ngProgress");
    ng_progress.color("rgb(207,181,150)");
    return ng_progress;
  };

  complete_progress = function() {
    var ngProgress;
    if (working) {
      ngProgress = getNgProgress();
      ngProgress.complete();
      return working = false;
    }
  };

  return {
    request: function(request) {
      var ngProgress;
      ngProgress = getNgProgress();
      if (request.url.indexOf('.html') > 0) {
        return request;
      }
      if (!working) {
        ngProgress.reset();
        ngProgress.start();
        working = true;
      }
      return request;
    },
    requestError: function(request) {
      complete_progress();
      return request;
    },
    response: function(response) {
      complete_progress();
      return response;
    },
    responseError: function(response) {
      complete_progress();
      return response;
    }
  }
});

app.config(function ($httpProvider) {
  $httpProvider.interceptors.push('interceptorNgProgress');
});
<|endoftext|>


<commit_before>var gulp = require('gulp');
var reactify = require('reactify');
var source = require('vinyl-source-stream');
var watchify = require('watchify');

var production = process.env.NODE_ENV === 'production';

function scripts(watch) {
	var bundler = watch ? watchify() : browserify();
	bundler.require('./weotu_ui/static/src/index.jsx', {expose: 'index'}); // {basedir: __dirname}
	bundler.require('./weotu_ui/static/src/sign-in.jsx', {expose: 'sign-in'}); // {basedir: __dirname}
	bundler.transform('reactify');

	// Optionally, you can apply transforms
	// and other configuration options on the
	// bundler just as you would with browserify
	//bundler.transform('brfs');

	bundler.on('update', rebundle);

	function rebundle() {
		return bundler.bundle({debug: !production})
			.pipe(source('bundle.js'))
			.pipe(gulp.dest('./weotu_ui/static/dist'));
	}

	return rebundle();
}

gulp.task('default', function() {
	return scripts(false);
});

gulp.task('watch', function() {
	return scripts(true);
});
<commit_msg>Replace tabs with spaces.<commit_after>var gulp = require('gulp');
var reactify = require('reactify');
var source = require('vinyl-source-stream');
var watchify = require('watchify');

var production = process.env.NODE_ENV === 'production';

function scripts(watch) {
  var bundler = watch ? watchify() : browserify();
  bundler.require('./weotu_ui/static/src/index.jsx', {expose: 'index'}); // {basedir: __dirname}
  bundler.require('./weotu_ui/static/src/sign-in.jsx', {expose: 'sign-in'}); // {basedir: __dirname}
  bundler.transform('reactify');

  // Optionally, you can apply transforms
  // and other configuration options on the
  // bundler just as you would with browserify
  //bundler.transform('brfs');

  bundler.on('update', rebundle);

  function rebundle() {
    return bundler.bundle({debug: !production})
      .pipe(source('bundle.js'))
      .pipe(gulp.dest('./weotu_ui/static/dist'));
  }

  return rebundle();
}

gulp.task('default', function() {
  return scripts(false);
});

gulp.task('watch', function() {
  return scripts(true);
});
<|endoftext|>