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.9 KiB

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 inline = require('gulp-inline');
  25. const inlineImages = require('gulp-css-base64');
  26. const favicon = require('gulp-base64-favicon');
  27. const dataFolder = 'espurna/data/';
  28. const staticFolder = 'espurna/static/';
  29. String.prototype.replaceAll = function(search, replacement) {
  30. var target = this;
  31. return target.split(search).join(replacement);
  32. };
  33. var toHeader = function(filename) {
  34. var source = dataFolder + filename;
  35. var destination = staticFolder + filename + '.h';
  36. var safename = filename.replaceAll('.', '_');
  37. var wstream = fs.createWriteStream(destination);
  38. wstream.on('error', function (err) {
  39. console.log(err);
  40. });
  41. var data = fs.readFileSync(source);
  42. wstream.write('#define ' + safename + '_len ' + data.length + '\n');
  43. wstream.write('const uint8_t ' + safename + '[] PROGMEM = {')
  44. for (i=0; i<data.length; i++) {
  45. if (i % 20 == 0) wstream.write("\n");
  46. wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
  47. if (i<data.length-1) wstream.write(',');
  48. }
  49. wstream.write('\n};')
  50. wstream.end();
  51. }
  52. gulp.task('build_certs', function() {
  53. toHeader('server.cer');
  54. toHeader('server.key');
  55. });
  56. gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
  57. toHeader('index.html.gz');
  58. });
  59. gulp.task('buildfs_inline', 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']);