-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
158 lines (141 loc) · 4.6 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* eslint-disable @typescript-eslint/no-var-requires */
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
const gulp = require('gulp');
const cp = require('child_process');
const decompress = require('gulp-decompress');
const download = require('gulp-download');
const rename = require('gulp-rename');
const filter = require('gulp-filter');
const gRegexRename = require('gulp-regex-rename');
const fs = require('node:fs');
const BAZEL_ECLIPSE_DIR = '../bazel-eclipse';
const BAZEL_ECLIPSE_LATEST_URL =
'https://opensource.salesforce.com/bazel-eclipse/latest/p2-repository.zip';
const NON_NPM_REPOSITORY_RE = new RegExp(
String.raw`"resolved":\s*"https://(?!(registry\.npmjs\.org\/?))`,
'g'
);
// a little helper to drop OSGi versions from bundle jar file name
const DROP_JAR_VERSION = gRegexRename(/_\d+\.\d+\.\d+(\.[^\.]+)?\.jar/, '.jar');
// read the package.json once so we can use it in the gulp script
const packageJson = JSON.parse(fs.readFileSync('./package.json').toString());
// we only need the headless jars of the Bazel JDT Language Server extension
const declaredServerJars = new Set(
packageJson.contributes.javaExtensions.map(
(path) => path.split('/').reverse()[0]
)
);
const jarIsIncludedInPackageJson = filter((file) => {
return declaredServerJars.has(file.basename);
});
gulp.task('download_server', function (done) {
downloadServerImpl();
done();
});
gulp.task('build_server', function (done) {
buildServerImpl();
done();
});
gulp.task('build_or_download', function (done) {
if (!fs.existsSync(BAZEL_ECLIPSE_DIR)) {
console.log(
'NOTE: bazel-eclipse is not found as a sibling directory, downloading the latest snapshot of the Bazel JDT Language Server extension...'
);
downloadServerImpl();
} else {
buildServerImpl();
}
done();
});
gulp.task('prepare_pre_release', function (done) {
// parse existing version (using ECMA script regex from https://semver.org/)
const stableVersion = packageJson.version.match(
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
);
const major = stableVersion[1];
// unfortunately, VS Code Marketplace does not support full semver
// also, the limit is < 2147483647 on VS Code Marketplace
// thus, we use year (just the last two digits) as minor
// and patch that is based starting with the month up to the minute (for granularity)
const date = new Date();
const year = date.getUTCFullYear() - 2000;
const month = date.getUTCMonth() + 1;
const day = date.getUTCDate();
const hours = date.getUTCHours();
const minutes = date.getUTCMinutes();
const patch = `1${prependZero(month)}${prependZero(day)}${prependZero(
hours
)}${prependZero(minutes)}`;
const insiderPackageJson = Object.assign(packageJson, {
version: `${major}.${year}.${patch}`,
});
console.log(`Applying pre-release version '${major}.${year}.${patch}'...`);
fs.writeFileSync(
'./package.json',
JSON.stringify(insiderPackageJson, null, '\t')
);
done();
});
gulp.task('repo_check', function (done) {
const data = fs.readFileSync('./package-lock.json', { encoding: 'utf-8' });
if (NON_NPM_REPOSITORY_RE.test(data)) {
done(
new Error(
"Found references to the internal registry in the file package-lock.json. Please fix it with replacing all URLs using 'https://registry.npmjs.org'!"
)
);
} else {
done();
}
});
function isWin() {
return /^win/.test(process.platform);
}
function isMac() {
return /^darwin/.test(process.platform);
}
function isLinux() {
return /^linux/.test(process.platform);
}
function mvnw() {
return isWin() ? 'mvnw.cmd' : './mvnw';
}
function prependZero(num) {
if (num > 99) {
throw new Error('Unexpected value to prepend with zero');
}
return `${num < 10 ? '0' : ''}${num}`;
}
function downloadServerImpl() {
fs.rmSync('./server', { recursive: true, force: true });
download(BAZEL_ECLIPSE_LATEST_URL)
.pipe(decompress())
.pipe(filter(['plugins/*.jar']))
.pipe(
rename(function (path) {
return {
dirname: '', // flatten
basename: path.basename,
extname: path.extname,
};
})
)
.pipe(DROP_JAR_VERSION)
.pipe(jarIsIncludedInPackageJson)
.pipe(gulp.dest('./server'));
}
function buildServerImpl() {
fs.rmSync('./server', { recursive: true, force: true });
cp.execSync(mvnw() + ' clean package -DskipTests=true', {
cwd: BAZEL_ECLIPSE_DIR,
stdio: [0, 1, 2],
});
gulp
.src(
BAZEL_ECLIPSE_DIR + '/releng/p2repository/target/repository/plugins/*.jar'
)
.pipe(DROP_JAR_VERSION)
.pipe(jarIsIncludedInPackageJson)
.pipe(gulp.dest('./server'));
}