Browse Source

Translate and build files

i18n
Xose Pérez 6 years ago
parent
commit
c11fb91904
2 changed files with 64 additions and 52 deletions
  1. +62
    -50
      code/gulpfile.js
  2. +2
    -2
      code/package.json

+ 62
- 50
code/gulpfile.js View File

@ -2,7 +2,7 @@
ESP8266 file system builder ESP8266 file system builder
Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -19,9 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/*eslint quotes: ["error", "single"]*/
/*eslint-env es6*/
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// File system builder // File system builder
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -35,84 +32,94 @@ const gzip = require('gulp-gzip');
const inline = require('gulp-inline'); const inline = require('gulp-inline');
const inlineImages = require('gulp-css-base64'); const inlineImages = require('gulp-css-base64');
const favicon = require('gulp-base64-favicon'); const favicon = require('gulp-base64-favicon');
<<<<<<< Updated upstream
=======
const htmllint = require('gulp-htmllint'); const htmllint = require('gulp-htmllint');
const gutil = require('gulp-util'); const gutil = require('gulp-util');
const csslint = require('gulp-csslint'); const csslint = require('gulp-csslint');
const i18n = require('gulp-international');
// -----------------------------------------------------------------------------
>>>>>>> Stashed changes
const dataFolder = 'espurna/data/'; const dataFolder = 'espurna/data/';
const staticFolder = 'espurna/static/'; const staticFolder = 'espurna/static/';
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.split(search).join(replacement);
};
// -----------------------------------------------------------------------------
const map = require('map-stream');
var toHeader = function(filename) {
var buildHeaderFile = function() {
var source = dataFolder + filename;
var destination = staticFolder + filename + '.h';
var safename = filename.replaceAll('.', '_');
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.split(search).join(replacement);
};
var wstream = fs.createWriteStream(destination);
wstream.on('error', function (err) {
console.log(err);
});
return map(function(file, cb) {
var data = fs.readFileSync(source);
var parts = file.path.split("/");
var filename = parts[parts.length - 1];
var destination = staticFolder + filename + ".h";
var safename = filename.replaceAll('.', '_');
var wstream = fs.createWriteStream(destination);
wstream.on('error', function (err) {
console.log(err);
});
<<<<<<< Updated upstream
wstream.write('#define ' + safename + '_len ' + data.length + '\n'); wstream.write('#define ' + safename + '_len ' + data.length + '\n');
wstream.write('const uint8_t ' + safename + '[] PROGMEM = {');
wstream.write('const uint8_t ' + safename + '[] PROGMEM = {')
for (var i=0; i<data.length; i++) {
if (i % 20 == 0) wstream.write('\n');
for (i=0; i<data.length; i++) {
if (i % 20 == 0) wstream.write("\n");
wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2)); wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
if (i<data.length-1) {
wstream.write(',');
}
if (i<data.length-1) wstream.write(',');
} }
wstream.write('\n};');
wstream.write('\n};')
wstream.end(); wstream.end();
=======
var data = fs.readFileSync(file.path);
wstream.write('#define ' + safename + '_len ' + data.length + '\n');
wstream.write('const uint8_t ' + safename + '[] PROGMEM = {');
};
for (var i=0; i<data.length; i++) {
if (i % 20 == 0) wstream.write('\n');
wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
if (i<data.length-1) {
wstream.write(',');
}
}
function htmllintReporter(filepath, issues) {
if (issues.length > 0) {
issues.forEach(function (issue) {
gutil.log(gutil.colors.cyan('[gulp-htmllint] ') + gutil.colors.white(filepath + ' [' + issue.line + ',' + issue.column + ']: ') + gutil.colors.red('(' + issue.code + ') ' + issue.msg));
});
process.exitCode = 1;
}
};
wstream.write('\n};');
wstream.end();
cb(0, file);
});
>>>>>>> Stashed changes
}
gulp.task('build_certs', function() { gulp.task('build_certs', function() {
toHeader('server.cer'); toHeader('server.cer');
toHeader('server.key'); toHeader('server.key');
}); });
gulp.task('csslint', function() {
gulp.src('html/*.css')
.pipe(csslint({ids: false}))
.pipe(csslint.formatter());
});
gulp.task('buildfs_embeded', ['buildfs_inline'], function() { gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
toHeader('index.html.gz');
gulp.src(dataFolder + 'index.*')
.pipe(buildHeaderFile());
}); });
gulp.task('buildfs_inline', function() { gulp.task('buildfs_inline', function() {
return gulp.src('html/*.html') return gulp.src('html/*.html')
.pipe(htmllint({
'failOnError': true,
'rules': {
'id-class-style': false,
'label-req-for': false,
}
}, htmllintReporter))
.pipe(favicon()) .pipe(favicon())
.pipe(inline({ .pipe(inline({
base: 'html/', base: 'html/',
js: [uglify],
js: uglify,
css: [cleancss, inlineImages], css: [cleancss, inlineImages],
disabledTypes: ['svg', 'img'] disabledTypes: ['svg', 'img']
})) }))
@ -122,9 +129,14 @@ gulp.task('buildfs_inline', function() {
minifyCSS: true, minifyCSS: true,
minifyJS: true minifyJS: true
})) }))
.pipe(i18n({
warn: true,
whitelist: ['ca_ES'],
filename: '${name}.${lang}.${ext}',
locales: './html/locales/'
}))
.pipe(gzip()) .pipe(gzip())
.pipe(gulp.dest(dataFolder)); .pipe(gulp.dest(dataFolder));
});
})
gulp.task('default', ['buildfs_embeded']); gulp.task('default', ['buildfs_embeded']);

+ 2
- 2
code/package.json View File

@ -11,11 +11,11 @@
"gulp-base64-favicon": "^1.0.2", "gulp-base64-favicon": "^1.0.2",
"gulp-clean-css": "^3.4.2", "gulp-clean-css": "^3.4.2",
"gulp-css-base64": "^1.3.4", "gulp-css-base64": "^1.3.4",
"gulp-csslint": "^1.0.0",
"gulp-gzip": "^1.4.0", "gulp-gzip": "^1.4.0",
"gulp-htmllint": "0.0.14",
"gulp-htmlmin": "^2.0.0", "gulp-htmlmin": "^2.0.0",
"gulp-i18n-localize": "^1.2.7",
"gulp-inline": "^0.1.1", "gulp-inline": "^0.1.1",
"gulp-international": "^1.1.0",
"gulp-uglify": "^1.5.3", "gulp-uglify": "^1.5.3",
"gulp-util": "^3.0.8" "gulp-util": "^3.0.8"
}, },


Loading…
Cancel
Save