-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
executable file
·169 lines (149 loc) · 4.95 KB
/
gulpfile.js
File metadata and controls
executable file
·169 lines (149 loc) · 4.95 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
(function () {
'use strict';
const gulp = require('gulp');
const eslint = require('gulp-eslint');
gulp.task('eslint', () => {
/**
* ESLint ignores files with node_modules paths.
* So, it's best have gulp ignore the directory as well.
* Also, be sure to return the stream from the task.
* Otherwise, the task my end before the stream has finished.
*/
return gulp.src(['**/*.js', '!node_modules', '!public/system/lib/**/*.js', '!test/**/*.js'])
// eslint() attaches the lint output to the "eslint" property
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an erro code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError());
// gulp.task('default', ['lint'], function () {
// // This will only run if the lint task is successful...
// });
});
/**
*
*
* Support gulp
*
*/
// const del = require('del');
const path = require('path');
const gutil = require('gulp-util');
const through = require('through');
const gulpLoadPlugins = require('gulp-load-plugins');
// const karma = require('karma').server;
const _ = require('lodash');
var plugins = gulpLoadPlugins({
DEBUG: true
}),
paths = {
js: [
'*.js',
'test/**/*.js',
'!test/coverage/**',
'!bower_components/**',
'packages/**/*.js',
'!packages/**/node_moudles/**',
'!packages/contrib/**/*.js',
'!packages/contrib/**/node_modules/**'
],
html: [
'packages/**/public/**/views/**',
'packages/**/server/views/**'
],
css: [
'!bower_components/**',
'packages/**/public/**/css/*.css',
'!packages/contrib/**/public/**/css/*.css'
],
less: ['**/public/**/css/*.less']
},
assets = require('./config/assets.json');
function count(taskName, message) {
var fileCount = 0;
function countFiles() {
fileCount++;
}
function endStream() {
gutil.log(gutil.colors.cyan(taskName + ': ') + fileCount + message || 'files processed.');
this.emit('end');
}
return through(countFiles, endStream);
}
function tokenizeConfig(config) {
var destTokens = _.keys(config)[0].split('/');
return {
srcGlob: _.flatten(_.values(config)),
destDir: destTokens[destTokens.length - 2],
destFile: destTokens[destTokens.length - 1]
};
}
gulp.task('jshint', () => {
return gulp.src(paths.js)
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('jshint-stylish'))
.pipe(plugins.jshint.reporter('fail'))
.pipe(count('jshint', 'files lint free'));
});
gulp.task('uglify', () => {
var config = tokenizeConfig(assets.core.js);
if (config.srcGlob.length) {
return gulp.src(config.srcGlob)
.pipe(plugins.concat(config.destFile))
.pipe(
plugins.uglify({
mangle: true
})
)
.pipe(
gulp.dest(
path.join(
'bower_components/build',
config.destDir
)
)
);
}
});
gulp.task('cssmin', () => {
var config = tokenizeConfig(assets.core.css);
if (config.srcGlob.length) {
return gulp.src(config.srcGlob)
.pipe(
plugins.cssmin({
keepBreaks: true
})
)
.pipe(
plugins.concat(config.destFile)
)
.pipe(
gulp.dest(
path.join(
'bower_components/build',
config.destDir
)
)
);
}
});
gulp.task('env:develop', () => {
process.env.NODE_ENV = 'development';
});
gulp.task('env:production', () => {
process.env.NODE_ENV = 'production';
});
gulp.task('develop', ['env:develop'], () => {
plugins.nodemon({
script: 'server.js',
ext: 'html js',
env: {
'NODE_ENV': 'development'
},
ignore: ['./node_modules'],
nodeArgs: ['--debug']
});
});
}());