diff --git a/.gitignore b/.gitignore index c74a142..2427739 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ example cfstatic.sublime-project cfstatic.sublime-workspace *.less.css -mxunit \ No newline at end of file +mxunit +.vscode \ No newline at end of file diff --git a/org/cfstatic/CfStatic.cfc b/org/cfstatic/CfStatic.cfc index af6ca87..f220040 100755 --- a/org/cfstatic/CfStatic.cfc +++ b/org/cfstatic/CfStatic.cfc @@ -1,1498 +1,1526 @@ + + this._includeMappings = {}; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _setProperties( argumentCollection = arguments ); - _loadCompilers( javaLoaderScope = javaLoaderScope ); - _processStaticFiles(); - - return this; - - - - - - - - - - var includes = _getRequestIncludes(); - var include = _appendFileTypesToSpecialIncludes( resource ); - - if ( arguments.throwOnMissing and not _resourceExists( arguments.resource ) ) { - $throw( type="cfstatic.missing.include", message="CfStatic include() error: The requested include, [#arguments.resource#], does not exist." ); - } - - ArrayAppend( includes, include ); - - _setRequestIncludes( includes ); - - return _chainable(); - - - - - - - - StructAppend( _getRequestData(), data ); - - return _chainable(); - - - - - - - - - var filters = ""; - var renderCache = ""; - var buffer = $getStringBuffer(); - var needToRender = ""; - var includeAll = ""; - var types = ListToArray( 'css,js' ); - var i = 0; - var n = 0; - - for( i=1; i LTE ArrayLen( types ); i++ ){ - needToRender = not StructKeyExists( arguments, "type" ) or type eq types[i]; - - if ( needToRender ) { - if ( types[i] EQ 'js' ) { - buffer.append( _renderRequestData() ); - } + + _setProperties( argumentCollection = arguments ); + _loadCompilers( javaLoaderScope = javaLoaderScope ); + _processStaticFiles(); - filters = _getRequestIncludeFilters( types[i], debugMode ); + return this; + + - if ( _anythingToRender( filters ) ) { - renderCache = _getRenderedIncludeCache( types[i], debugMode )._ordered; - includeAll = not ArrayLen( filters ) and _getIncludeAllByDefault(); + + + + - if ( includeAll ){ - buffer.append( ArrayToList( renderCache, $newline() ) ); + + var includes = _getRequestIncludes(); + var include = _appendFileTypesToSpecialIncludes( resource ); - } else { - for( n=1; n LTE ArrayLen( filters ); n=n+1 ){ - buffer.append( renderCache[ filters[ n ] ] ); + if ( arguments.throwOnMissing and not _resourceExists( arguments.resource ) ) { + $throw( type="cfstatic.missing.include", message="CfStatic include() error: The requested include, [#arguments.resource#], does not exist." ); + } + + ArrayAppend( includes, include ); + + _setRequestIncludes( includes ); + + return _chainable(); + + + + + + + + StructAppend( _getRequestData(), data ); + + return _chainable(); + + + + + + + + + var filters = ""; + var renderCache = ""; + var buffer = $getStringBuffer(); + var needToRender = ""; + var includeAll = ""; + var types = ListToArray( 'css,js' ); + var i = 0; + var n = 0; + + for( i=1; i LTE ArrayLen( types ); i++ ){ + needToRender = not StructKeyExists( arguments, "type" ) or type eq types[i]; + + if ( needToRender ) { + if ( types[i] EQ 'js' ) { + buffer.append( _renderRequestData() ); + } + + filters = _getRequestIncludeFilters( types[i], debugMode ); + + if ( _anythingToRender( filters ) ) { + renderCache = _getRenderedIncludeCache( types[i], debugMode )._ordered; + includeAll = not ArrayLen( filters ) and _getIncludeAllByDefault(); + + if ( includeAll ){ + buffer.append( ArrayToList( renderCache, $newline() ) ); + + } else { + for( n=1; n LTE ArrayLen( filters ); n=n+1 ){ + buffer.append( renderCache[ filters[ n ] ] ); + } } } - } - _clearRequestData( types[i] ); + _clearRequestData( types[i] ); + } } - } - - return buffer.toString(); - - - - - - - - - - - var include = _appendFileTypesToSpecialIncludes( resource ); - - if ( arguments.throwOnMissing and not _resourceExists( arguments.resource ) ) { - $throw( type="cfstatic.missing.include", message="CfStatic include() error: The requested include, [#arguments.resource#], does not exist." ); - } - - renderCache = _getRenderedIncludeCache( type, debugMode )._urls; - - if ( StructKeyExists( renderCache, resource ) ) { - return renderCache[ resource ]; - } - - if ( throwOnMissing ) { - $throw( type="cfstatic.missing.include", message="CfStatic getIncludeUrl() error: The requested include, [#arguments.resource#], does not exist." ); - } - - return ""; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var rootDir = $normalizeUnixAndWindowsPaths( $ensureFullDirectoryPath( staticDirectory ) ); - - _setRootDirectory ( rootDir ); - _setJsDirectory ( jsDirectory ); - _setCssDirectory ( cssDirectory ); - _setOutputDirectory ( $listAppend(rootDir , outputDirectory, '/') ); - _setJsUrl ( $listAppend(staticUrl, jsDirectory , '/') ); - _setCssUrl ( $listAppend(staticUrl, cssDirectory , '/') ); - _setMinifiedUrl ( $listAppend(staticUrl, outputDirectory, '/') ); - _setMinifyMode ( minifyMode ); - _setDownloadExternals ( downloadExternals ); - _setDebugAllowed ( debugAllowed ); - _setDebugKey ( debugKey ); - _setDebugPassword ( debugPassword ); - _setDebug ( debug ); - _setForceCompilation ( forceCompilation ); - _setCheckForUpdates ( checkForUpdates ); - _setAddCacheBusters ( addCacheBusters ); - _setAddImageCacheBusters ( addImageCacheBusters ); - _setIncludeAllByDefault ( includeAllByDefault ); - _setEmbedCssImages ( embedCssImages ); - _setIncludePattern ( includePattern ); - _setExcludePattern ( excludePattern ); - _setOutputCharset ( outputCharset ); - _setLessGlobals ( lessGlobals ); - _setJsDataVariable ( jsDataVariable ); - _setJsDependencyFile ( jsDependencyFile ); - _setCssDependencyFile ( cssDependencyFile ); - _setThrowOnMissingInclude( throwOnMissingInclude ); - - - - - - var jsDir = $listAppend( _getRootDirectory(), _getJsDirectory() , '/' ); - var cssDir = $listAppend( _getRootDirectory(), _getCssDirectory(), '/' ); - - + + return buffer.toString(); + + + + + + + + + - _clearoutTemporaryLessFiles(); - _scanForImportedLessFiles(); - _compileLess(); - _compileCoffeeScript(); + var include = _appendFileTypesToSpecialIncludes( resource ); + + if ( arguments.throwOnMissing and not _resourceExists( arguments.resource ) ) { + $throw( type="cfstatic.missing.include", message="CfStatic include() error: The requested include, [#arguments.resource#], does not exist." ); + } - _setJsPackages ( _packageDirectory( jsDir , _getJsUrl() , _getMinifiedUrl(), 'js' , _getDependenciesFromFile( 'js' ) ) ); - _setCssPackages( _packageDirectory( cssDir, _getCssUrl(), _getMinifiedUrl(), 'css', _getDependenciesFromFile( 'css' ) ) ); + renderCache = _getRenderedIncludeCache( type, debugMode )._urls; - _cacheRenderedIncludes(); - _cacheIncludeMappings(); - _compileCssAndJavascript(); + if ( StructKeyExists( renderCache, resource ) ) { + return renderCache[ resource ]; + } - if( _getCheckForUpdates() ) { - _setFileStateCache( _getFileState() ); + if ( throwOnMissing ) { + $throw( type="cfstatic.missing.include", message="CfStatic getIncludeUrl() error: The requested include, [#arguments.resource#], does not exist." ); } + + return ""; - - - - - - - - - - - - - - - - var mappings = StructNew(); - var jsPackages = _getJsPackages().getOrdered(); - var cssPackages = _getCssPackages().getOrdered(); - var i = 0; - - for( i=1; i LTE ArrayLen( jsPackages ); i=i+1 ){ - mappings = _getIncludeMappingsForPackage( jsPackages[i], 'js', mappings ); - } - _setIncludeMappings( mappings, 'js' ); - - mappings = StructNew(); - for( i=1; i LTE ArrayLen( cssPackages ); i=i+1 ){ - mappings = _getIncludeMappingsForPackage( cssPackages[i], 'css', mappings ); - } - _setIncludeMappings( mappings, 'css' ); - - - - - - - - - - var package = _getPackage( packageName, packageType ); - var include = packageName; - var rootDir = iif( packageType EQ 'css', DE( _getCssDirectory() ), DE( _getJsDirectory() ) ); - var dependencies = package.getDependencies( includeConditionals=false ); - var files = package.getOrdered(); - var i = 0; - - if ( include NEQ 'externals' ) { - include = '/' & rootDir & include; - } - - mappings[ include ] = StructNew(); - mappings[ include ].packages = ArrayNew(1); - mappings[ include ].files = ArrayNew(1); - - ArrayAppend( mappings[ include ].packages, packageName ); - - for( i=1; i LTE ArrayLen(dependencies); i++ ){ - ArrayAppend( mappings[ include ].packages, dependencies[i] ); - } - - for( i=1; i LTE ArrayLen( files ); i++ ){ - mappings = _getIncludeMappingsForFile( - filePath = files[i] - , file = package.getStaticFile( files[i] ) - , pkgInclude = include - , mappings = mappings - ); - } - - return mappings; - - - - - - - - - - - var include = filePath; - var dependencies = file.getDependencies( recursive = true, includeConditionals = false ); - var i = 1; - - if ( pkgInclude NEQ 'externals' ) { - include = pkgInclude & ListLast( include, '/' ); - } - - mappings[include] = StructNew(); - mappings[include].packages = mappings[pkgInclude].packages; - mappings[include].files = ArrayNew(1); - - ArrayAppend( mappings[include].files , filePath ); - ArrayAppend( mappings[pkgInclude].files, filePath ); - - for( i=1; i LTE ArrayLen( dependencies ); i++ ){ - ArrayAppend( mappings[include].files , dependencies[i].getPath() ); - ArrayAppend( mappings[pkgInclude].files, dependencies[i].getPath() ); - } - - return mappings; - - - - - - - - var includes = _getRequestIncludes(); - var mappings = _getIncludeMappings( type ); - var filters = StructNew(); - var fileMode = debugMode or ListFindNoCase( "file,none", _getMinifyMode() ); - var allMode = not debugMode and _getMinifyMode() eq "all"; - var renderCache = _getRenderedIncludeCache( type, debugMode ); - var files = ""; - var i = 0; - var n = 0; - - for( i=1; i LTE ArrayLen( includes ); i++ ){ - - if ( StructKeyExists( mappings, includes[i] ) ) { - if ( fileMode ) { - files = mappings[includes[i]].files; - } else { - files = mappings[includes[i]].packages; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + var rootDir = $normalizeUnixAndWindowsPaths( $ensureFullDirectoryPath( staticDirectory ) ); + + _setRootDirectory ( rootDir ); + _setJsDirectory ( jsDirectory ); + _setCssDirectory ( cssDirectory ); + _setOutputDirectory ( $listAppend(rootDir , outputDirectory, '/') ); + _setJsUrl ( $listAppend(staticUrl, jsDirectory , '/') ); + _setCssUrl ( $listAppend(staticUrl, cssDirectory , '/') ); + _setMinifiedUrl ( $listAppend(staticUrl, outputDirectory, '/') ); + _setMinifyMode ( minifyMode ); + _setDownloadExternals ( downloadExternals ); + _setDebugAllowed ( debugAllowed ); + _setDebugKey ( debugKey ); + _setDebugPassword ( debugPassword ); + _setDebug ( debug ); + _setForceCompilation ( forceCompilation ); + _setCheckForUpdates ( checkForUpdates ); + _setAddCacheBusters ( addCacheBusters ); + _setAddImageCacheBusters ( addImageCacheBusters ); + _setIncludeAllByDefault ( includeAllByDefault ); + _setEmbedCssImages ( embedCssImages ); + _setIncludePattern ( includePattern ); + _setExcludePattern ( excludePattern ); + _setOutputCharset ( outputCharset ); + _setLessGlobals ( lessGlobals ); + _setJsDataVariable ( jsDataVariable ); + _setJsDependencyFile ( jsDependencyFile ); + _setCssDependencyFile ( cssDependencyFile ); + _setThrowOnMissingInclude( throwOnMissingInclude ); + _setUseGoogleClosure ( useGoogleClosure ); + + + + + + var jsDir = $listAppend( _getRootDirectory(), _getJsDirectory() , '/' ); + var cssDir = $listAppend( _getRootDirectory(), _getCssDirectory(), '/' ); + + + + _clearoutTemporaryLessFiles(); + _scanForImportedLessFiles(); + _compileLess(); + _compileCoffeeScript(); + + _setJsPackages ( _packageDirectory( jsDir , _getJsUrl() , _getMinifiedUrl(), 'js' , _getDependenciesFromFile( 'js' ) ) ); + _setCssPackages( _packageDirectory( cssDir, _getCssUrl(), _getMinifiedUrl(), 'css', _getDependenciesFromFile( 'css' ) ) ); + + _cacheRenderedIncludes(); + _cacheIncludeMappings(); + _compileCssAndJavascript(); + + if( _getCheckForUpdates() ) { + _setFileStateCache( _getFileState() ); } + + + + + + + + + + + + + + + + + var mappings = StructNew(); + var jsPackages = _getJsPackages().getOrdered(); + var cssPackages = _getCssPackages().getOrdered(); + var i = 0; + + for( i=1; i LTE ArrayLen( jsPackages ); i=i+1 ){ + mappings = _getIncludeMappingsForPackage( jsPackages[i], 'js', mappings ); + } + _setIncludeMappings( mappings, 'js' ); + + mappings = StructNew(); + for( i=1; i LTE ArrayLen( cssPackages ); i=i+1 ){ + mappings = _getIncludeMappingsForPackage( cssPackages[i], 'css', mappings ); + } + _setIncludeMappings( mappings, 'css' ); + + + + + + + + + + var package = _getPackage( packageName, packageType ); + var include = packageName; + var rootDir = iif( packageType EQ 'css', DE( _getCssDirectory() ), DE( _getJsDirectory() ) ); + var dependencies = package.getDependencies( includeConditionals=false ); + var files = package.getOrdered(); + var i = 0; + + if ( include NEQ 'externals' ) { + include = '/' & rootDir & include; + } + + mappings[ include ] = StructNew(); + mappings[ include ].packages = ArrayNew(1); + mappings[ include ].files = ArrayNew(1); + + ArrayAppend( mappings[ include ].packages, packageName ); + + for( i=1; i LTE ArrayLen(dependencies); i++ ){ + ArrayAppend( mappings[ include ].packages, dependencies[i] ); + } + + for( i=1; i LTE ArrayLen( files ); i++ ){ + mappings = _getIncludeMappingsForFile( + filePath = files[i] + , file = package.getStaticFile( files[i] ) + , pkgInclude = include + , mappings = mappings + ); + } + + return mappings; + + + + + + + + + + + var include = filePath; + var dependencies = file.getDependencies( recursive = true, includeConditionals = false ); + var i = 1; + + if ( pkgInclude NEQ 'externals' ) { + include = pkgInclude & ListLast( include, '/' ); + } + + mappings[include] = StructNew(); + mappings[include].packages = mappings[pkgInclude].packages; + mappings[include].files = ArrayNew(1); + + ArrayAppend( mappings[include].files , filePath ); + ArrayAppend( mappings[pkgInclude].files, filePath ); + + for( i=1; i LTE ArrayLen( dependencies ); i++ ){ + ArrayAppend( mappings[include].files , dependencies[i].getPath() ); + ArrayAppend( mappings[pkgInclude].files, dependencies[i].getPath() ); + } - for( n=1; n LTE ArrayLen( files ); n++ ){ - if ( allMode ){ - filters[ renderCache[ "/" ] ] = 1; + return mappings; + + + + + + + + var includes = _getRequestIncludes(); + var mappings = _getIncludeMappings( type ); + var filters = StructNew(); + var fileMode = debugMode or ListFindNoCase( "file,none", _getMinifyMode() ); + var allMode = not debugMode and _getMinifyMode() eq "all"; + var renderCache = _getRenderedIncludeCache( type, debugMode ); + var files = ""; + var i = 0; + var n = 0; + + for( i=1; i LTE ArrayLen( includes ); i++ ){ + + if ( StructKeyExists( mappings, includes[i] ) ) { + if ( fileMode ) { + files = mappings[includes[i]].files; } else { - filters[ renderCache[ files[n] ] ] = 1; + files = mappings[includes[i]].packages; + } + + for( n=1; n LTE ArrayLen( files ); n++ ){ + if ( allMode ){ + filters[ renderCache[ "/" ] ] = 1; + } else { + filters[ renderCache[ files[n] ] ] = 1; + } } } } - } - - filters = StructKeyArray( filters ); - arraySort( filters, "numeric" ); - - return filters; - - - - - - _setupRenderedIncludeCache(); - - switch( _getMinifyMode() ){ - case 'all' : _cacheRenderedIncludesForAllMode() ; break; - case 'package' : _cacheRenderedIncludesForPackageMode(); break; - default : _cacheRenderedIncludesForFileMode() ; break; - } - - _cacheRenderedIncludesForFileMode( debug = true ); - - - - - - _addRenderedIncludeToCache( 'js', '/', _getJsPackages().renderIncludes( - minification = _getMinifyMode() - , downloadExternals = _getDownloadExternals() - ) ); - _addRenderedIncludeToCache( 'css', '/', _getCssPackages().renderIncludes( - minification = _getMinifyMode() - , downloadExternals = _getDownloadExternals() - ) ); - - - - - - var collection = ""; - var packages = ""; - var package = ""; - var types = ListToArray("js,css"); - var minifyMode = ""; - var type = ""; - var i = 0; - var n = 0; - - for( n=1; n LTE ArrayLen( types ); n=n+1 ){ - type = types[n]; - if ( type EQ 'js' ) { - collection = _getJsPackages(); - } else { - collection = _getCssPackages(); + filters = StructKeyArray( filters ); + arraySort( filters, "numeric" ); + + return filters; + + + + + + _setupRenderedIncludeCache(); + + switch( _getMinifyMode() ){ + case 'all' : _cacheRenderedIncludesForAllMode() ; break; + case 'package' : _cacheRenderedIncludesForPackageMode(); break; + default : _cacheRenderedIncludesForFileMode() ; break; } - packages = collection.getOrdered(); + _cacheRenderedIncludesForFileMode( debug = true ); + + - for( i=1; i LTE ArrayLen( packages ); i=i+1 ){ - package = collection.getPackage( packages[i] ); + + + _addRenderedIncludeToCache( 'js', '/', _getJsPackages().renderIncludes( + minification = _getMinifyMode() + , downloadExternals = _getDownloadExternals() + ) ); + _addRenderedIncludeToCache( 'css', '/', _getCssPackages().renderIncludes( + minification = _getMinifyMode() + , downloadExternals = _getDownloadExternals() + ) ); + + - if ( packages[i] EQ 'external' and not _getDownloadExternals() ){ - minifyMode = 'none'; + + + var collection = ""; + var packages = ""; + var package = ""; + var types = ListToArray("js,css"); + var minifyMode = ""; + var type = ""; + var i = 0; + var n = 0; + + for( n=1; n LTE ArrayLen( types ); n=n+1 ){ + type = types[n]; + + if ( type EQ 'js' ) { + collection = _getJsPackages(); } else { - minifyMode = _getMinifyMode(); + collection = _getCssPackages(); } + packages = collection.getOrdered(); + + + for( i=1; i LTE ArrayLen( packages ); i=i+1 ){ + package = collection.getPackage( packages[i] ); - _addRenderedIncludeToCache( type, packages[i], package.renderIncludes( - minification = minifyMode - ) ); + if ( packages[i] EQ 'external' and not _getDownloadExternals() ){ + minifyMode = 'none'; + } else { + minifyMode = _getMinifyMode(); + } + + _addRenderedIncludeToCache( type, packages[i], package.renderIncludes( + minification = minifyMode + ) ); + } } - } - - - - - - - - var types = ListToArray("js,css"); - var type = ""; - var collection = ""; - var packages = ""; - var package = ""; - var files = ""; - var file = ""; - var i = 0; - var n = 0; - var x = 0; - var minified = iif( debug, DE( false ), DE( _getMinifyMode() EQ 'file' ) ); - - for( n=1; n LTE ArrayLen( types ); n=n+1 ){ - type = types[n]; + + - if ( type EQ 'js' ) { - collection = _getJsPackages(); - } else { - collection = _getCssPackages(); + + + + + var types = ListToArray("js,css"); + var type = ""; + var collection = ""; + var packages = ""; + var package = ""; + var files = ""; + var file = ""; + var i = 0; + var n = 0; + var x = 0; + var minified = iif( debug, DE( false ), DE( _getMinifyMode() EQ 'file' ) ); + + for( n=1; n LTE ArrayLen( types ); n=n+1 ){ + type = types[n]; + + if ( type EQ 'js' ) { + collection = _getJsPackages(); + } else { + collection = _getCssPackages(); + } + packages = collection.getOrdered(); + for( i=1; i LTE ArrayLen( packages ); i=i+1 ){ + package = collection.getPackage( packages[i] ); + files = package.getOrdered(); + + for( x=1; x LTE ArrayLen( files ); x=x+1 ) { + file = package.getStaticFile( files[x] ); + + _addRenderedIncludeToCache( + type = type + , path = files[x] + , debug = debug + , rendered = file.renderInclude( + minified = minified and ( packages[i] neq 'external' or _getDownloadExternals() ) + ) + ); + } + } } - packages = collection.getOrdered(); - for( i=1; i LTE ArrayLen( packages ); i=i+1 ){ - package = collection.getPackage( packages[i] ); - files = package.getOrdered(); - - for( x=1; x LTE ArrayLen( files ); x=x+1 ) { - file = package.getStaticFile( files[x] ); - - _addRenderedIncludeToCache( - type = type - , path = files[x] - , debug = debug - , rendered = file.renderInclude( - minified = minified and ( packages[i] neq 'external' or _getDownloadExternals() ) - ) - ); + + + + + + var jsDir = $listAppend( _getRootDirectory(), _getJsDirectory() , '/' ); + var cssDir = $listAppend( _getRootDirectory(), _getCssDirectory(), '/' ); + var jsFiles = $directoryList( jsDir ); + var cssFiles = $directoryList( cssDir ); + var jsDependencyFile = $ensureFullFilePath( _getJsDependencyFile() ); + var cssDependencyFile = $ensureFullFilePath( _getJsDependencyFile() ); + var state = StructNew(); + var ext = ""; + var path = ""; + var i = 0; + var included = ""; + + for( i=1; i LTE jsFiles.recordCount; i++ ){ + ext = ListLast( jsFiles.name[i], '.' ); + path = $normalizeUnixAndWindowsPaths( $listAppend( jsFiles.directory[i], jsFiles.name[i], '/' ) ); + included = ListFindNoCase( "js,coffee", ext ) and $shouldFileBeIncluded( path, _getIncludePattern(), _getExcludePattern() ); + if ( included ) { + state[path] = jsFiles.dateLastModified[i]; } } - } - - - - - - var jsDir = $listAppend( _getRootDirectory(), _getJsDirectory() , '/' ); - var cssDir = $listAppend( _getRootDirectory(), _getCssDirectory(), '/' ); - var jsFiles = $directoryList( jsDir ); - var cssFiles = $directoryList( cssDir ); - var jsDependencyFile = $ensureFullFilePath( _getJsDependencyFile() ); - var cssDependencyFile = $ensureFullFilePath( _getJsDependencyFile() ); - var state = StructNew(); - var ext = ""; - var path = ""; - var i = 0; - var included = ""; - - for( i=1; i LTE jsFiles.recordCount; i++ ){ - ext = ListLast( jsFiles.name[i], '.' ); - path = $normalizeUnixAndWindowsPaths( $listAppend( jsFiles.directory[i], jsFiles.name[i], '/' ) ); - included = ListFindNoCase( "js,coffee", ext ) and $shouldFileBeIncluded( path, _getIncludePattern(), _getExcludePattern() ); - if ( included ) { - state[path] = jsFiles.dateLastModified[i]; + + for( i=1; i LTE cssFiles.recordCount; i++ ){ + ext = ListLast( cssFiles.name[i], '.' ); + path = $normalizeUnixAndWindowsPaths( $listAppend( cssFiles.directory[i], cssFiles.name[i], '/' ) ); + included = ListFindNoCase( "css,less", ext ) and $shouldFileBeIncluded( path, _getIncludePattern(), _getExcludePattern() ); + if ( included ) { + state[path] = cssFiles.dateLastModified[i]; + } + } + + if ( Len( Trim( jsDependencyFile ) ) and FileExists( jsDependencyFile ) ) { + state[ jsDependencyFile ] = $fileLastModified( jsDependencyFile ); + } + if ( Len( Trim( cssDependencyFile ) ) and FileExists( cssDependencyFile ) ) { + state[ cssDependencyFile ] = $fileLastModified( cssDependencyFile ); } - } - - for( i=1; i LTE cssFiles.recordCount; i++ ){ - ext = ListLast( cssFiles.name[i], '.' ); - path = $normalizeUnixAndWindowsPaths( $listAppend( cssFiles.directory[i], cssFiles.name[i], '/' ) ); - included = ListFindNoCase( "css,less", ext ) and $shouldFileBeIncluded( path, _getIncludePattern(), _getExcludePattern() ); - if ( included ) { - state[path] = cssFiles.dateLastModified[i]; + + + + return Hash( SerializeJson( state ) ); + + + + + + + + + + + + + var jlScope = server; + var jlScopeKey = "_cfstaticJavaLoaders_v2"; + + if ( javaLoaderScope EQ 'application' ){ + jlScope = application; } - } - - if ( Len( Trim( jsDependencyFile ) ) and FileExists( jsDependencyFile ) ) { - state[ jsDependencyFile ] = $fileLastModified( jsDependencyFile ); - } - if ( Len( Trim( cssDependencyFile ) ) and FileExists( cssDependencyFile ) ) { - state[ cssDependencyFile ] = $fileLastModified( cssDependencyFile ); - } - - - - return Hash( SerializeJson( state ) ); - - - - - - - - - - - - - var jlScope = server; - var jlScopeKey = "_cfstaticJavaLoaders_v2"; - - if ( javaLoaderScope EQ 'application' ){ - jlScope = application; - } - - if ( not StructKeyExists( jlScope, jlScopeKey ) ) { - jlScope[ jlScopeKey ] = _loadJavaLoaders(); - } - - _setYuiCompressor ( CreateObject('component','org.cfstatic.util.YuiCompressor' ).init( jlScope[jlScopeKey].yui ) ); - _setLessCompiler ( CreateObject('component','org.cfstatic.util.LessCompiler' ).init( jlScope[jlScopeKey].less ) ); - _setCoffeeScriptCompiler ( CreateObject('component','org.cfstatic.util.CoffeeScriptCompiler').init( jlScope[jlScopeKey].coffee ) ); - _setCssImageParser ( CreateObject('component','org.cfstatic.util.CssImageParser' ).init( _getCssUrl(), $listAppend(_getRootDirectory(), _getCssDirectory(), '/' ) ) ); - - - - - - var jarsForYui = ArrayNew(1); - var jarsForLess = ArrayNew(1); - var jarsForCoffee = ArrayNew(1); - var cfstaticJavaloaders = StructNew(); - - jarsForYui[1] = ExpandPath('/org/cfstatic/lib/yuiCompressor/yuicompressor-2.4.7.jar'); - jarsForYui[2] = ExpandPath('/org/cfstatic/lib/cfstatic.jar'); - jarsForLess[1] = ExpandPath('/org/cfstatic/lib/less/lesscss-engine-1.4.2.jar'); - jarsForCoffee[1] = ExpandPath('/org/cfstatic/lib/jcoffeescript/jcoffeescript-1.3.3.jar'); - - cfstaticJavaloaders.yui = CreateObject('component','org.cfstatic.lib.javaloader.JavaLoader').init( jarsForYui ); - cfstaticJavaloaders.less = CreateObject('component','org.cfstatic.lib.javaloader.JavaLoader').init( jarsForLess ); - cfstaticJavaloaders.coffee = CreateObject('component','org.cfstatic.lib.javaloader.JavaLoader').init( jarsForCoffee ); - - return cfstaticJavaloaders; - - - - - - switch(_getMinifyMode()){ - case 'file': - _compileFiles(); - break; - - case 'package': - _compilePackages(); - break; - - case 'all': - _compileAll(); - break; - } - - - - - - var cssDir = $listAppend(_getRootdirectory(), _getCssdirectory(), '/'); - var files = $directoryList(cssDir, '*.less'); - var globalsModified = _getLessGlobalsLastModified(); - var i = 0; - var file = ""; - var target = ""; - var compiled = ""; - var needsCompiling = ""; - var lastModified = ""; - - for( i=1; i LTE files.recordCount; i++ ){ - file = $normalizeUnixAndWindowsPaths( $listAppend( files.directory[i], files.name[i], '/') ); - if ( $shouldFileBeIncluded( file, _getIncludePattern(), _getExcludePattern() ) ){ - target = file & '.css'; - lastModified = $fileLastModified(target); - needsCompiling = ( _getForceCompilation() or not fileExists(target) or lastModified LT globalsModified or lastModified LT $fileLastModified(file) ); - if ( needsCompiling ){ - compiled = _getLesscompiler().compile( file, _getLessGlobals() ); - - $fileWrite( target, compiled, _getOutputCharset() ); + + if ( not StructKeyExists( jlScope, jlScopeKey ) ) { + jlScope[ jlScopeKey ] = _loadJavaLoaders(); + } + + _setYuiCompressor ( CreateObject('component','org.cfstatic.util.YuiCompressor' ).init( jlScope[jlScopeKey].yui ) ); + _setLessCompiler ( CreateObject('component','org.cfstatic.util.LessCompiler' ).init( jlScope[jlScopeKey].less ) ); + _setCoffeeScriptCompiler ( CreateObject('component','org.cfstatic.util.CoffeeScriptCompiler').init( jlScope[jlScopeKey].coffee ) ); + _setCssImageParser ( CreateObject('component','org.cfstatic.util.CssImageParser' ).init( _getCssUrl(), $listAppend(_getRootDirectory(), _getCssDirectory(), '/' ) ) ); + _setClosureCompiler ( CreateObject('component','org.cfstatic.util.ClosureCompiler' ).init( jlScope[jlScopeKey].closure ) ); + + + + + + var jarsForYui = ArrayNew(1); + var jarsForLess = ArrayNew(1); + var jarsForCoffee = ArrayNew(1); + var jarsForClosure = ArrayNew(1); + var cfstaticJavaloaders = StructNew(); + + jarsForYui[1] = ExpandPath('/org/cfstatic/lib/yuiCompressor/yuicompressor-2.4.7.jar'); + jarsForYui[2] = ExpandPath('/org/cfstatic/lib/cfstatic.jar'); + jarsForLess[1] = ExpandPath('/org/cfstatic/lib/less/lesscss-engine-1.4.2.jar'); + jarsForCoffee[1] = ExpandPath('/org/cfstatic/lib/jcoffeescript/jcoffeescript-1.3.3.jar'); + jarsForClosure[1]= ExpandPath('/org/cfstatic/lib/closureCompiler/closure-compiler-v20231112.jar'); + + cfstaticJavaloaders.yui = CreateObject('component','org.cfstatic.lib.javaloader.JavaLoader').init( jarsForYui ); + cfstaticJavaloaders.less = CreateObject('component','org.cfstatic.lib.javaloader.JavaLoader').init( jarsForLess ); + cfstaticJavaloaders.coffee = CreateObject('component','org.cfstatic.lib.javaloader.JavaLoader').init( jarsForCoffee ); + cfstaticJavaloaders.closure = CreateObject('component','org.cfstatic.lib.javaloader.JavaLoader').init( jarsForClosure ); + + return cfstaticJavaloaders; + + + + + + switch(_getMinifyMode()){ + case 'file': + _compileFiles(); + break; + + case 'package': + _compilePackages(); + break; + + case 'all': + _compileAll(); + break; + } + + + + + + var cssDir = $listAppend(_getRootdirectory(), _getCssdirectory(), '/'); + var files = $directoryList(cssDir, '*.less'); + var globalsModified = _getLessGlobalsLastModified(); + var i = 0; + var file = ""; + var target = ""; + var compiled = ""; + var needsCompiling = ""; + var lastModified = ""; + + for( i=1; i LTE files.recordCount; i++ ){ + file = $normalizeUnixAndWindowsPaths( $listAppend( files.directory[i], files.name[i], '/') ); + if ( $shouldFileBeIncluded( file, _getIncludePattern(), _getExcludePattern() ) ){ + target = file & '.css'; + lastModified = $fileLastModified(target); + needsCompiling = ( _getForceCompilation() or not fileExists(target) or lastModified LT globalsModified or lastModified LT $fileLastModified(file) ); + if ( needsCompiling ){ + compiled = _getLesscompiler().compile( file, _getLessGlobals() ); + + $fileWrite( target, compiled, _getOutputCharset() ); + } } } - } - - - - - - var jsDir = $listAppend(_getRootdirectory(), _getJsdirectory(), '/'); - var files = $directoryList(jsDir, '*.coffee'); - var i = 0; - var file = ""; - var target = ""; - var compiled = ""; - var needsCompiling = ""; - - for( i=1; i LTE files.recordCount; i++ ){ - file = $normalizeUnixAndWindowsPaths( $listAppend(files.directory[i], files.name[i], '/') ); - if ( $shouldFileBeIncluded( file, _getIncludePattern(), _getExcludePattern() ) ){ - target = file & '.js'; - needsCompiling = ( _getForceCompilation() or not fileExists(target) or $fileLastModified(target) LT $fileLastModified(file) ); - if ( needsCompiling ){ - compiled = _getCoffeeScriptCompiler().compile( file ); - - $fileWrite( target, Trim(compiled), _getOutputCharset() ); + + + + + + var jsDir = $listAppend(_getRootdirectory(), _getJsdirectory(), '/'); + var files = $directoryList(jsDir, '*.coffee'); + var i = 0; + var file = ""; + var target = ""; + var compiled = ""; + var needsCompiling = ""; + + for( i=1; i LTE files.recordCount; i++ ){ + file = $normalizeUnixAndWindowsPaths( $listAppend(files.directory[i], files.name[i], '/') ); + if ( $shouldFileBeIncluded( file, _getIncludePattern(), _getExcludePattern() ) ){ + target = file & '.js'; + needsCompiling = ( _getForceCompilation() or not fileExists(target) or $fileLastModified(target) LT $fileLastModified(file) ); + if ( needsCompiling ){ + compiled = _getCoffeeScriptCompiler().compile( file ); + + $fileWrite( target, Trim(compiled), _getOutputCharset() ); + } } } - } - - - - - - var packages = ""; - var package = ""; - var files = ""; - var file = ""; - var content = $getStringBuffer(); - var i = ""; - var n = ""; - var filePath = ""; - var fileName = ""; - - if ( _compilationNecessary(_getJsPackages() ) ) { - packages = _getJsPackages().getOrdered(); - for( i=1; i LTE ArrayLen( packages ); i++ ){ - if ( _getDownloadexternals() OR packages[i] NEQ 'external' ) { - package = _getJsPackages().getPackage(packages[i]); + + + + + + var packages = ""; + var package = ""; + var files = ""; + var file = ""; + var content = $getStringBuffer(); + var i = ""; + var n = ""; + var filePath = ""; + var fileName = ""; + + if ( _compilationNecessary(_getJsPackages() ) ) { + packages = _getJsPackages().getOrdered(); + for( i=1; i LTE ArrayLen( packages ); i++ ){ + if ( _getDownloadexternals() OR packages[i] NEQ 'external' ) { + package = _getJsPackages().getPackage(packages[i]); + files = package.getOrdered(); + + for( n=1; n LTE ArrayLen(files); n++ ){ + file = package.getStaticFile( files[n] ); + content.append( _compileJsFile( file ) ); + } + } + } + + fileName = _getJsPackages().getMinifiedFileName(); + filePath = $listAppend( _getOutputDirectory(), filename, '/' ); + $fileWrite( filePath, content.toString(), _getOutputCharset() ); + } + + content = $getStringBuffer(); + if ( _compilationNecessary(_getCssPackages() ) ) { + packages = _getCssPackages().getOrdered(); + for( i=1; i LTE ArrayLen(packages); i++ ){ + package = _getCssPackages().getPackage(packages[i]); files = package.getOrdered(); for( n=1; n LTE ArrayLen(files); n++ ){ file = package.getStaticFile( files[n] ); - content.append( _compileJsFile( file ) ); + content.append( _compileCssFile( file ) ); } } + + fileName = _getCssPackages().getMinifiedFileName(); + filePath = $listAppend( _getOutputDirectory(), filename, '/' ); + $fileWrite( filePath, content.toString(), _getOutputCharset() ); } - fileName = _getJsPackages().getMinifiedFileName(); - filePath = $listAppend( _getOutputDirectory(), filename, '/' ); - $fileWrite( filePath, content.toString(), _getOutputCharset() ); - } + $directoryClean( directory=_getOutputDirectory(), excludeFiles=ListAppend( _getJsPackages().getMinifiedFileName(), _getCssPackages().getMinifiedFileName() ), fileTypes="css,js" ); + + - content = $getStringBuffer(); - if ( _compilationNecessary(_getCssPackages() ) ) { - packages = _getCssPackages().getOrdered(); + + + var packages = ""; + var package = ""; + var files = ""; + var file = ""; + var content = ""; + var i = ""; + var n = ""; + var filePath = ""; + var fileName = ""; + var fileList = ""; + + packages = _getJsPackages().getOrdered(); for( i=1; i LTE ArrayLen(packages); i++ ){ - package = _getCssPackages().getPackage(packages[i]); - files = package.getOrdered(); + content = $getStringBuffer(); + package = _getJsPackages().getPackage( packages[i] ); + fileName = package.getMinifiedFileName(); - for( n=1; n LTE ArrayLen(files); n++ ){ - file = package.getStaticFile( files[n] ); - content.append( _compileCssFile( file ) ); - } - } + if ( ( _getDownloadexternals() OR packages[i] NEQ 'external' ) AND _compilationNecessary( package ) ) { + files = package.getOrdered(); - fileName = _getCssPackages().getMinifiedFileName(); - filePath = $listAppend( _getOutputDirectory(), filename, '/' ); - $fileWrite( filePath, content.toString(), _getOutputCharset() ); - } - - $directoryClean( directory=_getOutputDirectory(), excludeFiles=ListAppend( _getJsPackages().getMinifiedFileName(), _getCssPackages().getMinifiedFileName() ), fileTypes="css,js" ); - - - - - - var packages = ""; - var package = ""; - var files = ""; - var file = ""; - var content = ""; - var i = ""; - var n = ""; - var filePath = ""; - var fileName = ""; - var fileList = ""; - - packages = _getJsPackages().getOrdered(); - for( i=1; i LTE ArrayLen(packages); i++ ){ - content = $getStringBuffer(); - package = _getJsPackages().getPackage( packages[i] ); - fileName = package.getMinifiedFileName(); - - if ( ( _getDownloadexternals() OR packages[i] NEQ 'external' ) AND _compilationNecessary( package ) ) { - files = package.getOrdered(); - - for( n=1; n LTE ArrayLen(files); n++ ){ - file = package.getStaticFile( files[n] ); - content.append( _compileJsFile( file ) ); + for( n=1; n LTE ArrayLen(files); n++ ){ + file = package.getStaticFile( files[n] ); + content.append( _compileJsFile( file ) ); + } + + filePath = $listAppend( _getOutputDirectory(), filename, '/' ); + $fileWrite(filePath, content.toString(), _getOutputCharset() ); } - filePath = $listAppend( _getOutputDirectory(), filename, '/' ); - $fileWrite(filePath, content.toString(), _getOutputCharset() ); + fileList = ListAppend( fileList, package.getMinifiedFileName() ); } - fileList = ListAppend( fileList, package.getMinifiedFileName() ); - } + packages = _getCssPackages().getOrdered(); + for( i=1; i LTE ArrayLen(packages); i++ ){ + content = $getStringBuffer(); + package = _getCssPackages().getPackage(packages[i]); + fileName = package.getMinifiedFileName(); - packages = _getCssPackages().getOrdered(); - for( i=1; i LTE ArrayLen(packages); i++ ){ - content = $getStringBuffer(); - package = _getCssPackages().getPackage(packages[i]); - fileName = package.getMinifiedFileName(); + if ( ( _compilationNecessary( package ) ) AND ( _getDownloadexternals() OR packages[i] NEQ 'external' ) ) { + files = package.getOrdered(); - if ( ( _compilationNecessary( package ) ) AND ( _getDownloadexternals() OR packages[i] NEQ 'external' ) ) { - files = package.getOrdered(); + for( n=1; n LTE ArrayLen(files); n++ ){ + file = package.getStaticFile( files[n] ); + content.append( _compileCssFile( file ) ); + } - for( n=1; n LTE ArrayLen(files); n++ ){ - file = package.getStaticFile( files[n] ); - content.append( _compileCssFile( file ) ); + filePath = $listAppend( _getOutputDirectory(), filename, '/' ); + $fileWrite( filePath, content.toString(), _getOutputCharset() ); } - filePath = $listAppend( _getOutputDirectory(), filename, '/' ); - $fileWrite( filePath, content.toString(), _getOutputCharset() ); + fileList = ListAppend( fileList, package.getMinifiedFileName() ); } - fileList = ListAppend( fileList, package.getMinifiedFileName() ); - } - - $directoryClean( directory=_getOutputDirectory(), excludeFiles=fileList, fileTypes="css,js" ); - - - - - - var packages = ""; - var package = ""; - var files = ""; - var file = ""; - var content = ""; - var i = ""; - var n = ""; - var filePath = ""; - var fileName = ""; - var fileList = ""; - - packages = _getJsPackages().getOrdered(); - for( i=1; i LTE ArrayLen(packages); i++ ){ - if ( _getDownloadexternals() OR packages[i] NEQ 'external' ) { - package = _getJsPackages().getPackage(packages[i]); - files = package.getOrdered(); - - for( n=1; n LTE ArrayLen(files); n++ ){ - file = package.getStaticFile( files[n] ); - fileName = file.getMinifiedFileName(); - - if ( _compilationNecessary( file ) ) { - content = _compileJsFile( file ); - filePath = $listAppend( _getOutputDirectory(), filename, '/' ); - $fileWrite( filePath, content, _getOutputCharset() ); + $directoryClean( directory=_getOutputDirectory(), excludeFiles=fileList, fileTypes="css,js" ); + + + + + + var packages = ""; + var package = ""; + var files = ""; + var file = ""; + var content = ""; + var i = ""; + var n = ""; + var filePath = ""; + var fileName = ""; + var fileList = ""; + + packages = _getJsPackages().getOrdered(); + for( i=1; i LTE ArrayLen(packages); i++ ){ + if ( _getDownloadexternals() OR packages[i] NEQ 'external' ) { + package = _getJsPackages().getPackage(packages[i]); + files = package.getOrdered(); + + for( n=1; n LTE ArrayLen(files); n++ ){ + file = package.getStaticFile( files[n] ); + fileName = file.getMinifiedFileName(); + + if ( _compilationNecessary( file ) ) { + content = _compileJsFile( file ); + filePath = $listAppend( _getOutputDirectory(), filename, '/' ); + $fileWrite( filePath, content, _getOutputCharset() ); + } + fileList = ListAppend( fileList, fileName ); } - fileList = ListAppend( fileList, fileName ); } } - } - - packages = _getCssPackages().getOrdered(); - for( i=1; i LTE ArrayLen(packages); i++ ){ - if ( _getDownloadexternals() OR packages[i] NEQ 'external' ) { - package = _getCssPackages().getPackage(packages[i]); - files = package.getOrdered(); - - for( n=1; n LTE ArrayLen(files); n++ ){ - file = package.getStaticFile( files[n] ); - fileName = file.getMinifiedFileName(); - - if ( _compilationNecessary( file ) ) { - content = _compileCssFile( file ); - filePath = $listAppend( _getOutputDirectory(), filename, '/' ); - $fileWrite( filePath, content, _getOutputCharset() ); + + packages = _getCssPackages().getOrdered(); + for( i=1; i LTE ArrayLen(packages); i++ ){ + if ( _getDownloadexternals() OR packages[i] NEQ 'external' ) { + package = _getCssPackages().getPackage(packages[i]); + files = package.getOrdered(); + + for( n=1; n LTE ArrayLen(files); n++ ){ + file = package.getStaticFile( files[n] ); + fileName = file.getMinifiedFileName(); + + if ( _compilationNecessary( file ) ) { + content = _compileCssFile( file ); + filePath = $listAppend( _getOutputDirectory(), filename, '/' ); + $fileWrite( filePath, content, _getOutputCharset() ); + } + fileList = ListAppend( fileList, fileName ); } - fileList = ListAppend( fileList, fileName ); } } - } - $directoryClean( directory=_getOutputDirectory(), excludeFiles=fileList, fileTypes="js,css" ); - - + $directoryClean( directory=_getOutputDirectory(), excludeFiles=fileList, fileTypes="js,css" ); + + - - + + - - var alreadyMinified = file.getProperty('minified', 'false', 'string'); + + var alreadyMinified = file.getProperty('minified', 'false', 'string'); - if ( alreadyMinified ) { - return file.getContent(); - } + if ( alreadyMinified ) { + return file.getContent(); + } - return _getYuiCompressor().compressJs( file.getContent() ); - - + if(_getUseGoogleClosure() || file.getProperty('ecma6', false)){ + return _getClosureCompiler().compressJs( file.getContent() ); + } - - + return _getYuiCompressor().compressJs( file.getContent() ); + + - - var content = file.getContent(); - var alreadyMinified = file.getProperty('minified', 'false', 'string'); + + - if ( not alreadyMinified ) { - content = _getYuiCompressor().compressCss( content ); - } - content = _getCssImageParser().parse( - source = content - , filePath = file.getPath() - , embedImagesRegex = _getEmbedCssImages() - , addCachebusters = _getAddImageCacheBusters() - ); + + var content = file.getContent(); + var alreadyMinified = file.getProperty('minified', 'false', 'string'); - return content; - - + if ( not alreadyMinified ) { + content = _getYuiCompressor().compressCss( content ); + } + content = _getCssImageParser().parse( + source = content + , filePath = file.getPath() + , embedImagesRegex = _getEmbedCssImages() + , addCachebusters = _getAddImageCacheBusters() + ); - - + return content; + + - - var minFile = $listAppend( _getOutputDirectory(), collectionPackageOrFile.getMinifiedFileName(), '/' ); + + - if ( _getForceCompilation() ) { - return true; - } + + var minFile = $listAppend( _getOutputDirectory(), collectionPackageOrFile.getMinifiedFileName(), '/' ); - if ( not fileExists(minFile) ) { - return true; - } + if ( _getForceCompilation() ) { + return true; + } - return $fileLastModified( minFile ) LT collectionPackageOrFile.getLastModified(); - - + if ( not fileExists(minFile) ) { + return true; + } - - - var data = _getRequestData(); - if ( StructIsEmpty(data) ) { - return ""; - } - - return '' & $newline(); - - - - - - - - - - if ( not StructKeyExists(request, '_cfstaticIncludes') ) { - _setupRequest(); - } - - return request['_cfstaticIncludes']; - - - - - - - - - - if ( not StructKeyExists(request, '_cfstaticData') ) { - _setupRequest(); - } - - return request['_cfstaticData']; - - - - - - _setRequestIncludes( ArrayNew(1) ); - _setRequestData ( StructNew() ); - - if ( _getCheckForUpdates() and _filesHaveChanged() ) { - _processStaticFiles(); - } - - - - - - - - var includes = _getRequestIncludes(); - var i = 0; - var rootDir = '/' & iif( type EQ 'css', DE( _getCssDirectory() ), DE( _getJsDirectory() ) ) & '/'; - var rootDirLen = Len( rootDir ); - - if ( type EQ 'js' ) { - _setRequestData( StructNew() ); - } - - for( i=ArrayLen( includes ); i GTE 1 ; i=i-1 ){ - if ( Left( includes[i], rootDirLen ) EQ rootDir ) { - ArrayDeleteAt( includes, i ); - } - } - - _setRequestIncludes( includes ); - - - - - - - - var ext = ListLast( includedFile, '.' ); - - switch( ext ){ - case "less" : return includedFile & '.css'; - case "coffee" : return includedFile & '.js'; - } - - return includedFile; - - - - - - - - - - - - - - - - - - var dependencyFile = ""; - var dependencies = StructNew(); - var rootDir = ""; - - if ( type eq 'css' ) { - dependencyFile = _getCssDependencyFile(); - rootDir = $ListAppend( _getRootDirectory(), _getCssdirectory(), '/' ); - } else { - dependencyFile = _getJsDependencyFile(); - rootDir = $ListAppend( _getRootDirectory(), _getJsdirectory(), '/' ); - } - - if ( Len(Trim( dependencyFile ) ) ) { - dependencies = CreateObject( 'component', 'org.cfstatic.util.DependencyFileParser' ).parse( dependencyFile, rootDir ); - } - - return dependencies; - - - - - - _renderedIncludeCache = StructNew(); - _renderedIncludeCache.js = StructNew(); - _renderedIncludeCache.css = StructNew(); - - _renderedIncludeCache.debug = StructNew(); - _renderedIncludeCache.debug.js = StructNew(); - _renderedIncludeCache.debug.css = StructNew(); - - _renderedIncludeCache.js['_ordered'] = ArrayNew(1); - _renderedIncludeCache.css['_ordered'] = ArrayNew(1); - _renderedIncludeCache.debug.js['_ordered'] = ArrayNew(1); - _renderedIncludeCache.debug.css['_ordered'] = ArrayNew(1); - - _renderedIncludeCache.js['_urls'] = StructNew(); - _renderedIncludeCache.css['_urls'] = StructNew(); - _renderedIncludeCache.debug.js['_urls'] = StructNew(); - _renderedIncludeCache.debug.css['_urls'] = StructNew(); - - - - - - - - - - - var node = ""; - if ( debug ) { - node = _renderedIncludeCache.debug[ type ]; - } else { - node = _renderedIncludeCache[ type ]; - } - - ArrayAppend( node[ '_ordered' ], rendered ); - node[ path ] = ArrayLen( node['_ordered'] ); - node[ '_urls' ][ path ] = $extractUrlFromRenderedInclude( rendered ); - - - - - - - - - if ( debug ) { - return _renderedIncludeCache.debug[ type ]; - } - - return _renderedIncludeCache[ type ]; - - - - - - - // configured (permanent) debugging - if ( _getDebug() ) { - return true; - } - - // request level debugging - if ( _getDebugAllowed() ) { - return StructKeyExists(url, _getDebugKey()) and url[_getDebugKey()] EQ _getDebugPassword(); - } - - return false; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if ( not directoryExists( outputDirectory ) ) { - try { - $directoryCreate( outputDirectory ); - } catch( "java.io.IOException" e ) { - $throw( type = "org.cfstatic.CfStatic.badOutputDir" - , message = "The output directory, '#outputDirectory#', does not exist and could not be created by CfStatic." - , detail = e.detail - ); + return $fileLastModified( minFile ) LT collectionPackageOrFile.getLastModified(); + + + + + + var data = _getRequestData(); + if ( StructIsEmpty(data) ) { + return ""; + } + + return '' & $newline(); + + + + + + + + + + if ( not StructKeyExists(request, '_cfstaticIncludes') ) { + _setupRequest(); + } + + return request['_cfstaticIncludes']; + + + + + + + + + + if ( not StructKeyExists(request, '_cfstaticData') ) { + _setupRequest(); + } + + return request['_cfstaticData']; + + + + + + _setRequestIncludes( ArrayNew(1) ); + _setRequestData ( StructNew() ); + + if ( _getCheckForUpdates() and _filesHaveChanged() ) { + _processStaticFiles(); + } + + + + + + + + var includes = _getRequestIncludes(); + var i = 0; + var rootDir = '/' & iif( type EQ 'css', DE( _getCssDirectory() ), DE( _getJsDirectory() ) ) & '/'; + var rootDirLen = Len( rootDir ); + + if ( type EQ 'js' ) { + _setRequestData( StructNew() ); + } - } catch( Application e ) { - if ( e.message EQ "The specified directory #outputDirectory# could not be created." ) { - failed = true; + for( i=ArrayLen( includes ); i GTE 1 ; i=i-1 ){ + if ( Left( includes[i], rootDirLen ) EQ rootDir ) { + ArrayDeleteAt( includes, i ); + } + } + _setRequestIncludes( includes ); + + + + + + + + var ext = ListLast( includedFile, '.' ); + + switch( ext ){ + case "less" : return includedFile & '.css'; + case "coffee" : return includedFile & '.js'; + } + + return includedFile; + + + + + + + + + + + + + + + + + + var dependencyFile = ""; + var dependencies = StructNew(); + var rootDir = ""; + + if ( type eq 'css' ) { + dependencyFile = _getCssDependencyFile(); + rootDir = $ListAppend( _getRootDirectory(), _getCssdirectory(), '/' ); + } else { + dependencyFile = _getJsDependencyFile(); + rootDir = $ListAppend( _getRootDirectory(), _getJsdirectory(), '/' ); + } + + if ( Len(Trim( dependencyFile ) ) ) { + dependencies = CreateObject( 'component', 'org.cfstatic.util.DependencyFileParser' ).parse( dependencyFile, rootDir ); + } + + return dependencies; + + + + + + _renderedIncludeCache = StructNew(); + _renderedIncludeCache.js = StructNew(); + _renderedIncludeCache.css = StructNew(); + + _renderedIncludeCache.debug = StructNew(); + _renderedIncludeCache.debug.js = StructNew(); + _renderedIncludeCache.debug.css = StructNew(); + + _renderedIncludeCache.js['_ordered'] = ArrayNew(1); + _renderedIncludeCache.css['_ordered'] = ArrayNew(1); + _renderedIncludeCache.debug.js['_ordered'] = ArrayNew(1); + _renderedIncludeCache.debug.css['_ordered'] = ArrayNew(1); + + _renderedIncludeCache.js['_urls'] = StructNew(); + _renderedIncludeCache.css['_urls'] = StructNew(); + _renderedIncludeCache.debug.js['_urls'] = StructNew(); + _renderedIncludeCache.debug.css['_urls'] = StructNew(); + + + + + + + + + + + var node = ""; + if ( debug ) { + node = _renderedIncludeCache.debug[ type ]; + } else { + node = _renderedIncludeCache[ type ]; + } + + ArrayAppend( node[ '_ordered' ], rendered ); + node[ path ] = ArrayLen( node['_ordered'] ); + node[ '_urls' ][ path ] = $extractUrlFromRenderedInclude( rendered ); + + + + + + + + + if ( debug ) { + return _renderedIncludeCache.debug[ type ]; + } + + return _renderedIncludeCache[ type ]; + + + + + + + // configured (permanent) debugging + if ( _getDebug() ) { + return true; + } + + // request level debugging + if ( _getDebugAllowed() ) { + return StructKeyExists(url, _getDebugKey()) and url[_getDebugKey()] EQ _getDebugPassword(); + } + + return false; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + if ( not directoryExists( outputDirectory ) ) { + try { + $directoryCreate( outputDirectory ); + } catch( "java.io.IOException" e ) { $throw( type = "org.cfstatic.CfStatic.badOutputDir" - , message = "The output directory, '#outputDirectory#', does not exist and could not be created by CfStatic." - , detail = e.detail + , message = "The output directory, '#outputDirectory#', does not exist and could not be created by CfStatic." + , detail = e.detail ); + + } catch( Application e ) { + if ( e.message EQ "The specified directory #outputDirectory# could not be created." ) { + failed = true; + + $throw( type = "org.cfstatic.CfStatic.badOutputDir" + , message = "The output directory, '#outputDirectory#', does not exist and could not be created by CfStatic." + , detail = e.detail + ); + } + } + } + + _outputDirectory = outputDirectory; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _jsPackages = ""; + _cssPackages = ""; + + + + + + + + + var pkgCollection = ""; + if ( packageType EQ 'css' ) { + pkgCollection = _getCssPackages(); + } else { + pkgCollection = _getJsPackages(); + } + + return pkgCollection.getPackage( packageName ); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + var cssDir = $listAppend(_getRootdirectory(), _getCssdirectory(), '/'); + var files = $directoryList( cssDir, '*.less' ); + var file = ""; + var i = ""; + + for( i=1; i LTE files.recordCount; i++ ){ + file = $normalizeUnixAndWindowsPaths( $listAppend( files.directory[i], files.name[i], '/') ); + if ( $isTemporaryFileName( file ) ) { + $fileDelete( file ); } } - } - - _outputDirectory = outputDirectory; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _jsPackages = ""; - _cssPackages = ""; - - - - - - - - - var pkgCollection = ""; - if ( packageType EQ 'css' ) { - pkgCollection = _getCssPackages(); - } else { - pkgCollection = _getJsPackages(); - } - - return pkgCollection.getPackage( packageName ); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var cssDir = $listAppend(_getRootdirectory(), _getCssdirectory(), '/'); - var files = $directoryList( cssDir, '*.less' ); - var file = ""; - var i = ""; - - for( i=1; i LTE files.recordCount; i++ ){ - file = $normalizeUnixAndWindowsPaths( $listAppend( files.directory[i], files.name[i], '/') ); - if ( $isTemporaryFileName( file ) ) { - $fileDelete( file ); + + + + + + var cssDir = $listAppend(_getRootdirectory(), _getCssdirectory(), '/'); + var files = $directoryList(cssDir, '*.less'); + var globals = ListToArray( _getLessGlobals() ); + var i = 0; + var file = ""; + var imports = ""; + var importStruct = ""; + + + for( i=1; i LTE files.recordCount; i++ ){ + file = $normalizeUnixAndWindowsPaths( $listAppend( files.directory[i], files.name[i], '/') ); + if ( not $isTemporaryFileName( file ) ) { + imports = ListAppend( imports, _readLessImports( file ) ); + } } - } - - - - - - var cssDir = $listAppend(_getRootdirectory(), _getCssdirectory(), '/'); - var files = $directoryList(cssDir, '*.less'); - var globals = ListToArray( _getLessGlobals() ); - var i = 0; - var file = ""; - var imports = ""; - var importStruct = ""; - - - for( i=1; i LTE files.recordCount; i++ ){ - file = $normalizeUnixAndWindowsPaths( $listAppend( files.directory[i], files.name[i], '/') ); - if ( not $isTemporaryFileName( file ) ) { - imports = ListAppend( imports, _readLessImports( file ) ); + + for( i=1; i LTE ArrayLen(globals); i++ ) { + imports = ListAppend( imports, _readLessImports( globals[i] ) ); } - } - - for( i=1; i LTE ArrayLen(globals); i++ ) { - imports = ListAppend( imports, _readLessImports( globals[i] ) ); - } - - _lessImports = $uniqueList( imports ); - - - - - - - - var searchResults = ""; - var imports = ""; - var importPath = ""; - var i = 0; - - if ( fileExists( filePath ) ){ - searchResults = $reSearch( '@import url\((.+?)\)', $fileRead( filePath ) ); - - if ( StructKeyExists( searchResults, "$1" ) ) { - for( i=1; i LTE ArrayLen(searchResults.$1); i++){ - importPath = Replace( searchResults.$1[i], '"', '', 'all' ); - importPath = Replace( importPath, "'", '', 'all' ); - importPath = getDirectoryFromPath(filePath) & Trim(importPath); - imports = ListAppend(imports, importPath); - imports = ListAppend(imports, _readLessImports(importPath)); + + _lessImports = $uniqueList( imports ); + + + + + + + + var searchResults = ""; + var imports = ""; + var importPath = ""; + var i = 0; + + if ( fileExists( filePath ) ){ + searchResults = $reSearch( '@import url\((.+?)\)', $fileRead( filePath ) ); + + if ( StructKeyExists( searchResults, "$1" ) ) { + for( i=1; i LTE ArrayLen(searchResults.$1); i++){ + importPath = Replace( searchResults.$1[i], '"', '', 'all' ); + importPath = Replace( importPath, "'", '', 'all' ); + importPath = getDirectoryFromPath(filePath) & Trim(importPath); + imports = ListAppend(imports, importPath); + imports = ListAppend(imports, _readLessImports(importPath)); + } } } - } - - return imports; - - - - - - var globals = ListToArray( ListAppend(_getLessGlobals(), _lessImports) ); - var lastModified = "1900-01-01"; - var fileModified = ""; - var i = 0; - - for( i=1; i LTE ArrayLen(globals); i++ ) { - fileModified = $fileLastModified( globals[i] ); - if ( fileModified GT lastModified ){ - lastModified = fileModified; + + return imports; + + + + + + var globals = ListToArray( ListAppend(_getLessGlobals(), _lessImports) ); + var lastModified = "1900-01-01"; + var fileModified = ""; + var i = 0; + + for( i=1; i LTE ArrayLen(globals); i++ ) { + fileModified = $fileLastModified( globals[i] ); + if ( fileModified GT lastModified ){ + lastModified = fileModified; + } } - } - return lastModified; - - + return lastModified; + + - - + + - - - \ No newline at end of file + + + \ No newline at end of file diff --git a/org/cfstatic/core/StaticFile.cfc b/org/cfstatic/core/StaticFile.cfc index 002762c..920e4c4 100644 --- a/org/cfstatic/core/StaticFile.cfc +++ b/org/cfstatic/core/StaticFile.cfc @@ -6,6 +6,7 @@ _url = ""; _minifiedUrl = ""; _fileType = ""; + _ecma6 = ""; _cacheBust = true; _dependencies = ArrayNew(1); _properties = StructNew(); diff --git a/org/cfstatic/lib/closureCompiler/closure-compiler-v20231112.jar b/org/cfstatic/lib/closureCompiler/closure-compiler-v20231112.jar new file mode 100644 index 0000000..5b1541f Binary files /dev/null and b/org/cfstatic/lib/closureCompiler/closure-compiler-v20231112.jar differ diff --git a/org/cfstatic/util/ClosureCompiler.cfc b/org/cfstatic/util/ClosureCompiler.cfc new file mode 100644 index 0000000..e473ffd --- /dev/null +++ b/org/cfstatic/util/ClosureCompiler.cfc @@ -0,0 +1,53 @@ +/** + * I am a CF wrapper to the ClosureCompiler jar to use as the default rather than YUI + * set the option useGoogleClosure = true when initialising cfstatic. To use + * on an individual file add the annotation @ecma6 true eg + *

+ *
+ * see https://blog.bolinfest.com/2009/11/calling-closure-compiler-from-java.html
+ * and https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/CommandLineRunner.java
+ */
+component extends="org.cfstatic.util.Base" {
+
+	/**
+	 * Constructor, taking a javaloader instance preloaded with the path to the Google Closure Compiler jar.
+	 *
+	 * @javaloader An instance of the javaloader with class path of Closure Compiler jar preloaded. Optional.
+	 */
+	public org.cfstatic.util.ClosureCompiler function init(any javaLoader){
+		if ( arguments.keyExists("javaLoader") ) {
+			super._setJavaLoader( javaLoader );
+		}
+		return this;
+	}
+
+	/**
+	 * I take a js input string and return a compressed version.
+	 *
+	 * @string the JavaScript String to compile
+	 */
+	public string function compressJs(required string source){
+
+		var compiler = $loadJavaClass( 'com.google.javascript.jscomp.Compiler' ).init();
+		var options = $loadJavaClass( 'com.google.javascript.jscomp.CompilerOptions' ).init();
+		var compilationLevel = $loadJavaClass( 'com.google.javascript.jscomp.CompilationLevel').fromString("SIMPLE_OPTIMIZATIONS");
+
+		try{
+			options.setEnvironment(options.Environment.valueOf("BROWSER"));
+			options.setEmitUseStrict(false);
+			options.setOutputCharset(new java("java.nio.charset.StandardCharsets").UTF_8);
+			compilationLevel.setOptionsForCompilationLevel(options);
+			// To get the complete set of externs, the logic in CompilerRunner.getDefaultExterns() should be used here.
+			var externals = $loadJavaClass( 'com.google.javascript.jscomp.SourceFile' ).fromCode("externs.js","function alert(x) {}");
+			// The dummy input name "input.js" is used here so that any warnings or errors will cite line numbers in terms of input.js.
+			var rawJs =  $loadJavaClass( 'com.google.javascript.jscomp.SourceFile' ).fromCode("input.js", arguments.source);
+			// compiler.compile returns a com.google.javascript.jscomp.Result but we do not need it
+			compiler.compile(externals, rawJs, options);
+		} catch(any e){
+			writeDump(e, "console");
+			$throw( argumentCollection = e );
+		}
+		// The compiler is responsible for generating the compiled code; it is not accessible via the Result.
+		return compiler.toSource();
+	}
+}
\ No newline at end of file