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.

123 lines
3.6 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. /* Process HTML, CSS, JS, IMAGES and FAVICON --- INLINE --- */
  63. gulp.task('inline', function() {
  64. return gulp.src('html/*.html')
  65. .pipe(favicon())
  66. .pipe(inline({
  67. base: 'html/',
  68. js: uglify,
  69. css: [cleancss, inlineImages],
  70. disabledTypes: ['svg', 'img']
  71. }))
  72. .pipe(htmlmin({
  73. collapseWhitespace: true,
  74. removeComments: true,
  75. minifyCSS: true,
  76. minifyJS: true
  77. }))
  78. .pipe(gzip())
  79. .pipe(gulp.dest(dataFolder));
  80. })
  81. /* Process HTML, CSS, JS */
  82. gulp.task('html', function() {
  83. return gulp.src('html/*.html')
  84. .pipe(useref())
  85. .pipe(plumber())
  86. .pipe(gulpif('*.css', cleancss()))
  87. .pipe(gulpif('*.js', uglify()))
  88. .pipe(gulpif('*.html', htmlmin({
  89. collapseWhitespace: true,
  90. removeComments: true,
  91. minifyCSS: true,
  92. minifyJS: true
  93. })))
  94. .pipe(gzip())
  95. .pipe(gulp.dest(dataFolder));
  96. });
  97. /* Build file system */
  98. gulp.task('buildfs_split', ['clean', 'files', 'html']);
  99. gulp.task('buildfs_inline', ['clean', 'inline']);
  100. gulp.task('buildfs_embed', ['buildfs_inline', 'embed']);
  101. gulp.task('default', ['buildfs_inline']);