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.

154 lines
4.4 KiB

8 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
8 years ago
8 years ago
  1. /*
  2. ESP8266 file system builder
  3. Copyright (C) 2016-2017 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. // -----------------------------------------------------------------------------
  16. // File system builder
  17. // -----------------------------------------------------------------------------
  18. const fs = require('fs');
  19. const gulp = require('gulp');
  20. const htmlmin = require('gulp-htmlmin');
  21. const uglify = require('gulp-uglify');
  22. const gzip = require('gulp-gzip');
  23. const inline = require('gulp-inline');
  24. const inlineImages = require('gulp-css-base64');
  25. const favicon = require('gulp-base64-favicon');
  26. const htmllint = require('gulp-htmllint');
  27. const log = require('fancy-log');
  28. const csslint = require('gulp-csslint');
  29. const i18n = require('gulp-international');
  30. const crass = require('gulp-crass');
  31. const replace = require('gulp-replace');
  32. const dataFolder = 'espurna/data/';
  33. const staticFolder = 'espurna/static/';
  34. // -----------------------------------------------------------------------------
  35. const map = require('map-stream');
  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.log(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 (i % 20 == 0) wstream.write('\n');
  55. wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
  56. if (i<data.length-1) {
  57. wstream.write(',');
  58. }
  59. }
  60. wstream.write('\n};');
  61. wstream.end();
  62. cb(0, file);
  63. });
  64. }
  65. var htmllintReporter = function(filepath, issues) {
  66. if (issues.length > 0) {
  67. issues.forEach(function (issue) {
  68. log.info(
  69. '[gulp-htmllint] ' +
  70. filepath + ' [' +
  71. issue.line + ',' +
  72. issue.column + ']: ' +
  73. '(' + issue.code + ') ' +
  74. issue.msg
  75. );
  76. });
  77. process.exitCode = 1;
  78. }
  79. };
  80. gulp.task('build_certs', function() {
  81. toHeader('server.cer');
  82. toHeader('server.key');
  83. });
  84. gulp.task('csslint', function() {
  85. gulp.src('html/*.css').
  86. pipe(csslint({ids: false})).
  87. pipe(csslint.formatter());
  88. });
  89. gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
  90. gulp.src(dataFolder + 'index.*')
  91. .pipe(buildHeaderFile());
  92. });
  93. gulp.task('buildfs_inline', function() {
  94. return gulp.src('html/*.html')
  95. .pipe(htmllint({
  96. 'failOnError': true,
  97. 'rules': {
  98. 'id-class-style': false,
  99. 'label-req-for': false,
  100. }
  101. }, htmllintReporter))
  102. .pipe(favicon())
  103. .pipe(inline({
  104. base: 'html/',
  105. js: [uglify],
  106. css: [crass, inlineImages],
  107. disabledTypes: ['svg', 'img']
  108. }))
  109. .pipe(htmlmin({
  110. collapseWhitespace: true,
  111. removeComments: true,
  112. minifyCSS: true,
  113. minifyJS: true
  114. }))
  115. .pipe(i18n({
  116. warn: true,
  117. whitelist: ['ca_ES'],
  118. filename: '${name}.${lang}.${ext}',
  119. locales: './html/locales/'
  120. }))
  121. .pipe(replace('pure-', 'p-'))
  122. .pipe(gzip())
  123. .pipe(gulp.dest(dataFolder));
  124. })
  125. gulp.task('default', ['buildfs_embeded']);