-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathgulpfile.js
141 lines (117 loc) · 4.99 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
(function( require ) {
const gulp = require( "gulp" );
// const gulpSequence = require('run-sequence').use( gulp );
const karma = require( "gulp-karma-runner" );
const fs = require('fs');
function createKarmaServer() {
return karma.server({
singleRun: true,
autoWatch: true,
concurrency: Infinity,
port: 9876,
frameworks: [ "mocha", "chai" ],
browsers: [ "Chrome" ],
basePath: "",
exclude: [],
preprocessors: {
'src/**/*.js': ['coverage']
},
reporters: [ 'spec', 'coverage' ],
coverageReporter: {
type : 'lcov',
dir : 'coverage/'
},
colors: true
});
}
function gulpTestRun( angularVersion = "1.6.0", isMinified = false ) {
const ext = isMinified ? '.min' : '';
return gulp.src([
`test/angular-${angularVersion}/angular.js`,
`test/angular-${angularVersion}/angular-mocks.js`,
`dist/angular-mocks-async${ext}.js`,
'test/angular-mocks-async-internal-tests.js',
'test/angular-mocks-async-test.js'
], { "read": false })
.pipe( createKarmaServer() );
}
gulp.task( "dist", function () {
const compressor = require( "node-minify" );
let copyPromise = new Promise( function( resolve, reject ) {
/// copy sources
try {
const srcFile = 'src/angular-mocks-async.js';
const destFile = 'dist/angular-mocks-async.js';
fs.createReadStream(
srcFile
).pipe(fs.createWriteStream(
destFile
).on('finish', function () {
resolve( destFile );
}));
console.log(`processed: ${destFile}`);
} catch (e) {
console.error(e);
throw e;
}
});
// minify all distributions
return copyPromise.then( function( compiledFile ) {
try {
// generate dest file
const destFile = (function( srcFile ) {
let split = srcFile.split( "." );
split.splice( split.length - 1, 0, "min" );
return split.join( "." );
})( compiledFile );
return new Promise( function( resolve, reject ) {
compressor.minify({
compressor: 'gcc',
input: compiledFile,
output: destFile,
sync: true,
options: {},
callback: function( error ) {
if( error ) {
console.error( error );
reject( error );
}
console.log(`minified: ${destFile}`);
resolve( destFile );
}
});
});
} catch( e ) {
console.error( e );
throw e;
}
});
});
gulp.task( "test-with-angular-1.6.0", [ "test-with-angular-1.6.0-minified", "test-with-angular-1.6.0-unminified" ]);
gulp.task( "test-with-angular-1.6.0-unminified", () => gulpTestRun( "1.6.0" ) );
gulp.task( "test-with-angular-1.6.0-minified", () => gulpTestRun( "1.6.0", true ) );
gulp.task( "test-with-angular-1.5.0", [ "test-with-angular-1.5.0-minified", "test-with-angular-1.5.0-unminified" ]);
gulp.task( "test-with-angular-1.5.0-unminified", () => gulpTestRun( "1.5.0" ) );
gulp.task( "test-with-angular-1.5.0-minified", () => gulpTestRun( "1.5.0", true ) );
gulp.task( "test-with-angular-1.4.0", [ "test-with-angular-1.4.0-minified", "test-with-angular-1.4.0-unminified" ]);
gulp.task( "test-with-angular-1.4.0-unminified", () => gulpTestRun( "1.4.0" ) );
gulp.task( "test-with-angular-1.4.0-minified", () => gulpTestRun( "1.4.0", true ) );
gulp.task( "test-with-angular-1.3.17", [ "test-with-angular-1.3.17-minified", "test-with-angular-1.3.17-unminified" ]);
gulp.task( "test-with-angular-1.3.17-minified", () => gulpTestRun( "1.3.17" ) );
gulp.task( "test-with-angular-1.3.17-unminified", () => gulpTestRun( "1.3.17", true ) );
function runSequential( tasks ) {
if( !tasks || tasks.length <= 0 ) return;
const task = tasks[0];
gulp.start( task, () => {
console.log( `${task} finished` );
runSequential( tasks.slice(1) );
} );
}
gulp.task( "test-with-angular-all-versions", () => runSequential([
"test-with-angular-1.3.17",
"test-with-angular-1.4.0",
"test-with-angular-1.5.0",
"test-with-angular-1.6.0",
]));
gulp.task( "test-with-angular-1.3.0", () => gulpTestRun("1.3.0") );
}( require ));