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.

142 lines
4.2 KiB

8 years ago
8 years ago
8 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 cleancss = require('gulp-clean-css');
  22. const uglify = require('gulp-uglify');
  23. const gzip = require('gulp-gzip');
  24. const inline = require('gulp-inline');
  25. const inlineImages = require('gulp-css-base64');
  26. const favicon = require('gulp-base64-favicon');
  27. <<<<<<< Updated upstream
  28. =======
  29. const htmllint = require('gulp-htmllint');
  30. const gutil = require('gulp-util');
  31. const csslint = require('gulp-csslint');
  32. const i18n = require('gulp-international');
  33. // -----------------------------------------------------------------------------
  34. >>>>>>> Stashed changes
  35. const dataFolder = 'espurna/data/';
  36. const staticFolder = 'espurna/static/';
  37. // -----------------------------------------------------------------------------
  38. const map = require('map-stream');
  39. var buildHeaderFile = function() {
  40. String.prototype.replaceAll = function(search, replacement) {
  41. var target = this;
  42. return target.split(search).join(replacement);
  43. };
  44. return map(function(file, cb) {
  45. var parts = file.path.split("/");
  46. var filename = parts[parts.length - 1];
  47. var destination = staticFolder + filename + ".h";
  48. var safename = filename.replaceAll('.', '_');
  49. var wstream = fs.createWriteStream(destination);
  50. wstream.on('error', function (err) {
  51. console.log(err);
  52. });
  53. <<<<<<< Updated upstream
  54. wstream.write('#define ' + safename + '_len ' + data.length + '\n');
  55. wstream.write('const uint8_t ' + safename + '[] PROGMEM = {')
  56. for (i=0; i<data.length; i++) {
  57. if (i % 20 == 0) wstream.write("\n");
  58. wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
  59. if (i<data.length-1) wstream.write(',');
  60. }
  61. wstream.write('\n};')
  62. wstream.end();
  63. =======
  64. var data = fs.readFileSync(file.path);
  65. wstream.write('#define ' + safename + '_len ' + data.length + '\n');
  66. wstream.write('const uint8_t ' + safename + '[] PROGMEM = {');
  67. for (var i=0; i<data.length; i++) {
  68. if (i % 20 == 0) wstream.write('\n');
  69. wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
  70. if (i<data.length-1) {
  71. wstream.write(',');
  72. }
  73. }
  74. wstream.write('\n};');
  75. wstream.end();
  76. cb(0, file);
  77. });
  78. >>>>>>> Stashed changes
  79. }
  80. gulp.task('build_certs', function() {
  81. toHeader('server.cer');
  82. toHeader('server.key');
  83. });
  84. gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
  85. gulp.src(dataFolder + 'index.*')
  86. .pipe(buildHeaderFile());
  87. });
  88. gulp.task('buildfs_inline', function() {
  89. return gulp.src('html/*.html')
  90. .pipe(favicon())
  91. .pipe(inline({
  92. base: 'html/',
  93. js: uglify,
  94. css: [cleancss, inlineImages],
  95. disabledTypes: ['svg', 'img']
  96. }))
  97. .pipe(htmlmin({
  98. collapseWhitespace: true,
  99. removeComments: true,
  100. minifyCSS: true,
  101. minifyJS: true
  102. }))
  103. .pipe(i18n({
  104. warn: true,
  105. whitelist: ['ca_ES'],
  106. filename: '${name}.${lang}.${ext}',
  107. locales: './html/locales/'
  108. }))
  109. .pipe(gzip())
  110. .pipe(gulp.dest(dataFolder));
  111. })
  112. gulp.task('default', ['buildfs_embeded']);