This repository was archived by the owner on May 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
154 lines (128 loc) · 3.62 KB
/
gulpfile.js
File metadata and controls
154 lines (128 loc) · 3.62 KB
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
/*
Joose Utils Gulpfile
Author: @Scoobter17 Phil Gibbins
*/
'use strict';
/******************************************************************************/
/* GULP CONFIG */
/* App Dependencies --------------------------------------------------------- */
// Gulp
var gulp = require('gulp');
// Processing
var browserify = require('browserify');
// Testing
var karmaServer = require('karma').Server;
// Utilites
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var argv = require('yargs').argv;
var open = require('gulp-open');
var clean = require('gulp-clean');
/* Variables ---------------------------------------------------------------- */
var appName = 'joose-utils';
var filePaths = {
allFilesInAllFolders: '**/*',
js: {
src: 'src/',
dist: 'dist/'
},
test: {
src: 'test/src/',
dist: 'test/dist/',
report: './test/report/'
}
};
var fileNames = {
test: {
src: 'spec',
dist: 'spec',
report: 'unit-test-report'
}
}
var fileExtensions = {
js: {
src: '.js',
dist: '.js'
},
test: {
report: '.html'
}
};
/******************************************************************************/
/* SCRIPTS */
/**
* Task to transpile ES2015 code to ES5
*/
gulp.task('transpile-to-es5', function() {
var input;
var outputFileName;
var outputDir;
// set config based on command params
switch (argv.files) {
case 'test':
console.log('\nRunning es2015 test transpilation...');
input = './' + filePaths.test.src + fileNames.test.src + fileExtensions.js.src;
outputFileName = fileNames.test.dist + fileExtensions.js.dist;
outputDir = './' + filePaths.test.dist;
break;
case 'es5':
console.log('\nRunning es5 browser transpilation...');
input = './' + filePaths.js.src + appName + '-es5' + fileExtensions.js.src;
outputFileName = appName + '-es5' + fileExtensions.js.dist;
outputDir = './' + filePaths.js.dist;
break;
default:
console.log('\nRunning es2015 -> es5 transpilation...');
input = './' + filePaths.js.src + appName + fileExtensions.js.src;
outputFileName = appName + fileExtensions.js.dist;
outputDir = './' + filePaths.js.dist;
break;
}
console.log('Testing type: ', argv.test);
console.log('Input File: ', input);
console.log('Output File: ', outputDir + outputFileName + '\n');
// transpile code to ES5
return browserify(input)
.transform('babelify')
.bundle()
.pipe(source(outputFileName))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(outputDir));
});
/******************************************************************************/
/* TESTING */
/**
* Task to fire up Karma Testing Server and run unit tests
*/
gulp.task('run-unit-tests', ['delete-unit-test-report', 'transpile-to-es5'], function(done) {
return new karmaServer({
basePath: '../',
configFile: require('path').resolve('test/karma.conf.js'),
singleRun: true
}, function() {
done(); // console stacktrace if not in anon func
}).start();
});
/**
* Task to simply open Jasmine HTML unit test report in default browser
*/
gulp.task('open-unit-test-report', function() {
gulp.src(filePaths.test.report + fileNames.report + fileExtensions.test.report)
.pipe(open());
});
/**
* Task to open Jasmine HTML report after running unit tests
*/
gulp.task('run-unit-tests-and-open-report', ['run-unit-tests'], function() {
gulp.src(filePaths.test.report + fileNames.report + fileExtensions.test.report)
.pipe(open());
});
/**
* Task to delete unit test reports
*/
gulp.task('delete-unit-test-report', function() {
return gulp.src(filePaths.test.report + fileNames.report + fileExtensions.test.report)
.pipe(clean());
});