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.

131 lines
3.8 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
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. /* Clean destination folder */
  33. gulp.task('clean', function() {
  34. del([ dataFolder + '*']);
  35. return true;
  36. });
  37. /* Copy static files */
  38. gulp.task('files', function() {
  39. return gulp.src([
  40. 'html/**/*.{jpg,jpeg,png,ico,gif}',
  41. 'html/fsversion'
  42. ])
  43. .pipe(gulp.dest(dataFolder));
  44. });
  45. gulp.task('embed', function() {
  46. var source = dataFolder + 'index.html.gz';
  47. var destination = dataFolder + '../config/data.h';
  48. var wstream = fs.createWriteStream(destination);
  49. wstream.on('error', function (err) {
  50. console.log(err);
  51. });
  52. var data = fs.readFileSync(source);
  53. wstream.write('#define index_html_gz_len ' + data.length + '\n');
  54. wstream.write('const uint8_t index_html_gz[] PROGMEM = {')
  55. for (i=0; i<data.length; i++) {
  56. wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
  57. if (i<data.length-1) wstream.write(',');
  58. }
  59. wstream.write('};\n')
  60. wstream.end();
  61. });
  62. gulp.task('inline_images', function() {
  63. return gulp.src(['html/src/checkboxes.css'])
  64. .pipe(inlineImages({
  65. baseDir: "../"
  66. }))
  67. .pipe(gulp.dest('html/'));
  68. });
  69. /* Process HTML, CSS, JS, IMAGES and FAVICON --- INLINE --- */
  70. gulp.task('inline', function() {
  71. return gulp.src('html/*.html')
  72. .pipe(favicon())
  73. .pipe(inline({
  74. base: 'html/',
  75. js: uglify,
  76. css: cleancss,
  77. disabledTypes: ['svg', 'img']
  78. }))
  79. .pipe(htmlmin({
  80. collapseWhitespace: true,
  81. removeComments: true,
  82. minifyCSS: true,
  83. minifyJS: true
  84. }))
  85. .pipe(gzip())
  86. .pipe(gulp.dest(dataFolder));
  87. })
  88. /* Process HTML, CSS, JS */
  89. gulp.task('html', function() {
  90. return gulp.src('html/*.html')
  91. .pipe(useref())
  92. .pipe(plumber())
  93. .pipe(gulpif('*.css', cleancss()))
  94. .pipe(gulpif('*.js', uglify()))
  95. .pipe(gulpif('*.html', htmlmin({
  96. collapseWhitespace: true,
  97. removeComments: true,
  98. minifyCSS: true,
  99. minifyJS: true
  100. })))
  101. .pipe(gzip())
  102. .pipe(gulp.dest(dataFolder));
  103. });
  104. /* Build file system */
  105. gulp.task('buildfs_split', ['clean', 'files', 'html']);
  106. gulp.task('buildfs_inline', ['clean', 'inline_images', 'inline']);
  107. gulp.task('buildfs_embed', ['buildfs_inline', 'embed']);
  108. gulp.task('default', ['buildfs_inline']);