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.

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