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.

170 lines
4.6 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 remover = require('gulp-remove-code');
  34. const dataFolder = 'espurna/data/';
  35. const staticFolder = 'espurna/static/';
  36. var toHeader = function(filename) {
  37. var source = dataFolder + filename;
  38. var destination = staticFolder + filename + '.h';
  39. var safename = filename.split('.').join('_');
  40. var wstream = fs.createWriteStream(destination);
  41. wstream.on('error', function (err) {
  42. log.error(err);
  43. });
  44. var data = fs.readFileSync(source);
  45. wstream.write('#define ' + safename + '_len ' + data.length + '\n');
  46. wstream.write('const uint8_t ' + safename + '[] PROGMEM = {');
  47. for (var i=0; i<data.length; i++) {
  48. if (0 === (i % 20)) {
  49. wstream.write('\n');
  50. }
  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. var htmllintReporter = function(filepath, issues) {
  60. if (issues.length > 0) {
  61. issues.forEach(function (issue) {
  62. log.info(
  63. '[gulp-htmllint] ' +
  64. filepath + ' [' +
  65. issue.line + ',' +
  66. issue.column + ']: ' +
  67. '(' + issue.code + ') ' +
  68. issue.msg
  69. );
  70. });
  71. process.exitCode = 1;
  72. }
  73. };
  74. gulp.task('build_certs', function() {
  75. toHeader('server.cer');
  76. toHeader('server.key');
  77. });
  78. gulp.task('csslint', function() {
  79. gulp.src('html/*.css').
  80. pipe(csslint({ids: false})).
  81. pipe(csslint.formatter());
  82. });
  83. gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
  84. toHeader('index.html.gz');
  85. });
  86. gulp.task('buildfs_inline', function() {
  87. var remover_config = {
  88. sensor: false,
  89. light: false,
  90. rfbridge: false
  91. };
  92. var modules = 'MODULES' in process.env ? process.env.MODULES : false;
  93. if (false === modules) {
  94. for (var i in remover_config) {
  95. remover_config[i] = true;
  96. }
  97. } else {
  98. var list = modules.split(' ');
  99. for (var i in list) {
  100. if (list[i] != "") {
  101. remover_config[list[i]] = true;
  102. }
  103. }
  104. }
  105. log.info("Modules: " + JSON.stringify(remover_config));
  106. return gulp.src('html/*.html').
  107. pipe(htmllint({
  108. 'failOnError': true,
  109. 'rules': {
  110. 'id-class-style': false,
  111. 'label-req-for': false,
  112. }
  113. }, htmllintReporter)).
  114. pipe(favicon()).
  115. pipe(inline({
  116. base: 'html/',
  117. js: [],
  118. css: [crass, inlineImages],
  119. disabledTypes: ['svg', 'img']
  120. })).
  121. pipe(remover(remover_config)).
  122. pipe(htmlmin({
  123. collapseWhitespace: true,
  124. removeComments: true,
  125. minifyCSS: true,
  126. minifyJS: true
  127. })).
  128. pipe(replace('pure-', 'p-')).
  129. pipe(gzip()).
  130. pipe(gulp.dest(dataFolder));
  131. });
  132. gulp.task('test', function() {
  133. return gulp.src('html/custom.js').
  134. pipe(remover({
  135. sensor: false,
  136. light: false,
  137. rfbridge: false
  138. })).
  139. pipe(gulp.dest('/home/xose/tmp/'));
  140. });
  141. gulp.task('default', ['buildfs_embeded']);