Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. var gulp = require('gulp'),
  2. concat = require('gulp-concat-util'),
  3. header = require('gulp-header'),
  4. footer = require('gulp-footer'),
  5. del = require('del'),
  6. merge = require('merge-stream'),
  7. jshint = require('gulp-jshint'),
  8. jasmine = require('gulp-jasmine'),
  9. source = require('vinyl-source-stream'),
  10. buffer = require('gulp-buffer'),
  11. browserify = require('browserify'),
  12. rename = require("gulp-rename"),
  13. transform = require('vinyl-transform'),
  14. through = require('through2'),
  15. fs = require('fs');
  16.  
  17. function getAppStream() {
  18. return browserify('src/js/app/main.js')
  19. .bundle()
  20. .pipe(source('app.js'))
  21. .pipe(buffer());
  22. }
  23.  
  24. gulp.task('lint:app', function () {
  25. return gulp.src(['src/js/app/**/*.js'])
  26. .pipe(jshint())
  27. .pipe(jshint.reporter('default'));
  28. });
  29.  
  30. gulp.task('clean', function () {
  31. return del(['build']);
  32. });
  33.  
  34. gulp.task('vendor', ['clean'], function () {
  35. return gulp.src(['vendor/**'])
  36. .pipe(gulp.dest('build/vendor'));
  37. });
  38.  
  39. gulp.task('css', ['clean'], function () {
  40. return gulp.src(['src/css/**/*.css'])
  41. .pipe(concat('app.css'))
  42. .pipe(gulp.dest('build'));
  43. });
  44.  
  45. gulp.task('js', ['clean', 'lint:app'], function () {
  46. var app = getAppStream()
  47. .pipe(header('(function(global) {'))
  48. .pipe(footer('}(window.TwitchLanguageFilter = window.TwitchLanguageFilter || {}));'));
  49.  
  50. var manifest = gulp.src(['src/manifest.json']);
  51.  
  52. var launcher = gulp.src(['src/js/launcher.js'])
  53. .pipe(jshint())
  54. .pipe(jshint.reporter('default'))
  55.  
  56. return merge(app, launcher, manifest)
  57. .pipe(gulp.dest('build'));
  58. });
  59.  
  60. gulp.task('test', function () {
  61. return gulp.src(['test/**/*.spec.js'])
  62. .pipe(jasmine());
  63. });
  64.  
  65. gulp.task('dev', ['js', 'css', 'vendor'], function () {
  66.  
  67. });
  68.  
  69. if (!String.prototype.endsWith) {
  70. String.prototype.endsWith = function (searchString, position) {
  71. var subjectString = this.toString();
  72. if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
  73. position = subjectString.length;
  74. }
  75. position -= searchString.length;
  76. var lastIndex = subjectString.indexOf(searchString, position);
  77. return lastIndex !== -1 && lastIndex === position;
  78. };
  79. }
  80.  
  81. gulp.task('env', ['clean'], function () {
  82. var configTransform = function (file) {
  83. return through(function (buff, enc, next) {
  84. if (file.endsWith('config\\index.js')) {
  85. var config = fs.readFileSync('src/js/app/config/debug.config.js', 'utf8');
  86. this.push(config);
  87. } else {
  88. this.push(buff);
  89. }
  90.  
  91. next();
  92. });
  93. };
  94.  
  95. browserify('src/js/app/main.js')
  96. .transform(configTransform)
  97. .bundle()
  98. .pipe(source('app.js'))
  99. .pipe(buffer())
  100. .pipe(gulp.dest('build'));
  101.  
  102. });
  103.  
  104. gulp.task('watch', ['default'], function () {
  105. gulp.watch(['src/**', 'test/**'], ['default']);
  106. });
  107.  
  108. gulp.task('default', ['dev', 'test'], function () {
  109.  
  110. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement