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.

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