forked from IBM/taxinomitis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
193 lines (155 loc) · 5.44 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
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
const gulp = require('gulp');
const bower = require('gulp-bower');
const mocha = require('gulp-mocha');
const tslint = require('gulp-tslint');
const ts = require('gulp-typescript');
const cleanCSS = require('gulp-clean-css');
const concat = require('gulp-concat');
const minify = require('gulp-uglify');
const template = require('gulp-template');
const autoprefixer = require('gulp-autoprefixer');
const rename = require('gulp-rename');
const ngAnnotate = require('gulp-ng-annotate');
const sequence = require('gulp-sequence');
const sourcemaps = require('gulp-sourcemaps');
const del = require('del');
// something unique to protect against problems from browsers
// caching old versions of JS
const now = new Date();
const VERSION = now.getTime();
const paths = {
json : ['src/**/*.json'],
ts : ['src/**/*.ts'],
tstest : ['src/tests/**/*.ts'],
js : ['dist/**/*.js'],
jslib : [
'dist/lib/**/*.js', '!dist/lib/app.js',
// files with type definitions only - not testable
'!dist/lib/**/*-types.js',
],
jstest : ['dist/tests/**/*.js'],
css : ['public/app.css', 'public/components/**/*.css'],
webjs : [
'public/app.run.js',
'public/components/**/*.js',
]
};
gulp.task('clean', () => {
const tsProject = ts.createProject('tsconfig.json');
const target = tsProject.config.compilerOptions.outDir;
return del([target, './web']);
});
gulp.task('bower', function() {
return bower({ cwd : './public', directory : '../web/static/bower_components' });
});
gulp.task('twitter', function() {
return gulp.src('public/twitter-card.html').pipe(gulp.dest('web/dynamic'));
});
gulp.task('crossdomain', function() {
return gulp.src('public/crossdomain.xml').pipe(gulp.dest('web/dynamic'));
});
gulp.task('scratchxinstall', ['crossdomain'], function() {
return gulp.src('public/scratchx/**').pipe(gulp.dest('web/scratchx'));
});
gulp.task('scratch3install', ['crossdomain'], function() {
return gulp.src('public/scratch3/**').pipe(gulp.dest('web/scratch3'));
});
gulp.task('datasets', function() {
return gulp.src('public/datasets/**').pipe(gulp.dest('web/datasets'));
});
gulp.task('compile', () => {
let errors = false;
const tsProject = ts.createProject('tsconfig.json');
const target = tsProject.config.compilerOptions.outDir;
const tsResult = tsProject.src()
.pipe(tsProject())
.on('error', () => { errors = true; });
return tsResult.js
.pipe(gulp.dest(target))
.on('finish', () => { errors && process.exit(1); });
});
gulp.task('css', ['html'], () => {
return gulp.src(paths.css)
.pipe(cleanCSS())
.pipe(autoprefixer())
.pipe(concat('style-' + VERSION + '.min.css'))
.pipe(gulp.dest('web/static'));
});
gulp.task('jsapp', () => {
return gulp.src('public/app.js')
.pipe(template({ VERSION }))
.pipe(rename('app-' + VERSION + '.js'))
.pipe(gulp.dest('web/static'));
});
gulp.task('angularcomponents', ['jsapp'], () => {
return gulp.src('public/components/**')
.pipe(gulp.dest('web/static/components-' + VERSION));
});
gulp.task('languages', [], () => {
return gulp.src('public/languages/**')
.pipe(gulp.dest('web/static/languages-' + VERSION));
});
gulp.task('images', () => {
return gulp.src('public/images/*').pipe(gulp.dest('web/static/images'));
});
function concatAndMinifiyWebJs (isForProd) {
const webJsWithAuth = (isForProd ? [ 'public/auth0-prod-variables.js' ] : [ 'public/auth0-variables.js']).concat(paths.webjs);
return gulp.src(webJsWithAuth)
.pipe(sourcemaps.init())
.pipe(ngAnnotate())
.pipe(concat('mlapp.js'))
.pipe(minify())
.pipe(rename({ extname : '-' + VERSION + '.min.js' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('web/static'));
}
gulp.task('minifyjs', () => {
return concatAndMinifiyWebJs(false);
});
gulp.task('minifyprodjs', () => {
return concatAndMinifiyWebJs(true);
});
function prepareHtml (isForProd) {
const options = { VERSION };
if (isForProd) {
options.USE_IN_PROD_ONLY = ' ';
options.AFTER_USE_IN_PROD_ONLY = ' ';
}
else {
options.USE_IN_PROD_ONLY = '<!--';
options.AFTER_USE_IN_PROD_ONLY = '-->';
}
return gulp.src('public/index.html')
.pipe(template(options))
.pipe(gulp.dest('web/dynamic'));
}
gulp.task('html', () => {
return prepareHtml(false);
});
gulp.task('prodhtml', ['twitter'], () => {
return prepareHtml(true);
});
gulp.task('tslint', () => {
const tslintOptions = { formatter : 'verbose' };
return gulp.src(paths.ts)
.pipe(tslint(tslintOptions))
.pipe(tslint.report());
});
gulp.task('lint', ['tslint']);
gulp.task('test', () => {
const mochaOptions = {
reporter : 'spec',
timeout : 60000
};
return gulp.src(paths.jstest)
.pipe(mocha(mochaOptions));
});
gulp.task('web', ['css', 'minifyjs', 'images', 'html', 'angularcomponents', 'languages', 'datasets', 'scratchxinstall', 'scratch3install']);
gulp.task('build', ['web', 'compile']);
gulp.task('default', sequence('build', 'lint', 'test'));
gulp.task('buildprod', sequence(
'clean',
'bower',
['css', 'minifyprodjs', 'images', 'prodhtml', 'angularcomponents', 'languages', 'datasets', 'scratchxinstall', 'scratch3install'],
'compile',
'lint'));