-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
133 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
'use strict';
var gulp = require('gulp'),
gutil = require('gulp-util'),
rename = require('gulp-rename'),
ngAnnotate = require('gulp-ng-annotate'),
header = require('gulp-header'),
uglify = require('gulp-uglify'),
clean = require('gulp-rimraf'),
concat = require('gulp-concat-util'),
ngTemplates = require('gulp-ng-templates'),
pkg = require('./package.json'),
jshint = require('gulp-jshint'),
jshintStylish = require('jshint-stylish'),
compass = require('gulp-compass'),
cleanCSS = require('gulp-clean-css');
var today = new Date();
var config = {
paths: {
output: {
minified: 'dist/minified/',
unminified: 'dist/unminified/'
}
},
scripts: 'src/',
scss: 'src/scss/',
banners: {
unminified: '/*!\n' +
' * ' + pkg.prettyName + ' v' + pkg.version + '\n' +
' * ' + pkg.homepage + '\n' +
' *\n' +
' * Copyright (c) ' + (today.getFullYear()) + ' ' + pkg.author.name + '\n' +
' * License: ' + pkg.license + '\n' +
' *\n' +
' * Generated at ' + gutil.date(today, 'dddd, mmmm dS, yyyy, h:MM:ss TT') + '\n' +
' */',
minified: '/*! ' + pkg.prettyName + ' v' + pkg.version + ' License: ' + pkg.license + ' */'
}
};
// JavaScript
// =============
gulp.task('templates', function () {
return gulp.src(config.scripts + '**/*.html')
.pipe(ngTemplates({
filename: 'ng-arise-templates.min.js',
module: 'ngAriseTemplates'
}))
.pipe(gulp.dest(config.scripts + 'tmp'));
});
gulp.task('scripts', function () {
return gulp.src([config.scripts + '**/*.js', '!' + config.scripts + '**/*_test.js'])
.pipe(concat('ng-arise.js', {
separator: '\n\n',
process: function (src) {
// Remove all 'use strict'; from the code and
// replaces all double blank lines with one
return src.replace(/\r\n/g, '\n')
.replace(/'use strict';\n+/g, '')
.replace(/\n\n\s*\n/g, '\n\n');
}
}))
.pipe(concat.header(config.banners.unminified + '\n' +
'(function() {\n\'use strict\';\n\n'))
.pipe(concat.footer('\n}());'))
.pipe(gulp.dest(config.paths.output.unminified));
});
gulp.task('dist:js:clean', function () {
return gulp.src([config.paths.output.minified], {read: false})
.pipe(clean());
});
gulp.task('dist:js', ['dist:js:clean'], function () {
return gulp.src(config.paths.output.unminified + 'ng-arise.js')
.pipe(rename('ng-arise.min.js'))
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(header(config.banners.minified))
.pipe(gulp.dest(config.paths.output.minified));
});
// SCSS/CSS
// =============
gulp.task('styles', function () {
return gulp.src(config.scss + 'ng-arise.scss')
.pipe(compass({
sass: config.scss,
css: config.paths.output.unminified,
lineNumbers: false,
errLogToConsole: true
}))
.pipe(gulp.dest(config.paths.output.unminified));
});
gulp.task('dist:css:clean', function () {
return gulp.src([config.paths.output.minified + '**/*.css'], {read: false})
.pipe(clean());
});
gulp.task('dist:css', ['dist:css:clean', 'styles'], function () {
return gulp.src(config.paths.output.unminified + '*.css')
.pipe(cleanCSS())
.pipe(rename('ng-arise.min.css'))
.pipe(gulp.dest(config.paths.output.minified));
});
// Watches
// =============
gulp.task('watch', function () {
gulp.watch(config.scss + '/**/*.scss', ['styles']);
gulp.watch([config.scripts + '/**/*.js'], ['scripts']);
gulp.watch([config.scripts + '/**/*.html'], ['templates']);
});
// User commands
// =============
// Code linter
gulp.task('lint', function () {
return gulp.src([config.scripts + '**/*.js'])
.pipe(jshint('.jshintrc', '.jshintignore'))
.pipe(jshint.reporter(jshintStylish))
.pipe(jshint.reporter('fail'));
});
gulp.task('default', ['lint', 'templates', 'scripts', 'styles']);
gulp.task('build', ['templates', 'dist:js', 'dist:css']);