forked from kylebradshaw/mydatepicker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
98 lines (83 loc) · 3.17 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
var gulp = require('gulp');
var clean = require('gulp-clean');
var replace = require('gulp-replace');
var sequence = require('run-sequence');
var cleancss = require('gulp-clean-css');
var htmlmin = require('gulp-htmlmin');
var fs = require('fs');
var ts = require('gulp-typescript');
var merge = require('merge2');
var sourcemaps = require('gulp-sourcemaps');
var str1 = '//webpack1_';
var str2 = '//webpack2_';
var str3 = '/*';
var str4 = '*/';
var tsDistProject = ts.createProject('tsconfig.dist.json');
/*
*
* Gulp tasks to build dist and bundle versions.
* - Minifies the css file.
* - Minifies the html template file.
* - Add html template and styles as inline templates to the my-date-picker.component.
* - Creates dist folder - contain javascript files of the component.
*
*/
gulp.task('tsc.compile.dist', function () {
var tsResult = tsDistProject.src().pipe(sourcemaps.init()).pipe(tsDistProject());
return merge([
tsResult.js.pipe(gulp.dest('dist')),
tsResult.js.pipe(sourcemaps.write('./', {includeContent: false})).pipe(gulp.dest('dist')),
tsResult.dts.pipe(gulp.dest('dist'))
]);
});
gulp.task('backup.component.tmp', function() {
return gulp.src('./src/my-date-picker/my-date-picker.component.ts').pipe(gulp.dest('./tmp'));
});
gulp.task('minify.css', function() {
return gulp.src('./src/my-date-picker/my-date-picker.component.css')
.pipe(cleancss({compatibility: 'ie8'}))
.pipe(gulp.dest('./tmp'));
});
gulp.task('minify.html', function() {
return gulp.src('./src/my-date-picker/my-date-picker.component.html')
.pipe(htmlmin({collapseWhitespace: true, caseSensitive: true}))
.pipe(gulp.dest('./tmp'));
});
gulp.task('prepare.system.compile', function() {
var styles = fs.readFileSync('./tmp/my-date-picker.component.css', 'utf-8');
var htmlTpl = fs.readFileSync('./tmp/my-date-picker.component.html', 'utf-8');
styles = styles.split('\\e').join('\\\\e');
return gulp.src(['./src/my-date-picker/my-date-picker.component.ts'])
.pipe(replace(str1, str3))
.pipe(replace(str2, str4))
.pipe(replace('styles: [myDpStyles],', 'styles: [' + '`' + styles + '`' + '],'))
.pipe(replace('template: myDpTpl,', 'template: `' + htmlTpl + '`' + ','))
.pipe(gulp.dest(function(file) {
return file.base;
}));
});
gulp.task('delete.modified.component', function () {
return gulp.src(['./src/my-date-picker/my-date-picker.component.ts'], {read: false}).pipe(clean());
});
gulp.task('restore.original.component', function() {
return gulp.src('./tmp/my-date-picker.component.ts').pipe(gulp.dest('./src/my-date-picker/'));
});
gulp.task('delete.tmp', function () {
return gulp.src(['./tmp'], {read: false}).pipe(clean());
});
gulp.task('clean', function () {
return gulp.src(['./build', './tmp', './test-output'], {read: false}).pipe(clean());
});
gulp.task('all', function(cb) {
sequence(
'clean',
'backup.component.tmp',
'minify.css',
'minify.html',
'prepare.system.compile',
'tsc.compile.dist',
'delete.modified.component',
'restore.original.component',
'delete.tmp',
cb);
});