This repository has been archived on 2022-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
AriaNg/gulpfile.js

151 lines
4.2 KiB
JavaScript
Raw Normal View History

2016-05-13 18:09:12 +02:00
var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var browserSync = require('browser-sync');
var del = require('del');
var $ = gulpLoadPlugins();
var reload = browserSync.reload;
gulp.task('styles', function () {
2016-12-10 19:11:27 +01:00
return gulp.src([
'src/styles/**/*.css'
]).pipe($.autoprefixer({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR']}))
.pipe(gulp.dest('.tmp/styles'))
.pipe(reload({stream: true}));
2016-05-13 18:09:12 +02:00
});
gulp.task('scripts', function () {
2016-12-10 19:11:27 +01:00
return gulp.src([
'src/scripts/**/*.js'
]).pipe($.plumber())
.pipe(gulp.dest('.tmp/scripts'))
.pipe(reload({stream: true}));
2016-05-13 18:09:12 +02:00
});
2016-08-01 16:15:08 +02:00
gulp.task('views', function () {
2016-12-10 19:11:27 +01:00
return gulp.src([
'src/views/**/*.html'
]).pipe($.htmlmin({collapseWhitespace: true}))
.pipe($.angularTemplatecache({module: 'ariaNg', filename: 'views/templates.js', root: 'views/'}))
.pipe(gulp.dest('.tmp/scripts'));
2016-08-01 16:15:08 +02:00
});
2016-05-13 18:09:12 +02:00
gulp.task('lint', function () {
2016-12-10 19:11:27 +01:00
return gulp.src([
'src/scripts/**/*.js'
]).pipe(reload({stream: true, once: true}))
.pipe($.eslint.format())
.pipe($.if(!browserSync.active, $.eslint.failAfterError()))
.pipe(gulp.dest('src/scripts'));
2016-05-13 18:09:12 +02:00
});
2016-08-01 16:15:08 +02:00
gulp.task('html', ['styles', 'scripts', 'views'], function () {
2016-12-10 19:11:27 +01:00
return gulp.src([
'src/*.html'
]).pipe($.useref({searchPath: ['.tmp', 'src', '.']}))
.pipe($.injectVersion())
.pipe($.if('js/*.js', $.replace(/\/\/# sourceMappingURL=.*/g, '')))
.pipe($.if('css/*.css', $.replace(/\/\*# sourceMappingURL=.* \*\/$/g, '')))
.pipe($.if(['js/moment-with-locales-*.min.js', 'js/plugins.min.js', 'js/aria-ng.min.js'], $.uglify({preserveComments: 'license'})))
.pipe($.if(['css/plugins.min.css', 'css/aria-ng.min.css'], $.cssnano({safe: true, autoprefixer: false})))
.pipe($.if(['js/plugins.min.js', 'js/aria-ng.min.js', 'css/plugins.min.css', 'css/aria-ng.min.css'], $.rev()))
.pipe($.if('*.html', $.htmlmin({collapseWhitespace: true})))
.pipe($.revReplace())
.pipe(gulp.dest('dist'));
2016-05-13 18:09:12 +02:00
});
2016-05-26 17:52:34 +02:00
gulp.task('langs', function () {
2016-12-10 19:11:27 +01:00
return gulp.src([
'src/langs/**/*'
]).pipe(gulp.dest('dist/langs'));
2016-05-26 17:52:34 +02:00
});
2016-05-13 18:09:12 +02:00
gulp.task('images', function () {
2016-12-10 19:11:27 +01:00
return gulp.src([
'src/imgs/**/*'
]).pipe(gulp.dest('dist/imgs'));
2016-05-13 18:09:12 +02:00
});
gulp.task('fonts', function () {
2016-12-10 19:11:27 +01:00
return gulp.src([
'bower_components/font-awesome/fonts/fontawesome-webfont.*'
]).pipe(gulp.dest('.tmp/fonts'))
.pipe(gulp.dest('dist/fonts'));
2016-05-13 18:09:12 +02:00
});
2016-08-02 18:03:00 +02:00
gulp.task('manifest', function () {
2016-12-10 19:11:27 +01:00
return gulp.src([
'dist/css/**',
'dist/js/**',
'dist/fonts/fontawesome-webfont.woff2',
'dist/*.html'
], {base: 'dist/'})
.pipe($.manifest({
hash: true,
preferOnline: true,
network: ['*'],
filename: 'index.manifest',
exclude: 'index.manifest'
}))
.pipe(gulp.dest('dist'));
2016-08-02 18:03:00 +02:00
});
2016-05-13 18:09:12 +02:00
gulp.task('extras', function () {
2016-12-10 19:11:27 +01:00
return gulp.src([
2016-12-11 07:35:38 +01:00
'LICENSE',
2016-12-10 19:11:27 +01:00
'src/*.*',
'!src/*.html'
], {
dot: true
}).pipe(gulp.dest('dist'));
2016-05-13 18:09:12 +02:00
});
gulp.task('clean', del.bind(null, ['.tmp', 'dist']));
gulp.task('serve', ['styles', 'scripts', 'fonts'], function () {
2016-12-10 19:11:27 +01:00
browserSync({
notify: false,
port: 9000,
server: {
baseDir: ['.tmp', 'src'],
routes: {
'/bower_components': 'bower_components'
}
}
});
gulp.watch([
'src/*.html',
'src/langs/*.txt',
'src/views/*.html',
'src/imgs/**/*',
'.tmp/fonts/**/*'
]).on('change', reload);
gulp.watch('src/styles/**/*.css', ['styles']);
gulp.watch('src/scripts/**/*.js', ['scripts']);
gulp.watch('src/fonts/**/*', ['fonts']);
2016-05-13 18:09:12 +02:00
});
gulp.task('serve:dist', function () {
2016-12-10 19:11:27 +01:00
browserSync({
notify: false,
port: 9000,
server: {
baseDir: ['dist']
}
});
2016-05-13 18:09:12 +02:00
});
2016-08-02 18:03:00 +02:00
gulp.task('info', function () {
2016-12-10 19:11:27 +01:00
return gulp.src([
'dist/**/*'
]).pipe($.size({title: 'build', gzip: true}));
2016-05-13 18:09:12 +02:00
});
2016-08-02 18:03:00 +02:00
gulp.task('build', $.sequence('lint', 'html', 'langs', 'images', 'fonts', 'manifest', 'extras', 'info'));
2016-05-13 18:09:12 +02:00
gulp.task('default', ['clean'], function () {
2016-12-10 19:11:27 +01:00
gulp.start('build');
2016-05-13 18:09:12 +02:00
});