2017-11-03 00:04:42 +03:00
|
|
|
var gulp = require('gulp'),
|
|
|
|
bump = require('gulp-bump'),
|
|
|
|
git = require('gulp-git'),
|
2018-02-04 12:21:44 +03:00
|
|
|
sourcemaps = require('gulp-sourcemaps'),
|
2017-11-03 00:04:42 +03:00
|
|
|
tag_version = require('gulp-tag-version'),
|
|
|
|
tslint = require('gulp-tslint'),
|
2018-07-15 13:16:35 +03:00
|
|
|
ts = require('gulp-typescript'),
|
|
|
|
PluginError = require('plugin-error'),
|
2018-07-15 21:58:32 +03:00
|
|
|
minimist = require('minimist'),
|
2020-05-02 23:44:08 +03:00
|
|
|
path = require('path'),
|
|
|
|
webpack_stream = require('webpack-stream'),
|
|
|
|
webpack_config = require('./webpack.config.js');
|
2020-05-09 22:51:08 +03:00
|
|
|
webpack_dev_config = require('./webpack.dev.js');
|
2018-07-15 21:58:32 +03:00
|
|
|
|
|
|
|
const exec = require('child_process').exec;
|
|
|
|
const spawn = require('child_process').spawn;
|
|
|
|
|
|
|
|
const releaseOptions = {
|
|
|
|
semver: '',
|
2018-07-18 01:26:41 +03:00
|
|
|
gitHubToken: '',
|
2018-07-15 21:58:32 +03:00
|
|
|
};
|
2017-11-03 00:04:42 +03:00
|
|
|
|
2018-07-15 13:16:35 +03:00
|
|
|
// prettier
|
|
|
|
function runPrettier(command, done) {
|
2020-03-26 20:02:33 +03:00
|
|
|
exec(command, function (err, stdout) {
|
2018-07-15 13:16:35 +03:00
|
|
|
if (err) {
|
|
|
|
return done(new PluginError('runPrettier', { message: err }));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stdout) {
|
|
|
|
return done();
|
|
|
|
}
|
|
|
|
|
|
|
|
var files = stdout
|
|
|
|
.split(/\r?\n/)
|
2020-03-26 20:02:33 +03:00
|
|
|
.filter((f) => {
|
2020-06-18 19:53:41 +03:00
|
|
|
return f.endsWith('.ts') || f.endsWith('.js') || f.endsWith('.json') || f.endsWith('.md');
|
2018-07-15 13:16:35 +03:00
|
|
|
})
|
|
|
|
.join(' ');
|
|
|
|
|
|
|
|
if (!files) {
|
|
|
|
return done();
|
|
|
|
}
|
|
|
|
|
2018-07-15 21:58:32 +03:00
|
|
|
const prettierPath = path.normalize('./node_modules/.bin/prettier');
|
2020-03-26 20:02:33 +03:00
|
|
|
exec(`${prettierPath} --write ${files}`, function (err) {
|
2019-07-25 05:24:59 +03:00
|
|
|
if (err) {
|
|
|
|
return done(new PluginError('runPrettier', { message: err }));
|
2018-07-15 13:16:35 +03:00
|
|
|
}
|
2019-07-25 05:24:59 +03:00
|
|
|
return done();
|
|
|
|
});
|
2018-07-15 13:16:35 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-17 22:57:44 +03:00
|
|
|
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',
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-12-01 21:23:20 +03:00
|
|
|
if (!['patch', 'minor', 'major'].includes(options.semver)) {
|
|
|
|
return done(
|
|
|
|
new PluginError('updateVersion', {
|
|
|
|
message: 'Invalid `--semver` option. Possible values: patch, minor, major',
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2018-07-15 21:58:32 +03:00
|
|
|
|
2018-07-18 01:26:41 +03:00
|
|
|
const gitHubToken = options.gitHubToken || process.env.CHANGELOG_GITHUB_TOKEN;
|
|
|
|
if (!gitHubToken) {
|
2018-07-15 13:16:35 +03:00
|
|
|
return done(
|
2018-07-15 21:58:32 +03:00
|
|
|
new PluginError('createChangelog', {
|
2018-07-17 22:57:44 +03:00
|
|
|
message:
|
2018-07-18 01:26:41 +03:00
|
|
|
'Missing GitHub API Token. Supply token using `--gitHubToken` option or `CHANGELOG_GITHUB_TOKEN` environment variable.',
|
2018-07-15 13:16:35 +03:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-17 22:57:44 +03:00
|
|
|
done();
|
|
|
|
}
|
|
|
|
|
|
|
|
function createChangelog(done) {
|
2018-11-27 10:45:23 +03:00
|
|
|
const imageName = 'jpoon/github-changelog-generator';
|
2018-07-17 22:57:44 +03:00
|
|
|
const version = require('./package.json').version;
|
|
|
|
|
|
|
|
const options = minimist(process.argv.slice(2), releaseOptions);
|
|
|
|
const gitHubToken = options.gitHubToken || process.env.CHANGELOG_GITHUB_TOKEN;
|
|
|
|
|
2018-07-15 13:16:35 +03:00
|
|
|
var dockerRunCmd = spawn(
|
|
|
|
'docker',
|
|
|
|
[
|
2018-07-15 21:58:32 +03:00
|
|
|
'run',
|
|
|
|
'-it',
|
|
|
|
'--rm',
|
|
|
|
'-v',
|
2018-07-15 13:16:35 +03:00
|
|
|
process.cwd() + ':/usr/local/src/your-app',
|
|
|
|
imageName,
|
|
|
|
'--token',
|
2018-07-17 22:57:44 +03:00
|
|
|
gitHubToken,
|
2018-07-15 21:58:32 +03:00
|
|
|
'--future-release',
|
2018-07-15 22:12:27 +03:00
|
|
|
'v' + version,
|
2018-07-15 13:16:35 +03:00
|
|
|
],
|
|
|
|
{
|
|
|
|
cwd: process.cwd(),
|
|
|
|
stdio: 'inherit',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-03-26 20:02:33 +03:00
|
|
|
dockerRunCmd.on('exit', function (exitCode) {
|
2018-07-15 13:16:35 +03:00
|
|
|
done(exitCode);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function createGitTag() {
|
|
|
|
return gulp.src(['./package.json']).pipe(tag_version());
|
|
|
|
}
|
|
|
|
|
|
|
|
function createGitCommit() {
|
|
|
|
return gulp
|
|
|
|
.src(['./package.json', './package-lock.json', 'CHANGELOG.md'])
|
|
|
|
.pipe(git.commit('bump version'));
|
|
|
|
}
|
|
|
|
|
2018-07-15 21:58:32 +03:00
|
|
|
function updateVersion(done) {
|
|
|
|
var options = minimist(process.argv.slice(2), releaseOptions);
|
2018-07-15 13:16:35 +03:00
|
|
|
|
|
|
|
return gulp
|
|
|
|
.src(['./package.json', './package-lock.json'])
|
|
|
|
.pipe(bump({ type: options.semver }))
|
|
|
|
.pipe(gulp.dest('./'))
|
2018-07-15 21:58:32 +03:00
|
|
|
.on('end', () => {
|
2018-07-15 13:16:35 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-02 23:44:08 +03:00
|
|
|
function copyPackageJson() {
|
|
|
|
return gulp.src('./package.json').pipe(gulp.dest('out'));
|
|
|
|
}
|
|
|
|
|
2020-03-26 20:02:33 +03:00
|
|
|
gulp.task('tsc', function () {
|
2018-05-09 20:23:28 +03:00
|
|
|
var isError = false;
|
2018-05-08 08:38:18 +03:00
|
|
|
|
2018-05-03 21:33:50 +03:00
|
|
|
var tsProject = ts.createProject('tsconfig.json', { noEmitOnError: true });
|
2018-05-08 08:38:18 +03:00
|
|
|
var tsResult = tsProject
|
2018-02-04 14:46:50 +03:00
|
|
|
.src()
|
2018-02-04 12:21:44 +03:00
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(tsProject())
|
2018-07-15 13:16:35 +03:00
|
|
|
.on('error', () => {
|
2018-05-08 08:38:18 +03:00
|
|
|
isError = true;
|
|
|
|
})
|
2018-07-15 13:16:35 +03:00
|
|
|
.on('finish', () => {
|
2018-05-08 08:38:18 +03:00
|
|
|
isError && process.exit(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
return tsResult.js
|
|
|
|
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: '' }))
|
2018-02-04 12:21:44 +03:00
|
|
|
.pipe(gulp.dest('out'));
|
2017-11-03 00:04:42 +03:00
|
|
|
});
|
|
|
|
|
2020-05-02 23:44:08 +03:00
|
|
|
gulp.task('webpack', function () {
|
|
|
|
return gulp.src('./extension.ts').pipe(webpack_stream(webpack_config)).pipe(gulp.dest('out'));
|
|
|
|
});
|
|
|
|
|
2020-05-09 22:51:08 +03:00
|
|
|
gulp.task('webpack-dev', function () {
|
|
|
|
return gulp.src('./extension.ts').pipe(webpack_stream(webpack_dev_config)).pipe(gulp.dest('out'));
|
|
|
|
});
|
|
|
|
|
2020-03-26 20:02:33 +03:00
|
|
|
gulp.task('tslint', function () {
|
2018-07-15 13:16:35 +03:00
|
|
|
const program = require('tslint').Linter.createProgram('./tsconfig.json');
|
2018-02-03 13:07:57 +03:00
|
|
|
return gulp
|
2018-02-04 14:46:50 +03:00
|
|
|
.src(['**/*.ts', '!node_modules/**', '!typings/**'])
|
2018-05-24 11:05:35 +03:00
|
|
|
.pipe(
|
|
|
|
tslint({
|
|
|
|
formatter: 'prose',
|
2018-07-15 13:16:35 +03:00
|
|
|
program: program,
|
2018-05-24 11:05:35 +03:00
|
|
|
})
|
|
|
|
)
|
2018-02-03 13:07:57 +03:00
|
|
|
.pipe(tslint.report({ summarizeFailureOutput: true }));
|
2017-11-03 00:04:42 +03:00
|
|
|
});
|
|
|
|
|
2020-03-26 20:02:33 +03:00
|
|
|
gulp.task('prettier', function (done) {
|
2018-02-04 14:46:50 +03:00
|
|
|
// files changed
|
2018-07-15 13:16:35 +03:00
|
|
|
runPrettier('git diff --name-only HEAD', done);
|
2017-11-03 00:04:42 +03:00
|
|
|
});
|
|
|
|
|
2020-03-26 20:02:33 +03:00
|
|
|
gulp.task('forceprettier', function (done) {
|
2017-11-12 08:05:43 +03:00
|
|
|
// files managed by git
|
2018-07-15 13:16:35 +03:00
|
|
|
runPrettier('git ls-files', done);
|
2017-11-03 00:04:42 +03:00
|
|
|
});
|
|
|
|
|
2020-03-26 20:02:33 +03:00
|
|
|
gulp.task('commit-hash', function (done) {
|
|
|
|
git.revParse({ args: 'HEAD', quiet: true }, function (err, hash) {
|
2019-01-31 13:50:54 +03:00
|
|
|
require('fs').writeFileSync('out/version', hash);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-02-03 13:07:57 +03:00
|
|
|
// test
|
2020-05-02 23:44:08 +03:00
|
|
|
gulp.task('run-test', function (done) {
|
2018-07-27 22:37:20 +03:00
|
|
|
// the flag --grep takes js regex as a string and filters by test and test suite names
|
2018-07-27 22:23:52 +03:00
|
|
|
var knownOptions = {
|
|
|
|
string: 'grep',
|
|
|
|
default: { grep: '' },
|
|
|
|
};
|
|
|
|
var options = minimist(process.argv.slice(2), knownOptions);
|
|
|
|
|
2018-02-04 12:01:01 +03:00
|
|
|
var spawn = require('child_process').spawn;
|
2018-02-04 14:46:50 +03:00
|
|
|
const dockerTag = 'vscodevim';
|
|
|
|
|
|
|
|
console.log('Building container...');
|
|
|
|
var dockerBuildCmd = spawn(
|
|
|
|
'docker',
|
2020-06-09 22:48:57 +03:00
|
|
|
['build', '-f', './build/Dockerfile', './build/', '-t', dockerTag],
|
2018-02-04 14:46:50 +03:00
|
|
|
{
|
|
|
|
cwd: process.cwd(),
|
|
|
|
stdio: 'inherit',
|
|
|
|
}
|
|
|
|
);
|
2018-02-03 13:07:57 +03:00
|
|
|
|
2020-03-26 20:02:33 +03:00
|
|
|
dockerBuildCmd.on('exit', function (exitCode) {
|
2018-07-15 13:16:35 +03:00
|
|
|
if (exitCode !== 0) {
|
|
|
|
return done(
|
|
|
|
new PluginError('test', {
|
|
|
|
message: 'Docker build failed.',
|
|
|
|
})
|
|
|
|
);
|
2017-11-03 00:04:42 +03:00
|
|
|
}
|
2018-02-03 13:07:57 +03:00
|
|
|
|
2018-07-27 23:47:15 +03:00
|
|
|
const dockerRunArgs = [
|
|
|
|
'run',
|
|
|
|
'-it',
|
2020-06-09 22:48:57 +03:00
|
|
|
'--rm',
|
2018-07-27 23:47:15 +03:00
|
|
|
'--env',
|
|
|
|
`MOCHA_GREP=${options.grep}`,
|
|
|
|
'-v',
|
|
|
|
process.cwd() + ':/app',
|
|
|
|
dockerTag,
|
|
|
|
];
|
2018-02-04 14:46:50 +03:00
|
|
|
console.log('Running tests inside container...');
|
2018-07-27 23:47:15 +03:00
|
|
|
var dockerRunCmd = spawn('docker', dockerRunArgs, {
|
|
|
|
cwd: process.cwd(),
|
|
|
|
stdio: 'inherit',
|
|
|
|
});
|
2018-02-03 13:07:57 +03:00
|
|
|
|
2020-03-26 20:02:33 +03:00
|
|
|
dockerRunCmd.on('exit', function (exitCode) {
|
2018-07-15 13:16:35 +03:00
|
|
|
done(exitCode);
|
2018-02-03 13:07:57 +03:00
|
|
|
});
|
2017-11-03 00:04:42 +03:00
|
|
|
});
|
2018-02-03 13:07:57 +03:00
|
|
|
});
|
2017-11-03 00:04:42 +03:00
|
|
|
|
2020-05-02 23:44:08 +03:00
|
|
|
gulp.task('build', gulp.series('prettier', gulp.parallel('webpack', 'tslint'), 'commit-hash'));
|
2020-05-09 22:51:08 +03:00
|
|
|
gulp.task(
|
|
|
|
'build-dev',
|
|
|
|
gulp.series('prettier', gulp.parallel('webpack-dev', 'tslint'), 'commit-hash')
|
|
|
|
);
|
2020-05-02 23:44:08 +03:00
|
|
|
gulp.task('prepare-test', gulp.parallel('tsc', copyPackageJson));
|
|
|
|
gulp.task('test', gulp.series('prepare-test', 'run-test'));
|
2018-07-18 01:26:41 +03:00
|
|
|
gulp.task('changelog', gulp.series(validateArgs, createChangelog));
|
2018-07-17 22:57:44 +03:00
|
|
|
gulp.task(
|
|
|
|
'release',
|
2018-08-27 21:41:26 +03:00
|
|
|
gulp.series(
|
|
|
|
validateArgs,
|
|
|
|
updateVersion,
|
|
|
|
createChangelog,
|
|
|
|
'prettier',
|
|
|
|
createGitCommit,
|
|
|
|
createGitTag
|
|
|
|
)
|
2018-07-17 22:57:44 +03:00
|
|
|
);
|
2018-07-15 22:12:27 +03:00
|
|
|
gulp.task('default', gulp.series('build', 'test'));
|