@@ -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 *
@@ -310,8 +327,23 @@ if (processSpecificFiles) {
310327} else {
311328 console . log ( '==================================' ) ;
312329 console . log ( 'Processing all assets in project' ) ;
313- console . log ( 'Tip: Pass specific files to process only those:' ) ;
314- 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' ) ;
315347 console . log ( '==================================' ) ;
316348}
317349
@@ -404,6 +436,20 @@ if (processSpecificFiles) {
404436 allJsFiles = findFiles ( '.' , '.js' ) ;
405437}
406438
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+
407453// Filter out source files used in combinations.
408454const cssFilesToMinify = allCssFiles . filter ( ( file ) => {
409455 if ( combinedSourceFiles . includes ( file ) ) {
@@ -435,51 +481,63 @@ console.log(`\n=== Processing Assets ===`);
435481console . log ( `Found ${ cssFilesToMinify . length } CSS files and ${ jsFilesToMinify . length } JS files to minify.\n` ) ;
436482
437483// Step 5: Minify CSS files.
438- console . log ( '=== Minifying CSS ===' ) ;
439- cssFilesToMinify . forEach ( ( file ) => {
440- const minFile = file . replace ( '.css' , '.min.css' ) ;
441- console . log ( ` ${ file } → ${ minFile } ` ) ;
442- minifyCss ( file , minFile ) ;
443- } ) ;
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+ }
444494
445495// Step 6: Minify JS files.
446- console . log ( '\n=== Minifying JS ===' ) ;
447- jsFilesToMinify . forEach ( ( file ) => {
448- const minFile = file . replace ( '.js' , '.min.js' ) ;
449- console . log ( ` ${ file } → ${ minFile } ` ) ;
450- minifyJs ( file , minFile ) ;
451- } ) ;
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+ }
452506
453507// Step 7: Generate RTL versions for CSS files.
454- console . log ( '\n=== Generating RTL CSS ===' ) ;
455- const cssFilesForRtl = allCssFiles . filter ( ( file ) => ! file . includes ( '-rtl.' ) && ! file . endsWith ( '-rtl.css' ) ) ;
456-
457- if ( processSpecificFiles && cssFilesForRtl . length === 0 ) {
458- console . log ( ' No CSS files to process for RTL.' ) ;
459- }
508+ if ( processRtl ) {
509+ console . log ( '\n=== Generating RTL CSS ===' ) ;
510+ const cssFilesForRtl = allCssFiles . filter ( ( file ) => ! file . includes ( '-rtl.' ) && ! file . endsWith ( '-rtl.css' ) ) ;
460511
461- const rtlFilesGenerated = [ ] ;
462- cssFilesForRtl . forEach ( ( file ) => {
463- // Handle .min.css files correctly: name.min.css → name-rtl.min.css
464- const rtlFile = file . endsWith ( '.min.css' )
465- ? file . replace ( '.min.css' , '-rtl.min.css' )
466- : file . replace ( '.css' , '-rtl.css' ) ;
467- console . log ( ` ${ file } → ${ rtlFile } ` ) ;
468- if ( generateRtl ( file , rtlFile ) ) {
469- // Only format non-minified RTL files.
470- if ( ! rtlFile . endsWith ( '.min.css' ) ) {
471- rtlFilesGenerated . push ( rtlFile ) ;
472- }
512+ if ( processSpecificFiles && cssFilesForRtl . length === 0 ) {
513+ console . log ( ' No CSS files to process for RTL.' ) ;
473514 }
474- } ) ;
475515
476- // Step 8: Format RTL CSS files for better readability.
477- if ( rtlFilesGenerated . length > 0 ) {
478- console . log ( '\n=== Formatting RTL CSS ===' ) ;
479- rtlFilesGenerated . forEach ( ( file ) => {
480- console . log ( ` Formatting: ${ file } ` ) ;
481- 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+ }
482529 } ) ;
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 ===' ) ;
483541}
484542
485543// Final summary.
0 commit comments