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.

136 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 uglify = require('gulp-uglify');
  24. const gzip = require('gulp-gzip');
  25. const inline = require('gulp-inline');
  26. const inlineImages = require('gulp-css-base64');
  27. const favicon = require('gulp-base64-favicon');
  28. const htmllint = require('gulp-htmllint');
  29. const log = require('fancy-log');
  30. const csslint = require('gulp-csslint');
  31. const crass = require('gulp-crass');
  32. const replace = require('gulp-replace');
  33. const dataFolder = 'espurna/data/';
  34. const staticFolder = 'espurna/static/';
  35. var toHeader = function(filename) {
  36. var source = dataFolder + filename;
  37. var destination = staticFolder + filename + '.h';
  38. var safename = filename.split('.').join('_');
  39. var wstream = fs.createWriteStream(destination);
  40. wstream.on('error', function (err) {
  41. log.error(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 (var i=0; i<data.length; i++) {
  47. if (0 === (i % 20)) {
  48. wstream.write('\n');
  49. }
  50. wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
  51. if (i < (data.length - 1)) {
  52. wstream.write(',');
  53. }
  54. }
  55. wstream.write('\n};');
  56. wstream.end();
  57. };
  58. var htmllintReporter = function(filepath, issues) {
  59. if (issues.length > 0) {
  60. issues.forEach(function (issue) {
  61. log.info(
  62. '[gulp-htmllint] ' +
  63. filepath + ' [' +
  64. issue.line + ',' +
  65. issue.column + ']: ' +
  66. '(' + issue.code + ') ' +
  67. issue.msg
  68. );
  69. });
  70. process.exitCode = 1;
  71. }
  72. };
  73. gulp.task('build_certs', function() {
  74. toHeader('server.cer');
  75. toHeader('server.key');
  76. });
  77. gulp.task('csslint', function() {
  78. gulp.src('html/*.css').
  79. pipe(csslint({ids: false})).
  80. pipe(csslint.formatter());
  81. });
  82. gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
  83. toHeader('index.html.gz');
  84. });
  85. gulp.task('buildfs_inline', function() {
  86. return gulp.src('html/*.html').
  87. pipe(htmllint({
  88. 'failOnError': true,
  89. 'rules': {
  90. 'id-class-style': false,
  91. 'label-req-for': false,
  92. }
  93. }, htmllintReporter)).
  94. pipe(favicon()).
  95. pipe(inline({
  96. base: 'html/',
  97. js: [uglify],
  98. css: [crass, inlineImages],
  99. disabledTypes: ['svg', 'img']
  100. })).
  101. pipe(htmlmin({
  102. collapseWhitespace: true,
  103. removeComments: true,
  104. minifyCSS: true,
  105. minifyJS: true
  106. })).
  107. pipe(replace('pure-', 'p-')).
  108. pipe(gzip()).
  109. pipe(gulp.dest(dataFolder));
  110. });
  111. gulp.task('default', ['buildfs_embeded']);