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.

99 lines
2.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
  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 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('files', ['clean'], function() {
  34. return gulp.src([
  35. 'html/**/*.{jpg,jpeg,png,ico,gif}',
  36. 'html/fsversion'
  37. ])
  38. .pipe(gulp.dest(dataFolder));
  39. });
  40. gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
  41. var source = dataFolder + 'index.html.gz';
  42. var destination = dataFolder + 'index.html.gz.h';
  43. var wstream = fs.createWriteStream(destination);
  44. wstream.on('error', function (err) {
  45. console.log(err);
  46. });
  47. var data = fs.readFileSync(source);
  48. wstream.write('#define index_html_gz_len ' + data.length + '\n');
  49. wstream.write('const uint8_t index_html_gz[] PROGMEM = {')
  50. for (i=0; i<data.length; i++) {
  51. if (i % 1000 == 0) wstream.write("\n");
  52. wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
  53. if (i<data.length-1) wstream.write(',');
  54. }
  55. wstream.write('\n};')
  56. wstream.end();
  57. del([source]);
  58. });
  59. gulp.task('buildfs_inline', ['clean'], function() {
  60. return gulp.src('html/*.html')
  61. .pipe(favicon())
  62. .pipe(inline({
  63. base: 'html/',
  64. js: uglify,
  65. css: [cleancss, inlineImages],
  66. disabledTypes: ['svg', 'img']
  67. }))
  68. .pipe(htmlmin({
  69. collapseWhitespace: true,
  70. removeComments: true,
  71. minifyCSS: true,
  72. minifyJS: true
  73. }))
  74. .pipe(gzip())
  75. .pipe(gulp.dest(dataFolder));
  76. })
  77. gulp.task('default', ['buildfs_embeded']);