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.

91 lines
2.7 KiB

8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. /*
  2. ESP8266 file system builder
  3. Copyright (C) 2016-2017 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 htmlmin = require('gulp-htmlmin');
  21. const cleancss = require('gulp-clean-css');
  22. const uglify = require('gulp-uglify');
  23. const gzip = require('gulp-gzip');
  24. const del = require('del');
  25. const inline = require('gulp-inline');
  26. const inlineImages = require('gulp-css-base64');
  27. const favicon = require('gulp-base64-favicon');
  28. const dataFolder = 'espurna/static/';
  29. gulp.task('clean', function() {
  30. del([ dataFolder + '*']);
  31. return true;
  32. });
  33. gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
  34. var source = dataFolder + 'index.html.gz';
  35. var destination = dataFolder + 'index.html.gz.h';
  36. var wstream = fs.createWriteStream(destination);
  37. wstream.on('error', function (err) {
  38. console.log(err);
  39. });
  40. var data = fs.readFileSync(source);
  41. wstream.write('#define index_html_gz_len ' + data.length + '\n');
  42. wstream.write('const uint8_t index_html_gz[] PROGMEM = {')
  43. for (i=0; i<data.length; i++) {
  44. if (i % 20 == 0) wstream.write("\n");
  45. wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
  46. if (i<data.length-1) wstream.write(',');
  47. }
  48. wstream.write('\n};')
  49. wstream.end();
  50. del([source]);
  51. });
  52. gulp.task('buildfs_inline', ['clean'], function() {
  53. return gulp.src('html/*.html')
  54. .pipe(favicon())
  55. .pipe(inline({
  56. base: 'html/',
  57. js: uglify,
  58. css: [cleancss, inlineImages],
  59. disabledTypes: ['svg', 'img']
  60. }))
  61. .pipe(htmlmin({
  62. collapseWhitespace: true,
  63. removeComments: true,
  64. minifyCSS: true,
  65. minifyJS: true
  66. }))
  67. .pipe(gzip())
  68. .pipe(gulp.dest(dataFolder));
  69. })
  70. gulp.task('default', ['buildfs_embeded']);