This repository has been archived by the owner on Sep 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 490
/
gulpfile.js
210 lines (181 loc) · 5.58 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
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
'use strict';
/* eslint-env node */
/* eslint-disable no-console */
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const sourcesContent = require('@gulp-sourcemaps/sources-content');
const rename = require('gulp-rename');
const rollup = require('gulp-rollup');
const del = require('del');
const runseq = require('run-sequence');
const closure = require('google-closure-compiler').gulp();
const babel = require('rollup-plugin-babel');
const commonjs = require('rollup-plugin-commonjs');
const license = require('rollup-plugin-license');
function debugify(sourceName, fileName, extraRollupOptions) {
const outDir = fileName ? '.' : './bundles';
if (!fileName) {
fileName = sourceName;
}
const entry = `./entrypoints/${sourceName}-index.js`;
const options = {
input: entry,
output: {
format: 'iife',
name: 'webcomponentsjs'
},
allowRealFiles: true,
rollup: require('rollup')
};
Object.assign(options, extraRollupOptions);
return gulp.src(entry)
.pipe(rollup(options))
.pipe(rename(`${fileName}.js`))
.pipe(gulp.dest(outDir))
}
function closurify(sourceName, fileName) {
const outDir = fileName ? '.' : './bundles';
const smPrefix = fileName ? '' : '../';
if (!fileName) {
fileName = sourceName;
}
const closureOptions = {
compilation_level: 'ADVANCED',
language_in: 'ES6_STRICT',
language_out: 'ES5_STRICT',
isolation_mode: 'NONE',
output_wrapper_file: 'closure-output.txt',
assume_function_wrapper: true,
js_output_file: `${fileName}.js`,
warning_level: 'VERBOSE',
rewrite_polyfills: false,
module_resolution: 'NODE',
entry_point: `entrypoints/${sourceName}-index.js`,
dependency_mode: 'STRICT',
process_common_js_modules: true,
externs: [
'externs/webcomponents.js',
'node_modules/@webcomponents/custom-elements/externs/custom-elements.js',
'node_modules/@webcomponents/shadycss/externs/shadycss-externs.js',
'node_modules/@webcomponents/shadydom/externs/shadydom.js'
]
};
return gulp.src([
'entrypoints/*.js',
'src/*.js',
'node_modules/get-own-property-symbols/build/get-own-property-symbols.max.js',
'node_modules/promise-polyfill/src/**/*.js',
'node_modules/@webcomponents/**/*.js',
'!node_modules/@webcomponents/*/externs/*.js',
'!node_modules/@webcomponents/*/node_modules/**'
], {base: './', follow: true})
.pipe(sourcemaps.init())
.pipe(closure(closureOptions))
.pipe(sourcesContent())
.pipe(sourcemaps.mapSources(
// We load from node_modules, but the other polyfills are technically siblings of us.
// Therefore, rewrite the sourcemap files to fixup the directory location
sourcePath => sourcePath
.replace(/node_modules\/@webcomponents/, smPrefix + '..')
.replace(/node_modules/, smPrefix + '../..')
.replace(/^src/, smPrefix + 'src')
))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(outDir));
}
gulp.task('debugify-ce', () => {
return debugify('webcomponents-ce')
});
gulp.task('debugify-sd-ce-pf', () => {
const rollupOptions = {
plugins: [commonjs()]
};
return debugify('webcomponents-sd-ce-pf', null, rollupOptions)
});
gulp.task('debugify-sd-ce', () => {
return debugify('webcomponents-sd-ce')
});
gulp.task('debugify-sd', () => {
return debugify('webcomponents-sd')
});
gulp.task('debugify-bundle', () => {
const rollupOptions = {
plugins: [commonjs()]
};
return debugify('webcomponents-bundle', 'webcomponents-bundle', rollupOptions);
})
gulp.task('closurify-ce', () => {
return closurify('webcomponents-ce')
});
gulp.task('closurify-sd-ce-pf', () => {
return closurify('webcomponents-sd-ce-pf')
});
gulp.task('closurify-sd-ce', () => {
return closurify('webcomponents-sd-ce')
});
gulp.task('closurify-sd', () => {
return closurify('webcomponents-sd')
});
gulp.task('closurify-bundle', () => {
return closurify('webcomponents-bundle', 'webcomponents-bundle');
});
gulp.task('debugify-ce-es5-adapter', () => {
const rollupOptions = {
plugins: [
babel({
presets: [
['minify', {'keepFnName': true}]
],
}),
license({
banner: {
file: './license-header.txt'
}
})
]
};
return debugify('custom-elements-es5-adapter', 'custom-elements-es5-adapter', rollupOptions);
});
gulp.task('default', ['closure']);
gulp.task('clean', () => {
return del([
'custom-elements-es5-adapter.js{,.map}',
'bundles',
'webcomponents-bundle.js{,.map}'
]);
});
gulp.task('debug', (cb) => {
const tasks = [
'debugify-ce',
'debugify-sd',
'debugify-sd-ce',
'debugify-sd-ce-pf',
'debugify-bundle',
'debugify-ce-es5-adapter'
];
runseq('clean', tasks, cb);
});
gulp.task('closure', (cb) => {
const tasks = [
'closurify-ce',
'closurify-sd',
'closurify-sd-ce',
'closurify-sd-ce-pf',
'closurify-bundle',
'debugify-ce-es5-adapter'
];
runseq('clean', ...tasks, cb);
});
process.on('unhandledRejection', (err) => {
console.error('Unhandled Promise Rejection:', err);
process.exit(1);
})