-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
gulpfile.js
163 lines (138 loc) · 3.53 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
const { series, src, dest, watch, reload } = require('gulp');
const pkg = require('./package.json');
const uglify = require('gulp-uglify');
const browserSync = require('browser-sync');
const rename = require('gulp-rename');
const size = require('gulp-size');
const header = require('gulp-header');
const rimraf = require('gulp-rimraf');
const rollup = require('gulp-rollup');
const typescript = require('rollup-plugin-typescript');
const karma = require('karma').Server;
const bump = require('gulp-bump'),
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 %>*/';
function clean() {
//remove old files
return src(['./dist/*', './build/*'], { read: false })
.pipe(rimraf());
}
function rollupLib() {
return src(['./src/*.ts'])
.pipe(rollup({
allowRealFiles: true,
input: 'src/provider.ts',
format: 'umd',
file: 'dist/ng-i18next.js',
name: 'ngI18next',
globals: {
angular: 'angular', i18next: 'i18next'
},
external: [
'typescript',
'angular'
],
plugins: [
typescript()
]
}))
.pipe(rename('ng-i18next.js'))
.pipe(dest('./build/'));
}
function concatLib() {
return src('./build/ng-i18next.js')
.pipe(header(headerMeta, { pkg: pkg }))
.pipe(dest('./dist/'))
.pipe(rename(pkg.name + '.min.js'))
.pipe(uglify({ mangle: false }))
.pipe(header(headerMetaMin, { pkg: pkg }))
.pipe(size())
.pipe(dest('./dist/'));
}
//run tests
function karmaTest(done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
}, function () {
done();
});
}
//watch tests
function karmaTestWatch() {
return karma.start({
configFile: __dirname + '/karma.conf.js',
browsers: ['Chrome'],
singleRun: false,
autoWatch: true
});
}
//TODO: documentation
function info(done) {
var info = [
'',
' Usage:',
' - build: `gulp build`',
' - watch & test: `gulp karmaWatch`',
' - run examples: `gulp serve`',
' - Then open http://localhost:8000',
'',
' For pull requests please run:',
' gulp test',
' gulp rollup',
''
].join('\n');
console.info(info);
done()
}
function serve(done) {
// init browser sync
browserSync({
server: {
baseDir: ['.'],
index: './examples/index.html',
routes: {
"/examples": "examples"
}
}
});
// reload if any of those file changes
watch([
'./src/**/*.ts',
'./examples/**/*.js',
'./examples/**/*.html',
'./examples/**/*.css'
])
.on('change', browserSync.reload);
done();
}
exports.test = series(clean, karmaTest, rollupLib, concatLib);
exports.build = series(clean, karmaTest, rollupLib, concatLib);
exports.karmaWatch = series(clean, karmaTestWatch);
exports.serve = series(clean, karmaTest, rollupLib, concatLib, serve);
exports.default = series(info);