kopia lustrzana https://github.com/shoelace-style/shoelace
86 wiersze
2.7 KiB
JavaScript
86 wiersze
2.7 KiB
JavaScript
'use strict';
|
|
|
|
const Gulp = require('gulp-help')(require('gulp'));
|
|
const Chalk = require('chalk');
|
|
const CleanCSS = require('gulp-clean-css');
|
|
const Del = require('del');
|
|
const Path = require('path');
|
|
const Rename = require('gulp-rename');
|
|
const Watch = require('gulp-watch');
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Config
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
let styles = {
|
|
source: Path.join(__dirname, 'css/shoelace.css'),
|
|
target: Path.join(__dirname, 'dist')
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Build functions
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Compiles styles in source and outputs them in target
|
|
function buildStyles(source, target) {
|
|
console.log(Chalk.yellow('Building styles...'));
|
|
return Gulp.src(source)
|
|
.pipe(Rename({ suffix: '.min' }))
|
|
.pipe(CleanCSS({
|
|
format: 'keep-breaks',
|
|
specialComments: 'all'
|
|
}))
|
|
.on('error', (err) => {
|
|
console.error(Chalk.red(err.message));
|
|
})
|
|
.pipe(Gulp.dest(target))
|
|
.on('end', () => {
|
|
console.log(Chalk.green('✔︎ Styles at ' + new Date()));
|
|
});
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Build tasks
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Build styles
|
|
Gulp.task('build:styles', 'Build styles.', ['clean:styles'], () => {
|
|
buildStyles(styles.source, styles.target);
|
|
});
|
|
|
|
// Build all
|
|
Gulp.task('build', 'Run all build tasks.', [
|
|
'build:styles'
|
|
]);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Clean tasks
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Clean styles
|
|
Gulp.task('clean:styles', 'Delete generated styles.', () => {
|
|
return Del(styles.target);
|
|
});
|
|
|
|
// Clean all
|
|
Gulp.task('clean', 'Delete all generated files.', [
|
|
'clean:styles'
|
|
]);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Other tasks
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Watch for changes
|
|
Gulp.task('watch', 'Watch files and automatically build assets on change.', () => {
|
|
// Watch styles
|
|
Gulp.src(styles.source)
|
|
.pipe(Watch(styles.source))
|
|
.on('change', () => {
|
|
buildStyles(styles.source, styles.target);
|
|
});
|
|
});
|
|
|
|
// Default
|
|
Gulp.task('default', 'Run the default task.', ['help']);
|