@@ -5,9 +5,26 @@ const { mkdirSync } = require('fs');
55
66// Parse command line arguments.
77const args = process . argv . slice ( 2 ) ;
8+ const flags = args . filter ( arg => arg . startsWith ( '--' ) ) ;
89const specificFiles = args . filter ( arg => ! arg . startsWith ( '--' ) ) ;
910const processSpecificFiles = specificFiles . length > 0 ;
1011
12+ // Process flags for selective building.
13+ const hasCssFlag = flags . includes ( '--css' ) ;
14+ const hasJsFlag = flags . includes ( '--js' ) ;
15+ const hasNoCssFlag = flags . includes ( '--no-css' ) ;
16+ const hasNoJsFlag = flags . includes ( '--no-js' ) ;
17+ const hasRtlFlag = flags . includes ( '--rtl' ) ;
18+ const hasNoRtlFlag = flags . includes ( '--no-rtl' ) ;
19+
20+ // Determine what to process based on flags.
21+ // If no flags are specified, process everything (default).
22+ // If specific flags are specified, process only those.
23+ // If --no-* flags are specified, skip those.
24+ let processCss = hasNoCssFlag ? false : ( hasCssFlag || ! hasJsFlag ) ;
25+ let processJs = hasNoJsFlag ? false : ( hasJsFlag || ! hasCssFlag ) ;
26+ let processRtl = hasNoRtlFlag ? false : ( hasRtlFlag || processCss ) ;
27+
1128/**
1229 * Normalise file paths to use forward slashes.
1330 *
@@ -45,16 +62,13 @@ const config = {
4562 'includes/blocks' ,
4663 'includes/frontend/blocks' ,
4764 'includes/pro/blocks' ,
48- 'includes/build' ,
49- 'includes/frontend/js' ,
5065 ] ,
5166
5267 // File patterns to exclude from discovery.
5368 // Note: We exclude -rtl.css but not .min files to allow re-minification.
5469 excludePatterns : [
5570 / - r t l \. c s s $ / ,
5671 / ^ b u i l d - a s s e t s \. j s $ / ,
57- / ^ b u i l d - p r i s m \. j s $ / ,
5872 ] ,
5973
6074 // CSS files to combine - order matters!
@@ -313,8 +327,23 @@ if (processSpecificFiles) {
313327} else {
314328 console . log ( '==================================' ) ;
315329 console . log ( 'Processing all assets in project' ) ;
316- console . log ( 'Tip: Pass specific files to process only those:' ) ;
317- console . log ( ' node build-assets.js path/to/file.js path/to/file.css' ) ;
330+ console . log ( '' ) ;
331+ console . log ( 'Usage: node build-assets.js [files...] [flags]' ) ;
332+ console . log ( '' ) ;
333+ console . log ( 'Flags:' ) ;
334+ console . log ( ' --css Process CSS files (if specified, only CSS)' ) ;
335+ console . log ( ' --no-css Skip CSS processing' ) ;
336+ console . log ( ' --js Process JS files (if specified, only JS)' ) ;
337+ console . log ( ' --no-js Skip JS processing' ) ;
338+ console . log ( ' --rtl Generate RTL CSS (auto-enabled with CSS)' ) ;
339+ console . log ( ' --no-rtl Skip RTL generation' ) ;
340+ console . log ( '' ) ;
341+ console . log ( 'Examples:' ) ;
342+ console . log ( ' node build-assets.js # Process all CSS/JS' ) ;
343+ console . log ( ' node build-assets.js --css # Process CSS only (+RTL)' ) ;
344+ console . log ( ' node build-assets.js --js --no-rtl # Process JS without RTL' ) ;
345+ console . log ( ' node build-assets.js path/to/file.css # Process specific file' ) ;
346+ console . log ( ' node build-assets.js includes/admin/css/ # Process directory' ) ;
318347 console . log ( '==================================' ) ;
319348}
320349
@@ -407,6 +436,20 @@ if (processSpecificFiles) {
407436 allJsFiles = findFiles ( '.' , '.js' ) ;
408437}
409438
439+ // When specific files are provided, enable processing for file types that were found.
440+ // This ensures explicitly passed files are processed regardless of selective flags.
441+ if ( processSpecificFiles ) {
442+ if ( allCssFiles . length > 0 && ! hasNoCssFlag ) {
443+ processCss = true ;
444+ }
445+ if ( allJsFiles . length > 0 && ! hasNoJsFlag ) {
446+ processJs = true ;
447+ }
448+ }
449+
450+ // Recompute processRtl after processCss may have been updated for specific files.
451+ processRtl = hasNoRtlFlag ? false : ( hasRtlFlag || processCss ) ;
452+
410453// Filter out source files used in combinations.
411454const cssFilesToMinify = allCssFiles . filter ( ( file ) => {
412455 if ( combinedSourceFiles . includes ( file ) ) {
@@ -438,51 +481,63 @@ console.log(`\n=== Processing Assets ===`);
438481console . log ( `Found ${ cssFilesToMinify . length } CSS files and ${ jsFilesToMinify . length } JS files to minify.\n` ) ;
439482
440483// Step 5: Minify CSS files.
441- console . log ( '=== Minifying CSS ===' ) ;
442- cssFilesToMinify . forEach ( ( file ) => {
443- const minFile = file . replace ( '.css' , '.min.css' ) ;
444- console . log ( ` ${ file } → ${ minFile } ` ) ;
445- minifyCss ( file , minFile ) ;
446- } ) ;
484+ if ( processCss ) {
485+ console . log ( '=== Minifying CSS ===' ) ;
486+ cssFilesToMinify . forEach ( ( file ) => {
487+ const minFile = file . replace ( '.css' , '.min.css' ) ;
488+ console . log ( ` ${ file } → ${ minFile } ` ) ;
489+ minifyCss ( file , minFile ) ;
490+ } ) ;
491+ } else {
492+ console . log ( '=== Skipping CSS Minification ===' ) ;
493+ }
447494
448495// Step 6: Minify JS files.
449- console . log ( '\n=== Minifying JS ===' ) ;
450- jsFilesToMinify . forEach ( ( file ) => {
451- const minFile = file . replace ( '.js' , '.min.js' ) ;
452- console . log ( ` ${ file } → ${ minFile } ` ) ;
453- minifyJs ( file , minFile ) ;
454- } ) ;
496+ if ( processJs ) {
497+ console . log ( '\n=== Minifying JS ===' ) ;
498+ jsFilesToMinify . forEach ( ( file ) => {
499+ const minFile = file . replace ( '.js' , '.min.js' ) ;
500+ console . log ( ` ${ file } → ${ minFile } ` ) ;
501+ minifyJs ( file , minFile ) ;
502+ } ) ;
503+ } else {
504+ console . log ( '\n=== Skipping JS Minification ===' ) ;
505+ }
455506
456507// Step 7: Generate RTL versions for CSS files.
457- console . log ( '\n=== Generating RTL CSS ===' ) ;
458- const cssFilesForRtl = allCssFiles . filter ( ( file ) => ! file . includes ( '-rtl.' ) && ! file . endsWith ( '-rtl.css' ) ) ;
459-
460- if ( processSpecificFiles && cssFilesForRtl . length === 0 ) {
461- console . log ( ' No CSS files to process for RTL.' ) ;
462- }
508+ if ( processRtl ) {
509+ console . log ( '\n=== Generating RTL CSS ===' ) ;
510+ const cssFilesForRtl = allCssFiles . filter ( ( file ) => ! file . includes ( '-rtl.' ) && ! file . endsWith ( '-rtl.css' ) ) ;
463511
464- const rtlFilesGenerated = [ ] ;
465- cssFilesForRtl . forEach ( ( file ) => {
466- // Handle .min.css files correctly: name.min.css → name-rtl.min.css
467- const rtlFile = file . endsWith ( '.min.css' )
468- ? file . replace ( '.min.css' , '-rtl.min.css' )
469- : file . replace ( '.css' , '-rtl.css' ) ;
470- console . log ( ` ${ file } → ${ rtlFile } ` ) ;
471- if ( generateRtl ( file , rtlFile ) ) {
472- // Only format non-minified RTL files.
473- if ( ! rtlFile . endsWith ( '.min.css' ) ) {
474- rtlFilesGenerated . push ( rtlFile ) ;
475- }
512+ if ( processSpecificFiles && cssFilesForRtl . length === 0 ) {
513+ console . log ( ' No CSS files to process for RTL.' ) ;
476514 }
477- } ) ;
478515
479- // Step 8: Format RTL CSS files for better readability.
480- if ( rtlFilesGenerated . length > 0 ) {
481- console . log ( '\n=== Formatting RTL CSS ===' ) ;
482- rtlFilesGenerated . forEach ( ( file ) => {
483- console . log ( ` Formatting: ${ file } ` ) ;
484- formatCss ( file ) ;
516+ const rtlFilesGenerated = [ ] ;
517+ cssFilesForRtl . forEach ( ( file ) => {
518+ // Handle .min.css files correctly: name.min.css → name-rtl.min.css
519+ const rtlFile = file . endsWith ( '.min.css' )
520+ ? file . replace ( '.min.css' , '-rtl.min.css' )
521+ : file . replace ( '.css' , '-rtl.css' ) ;
522+ console . log ( ` ${ file } → ${ rtlFile } ` ) ;
523+ if ( generateRtl ( file , rtlFile ) ) {
524+ // Only format non-minified RTL files.
525+ if ( ! rtlFile . endsWith ( '.min.css' ) ) {
526+ rtlFilesGenerated . push ( rtlFile ) ;
527+ }
528+ }
485529 } ) ;
530+
531+ // Step 8: Format RTL CSS files for better readability.
532+ if ( rtlFilesGenerated . length > 0 ) {
533+ console . log ( '\n=== Formatting RTL CSS ===' ) ;
534+ rtlFilesGenerated . forEach ( ( file ) => {
535+ console . log ( ` Formatting: ${ file } ` ) ;
536+ formatCss ( file ) ;
537+ } ) ;
538+ }
539+ } else {
540+ console . log ( '\n=== Skipping RTL Generation ===' ) ;
486541}
487542
488543// Final summary.
0 commit comments