Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.4 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. /*
  2. ESP8266 file system builder
  3. Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. // -----------------------------------------------------------------------------
  16. // File system builder
  17. // -----------------------------------------------------------------------------
  18. const fs = require('fs');
  19. const gulp = require('gulp');
  20. const plumber = require('gulp-plumber');
  21. const htmlmin = require('gulp-htmlmin');
  22. const cleancss = require('gulp-clean-css');
  23. const uglify = require('gulp-uglify');
  24. const gzip = require('gulp-gzip');
  25. const del = require('del');
  26. const useref = require('gulp-useref');
  27. const gulpif = require('gulp-if');
  28. const inline = require('gulp-inline');
  29. const inlineImages = require('gulp-css-base64');
  30. const favicon = require('gulp-base64-favicon');
  31. const dataFolder = 'espurna/data/';
  32. gulp.task('clean', function() {
  33. del([ dataFolder + '*']);
  34. return true;
  35. });
  36. gulp.task('files', ['clean'], function() {
  37. return gulp.src([
  38. 'html/**/*.{jpg,jpeg,png,ico,gif}',
  39. 'html/fsversion'
  40. ])
  41. .pipe(gulp.dest(dataFolder));
  42. });
  43. gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
  44. var source = dataFolder + 'index.html.gz';
  45. var destination = dataFolder + '../static/index.html.gz.h';
  46. var wstream = fs.createWriteStream(destination);
  47. wstream.on('error', function (err) {
  48. console.log(err);
  49. });
  50. var data = fs.readFileSync(source);
  51. wstream.write('#define index_html_gz_len ' + data.length + '\n');
  52. wstream.write('const uint8_t index_html_gz[] PROGMEM = {')
  53. for (i=0; i<data.length; i++) {
  54. if (i % 1000 == 0) wstream.write("\n");
  55. wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
  56. if (i<data.length-1) wstream.write(',');
  57. }
  58. wstream.write('\n};')
  59. wstream.end();
  60. });
  61. gulp.task('buildfs_inline', ['clean'], function() {
  62. return gulp.src('html/*.html')
  63. .pipe(favicon())
  64. .pipe(inline({
  65. base: 'html/',
  66. js: uglify,
  67. css: [cleancss, inlineImages],
  68. disabledTypes: ['svg', 'img']
  69. }))
  70. .pipe(htmlmin({
  71. collapseWhitespace: true,
  72. removeComments: true,
  73. minifyCSS: true,
  74. minifyJS: true
  75. }))
  76. .pipe(gzip())
  77. .pipe(gulp.dest(dataFolder));
  78. })
  79. gulp.task('buildfs_split', ['files'], function() {
  80. return gulp.src('html/*.html')
  81. .pipe(useref())
  82. .pipe(plumber())
  83. .pipe(gulpif('*.css', cleancss()))
  84. .pipe(gulpif('*.js', uglify()))
  85. .pipe(gulpif('*.html', htmlmin({
  86. collapseWhitespace: true,
  87. removeComments: true,
  88. minifyCSS: true,
  89. minifyJS: true
  90. })))
  91. .pipe(gzip())
  92. .pipe(gulp.dest(dataFolder));
  93. });
  94. gulp.task('default', ['buildfs_embeded']);