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.

117 lines
3.5 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 htmllint = require('gulp-htmllint');
  28. const gutil = require('gulp-util');
  29. const dataFolder = 'espurna/data/';
  30. const staticFolder = 'espurna/static/';
  31. String.prototype.replaceAll = function(search, replacement) {
  32. var target = this;
  33. return target.split(search).join(replacement);
  34. };
  35. var toHeader = function(filename) {
  36. var source = dataFolder + filename;
  37. var destination = staticFolder + filename + '.h';
  38. var safename = filename.replaceAll('.', '_');
  39. var wstream = fs.createWriteStream(destination);
  40. wstream.on('error', function (err) {
  41. console.log(err);
  42. });
  43. var data = fs.readFileSync(source);
  44. wstream.write('#define ' + safename + '_len ' + data.length + '\n');
  45. wstream.write('const uint8_t ' + safename + '[] PROGMEM = {')
  46. for (i=0; i<data.length; i++) {
  47. if (i % 20 == 0) wstream.write("\n");
  48. wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
  49. if (i<data.length-1) wstream.write(',');
  50. }
  51. wstream.write('\n};')
  52. wstream.end();
  53. }
  54. function htmllintReporter(filepath, issues) {
  55. if (issues.length > 0) {
  56. issues.forEach(function (issue) {
  57. gutil.log(gutil.colors.cyan('[gulp-htmllint] ') + gutil.colors.white(filepath + ' [' + issue.line + ',' + issue.column + ']: ') + gutil.colors.red('(' + issue.code + ') ' + issue.msg));
  58. });
  59. process.exitCode = 1;
  60. }
  61. }
  62. gulp.task('build_certs', function() {
  63. toHeader('server.cer');
  64. toHeader('server.key');
  65. });
  66. gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
  67. toHeader('index.html.gz');
  68. });
  69. gulp.task('buildfs_inline', function() {
  70. return gulp.src('html/*.html')
  71. .pipe(htmllint({
  72. 'failOnError': true,
  73. 'rules': {
  74. 'id-class-style': false,
  75. 'label-req-for': false,
  76. }
  77. }, htmllintReporter))
  78. .pipe(favicon())
  79. .pipe(inline({
  80. base: 'html/',
  81. js: [uglify],
  82. css: [cleancss, inlineImages],
  83. disabledTypes: ['svg', 'img']
  84. }))
  85. .pipe(htmlmin({
  86. collapseWhitespace: true,
  87. removeComments: true,
  88. minifyCSS: true,
  89. minifyJS: true
  90. }))
  91. .pipe(gzip())
  92. .pipe(gulp.dest(dataFolder));
  93. })
  94. gulp.task('default', ['buildfs_embeded']);