Skip to content

Commit

Permalink
Build: Fix copying top-level demos files
Browse files Browse the repository at this point in the history
* Build: Remove dead code, make the `external` variable local

1. Remove the `externalDir` variable that was computed but not used.
2. Remove the local unused `globalize` variable.
3. Declare the local `external` variable - previously, build code was
   overwriting the `external` global.

* Build: Fix copying top-level demos files

The logic to copy files from demos was faulty for top-level files - it was
copying them to the `undefined` subdirectory. This is now fixed.

Also, dot-files are no longer copied; we don't need the ESLint config copied,
for example.

Closes gh-216
Ref jquery/jquery-ui#2274
  • Loading branch information
mgol committed Jul 30, 2024
1 parent cd31d4f commit 4ce1b1d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ grunt.registerTask( "build-demos", function() {
return a.title.toLowerCase() > b.title.toLowerCase() ? 1 : -1;
}

var demosDir, externalDir, jqueryCore, repoDir, pkg, subdir,
var demosDir, jqueryCore, repoDir, pkg, subdir,
path = require( "path" ),
cheerio = require( "cheerio" ),
targetDir = grunt.config( "wordpress.dir" ) + "/resources/demos",
Expand All @@ -123,21 +123,24 @@ grunt.registerTask( "build-demos", function() {
repoDir = path.resolve( repoDir );

demosDir = path.join( repoDir, "demos" );
externalDir = path.join( repoDir, "external" ).replace( process.cwd() + "/", "" );
pkg = require( path.join( repoDir, "package" ) );
jqueryCore = fs.readFileSync( path.join( repoDir, "external/jquery/jquery.js" ) )
.toString().match( /jQuery JavaScript Library v([0-9.]*)/ )[ 1 ];

// Copy all demos files to /resources/demos
grunt.file.recurse( demosDir, function( abspath, rootdir, subdir, filename ) {
if ( filename.startsWith( "." ) ) {
return;
}

if ( filename === "index.html" ) {
return;
}

var content, $,
destDir = targetDir + "/" + subdir + "/",
destDir = `${ targetDir }${ subdir ? `/${ subdir }` : "" }/`,
dest = destDir + filename,
highlightDest = highlightDir + "/" + subdir + "/" + filename;
highlightDest = `${ highlightDir }${ subdir ? `/${ subdir }` : "" }/${ filename }`;

if ( /html$/.test( filename ) ) {
content = replaceResources( grunt.file.read( abspath ) );
Expand Down Expand Up @@ -180,7 +183,7 @@ grunt.registerTask( "build-demos", function() {
grunt.file.write( targetDir + "/demo-list.json", JSON.stringify( demoList, null, "\t" ) );

function deAmd( $, destDir ) {
var i18n, globalize,
var i18n, external,
bootstrap = $( "script[src='../bootstrap.js']" ),
require = $( "script[src='../../external/requirejs/require.js']" ),
extra = bootstrap.attr( "data-modules" );
Expand Down

0 comments on commit 4ce1b1d

Please sign in to comment.