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.

205 lines
5.9 KiB

8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 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. // Dependencies
  19. // -----------------------------------------------------------------------------
  20. const gulp = require('gulp');
  21. const runSequence = require('run-sequence');
  22. const through = require('through2');
  23. const htmlmin = require('gulp-htmlmin');
  24. const inline = require('gulp-inline');
  25. const inlineImages = require('gulp-css-base64');
  26. const favicon = require('gulp-base64-favicon');
  27. const crass = require('gulp-crass');
  28. const htmllint = require('gulp-htmllint');
  29. const csslint = require('gulp-csslint');
  30. const rename = require('gulp-rename');
  31. const replace = require('gulp-replace');
  32. const remover = require('gulp-remove-code');
  33. const gzip = require('gulp-gzip');
  34. const path = require('path');
  35. // -----------------------------------------------------------------------------
  36. // Configuration
  37. // -----------------------------------------------------------------------------
  38. const htmlFolder = 'html/';
  39. const configFolder = 'espurna/config/';
  40. const dataFolder = 'espurna/data/';
  41. const staticFolder = 'espurna/static/';
  42. // -----------------------------------------------------------------------------
  43. // Methods
  44. // -----------------------------------------------------------------------------
  45. var toHeader = function(name, debug) {
  46. return through.obj(function (source, encoding, callback) {
  47. var parts = source.path.split(path.sep);
  48. var filename = parts[parts.length - 1];
  49. var safename = name || filename.split('.').join('_');
  50. // Generate output
  51. var output = '';
  52. output += '#define ' + safename + '_len ' + source.contents.length + '\n';
  53. output += 'const uint8_t ' + safename + '[] PROGMEM = {';
  54. for (var i=0; i<source.contents.length; i++) {
  55. if (i > 0) { output += ','; }
  56. if (0 === (i % 20)) { output += '\n'; }
  57. output += '0x' + ('00' + source.contents[i].toString(16)).slice(-2);
  58. }
  59. output += '\n};';
  60. // clone the contents
  61. var destination = source.clone();
  62. destination.path = source.path + '.h';
  63. destination.contents = Buffer.from(output);
  64. if (debug) {
  65. console.info('Image ' + filename + ' \tsize: ' + source.contents.length + ' bytes');
  66. }
  67. callback(null, destination);
  68. });
  69. };
  70. var htmllintReporter = function(filepath, issues) {
  71. if (issues.length > 0) {
  72. issues.forEach(function (issue) {
  73. console.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. var buildWebUI = function(module) {
  86. var modules = {'light': false, 'sensor': false, 'rfbridge': false, 'rfm69': false};
  87. if ('all' === module) {
  88. modules['light'] = true;
  89. modules['sensor'] = true;
  90. modules['rfbridge'] = true;
  91. modules['rfm69'] = false; // we will never be adding this except when building RFM69GW
  92. } else if ('small' !== module) {
  93. modules[module] = true;
  94. }
  95. return gulp.src(htmlFolder + '*.html').
  96. pipe(htmllint({
  97. 'failOnError': true,
  98. 'rules': {
  99. 'id-class-style': false,
  100. 'label-req-for': false,
  101. }
  102. }, htmllintReporter)).
  103. pipe(favicon()).
  104. pipe(inline({
  105. base: htmlFolder,
  106. js: [],
  107. css: [crass, inlineImages],
  108. disabledTypes: ['svg', 'img']
  109. })).
  110. pipe(remover(modules)).
  111. pipe(htmlmin({
  112. collapseWhitespace: true,
  113. removeComments: true,
  114. minifyCSS: true,
  115. minifyJS: true
  116. })).
  117. pipe(replace('pure-', 'p-')).
  118. pipe(gzip()).
  119. pipe(rename('index.' + module + '.html.gz')).
  120. pipe(gulp.dest(dataFolder)).
  121. pipe(toHeader('webui_image', true)).
  122. pipe(gulp.dest(staticFolder));
  123. };
  124. // -----------------------------------------------------------------------------
  125. // Tasks
  126. // -----------------------------------------------------------------------------
  127. gulp.task('certs', function() {
  128. gulp.src(dataFolder + 'server.*').
  129. pipe(toHeader(debug=false)).
  130. pipe(gulp.dest(staticFolder));
  131. });
  132. gulp.task('csslint', function() {
  133. gulp.src(htmlFolder + '*.css').
  134. pipe(csslint({ids: false})).
  135. pipe(csslint.formatter());
  136. });
  137. gulp.task('webui_small', function() {
  138. return buildWebUI('small');
  139. });
  140. gulp.task('webui_sensor', function() {
  141. return buildWebUI('sensor');
  142. });
  143. gulp.task('webui_light', function() {
  144. return buildWebUI('light');
  145. });
  146. gulp.task('webui_rfbridge', function() {
  147. return buildWebUI('rfbridge');
  148. });
  149. gulp.task('webui_rfm69', function() {
  150. return buildWebUI('rfm69');
  151. });
  152. gulp.task('webui_all', function() {
  153. return buildWebUI('all');
  154. });
  155. gulp.task('webui', function(cb) {
  156. runSequence([
  157. 'webui_small',
  158. 'webui_sensor',
  159. 'webui_light',
  160. 'webui_rfbridge',
  161. 'webui_rfm69',
  162. 'webui_all'
  163. ], cb);
  164. });
  165. gulp.task('default', ['webui']);