understrap / understrap-child

The starter child theme for Understrap, the renowned open-source WordPress starter theme.
GNU General Public License v3.0
580 stars 330 forks source link

Add single files or all .css files in copy assets #361

Closed axlright closed 1 year ago

axlright commented 1 year ago

Can someone help structure the copyDir() argument in copy-assets.js to copy just one file or to copy all .css files? Right now, it seems set up to copy an entire directory. I remember the old Understrap Child worked will with this. I'll pulling css and js files out of a dist directory that has both js and css files in it in an NPM dependency. Ican't figure out how to copy only the css files and then only the js files.

THANKS!

bacoords commented 1 year ago

Hi-

This is untested code, but you can specify filetypes for the fs.readdir() method in the /src/build/copy-assets.js file using something along those lines:

    for (let entry of entries) {
        let srcPath = path.join(src, entry.name);
        let destPath = path.join(dest, entry.name);

        if ( entry.isDirectory() ) {
            await copyDir(srcPath, destPath);
        } else {
            if (path.extname(entry) == ".css") {
               await fs.copyFile(srcPath, destPath);
            }
        }
    }

One additional note: You can access old releases here if you'd like to see how things were done in the past.

axlright commented 1 year ago

Thanks so much @bacoords . I couldn't get the above solution to work. I have gone back through previous commits to see if there ever was a solution. I used to work with Understrap way back in the day when there were .css and .js rules in the old gulp copy-assets command (remember those days?) but this current version doesn't have a solution for node_modules directories that contain both .js and .css files that need to be sent to different directories in src.

That being said, this is a first world problem. I currently just copy all and then go in and delete the ones that shouldn't be where they were sent. In this case, @fancyapps/fancybox/dist has both js and css files in it.

Anywhoo, thanks for looking!