gulpfile.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. 'use strict';
  2. var gulp = require('gulp');
  3. var util = require('gulp-util');
  4. var sass = require('gulp-sass');
  5. var watch = require('gulp-watch');
  6. var autoprefixer = require('gulp-autoprefixer');
  7. var jsmin = require('gulp-jsmin');
  8. var cssmin = require('gulp-cssmin');
  9. var rename = require('gulp-rename');
  10. var mainBowerFiles = require('main-bower-files');
  11. var jsonToSass = require('gulp-json-to-sass');
  12. var concat = require('gulp-concat');
  13. var through = require('through2');
  14. // var fs = require('fs');
  15. // var json2js = require('gulp-json2js');
  16. // var data = require('gulp-data');
  17. // var shared_variables = JSON.parse(fs.readFileSync('./assets/json/shared_variables.json'));
  18. function handleError(err) {
  19. console.log(err.toString());
  20. }
  21. var config = {
  22. assetsDir : './assets',
  23. production: !!util.env.production
  24. }
  25. gulp.task('vars2sass', function () {
  26. gulp.src('./assets/json/shared_variables.json')
  27. .pipe(jsonToSass({
  28. jsonPath: './assets/json/shared_variables.json',
  29. scssPath: './assets/styles/base/_shared_variables.scss'
  30. }));
  31. });
  32. // this one is not working, works first run but then it's like it's caching the source
  33. // gulp.task('variables2js', function() {
  34. // gulp.src('./assets/scripts/shared_variables_model.js')
  35. // .pipe(rename('shared_variables.js'))
  36. // .pipe(data(function(file) {
  37. // delete require.cache['./assets/json/shared_variables.json'];
  38. // return require('./assets/json/shared_variables.json');
  39. // }))
  40. // .pipe(json2js())
  41. // .pipe(gulp.dest('./assets/scripts/'));
  42. // });
  43. gulp.task('vars2js', function() {
  44. gulp.src('./assets/json/shared_variables.json')
  45. .pipe(rename('shared_variables.js'))
  46. .pipe(through.obj(function (file, enc, cb) {
  47. // console.log('file',String(file.contents));
  48. // small pipe to wrappe json data into a js variable
  49. file.contents = new Buffer("edlp_vars = "+String(file.contents).trim()+";");
  50. cb(null, file);
  51. }))
  52. .pipe(gulp.dest('./assets/scripts/'));
  53. });
  54. gulp.task('scripts', function () {
  55. gulp.src(['./assets/scripts/shared_variables.js','./assets/scripts/main.js'])
  56. .pipe(concat('main.js'))
  57. .pipe(config.production ? jsmin() : util.noop())
  58. .pipe(rename({suffix: '.min'}))
  59. .pipe(gulp.dest('./assets/dist/scripts/'));
  60. });
  61. gulp.task('styles', function () {
  62. gulp.src('./assets/styles/app.scss')
  63. .pipe(sass().on('error', sass.logError))
  64. .pipe(autoprefixer({
  65. browsers: ['last 2 versions'],
  66. cascade: false
  67. })).on('error', handleError)
  68. .pipe(config.production ? cssmin() : util.noop())
  69. .pipe(rename({suffix: '.min'}))
  70. .pipe(gulp.dest('./assets/dist/styles/'));
  71. });
  72. gulp.task('bower', function() {
  73. gulp.src(mainBowerFiles({
  74. "overrides":{
  75. "history.js":{
  76. "main":"./scripts/bundled/html4+html5/jquery.history.js"
  77. },
  78. "jquery":{
  79. "ignore":true
  80. },
  81. "overlayScrollbars":{
  82. "main":[
  83. "./js/jquery.overlayScrollbars.min.js",
  84. "./css/OverlayScrollbars.min.css"
  85. ]
  86. }
  87. }
  88. }))
  89. .pipe(gulp.dest('./assets/dist/bower/'));
  90. });
  91. // default gulp task
  92. gulp.task('default', ['bower', 'vars2js', 'scripts', 'vars2sass', 'styles'], function() {
  93. gulp.watch('./assets/json/*.json', ['vars2js', 'vars2sass', 'styles', 'scripts']);
  94. gulp.watch('./assets/styles/*.scss', ['styles']);
  95. gulp.watch('./assets/styles/base/*.scss', ['styles']);
  96. gulp.watch('./assets/scripts/*.js', ['scripts']);
  97. });