11var gulp = require ( 'gulp' ) ;
2+ var fs = require ( 'fs' ) ;
23
34gulp . task ( 'copy-web-components-js' , function ( done ) {
45 console . log ( 'copying web-components javascript' ) ;
@@ -9,4 +10,60 @@ gulp.task('copy-web-components-js', function (done) {
910 return stream ;
1011} ) ;
1112
12- gulp . task ( 'javascript' , gulp . series ( 'copy-web-components-js' ) ) ;
13+ // Jekyll excludes files starting with `_` unless they are listed in the
14+ // `include` array in _config.yml. The Stencil build sometimes emits a
15+ // `_commonjsHelpers-<hash>.js` chunk whose hash changes with each
16+ // web-components release. This task reads the actual installed package,
17+ // finds the current filename (if any), and keeps _config.yml in sync so
18+ // the file is never silently dropped from the Jekyll build.
19+ gulp . task ( 'sync-jekyll-includes' , function ( done ) {
20+ var esmDir = './node_modules/@department-of-veterans-affairs/web-components/dist/esm/' ;
21+ var configPath = './_config.yml' ;
22+ var includePrefix = 'vendor/javascripts/component-library/dist/esm/' ;
23+
24+ try {
25+ var files = fs . readdirSync ( esmDir ) ;
26+ var helpersFile = files . find ( function ( f ) {
27+ return / ^ _ c o m m o n j s H e l p e r s - .* \. j s $ / . test ( f ) ;
28+ } ) ;
29+
30+ var config = fs . readFileSync ( configPath , 'utf8' ) ;
31+ var existingPattern = / v e n d o r \/ j a v a s c r i p t s \/ c o m p o n e n t - l i b r a r y \/ d i s t \/ e s m \/ _ c o m m o n j s H e l p e r s - [ ^ \s \n ] + / ;
32+
33+ if ( helpersFile ) {
34+ var includePath = includePrefix + helpersFile ;
35+
36+ if ( existingPattern . test ( config ) ) {
37+ var updated = config . replace ( existingPattern , includePath ) ;
38+ if ( updated !== config ) {
39+ fs . writeFileSync ( configPath , updated ) ;
40+ console . log ( 'sync-jekyll-includes: updated _config.yml to include ' + helpersFile ) ;
41+ } else {
42+ console . log ( 'sync-jekyll-includes: _config.yml already references ' + helpersFile ) ;
43+ }
44+ } else {
45+ // No existing _commonjsHelpers entry — insert one under the include: block.
46+ var includeBlockPattern = / ^ i n c l u d e : [ ^ \n ] * $ / m;
47+ var updatedConfig ;
48+ if ( includeBlockPattern . test ( config ) ) {
49+ updatedConfig = config . replace ( includeBlockPattern , function ( line ) {
50+ return line + '\n - ' + includePath ;
51+ } ) ;
52+ } else {
53+ updatedConfig = config + '\ninclude:\n - ' + includePath + '\n' ;
54+ }
55+ fs . writeFileSync ( configPath , updatedConfig ) ;
56+ console . log ( 'sync-jekyll-includes: added _config.yml include for ' + helpersFile ) ;
57+ }
58+ } else {
59+ console . log ( 'sync-jekyll-includes: no _commonjsHelpers file in web-components package, nothing to update' ) ;
60+ }
61+ } catch ( e ) {
62+ console . warn ( 'sync-jekyll-includes: could not sync _config.yml includes:' , e . message ) ;
63+ return done ( e ) ;
64+ }
65+
66+ return done ( ) ;
67+ } ) ;
68+
69+ gulp . task ( 'javascript' , gulp . series ( 'copy-web-components-js' , 'sync-jekyll-includes' ) ) ;
0 commit comments