-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
192 lines (176 loc) · 5.24 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
const gulp = require('gulp');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const ngAnnotate = require('gulp-ng-annotate');
const connect = require('gulp-connect');
const jsHint = require('gulp-jshint');
const stylish = require('jshint-stylish');
const minimist = require('minimist');
const ngConfig = require('gulp-ng-config');
const plumber = require('gulp-plumber');
const karma = require('gulp-karma');
const clean = require('gulp-clean');
const jscs = require('gulp-jscs');
const jscsStylish = require('gulp-jscs-stylish');
const jshintXMLReporter = require('gulp-jshint-xml-file-reporter');
const gulpFile = require('gulp-file');
const rename = require("gulp-rename");
const replace = require('gulp-replace');
const gulpIf = require('gulp-if');
const Server = require('karma').Server;
var knownOptions = {
string: 'env',
default: {env: 'dev'}
};
var options = minimist(process.argv.slice(2), knownOptions);
var scriptRoot = 'client/app';
var contentRoot = 'client/content/';
var scriptFolder = scriptRoot + '/**/*.js';
var jsHintOutput = './jshint.xml';
//Task for compiling custom JS files - concat, uglify, generate source maps and move to dist
gulp.task('scripts', function() {
return gulp.src([
scriptRoot + '/**/app.js',
scriptRoot + '/**/!(app).js'
])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(babel({
"presets": ["es2015"]
}))
.pipe(concat('app.js'))
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist/js'))
});
//Task for compiling custom CSS files - concat, compress and move to dist
gulp.task('sass', function() {
return gulp.src([contentRoot + 'css/styles.scss'])
.pipe(sass({includePaths: [contentRoot +'/css']}))
.pipe(plumber())
.pipe(concat('styles.css'))
.pipe(gulp.dest('dist/css'))
.pipe(connect.reload());
});
gulp.task('fonts', function() {
return gulp.src([
'node_modules/bootstrap/fonts/*.*',
contentRoot +'fonts/*.*'
])
.pipe(gulp.dest('dist/fonts'));
});
gulp.task('vendorCss', function() {
return gulp.src([
'node_modules/**/**.min.css'
])
.pipe(plumber())
.pipe(concat('vendor.css'))
.pipe(gulp.dest('dist/css'));
});
gulp.task('vendorScripts', function() {
return gulp.src([
'node_modules/**/jquery.min.js',
'node_modules/**/angular.min.js',
'node_modules/**/bootstrap.min.js',
'node_modules/**/angular-ui-router.min.js',
'node_modules/lodash/lodash.min.js'
])
.pipe(plumber())
.pipe(concat('vendor.js'))
.pipe(gulp.dest('dist/js'));
});
gulp.task('templates', function() {
gulp.src('index.html')
.pipe(gulp.dest('dist'));
gulp.src([
contentRoot + 'partials/**/*.html',
scriptRoot + '/**/*.html'
]).pipe(gulp.dest('dist/partials'));
return gulp.src(contentRoot + 'images/**/*').pipe(gulp.dest('dist/images'));
});
gulp.task('test', function (done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
gulp.task('watch', ['sass', 'scripts', 'templates', 'lint'], function() {
gulp.watch(contentRoot + 'css/**/*.scss', ['sass']);
gulp.watch('*.json', ['api_path']);
gulp.watch(scriptFolder, ['scripts', 'lint']);
gulp.watch([
'index.html',
contentRoot + 'partials/**/*.html',
scriptRoot + '/**/*.html',
contentRoot + 'images/**/*'
], ['templates']
);
});
gulp.task('api_path', function() {
var env = options.env || 'dev';
gulp.src('api.config.json')
.pipe(ngConfig('app.config', {
pretty: true
}))
.pipe(gulp.dest('dist'));
gulp.src(env+'.config.json')
.pipe(ngConfig('app.config', {
createModule: false,
pretty: true
}))
.pipe(rename('app.config.js'))
.pipe(gulp.dest('dist'));
});
gulp.task('server', function() {
connect.server({
root: 'dist',
port: 8080,
livereload: true,
fallback: 'dist/index.html'
});
});
gulp.task('lint', function() {
return gulp.src([
scriptFolder
])
.pipe(jsHint())
.pipe(jscs())
.on('error', function() {})
.pipe(jscsStylish.combineWithHintResults())
.pipe(jsHint.reporter(stylish));
});
gulp.task('lint-xmlout', function() {
return gulp.src(scriptFolder)
.pipe(jsHint())
.pipe(jscs())
.on('error', function() {})
.pipe(jscsStylish.combineWithHintResults())
.pipe(jsHint.reporter(stylish))
.pipe(jsHint.reporter(jshintXMLReporter))
.on('end', jshintXMLReporter.writeFile({
format: 'checkstyle',
filePath: jsHintOutput
}));
});
gulp.task('clean', function() {
gulp.src(jsHintOutput, {read: false})
.pipe(clean());
return gulp.src('dist', {read: false})
.pipe(clean());
});
//Default Task - used for local system build
gulp.task('default', function() {
gulp.start('templates');
gulp.start('fonts');
gulp.start('vendorCss');
gulp.start('sass');
gulp.start('vendorScripts');
gulp.start('scripts');
gulp.start('api_path');
gulp.start('server');
gulp.start('watch');
});