-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
99 lines (90 loc) · 2.48 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
const gulp = require('gulp');
const merge = require('merge-stream');
const fs = require('fs');
const color = require('gulp-color');
/**
* Determine the path to the dist directory
* @param {string} subpath
*/
const path = require('path');
const DIST = '';
const dist = (subpath) => {
return !subpath ? DIST : path.join(DIST, subpath);
}
/**
* Clean task
* Delete everything but the security folder (for now)
* @return {Promise}
*/
const del = require('del');
gulp.task('clean', () => {
return del(['dist/', '*.log', '**/*.log']).then((paths) => {
if (paths && paths.length > 0) {
let items = paths.join('\n');
console.log(color('Deleted ' + paths.length + ' distribution items:\n', 'MAGENTA'), color(items, 'YELLOW'));
} else {
console.log(color('Nothing to delete!', 'GREEN'));
}
});
});
/**
* Copy task
* Copy all files/folders except .js and .ts files from src to dist
*/
gulp.task('copy', ['clean'], () => {
return gulp.src(['src/**/*', '!src/*.ts', '!src/**/*.ts', '!src/test/'])
.pipe(gulp.dest(dist()));
});
/**
* Typescript task
* Compile the typescript and distribute to the dist directory
*/
const ts = require('gulp-typescript');
const tsProject = ts.createProject('tsconfig.json');
const gulpIgnore = require('gulp-ignore');
const sourcemaps = require('gulp-sourcemaps');
gulp.task('typescript', ['copy'], () => {
const tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject(ts.reporter.longReporter()));
return merge([
tsResult.dts.pipe(gulpIgnore.exclude(['src/test/**/*', 'node_modules']))
.pipe(gulp.dest(dist())),
tsResult.js.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(dist()))
]);
});
/****** Production Build Tasks ******/
const bump = require('gulp-bump');
/**
* Build:Major task
* Bump the major version number (1.0.0) in package.json
*/
gulp.task('build:major', ['default'], function() {
gulp.src(['./package.json'])
.pipe(bump({type: 'major'}))
.pipe(gulp.dest('./'));
});
/**
* Build:Minor task
* Bump the minor version number (0.1.0) in package.json
*/
gulp.task('build:minor', ['default'], function() {
gulp.src(['./package.json'])
.pipe(bump({type: 'minor'}))
.pipe(gulp.dest('./'));
});
/**
* Build:Patch task
* Bump the patch version number (0.1.0) in package.json
*/
gulp.task('build:patch', ['default'], function() {
gulp.src(['./package.json'])
.pipe(bump())
.pipe(gulp.dest('./'));
});
/**
* Default task
* Compile and copy all relevant files to the dist directory
*/
gulp.task('default', ['typescript']);