-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
167 lines (137 loc) · 3.74 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
164
165
166
167
var gulp = require('gulp');
var karma = require('gulp-karma');
var runSequence = require('run-sequence');
var webserver = require('gulp-webserver');
var sources = [
'source/**/*.ts'
];
var testFiles = []; // Declared in the karma.conf.js
var distDirectory = 'dist';
/**
* Main task: cleans, builds, run tests, and bundles up for distribution.
*/
gulp.task('all', function(callback) {
runSequence(
'clean',
'build',
'test',
callback);
});
gulp.task('build', function(callback) {
runSequence(
'compile',
'uglify',
'umdify',
//'map',
callback);
});
gulp.task('compile', function() {
return buildHelper(sources, distDirectory , 'forms-js-angular-1x.js');
});
gulp.task('clean', function() {
var clean = require('gulp-clean');
return gulp.src(distDirectory ).pipe(clean());
});
gulp.task('map', function() {
var shell = require('gulp-shell');
console.log('CWD: ' + process.cwd() + '/dist');
return shell.task(
'uglifyjs --compress --mangle --source-map forms-js-angular-1x.min.js.map --source-map-root . -o forms-js-angular-1x.min.js -- forms-js-angular-1x.js',
{cwd: process.cwd() + '/dist'}
)();
});
gulp.task('test', function(callback) {
runSequence(
['test:integration', 'test:unit'],
callback);
});
gulp.task('test:integration', function() {
var angularProtractor = require('gulp-angular-protractor');
gulp.src(testFiles)
.pipe(angularProtractor({
configFile: 'protractor.conf.js',
args: [
'--baseUrl', 'http://127.0.0.1:8000/examples/'
],
autoStartStopServer: true,
//debug: true
}))
.on('error', function(e) { throw e })
});
gulp.task('test:unit', function() {
// Be sure to return the stream
return gulp.src(testFiles)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(error) {
// Make sure failed tests cause gulp to exit non-zero
throw error;
});
});
gulp.task('test:watch', function() {
return gulp.src(testFiles)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'watch'
}));
});
gulp.task('compile:watch', function() {
return gulp.watch(sources, ['compile']);
});
gulp.task('build:watch', function() {
return gulp.watch(sources, ['build']);
});
gulp.task('uglify', function() {
var fs = require('fs');
var uglifyJs = require('uglify-js2');
var code = fs.readFileSync('dist/forms-js-angular-1x.js', 'utf8');
var parsed = uglifyJs.parse(code);
parsed.figure_out_scope();
var compressed = parsed.transform(uglifyJs.Compressor());
compressed.figure_out_scope();
compressed.compute_char_frequency();
compressed.mangle_names();
var finalCode = compressed.print_to_string();
fs.writeFileSync('dist/forms-js-angular-1x.min.js', finalCode);
});
gulp.task('umdify', function() {
umdHelper('dist/forms-js-angular-1x.js', 'dist');
umdHelper('dist/forms-js-angular-1x.min.js', 'dist');
});
var buildHelper = function(sources, directory, outputFile) {
var typeScriptCompiler = require('gulp-tsc');
return gulp
.src(sources)
.pipe(typeScriptCompiler({
module: "CommonJS",
emitError: false,
out: outputFile,
target: 'ES5'
}))
.pipe(gulp.dest(directory));
};
var umdHelper = function(sources, directory) {
var umd = require('gulp-umd');
return gulp
.src(sources)
.pipe(umd({
exports: function(file) {
return 'adaptor';
},
namespace: function(file) {
return 'adaptor';
}
//template: path.join(__dirname, 'templates/returnExports.js')
}))
.pipe(gulp.dest(directory));
};
gulp.task('server',['build'], function() {
gulp.src('.')
.pipe(webserver({
livereload: true,
directoryListing: true,
open: true
}));
});