forked from i18next/ng-i18next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
153 lines (118 loc) · 3.27 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
'use strict';
var gulp = require('gulp');
var pkg = require('./package.json');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var webserver = require('gulp-webserver');
var karma = require('gulp-karma');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var size = require('gulp-size');
var header = require('gulp-header');
var rimraf = require('gulp-rimraf');
var getToday = function() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
return yyyy + '-' + mm + '-' + dd;
};
var headerMeta = ['/*!',
' * <%= pkg.name %> - Version <%= pkg.version %> - ' + getToday(),
' * Copyright (c) ' + new Date().getFullYear() + ' <%= pkg.author.name %>',
' *',
' * <%= pkg.description %>',
' *',
' * - Source: https://github.com/i18next/ng-i18next/',
' * - Issues: https://github.com/i18next/ng-i18next/issues',
' *',
' * License: <%= pkg.license %> - https://github.com/i18next/ng-i18next/blob/master/LICENSE',
' *',
'*/\n'
].join('\n');
var headerMetaMin = '/*! <%= pkg.name %> - <%= pkg.version %> - ' + getToday() +
' - Copyright (c) ' + new Date().getFullYear() + ' <%= pkg.author.name %>; Licensed <%= pkg.license %>*/';
// JS hint task
gulp.task('jshint', function() {
return gulp.src([
'gulpfile.js',
'src/{,*/}*.js',
'test/{,*/}*.js',
'examples/{,*/}*.js'
])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('build', function() {
//remove old files
gulp.src('./dist/*', { read: false })
.pipe(rimraf());
return gulp.src(['./src/provider.js', './src/{,*/}*.js'])
.pipe(concat(pkg.name + '.js'))
.pipe(header(headerMeta, {pkg: pkg}))
.pipe(gulp.dest('./dist/'))
.pipe(rename(pkg.name + '.min.js'))
.pipe(uglify())
.pipe(header(headerMetaMin, {pkg: pkg}))
.pipe(size())
.pipe(gulp.dest('./dist/'));
});
//run tests
gulp.task('karma', function() {
gulp.src([
'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'node_modules/i18next-client/i18next.min.js',
'src/provider.js',
'src/{,*/}*.js',
'test/polyfills/*.js',
'test/{,*/}*Spec.js'
])
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run' //Run once
}))
.on('error', function(err) {
// Make sure failed tests cause gulp to exit non-zero
throw err;
});
});
//TODO: documentation
gulp.task('default', function() {
var info = [
'',
' Usage:',
' - build: `gulp build`',
' - watch & test: `gulp watch`',
' - run examples: `gulp serve`',
' - Then open http://localhost:8000',
'',
' For pull requests please run:',
' gulp test',
' gulp build',
''
].join('\n');
console.info(info);
});
gulp.task('test', ['jshint', 'karma']);
gulp.task('serve', function() {
gulp.src('./')
.pipe(webserver({
livereload: true,
fallback: './examples/index.html'
}));
});
gulp.task('watch', ['jshint', 'karma'], function() {
// watch for JS changes
gulp.watch('./src/{,*/}*.js', function() {
gulp.run('jshint', 'karma');
});
});
gulp.task('ci', ['test', 'build']);