-
Notifications
You must be signed in to change notification settings - Fork 67
/
gulpfile.js
152 lines (132 loc) · 4.8 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
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 tslint = require('gulp-tslint');
var shell = require('gulp-shell');
var jeditor = require("gulp-json-editor");
var str1 = '// webpack1_';
var str2 = '// webpack2_';
var str3 = '/*';
var str4 = '*/';
/*
*
* 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 ngx-my-date-picker.component.
* - Creates npmdist folder - contain files needed to publish to npm.
*
*/
gulp.task('clean', function () {
return gulp.src(['./build-example', './tmp', './test-output', './.tmpbuild', './npmdist'], {read: false}).pipe(clean());
});
gulp.task('backup.component.tmp', function() {
return gulp.src('./src/ngx-my-date-picker/ngx-my-date-picker.component.ts').pipe(gulp.dest('./tmp'));
});
gulp.task('minify.css', function() {
return gulp.src('./src/ngx-my-date-picker/ngx-my-date-picker.component.css')
.pipe(cleancss({compatibility: 'ie8'}))
.pipe(gulp.dest('./tmp'));
});
gulp.task('minify.html', function() {
return gulp.src('./src/ngx-my-date-picker/ngx-my-date-picker.component.html')
.pipe(htmlmin({collapseWhitespace: true, caseSensitive: true}))
.pipe(gulp.dest('./tmp'));
});
gulp.task('inline.template.and.styles.to.component', function() {
var styles = fs.readFileSync('./tmp/ngx-my-date-picker.component.css', 'utf-8');
var htmlTpl = fs.readFileSync('./tmp/ngx-my-date-picker.component.html', 'utf-8');
styles = styles.split('\\e').join('\\\\e');
return gulp.src(['./src/ngx-my-date-picker/ngx-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('ngc.compile.publish', shell.task([
'npm run ngc'
]));
gulp.task('copy.build.to.npmdist.directory', function() {
return gulp.src(
[
'./.tmpbuild/dist/**/*.*'
]).pipe(gulp.dest('./npmdist/dist/'));
});
gulp.task('delete.tmpbuild.folder', function () {
return gulp.src(['./.tmpbuild'], {read: false}).pipe(clean());
});
gulp.task('build.bundle', shell.task([
'npm run bundle'
]));
gulp.task('copy.files.to.npmdist.root.dir', function() {
return gulp.src(
[
'./LICENSE',
'./package/README.md',
'./package/index.d.ts',
'./package/index.js'
]).pipe(gulp.dest('./npmdist'));
});
gulp.task('edit.package.json.and.copy.to.npmdist.root.dir', function () {
gulp.src("./package.json")
.pipe(jeditor(function(json) {
json.scripts = {};
json.devDependencies = {};
json.files = [
'index.d.ts', 'index.js', 'LICENSE', 'package.json', 'README.md', 'dist', 'bundles'
];
return json;
}))
.pipe(gulp.dest("./npmdist"));
});
gulp.task('delete.modified.component', function () {
return gulp.src(['./src/ngx-my-date-picker/ngx-my-date-picker.component.ts'], {read: false}).pipe(clean());
});
gulp.task('restore.original.component', function() {
return gulp.src('./tmp/ngx-my-date-picker.component.ts').pipe(gulp.dest('./src/ngx-my-date-picker/'));
});
gulp.task('delete.tmp', function () {
return gulp.src(['./tmp'], {read: false}).pipe(clean());
});
gulp.task('tslint', function () {
return gulp.src([
"src/ngx-my-date-picker/directives/*.ts",
"src/ngx-my-date-picker/interfaces/*.ts",
"src/ngx-my-date-picker/services/*.ts",
"src/ngx-my-date-picker/index.ts",
"src/ngx-my-date-picker/ngx-my-date-picker.input.ts",
"src/ngx-my-date-picker/ngx-my-date-picker.component.ts",
"src/ngx-my-date-picker/ngx-my-date-picker.module.ts"])
.pipe(tslint({
configuration: "tslint.json"
}))
.pipe(tslint.report({
emitError: false
}));
});
gulp.task('all', function(cb) {
sequence(
'clean',
'backup.component.tmp',
'minify.css',
'minify.html',
'inline.template.and.styles.to.component',
'ngc.compile.publish',
'copy.build.to.npmdist.directory',
'delete.tmpbuild.folder',
'build.bundle',
'copy.files.to.npmdist.root.dir',
'edit.package.json.and.copy.to.npmdist.root.dir',
'delete.modified.component',
'restore.original.component',
'delete.tmp',
'tslint',
cb);
});