|
|
- /*
-
- ESP8266 file system builder
-
- Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
-
- 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
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- */
-
- // -----------------------------------------------------------------------------
- // File system builder
- // -----------------------------------------------------------------------------
-
- const fs = require('fs');
- const gulp = require('gulp');
- const plumber = require('gulp-plumber');
- const htmlmin = require('gulp-htmlmin');
- const cleancss = require('gulp-clean-css');
- const uglify = require('gulp-uglify');
- const gzip = require('gulp-gzip');
- const del = require('del');
- const useref = require('gulp-useref');
- const gulpif = require('gulp-if');
- const inline = require('gulp-inline');
- const inlineImages = require('gulp-css-base64');
- const favicon = require('gulp-base64-favicon');
-
- const dataFolder = 'espurna/data/';
-
- /* Clean destination folder */
- gulp.task('clean', function() {
- del([ dataFolder + '*']);
- return true;
- });
-
- /* Copy static files */
- gulp.task('files', function() {
- return gulp.src([
- 'html/**/*.{jpg,jpeg,png,ico,gif}',
- 'html/fsversion'
- ])
- .pipe(gulp.dest(dataFolder));
- });
-
- gulp.task('embed', function() {
-
- var source = dataFolder + 'index.html.gz';
- var destination = dataFolder + '../config/data.h';
-
- var wstream = fs.createWriteStream(destination);
- wstream.on('error', function (err) {
- console.log(err);
- });
-
- var data = fs.readFileSync(source);
-
- wstream.write('#define index_html_gz_len ' + data.length + '\n');
- wstream.write('const uint8_t index_html_gz[] PROGMEM = {')
-
- for (i=0; i<data.length; i++) {
- wstream.write('0x' + ('00' + data[i].toString(16)).slice(-2));
- if (i<data.length-1) wstream.write(',');
- }
-
- wstream.write('};\n')
- wstream.end();
-
- });
-
- gulp.task('inline_images', function() {
- return gulp.src(['html/src/checkboxes.css'])
- .pipe(inlineImages({
- baseDir: "../"
- }))
- .pipe(gulp.dest('html/'));
- });
-
- /* Process HTML, CSS, JS, IMAGES and FAVICON --- INLINE --- */
- gulp.task('inline', function() {
- return gulp.src('html/*.html')
- .pipe(favicon())
- .pipe(inline({
- base: 'html/',
- js: uglify,
- css: cleancss,
- disabledTypes: ['svg', 'img']
- }))
- .pipe(htmlmin({
- collapseWhitespace: true,
- removeComments: true,
- minifyCSS: true,
- minifyJS: true
- }))
- .pipe(gzip())
- .pipe(gulp.dest(dataFolder));
- })
-
- /* Process HTML, CSS, JS */
- gulp.task('html', function() {
- return gulp.src('html/*.html')
- .pipe(useref())
- .pipe(plumber())
- .pipe(gulpif('*.css', cleancss()))
- .pipe(gulpif('*.js', uglify()))
- .pipe(gulpif('*.html', htmlmin({
- collapseWhitespace: true,
- removeComments: true,
- minifyCSS: true,
- minifyJS: true
- })))
- .pipe(gzip())
- .pipe(gulp.dest(dataFolder));
- });
-
- /* Build file system */
- gulp.task('buildfs_split', ['clean', 'files', 'html']);
- gulp.task('buildfs_inline', ['clean', 'inline_images', 'inline']);
- gulp.task('buildfs_embed', ['buildfs_inline', 'embed']);
- gulp.task('default', ['buildfs_inline']);
|