-
Notifications
You must be signed in to change notification settings - Fork 124
/
gulpfile.js
58 lines (47 loc) · 1.5 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
const gulp = require('gulp');
const webpack = require('gulp-webpack');
const named = require('vinyl-named');
const map = require('vinyl-map');
const path = require('path');
const fs = require('fs');
let i = 0;
const wrapCode = (name, code) => `//META{"name":"p_${name}"}*//
/*@cc_on
@if (@_jscript)
${fs.readFileSync('ms_installer.js').toString().replace(/^/gm,'\t')}
@else @*/
${code.replace(/^/gm,'\t')}
/*@end @*/
`;
gulp.task('copy-templates', () =>
gulp.src('v2/*/plugin.js').pipe(map((code, filename) => {
gulp.src('v1template.js')
.pipe(gulp.dest(path.dirname(filename)));
return code;
}))
);
gulp.task('webpack', () =>
gulp.src('v2/*/v1template.js')
.pipe(named(file => file.dirname.split(path.sep).pop().replace(/\s+/g, '_').toLowerCase()))
.pipe(webpack({
output: {
filename: '[name].plugin.js',
libraryTarget: "var",
library: "p_[name]"
},
externals: {
'../modules/api': '{}',
'../modules/utils': '{}',
},
module: {
loaders: [
{
test: /\.json/,
loader: "json"
}
]
}
}))
.pipe(map((code, filename) => wrapCode(path.basename(filename, '.plugin.js'), code.toString())))
.pipe(gulp.dest('v1/')));
gulp.task('default', gulp.series('copy-templates', 'webpack'));