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.

103 lines
3.1 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. // Create the certificates following the instructions in
  54. // https://www.akadia.com/services/ssh_test_certificate.html
  55. // and place the key and crt files in the espurna/data/ folder
  56. // Then tun this task to create the .h files from those
  57. toHeader('espurna.crt');
  58. toHeader('espurna.key');
  59. });
  60. gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
  61. toHeader('index.html.gz');
  62. });
  63. gulp.task('buildfs_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. gulp.task('default', ['buildfs_embeded']);