-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
72 lines (61 loc) · 1.91 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
var gulp = require('gulp');
var fs = require('fs');
var ts = require('gulp-typescript');
var tsconfig = require('./tsconfig.json');
var exec = require('child_process').exec;
var paths = {
bin: 'bin/**/*',
typescript: 'src/**/*.ts',
javascript: '**/*.js',
docs: 'docs/**/*',
metadata: ['**/package.json', '!node_modules/**/package.json', '**/tsconfig.json', '**/jsconfig.json']
}
gulp.task('compile', ['stamp'], function () {
return gulp
.src(paths.typescript)
.pipe(ts(tsconfig.compilerOptions))
.pipe(gulp.dest('.'));
});
function updatePackage(version) {
var originalContents = fs.readFileSync('package.json', 'utf8');
var pkg = JSON.parse(originalContents);
pkg.version = version;
var updatedContents = JSON.stringify(pkg, null, '\t');
fs.writeFileSync('package.json', updatedContents);
}
function appendVersionToBuildNumber(version) {
var buildNumber = process.env.BUILD_BUILDNUMBER + '_' + version;
console.log('##vso[build.updatebuildnumber]%s', buildNumber);
}
gulp.task('stamp', function (callback) {
exec('git describe --abbrev=0', function (err, stdout, stderr) {
var version = stdout.toString().split('\n')[0];
console.log('git detected version was: %s', version);
updatePackage(version);
appendVersionToBuildNumber(version);
callback(err);
});
});
gulp.task('pack', ['compile'], function (callback) {
exec('npm pack', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
callback(err);
});
});
gulp.task('docs', function (callback) {
exec('make -C docs html', function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
callback(err);
});
});
gulp.task('watch', ['default'], function () {
gulp.watch(paths.metadata, ['pack']);
gulp.watch(paths.bin, ['pack']);
gulp.watch(paths.javascript, ['pack']);
gulp.watch(paths.typescript, ['compile']);
gulp.watch(paths.docs, ['docs']);
});
gulp.task('default', ['pack', 'docs']);
gulp.task('ci', ['pack']);