forked from benbaran/adal-angular4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
100 lines (88 loc) · 2.75 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
var
bump = require('gulp-bump'),
del = require('del'),
exec = require('child_process').exec,
gulp = require('gulp'),
replace = require('gulp-replace'),
watch = require('gulp-watch'),
fs = require('fs');
// delete content of ./dist directory
gulp.task('clean', function () {
del(['./dist/*', '!dist/index.js']);
});
// execute npm compile script
gulp.task('compile', function (cb) {
//gulp.task('compile', ['clean'], function (cb) {
exec('npm run compile', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
// include package.json file in ./dist folder
gulp.task('package', ['compile'], function () {
const pkgjson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
delete pkgjson.scripts;
delete pkgjson.devDependencies;
const filepath = './dist/package.json';
fs.writeFileSync(filepath, JSON.stringify(pkgjson, null, 2), 'utf-8');
});
// include type definition file for adal-angular
gulp.task('copy', ['package'], function () {
gulp.src(['adal-angular.d.ts']).pipe(gulp.dest('./dist/'));
})
// rewrite type definition file path for adal-angular in adal.service.d.ts
gulp.task('replace', ['copy'], function () {
gulp.src('./dist/adal.service.d.ts')
.pipe(replace('../adal-angular.d.ts', './adal-angular.d.ts'))
.pipe(gulp.dest('./dist/'))
})
// increase the version in package.json
gulp.task('bump', ['replace'], function () {
gulp.src('./package.json')
.pipe(bump({
type: 'patch'
}))
.pipe(gulp.dest('./'));
});
// git add
gulp.task('git-add', ['bump'], function (cb) {
exec('git add -A', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
// git commit
gulp.task('git-commit', ['git-add'], function (cb) {
var package = require('./package.json');
exec('git commit -m "Version ' + package.version + ' release."', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
// git push
gulp.task('git-push', ['git-commit'], function (cb) {
exec('git push', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
// publish ./dist directory to npm
gulp.task('publish', ['clean', 'git-push'], function (cb) {
exec('npm publish ./dist', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
// build ./dist folder
gulp.task('default', ['replace'], function () {});
// watch for changes and rebuild ./dist folder
gulp.task('watch', ['default'], function (cb) {
return watch('*', function () {
gulp.start('default');
});
});