forked from dbiele/TypeScript-Cordova-SystemJS-Angular2-beta
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
208 lines (176 loc) · 5.64 KB
/
gulpfile.js
File metadata and controls
208 lines (176 loc) · 5.64 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/// <binding BeforeBuild='copy.htmlfiles.to.www' />
'use strict';
var gulp = require('gulp');
var tsd = require('gulp-tsd');
var tslint = require('gulp-tslint');
var browserSync = require('browser-sync');
var del = require('del');
var plugins = require('gulp-load-plugins')();
var gulptypescript = require('gulp-typescript');
var karma = require('karma');
var sourceMaps = require('gulp-sourcemaps');
var fs = require('fs');
var webdriver = require('gulp-protractor').webdriver_update;
gulp.task('NPM+NODE.version', function (done) {
// adding require here so it doesn't run every time the gulpfile.js is loaded and run.
var checkEnvironment = require('./tools/check-environment.js');
checkEnvironment({ requiredNpmVersion: '>=2.14.7 <3.0.0', requiredNodeVersion: '>=4.2.1 <5.0.0' }, done);
});
gulp.task('install.tsd.files', function (callback) {
tsd({
command: 'reinstall',
config: '.tsd.json'
}, callback);
});
gulp.task('lint.typescript', function () {
// Rules can be found here
// https://github.com/palantir/tslint#supported-rules
// Microsoft Rules = https://github.com/Microsoft/tslint-microsoft-contrib/blob/master/tslint.json
var tslintConfig = require('./tools/tslint.json');
return gulp.src(['scripts/**/*.ts', '!scripts/typings/**'])
//Custom rules can be added to configuration. rulesDirectory: 'folder/folder'
.pipe(tslint({
configuration: tslintConfig
}))
.pipe(tslint.report('verbose', { emitError: true, reportLimit: 0 }));
});
gulp.task('copy.htmlfiles.to.www', gulp.series(
copyHTMLToWWW
));
//gulp.task('browser.sync.js-watch', ['js'], browserSync.reload);
gulp.task('browser.sync', function () {
browserSync.init({
server: {
baseDir: "./www/"
}
});
// add browserSync.reload to the tasks array to make
// all browsers reload after tasks are complete.
//gulp.watch("./www/scripts/*.js", ['browser.sync.js-watch']);
});
// remove the karma folder.
function karmaClean() {
//You can use multiple globbing patterns as you would with `gulp.src`
//If you are using del 2.0 or above, return its promise
return del(['.karma']);
}
// remove the test folder in scripts.
function unitClean() {
//You can use multiple globbing patterns as you would with `gulp.src`
//If you are using del 2.0 or above, return its promise
return del(['www/scripts/tests']);
}
function karmaTsSpec() {
// takes the .ts files and converts to .js
return karmaTs('scripts/tests/unit');
}
function ts(filesRoot, filesGlob, filesDest, project) {
var results = gulp.src(filesGlob)
.pipe(plugins.sourcemaps.init())
.pipe(plugins.typescript(project))
return results.js
.pipe(plugins.sourcemaps.write())
.pipe(gulp.dest(filesDest))
}
function karmaTs(root) {
var project = plugins.typescript.createProject('./scripts/tsconfig.json', {
outDir: '.karma'
});
var filesRoot = root;
var filesDest = '.karma';
var filesGlob = [
root + '/**/*.ts'
];
return ts(filesRoot, filesGlob, filesDest, project);
}
function convertTSJS() {
var tsconfigPath = './scripts/tsconfig.json';
return gulp.src(['./scripts/**/*.ts', '!./scripts/typings/*'])
.pipe(gulptypescript(gulptypescript.createProject(tsconfigPath)))
.pipe(gulp.dest("www/scripts"));
}
function copyHTMLToWWW() {
return gulp.src(['./scripts/**/*.html'])
.pipe(gulp.dest('./www/scripts/'));
}
/**
* This is used by the travis.yml file to compile the .ts files into .js before running the unit test.
*/
gulp.task("build.appfiles.typescript", gulp.series(
convertTSJS,
copyHTMLToWWW
));
function karmaRun(done) {
return new karma.Server({
configFile: __dirname + '/tools/karma.conf.js'
}, done).start();
}
gulp.task('post.build.cleanup', gulp.series(
unitClean
));
//remove the protractor folder
function protractorClean(){
return del(['.protractor']);
}
// Locate the protractor .ts files, convert to .js and save to .protractor folder
function protractorTs2Js() {
var protractorTsProject = plugins.typescript.createProject('./scripts/tsconfig.json', {
outDir: '.protractor',
module: 'commonjs'
});
var filesRoot = 'scripts/tests/e2e';
var filesDest = `.protractor/${filesRoot}`;
var filesGlob = [
`${filesRoot}/**/*.ts`
];
return ts(filesRoot, filesGlob, filesDest, protractorTsProject);
}
/**
* Ensures the selenium web drivers are installed
* Updates selenium standalone
* Updates chromedriver
*/
function protractorUpdate(done) {
webdriver({}, done);
}
/**
* Setup the test
*/
function protractorRun(cb) {
// use return and delete cb
gulp.src('.protractor/scripts/tests/e2e/**/*.spec.js')
.pipe(plugins.protractor.protractor({
configFile: './tools/protractor.conf.js'
}))
.on('error', e => { throw e })
.on('end',cb)
}
/**
* copy all www files to .protractor
*/
function copyWWWToProtractor() {
return gulp.src(['./www/**', '!./www/scripts/tests/**'])
.pipe(gulp.dest(".protractor/"));
}
gulp.task('unit.test.karma', gulp.series(
// Remember take in a callback or return a promise or event stream to avoid gulp 'The following tasks did not complete.'
//clear the karma folder
//karmaClean,
// convert the .ts files to .js and save in karma folder
//karmaTsSpec,
// run the karma server
karmaRun
));
/**
* Steps:
* Delete the .protractor folder.
* Convert .ts files to .js and save to .protractor folder.
*/
gulp.task('e2e.test.protractor', gulp.series(
protractorClean,
copyWWWToProtractor,
protractorTs2Js,
protractorUpdate,
protractorRun,
protractorClean
));