gulpfile.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. var gulp = require('gulp');
  2. var sass = require('gulp-sass');
  3. var header = require('gulp-header');
  4. var cleanCSS = require('gulp-clean-css');
  5. var rename = require('gulp-rename');
  6. var uglify = require('gulp-uglify');
  7. var beautify = require('gulp-html-beautify');
  8. var pkg = require('./package.json');
  9. var browserSync = require('browser-sync').create();
  10. var exec = require('child_process').exec;
  11. // Set the banner content
  12. var banner = ['/*!\n',
  13. ' * Start Bootstrap - <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n',
  14. ' * Copyright 2013-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
  15. ' * Licensed under <%= pkg.license %> (https://github.com/BlackrockDigital/<%= pkg.name %>/blob/master/LICENSE)\n',
  16. ' */\n',
  17. ''
  18. ].join('');
  19. // Copy third party libraries from /node_modules into /app/static/app/static/vendor
  20. gulp.task('vendor', function() {
  21. // Bootstrap
  22. gulp.src([
  23. './node_modules/bootstrap/dist/**/*',
  24. '!./node_modules/bootstrap/dist/css/bootstrap-grid*',
  25. '!./node_modules/bootstrap/dist/css/bootstrap-reboot*'
  26. ])
  27. .pipe(gulp.dest('./app/static/vendor/bootstrap'));
  28. // DataTables
  29. gulp.src([
  30. './node_modules/datatables.net/js/*.js',
  31. './node_modules/datatables.net-bs4/js/*.js',
  32. './node_modules/datatables.net-bs4/css/*.css'
  33. ])
  34. .pipe(gulp.dest('./app/static/vendor/datatables/'));
  35. // Font Awesome
  36. gulp.src([
  37. './node_modules/font-awesome/**/*',
  38. '!./node_modules/font-awesome/{less,less/*}',
  39. '!./node_modules/font-awesome/{scss,scss/*}',
  40. '!./node_modules/font-awesome/.*',
  41. '!./node_modules/font-awesome/*.{txt,json,md}'
  42. ])
  43. .pipe(gulp.dest('./app/static/vendor/font-awesome'));
  44. // jQuery
  45. gulp.src([
  46. './node_modules/jquery/dist/*',
  47. '!./node_modules/jquery/dist/core.js'
  48. ])
  49. .pipe(gulp.dest('./app/static/vendor/jquery'));
  50. // jQuery Easing
  51. gulp.src([
  52. './node_modules/jquery.easing/*.js'
  53. ])
  54. .pipe(gulp.dest('./app/static/vendor/jquery-easing'));
  55. });
  56. // Compile SASS
  57. gulp.task('css:compile', function() {
  58. return gulp.src('./app/static/sass/*.sass')
  59. .pipe(sass.sync({
  60. outputStyle: 'expanded'
  61. }).on('error', sass.logError))
  62. .pipe(gulp.dest('./app/static/css'));
  63. });
  64. // Minify CSS
  65. gulp.task('css:minify', ['css:compile'], function() {
  66. return gulp.src([
  67. './app/static/css/*.css',
  68. '!./app/static/css/*.min.css'
  69. ])
  70. .pipe(cleanCSS())
  71. .pipe(rename({
  72. suffix: '.min'
  73. }))
  74. .pipe(gulp.dest('./app/static/css'))
  75. .pipe(browserSync.stream());
  76. });
  77. // CSS
  78. gulp.task('css', ['css:compile', 'css:minify']);
  79. // Minify JavaScript
  80. gulp.task('js', function() {
  81. return gulp.src([
  82. './app/static/js/**/*.js',
  83. '!./app/static/js/**/*.min.js'
  84. ])
  85. .pipe(uglify())
  86. .pipe(rename({
  87. suffix: '.min'
  88. }))
  89. .pipe(gulp.dest('./app/static/js'))
  90. .pipe(browserSync.stream());
  91. });
  92. // Default task
  93. gulp.task('default', ['css', 'js', 'vendor']);
  94. // Configure the browserSync task
  95. gulp.task('browserSync', function() {
  96. browserSync.init({
  97. notify: false,
  98. proxy: '127.0.0.1:5000',
  99. open: false,
  100. });
  101. });
  102. //Run Flask server
  103. gulp.task('runserver', function() {
  104. exec('pipenv run ./start.sh');
  105. });
  106. // Dev task
  107. gulp.task('dev', ['runserver', 'css', 'js', 'vendor', 'browserSync'], function() {
  108. gulp.watch([
  109. './app/templates/**/*.html',
  110. './app/**/*.py',
  111. ], browserSync.reload);
  112. gulp.watch([
  113. './app/static/sass/*.sass',
  114. './app/static/css/*.css',
  115. '!./app/static/css/*.min.css',
  116. ], ['css']);
  117. gulp.watch([
  118. './app/static/js/**/*.js',
  119. '!./app/static/js/**/*.min.js'
  120. ],['js']);
  121. });