-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathgulpfile.js
122 lines (100 loc) · 3.13 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
const { series } = require('gulp');
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');
// watch for changes files and recompile
function watch_files() {
gulp.watch("*", gulp.series(clean, compile));
}
// 1. delete contents of dist directory
function clean(cb) {
del(['./dist/*', '!dist/index.js']);
cb();
}
// 2. compile to dist directory
function compile(cb) {
exec('npm run compile', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
})
}
// 3. include package.json file in ./dist folder
function package(cb) {
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');
console.log('package.json Copied to Dist Directory');
cb();
}
// 4. include type definition file for adal-angular
function copy(cb) {
gulp.src(['adal-angular.d.ts']).pipe(gulp.dest('./dist/'));
console.log('adal-angular.d.ts Copied to Dist Directory');
gulp.src(['README.md']).pipe(gulp.dest('./dist/'));
console.log('README.md Copied to Dist Directory');
cb();
}
// 5. rewrite type definition file path for adal-angular in adal.service.d.ts
function replace_d(cb) {
gulp.src('./dist/adal.service.d.ts')
.pipe(replace('../adal-angular.d.ts', './adal-angular.d.ts'))
.pipe(gulp.dest('./dist/'));
console.log('adal.service.d.ts Path Updated');
cb();
}
// 6. increase the version in package.json
function bump_version(cb) {
gulp.src('./package.json')
.pipe(bump({
type: 'patch'
}))
.pipe(gulp.dest('./'));
console.log('Version Bumped');
cb();
}
// 7. git add
function git_add(cb) {
exec('git add -A', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}
// 8. git commit
function git_commit(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);
});
}
// 9. git push
function git_push(cb) {
exec('git push', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}
// 10. publish ./dist directory to npm
function npm_publish(cb) {
exec('npm publish ./dist', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}
// Gulp Tasks
exports.watch = series(watch_files);
exports.build = series(clean, compile, package, copy, replace_d);
exports.commit = series(clean, compile, package, copy, replace_d, bump_version, git_add, git_commit, git_push);
exports.publish = series(clean, compile, package, copy, replace_d, bump_version, git_add, git_commit, git_push, npm_publish);