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.

174 lines
5.0 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
8 years ago
8 years ago
8 years ago
6 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 csslint = require('gulp-csslint');
  30. const crass = require('gulp-crass');
  31. const replace = require('gulp-replace');
  32. const remover = require('gulp-remove-code');
  33. const map = require('map-stream');
  34. const dataFolder = 'espurna/data/';
  35. const staticFolder = 'espurna/static/';
  36. var buildHeaderFile = function() {
  37. String.prototype.replaceAll = function(search, replacement) {
  38. var target = this;
  39. return target.split(search).join(replacement);
  40. };
  41. return map(function(file, cb) {
  42. var parts = file.path.split("/");
  43. var filename = parts[parts.length - 1];
  44. var destination = staticFolder + filename + ".h";
  45. var safename = filename.replaceAll('.', '_');
  46. var wstream = fs.createWriteStream(destination);
  47. wstream.on('error', function (err) {
  48. console.error(err);
  49. });
  50. var data = fs.readFileSync(file.path);
  51. wstream.write('#define ' + safename + '_len ' + data.length + '\n');
  52. wstream.write('const uint8_t ' + safename + '[] PROGMEM = {');
  53. for (var i=0; i<data.length; i++) {
  54. if (0 === (i % 20)) {
  55. wstream.write('\n');
  56. }
  57. wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
  58. if (i < (data.length - 1)) {
  59. wstream.write(',');
  60. }
  61. }
  62. wstream.write('\n};');
  63. wstream.end();
  64. var fstat = fs.statSync(file.path);
  65. console.log("Created '" + filename + "' size: " + fstat.size + " bytes");
  66. cb(0, destination);
  67. });
  68. }
  69. var htmllintReporter = function(filepath, issues) {
  70. if (issues.length > 0) {
  71. issues.forEach(function (issue) {
  72. console.info(
  73. '[gulp-htmllint] ' +
  74. filepath + ' [' +
  75. issue.line + ',' +
  76. issue.column + ']: ' +
  77. '(' + issue.code + ') ' +
  78. issue.msg
  79. );
  80. });
  81. process.exitCode = 1;
  82. }
  83. };
  84. gulp.task('build_certs', function() {
  85. gulp.src(dataFolder + 'server.*').
  86. pipe(buildHeaderFile());
  87. });
  88. gulp.task('csslint', function() {
  89. gulp.src('html/*.css').
  90. pipe(csslint({ids: false})).
  91. pipe(csslint.formatter());
  92. });
  93. gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
  94. gulp.src(dataFolder + 'index.*').
  95. pipe(buildHeaderFile());
  96. });
  97. gulp.task('buildfs_inline', function() {
  98. var remover_config = {
  99. sensor: false,
  100. light: false,
  101. rfbridge: false
  102. };
  103. var modules = 'WEBUI_MODULES' in process.env ? process.env.WEBUI_MODULES : false;
  104. if (false === modules || "all" === modules) {
  105. for (var i in remover_config) {
  106. remover_config[i] = true;
  107. }
  108. } else {
  109. var list = modules.split(' ');
  110. for (var i in list) {
  111. if (list[i] != "") {
  112. remover_config[list[i]] = true;
  113. }
  114. }
  115. }
  116. console.info("Modules " + JSON.stringify(remover_config));
  117. return gulp.src('html/*.html').
  118. pipe(htmllint({
  119. 'failOnError': true,
  120. 'rules': {
  121. 'id-class-style': false,
  122. 'label-req-for': false,
  123. }
  124. }, htmllintReporter)).
  125. pipe(favicon()).
  126. pipe(inline({
  127. base: 'html/',
  128. js: [],
  129. css: [crass, inlineImages],
  130. disabledTypes: ['svg', 'img']
  131. })).
  132. pipe(remover(remover_config)).
  133. pipe(htmlmin({
  134. collapseWhitespace: true,
  135. removeComments: true,
  136. minifyCSS: true,
  137. minifyJS: true
  138. })).
  139. pipe(replace('pure-', 'p-')).
  140. pipe(gzip()).
  141. pipe(gulp.dest(dataFolder));
  142. });
  143. gulp.task('default', ['buildfs_embeded']);