@@ -8,6 +8,7 @@ const rename = require("gulp-rename");
88const replace = require ( "gulp-replace" ) ;
99const stripCssComments = require ( "strip-css-comments" ) ;
1010const trim = require ( "trim" ) ;
11+ const decomment = require ( "decomment" ) ;
1112const sass = require ( "node-sass" ) ;
1213
1314gulp . task ( "compile" , ( ) => {
@@ -37,44 +38,56 @@ gulp.task("merge", () => {
3738 return gulp
3839 . src ( "./src/rh-button.js" )
3940 . pipe (
40- replace ( / e x t e n d s \s + R H E l e m e n t \s + { / , ( classStatement , line , jsFile ) => {
41- // extract the templateUrl and styleUrl with regex. Would prefer to do
42- // this by require'ing rh-card.js and asking it directly, but without
43- // node.js support for ES modules, we're stuck with this.
44- const oneLineFile = jsFile . split ( "\n" ) . join ( " " ) ;
45- const [
46- ,
47- templateUrl
48- ] = / g e t \s + t e m p l a t e U r l \( [ ^ ) ] * \) \s * { \s * r e t u r n \s + " ( [ ^ " ] + ) " / . exec (
49- oneLineFile
50- ) ;
51- const [
52- ,
53- styleUrl
54- ] = / g e t \s + s t y l e U r l \( [ ^ ) ] * \) \s * { \s * r e t u r n \s + " ( [ ^ " ] + ) " / . exec (
55- oneLineFile
56- ) ;
41+ replace (
42+ / e x t e n d s \s + R H E l e m e n t \s + { / g,
43+ ( classStatement , character , jsFile ) => {
44+ // extract the templateUrl and styleUrl with regex. Would prefer to do
45+ // this by require'ing rh-something.js and asking it directly, but without
46+ // node.js support for ES modules, we're stuck with this.
47+ const oneLineFile = jsFile
48+ . slice ( character )
49+ . split ( "\n" )
50+ . join ( " " ) ;
51+ const [
52+ ,
53+ templateUrl
54+ ] = / g e t \s + t e m p l a t e U r l \( [ ^ ) ] * \) \s * { \s * r e t u r n \s + " ( [ ^ " ] + ) " / . exec (
55+ oneLineFile
56+ ) ;
57+
58+ let html = fs
59+ . readFileSync ( path . join ( "./src" , templateUrl ) )
60+ . toString ( )
61+ . trim ( ) ;
62+
63+ html = decomment ( html ) ;
64+
65+ const [
66+ ,
67+ styleUrl
68+ ] = / g e t \s + s t y l e U r l \( [ ^ ) ] * \) \s * { \s * r e t u r n \s + " ( [ ^ " ] + ) " / . exec (
69+ oneLineFile
70+ ) ;
5771
58- const html = fs
59- . readFileSync ( path . join ( "./src" , templateUrl ) )
60- . toString ( )
61- . trim ( ) ;
72+ const styleFilePath = path . join ( "./src" , styleUrl ) ;
6273
63- const cssResult = sass . renderSync ( {
64- file : path . join ( "./src" , styleUrl )
65- } ) . css ;
74+ let cssResult = sass . renderSync ( {
75+ file : styleFilePath
76+ } ) . css ;
6677
67- return `${ classStatement }
78+ cssResult = stripCssComments ( cssResult ) . trim ( ) ;
79+
80+ return `${ classStatement }
6881 get html() {
6982 return \`
7083<style>
71- ${ stripCssComments ( cssResult ) . trim ( ) }
84+ ${ cssResult }
7285</style>
73-
7486${ html } \`;
7587 }
7688` ;
77- } )
89+ }
90+ )
7891 )
7992 . pipe ( gulp . dest ( "./" ) ) ;
8093} ) ;
0 commit comments