@@ -6,33 +6,41 @@ const modify = require('gulp-modify');
66const cheerio = require ( 'cheerio' ) ;
77const concat = require ( 'gulp-concat' ) ;
88
9- gulp . task ( 'icons' , function ( ) {
9+ function createCopyright ( ) {
10+ return `/**
11+ * @license
12+ * Copyright (c) 2015 - ${ new Date ( ) . getFullYear ( ) } Vaadin Ltd.
13+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
14+ */` ;
15+ }
16+
17+ function iconFileModifier ( prefix ) {
18+ return function ( file , contents ) {
19+ const id = file . path . replace ( / .* \/ ( .* ) .s v g / , '$1' ) ;
20+ const svg = cheerio . load ( contents , { xmlMode : true } ) ( 'svg' ) ;
21+ // Remove fill attributes.
22+ svg . children ( '[fill]' ) . removeAttr ( 'fill' ) ;
23+ // Add closing tags instead of self-closing.
24+ const content = svg . children ( ) . toString ( ) . replace ( / " \/ > / g, '"></path>' ) ;
25+ // Output the "meat" of the SVG as group element.
26+ return `<g id="${ prefix } ${ id } ">${ content } </g>` ;
27+ } ;
28+ }
29+
30+ gulp . task ( 'iron-icons' , function ( ) {
1031 return gulp
1132 . src ( [ 'assets/svg/*.svg' ] , { base : '.' } )
1233 . pipe (
1334 modify ( {
14- fileModifier : function ( file , contents ) {
15- const id = file . path . replace ( / .* \/ ( .* ) .s v g / , '$1' ) ;
16- const svg = cheerio . load ( contents , { xmlMode : true } ) ( 'svg' ) ;
17- // Remove fill attributes.
18- svg . children ( '[fill]' ) . removeAttr ( 'fill' ) ;
19- // Add closing tags instead of self-closing.
20- const content = svg . children ( ) . toString ( ) . replace ( / " \/ > / g, '"></path>' ) ;
21- // Output the "meat" of the SVG as group element.
22- return `<g id="${ id } ">${ content } </g>` ;
23- }
35+ fileModifier : iconFileModifier ( '' )
2436 } )
2537 )
2638 . pipe ( concat ( 'iconset.js' ) )
2739 . pipe (
2840 modify ( {
2941 fileModifier : function ( file , contents ) {
3042 // Enclose all icons in an iron-iconset-svg
31- return `/**
32- * @license
33- * Copyright (c) 2015 - 2021 Vaadin Ltd.
34- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
35- */
43+ return `${ createCopyright ( ) }
3644import '@polymer/iron-iconset-svg/iron-iconset-svg.js';
3745
3846const $_documentContainer = document.createElement('template');
@@ -47,3 +55,35 @@ document.head.appendChild($_documentContainer.content);\n`;
4755 )
4856 . pipe ( gulp . dest ( '.' ) ) ;
4957} ) ;
58+
59+ gulp . task ( 'vaadin-icons' , function ( ) {
60+ return gulp
61+ . src ( [ 'assets/svg/*.svg' ] , { base : '.' } )
62+ . pipe (
63+ modify ( {
64+ fileModifier : iconFileModifier ( 'vaadin:' )
65+ } )
66+ )
67+ . pipe ( concat ( 'vaadin-iconset.js' ) )
68+ . pipe (
69+ modify ( {
70+ fileModifier : function ( file , contents ) {
71+ // Enclose all icons in a vaadin-iconset
72+ return `${ createCopyright ( ) }
73+ import '@vaadin/vaadin-icon/vaadin-iconset.js';
74+ import '@vaadin/vaadin-icon/vaadin-icon.js';
75+
76+ const $_documentContainer = document.createElement('template');
77+
78+ $_documentContainer.innerHTML = \`<vaadin-iconset name="vaadin" size="16">
79+ <svg><defs>\n${ contents } \n</defs></svg>
80+ </vaadin-iconset>\`;
81+
82+ document.head.appendChild($_documentContainer.content);\n` ;
83+ }
84+ } )
85+ )
86+ . pipe ( gulp . dest ( '.' ) ) ;
87+ } ) ;
88+
89+ gulp . task ( 'icons' , gulp . parallel ( 'iron-icons' , 'vaadin-icons' ) ) ;
0 commit comments