forked from hackerspace-bootstrap/strichliste-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
136 lines (117 loc) · 4.13 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
var gulp = require('gulp');
var clean = require('gulp-clean');
var browserify = require('gulp-browserify');
var concat = require('gulp-concat');
var merge = require('merge-stream');
var order = require('gulp-order');
var less = require('gulp-less');
var sequence = require('run-sequence');
var ngAnnotate = require('gulp-ng-annotate');
var uglify = require('gulp-uglify');
var cssmin = require('gulp-minify-css');
var gulpIf = require('gulp-if');
var gutil = require('gulp-util');
var htmlMin = require('gulp-minify-html');
var colorguard = require('gulp-colorguard');
var bower = require('gulp-bower');
var gulpFilter = require('gulp-filter');
var SOURCE_DIR = 'src';
var TARGET_DIR = 'build';
var ENV = process.env.NODE_ENV;
var bowerComponents = {
js: [
'bower_components/jquery/dist/jquery.js',
'bower_components/angular/angular.js',
'bower_components/ng-idle/angular-idle.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-translate/angular-translate.js',
'bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.js',
'bower_components/Chart.js/Chart.js',
'bower_components/angular-chart.js/dist/angular-chart.js',
//'bower_components/tc-angular-chartjs/dist/tc-angular-chartjs.js',
'src/script/ext/*'
],
css: [
'bower_components/bootswatch-dist/css/bootstrap.css',
'bower_components/angular-chart.js/dist/angular-chart.css',
'bower_components/angular/angular-csp.css'
]
};
function isProduction () {
return ENV === 'production';
}
gulp.task('clean', function (callback) {
return gulp
.src(TARGET_DIR)
.pipe(clean());
});
gulp.task('static', function () {
return gulp
.src(SOURCE_DIR + '/static/*')
.pipe(gulp.dest(TARGET_DIR));
});
gulp.task('locales', function () {
return gulp
.src(SOURCE_DIR + '/locales/*')
.pipe(gulp.dest(TARGET_DIR + '/locales/'));
});
gulp.task('bower_components', function () {
return bower();
});
gulp.task('scripts', ['bower_components'], function () {
var jsFilter = gulpFilter(bowerComponents.js);
return gulp
.src(bowerComponents.js)
.pipe(concat('external.js'))
.pipe(gulpIf(isProduction, uglify()))
.pipe(gulp.dest(TARGET_DIR + '/js'))
.pipe(jsFilter.restore());
});
gulp.task('style', ['bower_components'], function () {
var cssFilter = gulpFilter(bowerComponents.css);
return gulp
.src(bowerComponents.css)
.pipe(concat('external.css'))
.pipe(gulpIf(isProduction, cssmin({ processImport: false })))
.pipe(gulp.dest(TARGET_DIR + '/css/'))
.pipe(cssFilter.restore());
});
gulp.task('style_app', function () {
return gulp
.src(SOURCE_DIR + '/style/*.less')
.pipe(less()).on('error', gutil.log)
.pipe(colorguard())
.pipe(gulpIf(isProduction, cssmin()))
.pipe(gulp.dest(TARGET_DIR + '/css'));
});
gulp.task('images', function () {
return gulp
.src(SOURCE_DIR + '/img/*')
.pipe(gulp.dest(TARGET_DIR + '/img'));
});
gulp.task('html', function () {
return gulp
.src(SOURCE_DIR + '/**/*.html')
.pipe(gulpIf(isProduction, htmlMin({empty: true})))
.pipe(gulp.dest(TARGET_DIR));
});
gulp.task('scripts_app', function () {
return gulp
.src(SOURCE_DIR + '/script/app.js')
.pipe(browserify()).on('error', gutil.log)
.pipe(gulpIf(isProduction, ngAnnotate()))
.pipe(gulpIf(isProduction, uglify()))
.pipe(gulp.dest(TARGET_DIR + '/js'));
});
gulp.task('build', function (callback) {
sequence('clean', ['html', 'static', 'locales', 'images', 'style_app', 'scripts', 'style', 'scripts_app'], callback);
});
gulp.task('dev', ['build'], function (callback) {
ENV = 'development';
gulp.watch(SOURCE_DIR + '/**/*.html', ['html']);
gulp.watch(SOURCE_DIR + '/style/**/*.less', ['style_app']);
gulp.watch(SOURCE_DIR + '/script/**/*.js', ['scripts_app']);
gulp.watch(SOURCE_DIR + '/img/**/*', ['images']);
gulp.watch(SOURCE_DIR + '/locales/*', ['locales']);
callback();
});