uci-doc/gulpfile.js

175 lines
5.1 KiB
JavaScript
Raw Normal View History

2020-01-12 06:33:02 -08:00
const gulp = require('gulp');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const minifyCSS = require('gulp-csso');
const cleanCSS = require('gulp-clean-css');
const autoprefixer = require('gulp-autoprefixer');
2020-03-15 08:37:48 -07:00
const iconfont = require('gulp-iconfont');
2020-01-12 06:33:02 -08:00
2020-03-15 08:37:48 -07:00
const realFavicon = require('gulp-real-favicon');
2020-03-15 10:38:10 -07:00
const path = require('path');
2020-01-12 06:33:02 -08:00
const fs = require('fs');
const svgSprite = require('gulp-svg-sprite');
var CSSDEST = 'static/'
var FAVICON_DATA_FILE = 'src/favicon/faviconData.json';
2020-03-15 08:37:48 -07:00
var TIMESTAMP = Math.round(Date.now() / 1000);
2020-01-12 06:33:02 -08:00
2020-03-15 08:37:48 -07:00
gulp.task('sass', function () {
return gulp.src('src/sass/main.scss')
.pipe(sass({ errLogToConsole: true }))
.pipe(cleanCSS({ format: 'beautify' }))
.pipe(autoprefixer({
cascade: false
}))
.pipe(gulp.dest(CSSDEST))
.pipe(cleanCSS())
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest(CSSDEST))
2020-01-12 06:33:02 -08:00
});
2020-03-15 08:37:48 -07:00
gulp.task('favicon-generate', function (done) {
realFavicon.generateFavicon({
masterPicture: 'src/favicon/favicon-master.svg',
dest: 'static/favicon',
iconsPath: '/',
design: {
ios: {
pictureAspect: 'backgroundAndMargin',
backgroundColor: '#ffffff',
margin: '14%',
assets: {
ios6AndPriorIcons: false,
ios7AndLaterIcons: false,
precomposedIcons: false,
declareOnlyDefaultIcon: true
}
},
desktopBrowser: {},
windows: {
pictureAspect: 'whiteSilhouette',
backgroundColor: '#2b5797',
onConflict: 'override',
assets: {
windows80Ie10Tile: false,
windows10Ie11EdgeTiles: {
small: false,
medium: true,
big: false,
rectangle: false
}
}
},
androidChrome: {
pictureAspect: 'shadow',
themeColor: '#ffffff',
manifest: {
display: 'standalone',
orientation: 'notSet',
onConflict: 'override',
declared: true
},
assets: {
legacyIcon: false,
lowResolutionIcons: false
}
},
safariPinnedTab: {
pictureAspect: 'blackAndWhite',
threshold: 74.21875,
themeColor: '#5bbad5'
}
},
settings: {
scalingAlgorithm: 'Mitchell',
errorOnImageTooSmall: false,
readmeFile: false,
htmlCodeFile: false,
usePathAsIs: false
},
markupFile: FAVICON_DATA_FILE
}, function () {
done();
});
2020-01-12 06:33:02 -08:00
});
2020-03-15 08:37:48 -07:00
gulp.task('favicon-check-update', function (done) {
var currentVersion = JSON.parse(fs.readFileSync(FAVICON_DATA_FILE)).version;
realFavicon.checkForUpdates(currentVersion, function (err) {
if (err) {
throw err;
}
});
done();
2020-01-12 06:33:02 -08:00
});
2020-03-15 08:37:48 -07:00
gulp.task('svg-sprite', function () {
config = {
svg: {
xmlDeclaration: false,
rootAttributes: {
style: "position: absolute; width: 0; height: 0; overflow: hidden;"
}
},
mode: {
inline: true,
symbol: {
dest: './',
sprite: 'svg-icon-symbols.html',
bust: false,
}
}
};
2020-01-12 06:33:02 -08:00
2020-03-15 08:37:48 -07:00
return gulp.src('src/icons/*.svg')
.pipe(svgSprite(config))
.pipe(gulp.dest('layouts/partials/'));
});
gulp.task('iconfont', function () {
2020-03-15 10:38:10 -07:00
var lastUnicode = 0xEA01;
var files = fs.readdirSync('src/iconfont');
// Filter files with containing unicode value
// and set last unicode
files.forEach(function (file) {
var basename = path.basename(file);
var matches = basename.match(/^(?:((?:u[0-9a-f]{4,6},?)+)\-)?(.+)\.svg$/i);
var currentCode = -1;
if (matches && matches[1]) {
currentCode = parseInt(matches[1].split('u')[1], 16);
}
if (currentCode >= lastUnicode) {
lastUnicode = ++currentCode;
}
});
return gulp.src(['src/iconfont/*.svg'])
2020-03-15 08:37:48 -07:00
.pipe(iconfont({
2020-03-15 10:38:10 -07:00
startUnicode: lastUnicode,
fontName: 'GeekdocIcons', // required
2020-03-15 08:37:48 -07:00
prependUnicode: true, // recommended option
2020-03-15 10:38:10 -07:00
normalize: true,
fontHeight: 1001,
centerHorizontally: true,
formats: ['woff', 'woff2'], // default, 'woff2' and 'svg' are available
2020-03-15 08:37:48 -07:00
timestamp: TIMESTAMP, // recommended to get consistent builds when watching files
}))
2020-03-15 10:38:10 -07:00
.pipe(gulp.dest('static/fonts/'));
2020-01-12 06:33:02 -08:00
});
gulp.task('default', gulp.series(
2020-03-15 08:37:48 -07:00
'sass',
'svg-sprite',
2020-03-15 10:38:10 -07:00
'iconfont',
2020-03-15 08:37:48 -07:00
'favicon-check-update',
'favicon-generate'
2020-01-12 06:33:02 -08:00
));
2020-03-15 08:37:48 -07:00
gulp.task('devel', function () {
2020-01-12 06:33:02 -08:00
gulp.watch('src/sass/**/*.*css', gulp.series('sass'));
});