forked from VSCodeVim/Vim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
144 lines (123 loc) · 3.31 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
var gulp = require('gulp'),
bump = require('gulp-bump'),
filter = require('gulp-filter'),
git = require('gulp-git'),
sourcemaps = require('gulp-sourcemaps'),
tag_version = require('gulp-tag-version'),
tslint = require('gulp-tslint'),
ts = require('gulp-typescript');
// compile
gulp.task('compile', function() {
var isError = false;
var tsProject = ts.createProject('tsconfig.json', { noEmitOnError: true });
var tsResult = tsProject
.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.on('error', function(error) {
isError = true;
})
.on('finish', function() {
isError && process.exit(1);
});
return tsResult.js
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: '' }))
.pipe(gulp.dest('out'));
});
// tslint
gulp.task('tslint', function() {
return gulp
.src(['**/*.ts', '!node_modules/**', '!typings/**'])
.pipe(
tslint({
formatter: 'prose',
program: require('tslint').Linter.createProgram('./tsconfig.json'),
})
)
.pipe(tslint.report({ summarizeFailureOutput: true }));
});
// prettier
function runPrettier(command, cb) {
var exec = require('child_process').exec;
exec(command, function(err, stdout, stderr) {
if (err) {
return cb(err);
}
if (!stdout) {
return cb();
}
var files = stdout
.split(/\r?\n/)
.filter(f => {
return f.endsWith('.ts') || f.endsWith('.js');
})
.join(' ');
if (!files) {
return cb();
}
const prettierPath = require('path').normalize('./node_modules/.bin/prettier');
exec(
`${prettierPath} --write --print-width 100 --single-quote --trailing-comma es5 ${files}`,
function(err, stdout, stderr) {
cb(err);
}
);
});
}
gulp.task('prettier', function(cb) {
// files changed
runPrettier('git diff --name-only HEAD', cb);
});
gulp.task('forceprettier', function(cb) {
// files managed by git
runPrettier('git ls-files', cb);
});
// test
gulp.task('test', function(cb) {
var spawn = require('child_process').spawn;
const dockerTag = 'vscodevim';
console.log('Building container...');
var dockerBuildCmd = spawn(
'docker',
['build', '-f', './build/Dockerfile', '.', '-t', dockerTag],
{
cwd: process.cwd(),
stdio: 'inherit',
}
);
dockerBuildCmd.on('exit', function(code) {
if (code !== 0) {
cb(code);
return;
}
console.log('Running tests inside container...');
console.log('To break, run `docker kill` in a separate terminal.');
var dockerRunCmd = spawn('docker', ['run', '-v', process.cwd() + ':/app', dockerTag], {
cwd: process.cwd(),
stdio: 'inherit',
});
dockerRunCmd.on('exit', function(code) {
cb(code);
});
});
});
// version bump
function versionBump(semver) {
return gulp
.src(['./package.json', './package-lock.json'])
.pipe(bump({ type: semver }))
.pipe(gulp.dest('./'))
.pipe(git.commit('bump version'))
.pipe(filter('package.json'))
.pipe(tag_version());
}
gulp.task('patch', ['default'], function() {
return versionBump('patch');
});
gulp.task('minor', ['default'], function() {
return versionBump('minor');
});
gulp.task('major', ['default'], function() {
return versionBump('major');
});
gulp.task('default', ['prettier', 'tslint', 'compile']);