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.

130 lines
3.8 KiB

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