Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
160 lines (142 loc) · 3.91 KB
/
Copy pathgulpfile.js
File metadata and controls
160 lines (142 loc) · 3.91 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
const gulp = require('gulp');
const bump = require('gulp-bump');
const tag_version = require('gulp-tag-version');
const ts = require('gulp-typescript');
const PluginError = require('plugin-error');
const minimist = require('minimist');
const path = require('path');
const es = require('event-stream');
const shell = require('gulp-shell');
const releaseOptions = {
semver: '',
};
function validateArgs(done) {
const options = minimist(process.argv.slice(2), releaseOptions);
if (!options.semver) {
return done(
new PluginError('updateVersion', {
message: 'Missing `--semver` option. Possible values: patch, minor, major',
}),
);
}
if (!['patch', 'minor', 'major'].includes(options.semver)) {
return done(
new PluginError('updateVersion', {
message: 'Invalid `--semver` option. Possible values: patch, minor, major',
}),
);
}
done();
}
function createGitTag() {
return gulp.src(['./package.json']).pipe(tag_version());
}
function updateVersion(done) {
var options = minimist(process.argv.slice(2), releaseOptions);
return gulp
.src(['./package.json', './yarn.lock'])
.pipe(bump({ type: options.semver }))
.pipe(gulp.dest('./'))
.on('end', () => {
done();
});
}
function updatePath() {
const input = es.through();
const output = input.pipe(
es.mapSync((f) => {
const contents = f.contents.toString('utf8');
const filePath = f.path;
let platformRelativepath = path.relative(
path.dirname(filePath),
path.resolve(process.cwd(), 'out/src/platform/node'),
);
platformRelativepath = platformRelativepath.replace(/\\/g, '/');
f.contents = Buffer.from(
contents.replace(
/\(\"platform\/([^"]*)\"\)/g,
'("' + (platformRelativepath === '' ? './' : platformRelativepath + '/') + '$1")',
),
'utf8',
);
return f;
}),
);
return es.duplex(input, output);
}
function copyPackageJson() {
return gulp.src('./package.json').pipe(gulp.dest('out'));
}
gulp.task('tsc', function () {
var isError = false;
var tsProject = ts.createProject('tsconfig.json', { noEmitOnError: true });
var tsResult = tsProject
.src()
.pipe(tsProject())
.on('error', () => {
isError = true;
})
.on('finish', () => {
isError && process.exit(1);
});
return tsResult.js.pipe(updatePath()).pipe(gulp.dest('out'));
});
// test
gulp.task('run-test', function (done) {
// the flag --grep takes js regex as a string and filters by test and test suite names
var knownOptions = {
string: 'grep',
default: { grep: '' },
};
var options = minimist(process.argv.slice(2), knownOptions);
var spawn = require('child_process').spawn;
const dockerTag = 'vscodevim';
console.log('Building container...');
var dockerBuildCmd = spawn(
'docker',
['build', '-f', './build/Dockerfile', './build/', '-t', dockerTag],
{
cwd: process.cwd(),
stdio: 'inherit',
},
);
dockerBuildCmd.on('exit', function (exitCode) {
if (exitCode !== 0) {
return done(
new PluginError('test', {
message: 'Docker build failed.',
}),
);
}
const dockerRunArgs = [
'run',
'-it',
'--rm',
'--env',
`MOCHA_GREP=${options.grep}`,
'-v',
process.cwd() + ':/app',
dockerTag,
];
console.log('Running tests inside container...');
var dockerRunCmd = spawn('docker', dockerRunArgs, {
cwd: process.cwd(),
stdio: 'inherit',
});
dockerRunCmd.on('exit', function (exitCode) {
done(exitCode);
});
});
});
gulp.task('prepare-test', gulp.parallel('tsc', copyPackageJson));
gulp.task('test', gulp.series('prepare-test', 'run-test'));
gulp.task(
'release',
gulp.series(
validateArgs,
updateVersion,
shell.task('git commit -am "bump version"'),
createGitTag,
),
);
gulp.task('default', shell.task('yarn build-dev'));