1- 'use strict' ;
2-
31const through = require ( 'through2' ) ;
42const path = require ( 'path' ) ;
53const gutil = require ( 'gulp-util' ) ;
6- const PLUGIN_NAME = 'gulp-css-to-polymer' ;
74
8- module . exports = ( opts ) => {
5+ const PLUGIN_NAME = 'gulp-css-to-polymer' ;
96
10- return through . obj ( function ( file , enc , cb ) {
7+ function generateModuleName ( options , file ) {
8+ return `${ options . prefix } ${ path . basename ( file . path , path . extname ( file . path ) ) } ${ options . suffix } ` ;
9+ }
1110
12- if ( file . isStream ( ) ) {
13- return cb ( new gutil . PluginError ( PLUGIN_NAME , 'Streaming not supported' ) ) ;
14- }
15- if ( file . isNull ( ) ) {
16- return cb ( null , file ) ;
17- }
11+ module . exports = opts => through . obj ( ( file , enc , cb ) => {
12+ const fileObj = file ;
1813
19- const moduleId = generateModuleName ( opts , file ) ;
20- const dirname = path . dirname ( file . path ) ;
14+ if ( file . isStream ( ) ) {
15+ return cb ( new gutil . PluginError ( PLUGIN_NAME , 'Streaming not supported' ) ) ;
16+ }
17+ if ( file . isNull ( ) ) {
18+ return cb ( null , file ) ;
19+ }
2120
22- const res = `import '@polymer/polymer/polymer-element.js';
21+ const moduleId = generateModuleName ( opts , file ) ;
22+ const dirname = path . dirname ( file . path ) ;
2323
24- const $_documentContainer = document.createElement('template');
25- $_documentContainer.innerHTML = \`<dom-module id=${ moduleId } ><template><style>${ file . contents . toString ( 'utf8' ) } </style></template></dom-module>\` ` ;
24+ const res = `import '@polymer/polymer/polymer-element';
2625
27- file . contents = new Buffer ( res ) ;
28- file . path = path . join ( dirname , moduleId ) + '.js' ;
26+ const $_documentContainer = document.createElement('template');
27+ $_documentContainer.innerHTML = \`<dom-module id=${ moduleId } >
28+ <template>
29+ <style>
30+ ${ file . contents . toString ( 'utf8' ) }
31+ </style>
32+ </template>
33+ </dom-module>\`;
2934
30- return cb ( null , file ) ;
31- } ) ;
35+ document.head.appendChild($_documentContainer.content);` ;
3236
33- } ;
37+ fileObj . contents = Buffer . from ( res ) ;
38+ fileObj . path = `${ path . join ( dirname , moduleId ) } .js` ;
3439
35- function generateModuleName ( options , file ) {
36- return `${ options . prefix } ${ path . basename ( file . path , path . extname ( file . path ) ) } ${ options . suffix } ` ;
37- }
40+ return cb ( null , file ) ;
41+ } ) ;
0 commit comments