xref: /aosp_15_r20/external/chromium-trace/catapult/third_party/polymer/components/shadycss/gulpfile.js (revision 1fa4b3da657c0e9ad43c0220bacf9731820715a5)
1/**
2 * @license
3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7 * Code distributed by Google as part of the polymer project is also
8 * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9 */
10
11'use strict';
12
13/* eslint-env node */
14/* eslint-disable no-console */
15
16const gulp = require('gulp');
17const sourcemaps = require('gulp-sourcemaps');
18const del = require('del');
19const rename = require('gulp-rename');
20const rollup = require('rollup-stream');
21const buffer = require('vinyl-buffer');
22const source = require('vinyl-source-stream');
23const closure = require('google-closure-compiler').gulp();
24const size = require('gulp-size');
25
26const modules = [
27  'css-parse',
28  'custom-style-element',
29  'make-element',
30  'svg-in-shadow',
31  'style-util',
32  'style-transformer',
33  'style-settings'
34];
35
36const moduleTasks = modules.map((m) => {
37  gulp.task(`test-module-${m}`, () => {
38    return rollup({
39      entry: `tests/module/${m}.js`,
40      format: 'iife',
41      moduleName: m.replace(/-/g, '_')
42    })
43    .pipe(source(`${m}.js`, 'tests/module'))
44    .pipe(gulp.dest('./tests/module/generated'))
45  });
46  return `test-module-${m}`;
47});
48
49gulp.task('clean-test-modules', () => del(['tests/module/generated']));
50
51gulp.task('test-modules', gulp.series(['clean-test-modules', ...moduleTasks]));
52
53function closurify(entry) {
54  gulp.task(`closure-${entry}`, () => {
55    return gulp.src(['src/*.js', 'entrypoints/*.js'], {base: './'})
56    .pipe(sourcemaps.init())
57    .pipe(closure({
58      compilation_level: 'ADVANCED',
59      language_in: 'ES6_STRICT',
60      language_out: 'ES5_STRICT',
61      isolation_mode: 'IIFE',
62      assume_function_wrapper: true,
63      js_output_file: `${entry}.min.js`,
64      entry_point: `./entrypoints/${entry}.js`,
65      dependency_mode: 'STRICT',
66      warning_level: 'VERBOSE',
67      rewrite_polyfills: false,
68      externs: 'externs/shadycss-externs.js'
69    }))
70    .pipe(size({showFiles: true, showTotal: false, gzip: true}))
71    .pipe(sourcemaps.write('.'))
72    .pipe(gulp.dest('.'))
73  });
74  return `closure-${entry}`;
75}
76
77function debugify(entry) {
78  gulp.task(`debug-${entry}`, () => {
79    return rollup({
80      entry: `entrypoints/${entry}.js`,
81      format: 'iife',
82      moduleName: `${entry}`.replace(/-/g, '_'),
83    })
84    .pipe(source(`${entry}.js`, 'entrypoints'))
85    .pipe(buffer())
86    .pipe(sourcemaps.init({loadMaps: true}))
87    .pipe(rename(`${entry}.min.js`))
88    .pipe(size({showFiles: true, showTotal: false, gzip: true}))
89    .pipe(gulp.dest('./'))
90  });
91  return `debug-${entry}`;
92}
93
94const entrypoints = [
95  'scoping-shim',
96  'apply-shim',
97  'custom-style-interface'
98]
99
100let closureTasks = entrypoints.map((e) => closurify(e));
101let debugTasks = entrypoints.map((e) => debugify(e));
102
103gulp.task('closure', gulp.series([...closureTasks]));
104
105gulp.task('default', gulp.series('closure', 'test-modules'));
106
107gulp.task('debug', gulp.series([...debugTasks]));
108