-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgulpfile.js
250 lines (216 loc) · 6.52 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
'use strict';
const gulp = require('gulp'),
eslint = require('gulp-eslint'),
sourcemaps = require('gulp-sourcemaps'),
closureCompiler = require('google-closure-compiler').gulp(),
babel = require('gulp-babel'),
colors = require('ansi-colors'),
log = require('fancy-log'),
bump = require('gulp-bump'),
git = require('gulp-git'),
args = require('yargs').argv,
fs = require('fs'),
gulpTypescript = require("gulp-typescript"),
through2 = require('through2'),
rename = require('gulp-rename'),
tsProject = gulpTypescript.createProject("tsconfig.json");
let files = ['./dist/multicolor-series.js', './samples/demo.js'],
decorator,
version;
decorator = [
'/**',
'----',
'*',
'* (c) 2012-2025 Black Label',
'*',
'* License: MIT',
'*/',
''
];
gulp.task("compile", () => {
return tsProject
.src()
.pipe(tsProject())
.js
.pipe(rename('multicolor-series.js'))
.pipe(through2.obj(async function (file, _encoding, callback) {
if (file.isBuffer()) {
let fileContent = file.contents.toString('utf8');
const removedSpecifiers = [],
removedPaths = [],
importPathReg = /import (.+?) from ["'](.+?)["'];/g,
formattedPathReg = /^highcharts-github\/ts\//,
exportReg = /\bexport\s*{[^}]*};?/g,
utilsPathReg = /^.*Utilities.*$/m;
fileContent = fileContent.replace(importPathReg, (_match, specifier, path) => {
removedSpecifiers.push(specifier);
removedPaths.push(`${path.replace(formattedPathReg, "")}.js`);
return '';
});
fileContent = fileContent.replace(
utilsPathReg,
'const { isArray, pick, SeriesRegistry, Series } = Highcharts;'
);
fileContent = fileContent.replace(exportReg, '');
const wrappedFileContent = decorator.join('\n') +
`(function (factory) {
if (typeof module === 'object' && module.exports) {
module.exports = factory;
} else {
factory(Highcharts);
}
}(function (Highcharts) {
${fileContent}
}));`;
file.contents = Buffer.from(wrappedFileContent, 'utf8');
}
this.push(file);
callback();
}))
.pipe(gulp.dest('dist'))
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['@babel/preset-env'],
overrides: [{
presets: [["@babel/preset-env", { targets: "defaults" }]]
}]
}))
.pipe(closureCompiler({
compilation_level: 'SIMPLE',
warning_level: 'DEFAULT', // VERBOSE
language_in: 'ECMASCRIPT6_STRICT',
language_out: 'ECMASCRIPT6_STRICT',
output_wrapper: '(function(){\n%output%\n}).call(this)',
js_output_file: 'multicolor-series.min.js',
externs: 'compileExterns.js'
}))
.pipe(sourcemaps.write('/'))
.pipe(gulp.dest('dist'))
});
gulp.task('lint', function () {
return gulp.src(['ts/*.ts'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('build', gulp.series('lint', 'compile'));
gulp.task('add-decorator', function (done) {
const minFile = './dist/multicolor-series.min.js',
main = fs.readFileSync(files[0], 'utf8'),
min = fs.readFileSync(minFile, 'utf8'),
old = main.match('(.*\r?\n){7}')[0];
fs.writeFileSync(files[0], main.replace(old, decorator.join('\n')), 'utf8');
fs.writeFileSync(minFile, decorator.join('\n') + min, 'utf8');
done();
});
gulp.task('get-version', function (done) {
const options = fs.readFileSync('package.json', {encoding: 'utf8'}),
optJSON = JSON.parse(options),
now = new Date();
version = optJSON.version;
decorator[1] = '* Multicolor Series v' + version + ' (' + now.toLocaleDateString('en-CA') + ')';
done();
});
gulp.task('release-commit', function (done) {
const message = 'Release version 3.1.0';
gulp.src(['package.json', 'manifest.json', 'dist/*'])
.pipe(git.add())
.pipe(git.commit(message, {emitData: true}))
.on('data', function (data) {
done();
})
.pipe(git.tag('v' + version, message));
});
gulp.task('checkout-master', function (done) {
git.checkout('master', function (err) {
if (err) throw err;
done();
});
});
gulp.task('checkout-gh-pages', function (done) {
git.checkout('gh-pages', function (err) {
if (err) throw err;
done();
});
});
gulp.task('merge-with-master', function (done) {
git.merge('master', function (err) {
if (err) throw err;
done();
});
});
gulp.task('push-tags', function (done) {
git.push('origin', 'master', {args: " --tags"}, function (err) {
if (err) throw err;
done();
});
});
gulp.task('push-gh-pages', function (done) {
git.push('origin', 'master', function (err) {
if (err) throw err;
done();
});
});
gulp.task('push-master', function (done) {
git.push('origin', 'gh-pages', function (err) {
if (err) throw err;
done();
});
});
gulp.task('bump-files', function () {
// Props to: http://stackoverflow.com/questions/36339694/how-to-increment-version-number-via-gulp-task
const type = args.type;
const v = args.ver;
let options = {};
if (v) {
options.version = v;
} else {
options.type = type;
}
return gulp
.src(['package.json', 'manifest.json'])
.pipe(bump(options))
.pipe(gulp.dest('./'));
});
gulp.task('default', function (done) {
log([
'\n',
colors.yellow('TASKS: '),
colors.cyan('prerelease:') + ' lint and compile sources',
colors.cyan('lint :') + ' lint TS files',
colors.cyan('compile :') + ' compile TS files',
colors.cyan('watch :') + ' watch changes in TS files and automatically lint',
colors.cyan('release :') + ' updates a version, usage: ',
colors.blue(' 1. gulp release:') + ' releases the package to the next minor revision.',
' Includes: linting, compiling, commit with new tags, merge with gh-pages, and push to the repo for commits and tags.',
' i.e. from 0.1.1 to 0.1.2',
colors.blue(' 2. gulp release --ver 1.1.1') + ' => Release the package with specific version.',
colors.blue(' 3. gulp release --type major') + ' => Increment major: 1.0.0',
colors.blue(' gulp release --type minor') + ' => Increment minor: 0.1.0',
colors.blue(' gulp release --type patch') + ' => Increment patch: 0.0.2',
colors.blue(' gulp release --type prerelease') + ' => Sets prerelease: 0.0.1-2',
''
].join('\n'));
done();
});
gulp.task('watch', function () {
return gulp.watch('ts/*.ts', gulp.series('lint', 'compile'));
});
gulp.task('prerelease', gulp.series('lint', 'compile'));
gulp.task('release',
gulp.series(
'lint',
'compile',
'bump-files',
'get-version',
'add-decorator',
// 'release-commit',
// 'checkout-gh-pages',
// 'merge-with-master',
// 'checkout-master',
// 'push-gh-pages',
// 'push-master',
// 'push-tags'
//'npm-publish'
)
);