From 71ae3800e07092084d9f91f53b529b952c59d510 Mon Sep 17 00:00:00 2001 From: jclausen Date: Wed, 25 Sep 2024 21:48:52 -0400 Subject: [PATCH] update build task --- build/Build.cfc | 458 +++++++++++++++++++++++++----------------------- 1 file changed, 239 insertions(+), 219 deletions(-) diff --git a/build/Build.cfc b/build/Build.cfc index 1f97ed8..558c51a 100644 --- a/build/Build.cfc +++ b/build/Build.cfc @@ -2,262 +2,282 @@ * Build process for ColdBox Modules * Adapt to your needs. */ -component{ - - /** - * Constructor - */ - function init(){ - // Setup Pathing - variables.cwd = getCWD().reReplace( "\.$", "" ); - variables.artifactsDir = cwd & "/.artifacts"; - variables.buildDir = cwd & "/.tmp"; - variables.apiDocsURL = "http://localhost:60299/apidocs/"; - variables.testRunner = "http://localhost:60299/tests/runner.cfm"; - - // Source Excludes Not Added to final binary - variables.excludes = [ - ".gitignore", - ".cfformat.json", - ".cflintrc", - ".editorconfig", - ".gitattributes", - ".markdownlint.json", - ".travis.yml", - ".artifacts", - ".tmp", - "build", - "test-harness", +component { + + /** + * Constructor + */ + function init(){ + // Setup Pathing + variables.cwd = getCWD().reReplace( "\.$", "" ); + variables.artifactsDir = cwd & "/.artifacts"; + variables.buildDir = cwd & "/.tmp"; + variables.apiDocsURL = "http://localhost:60299/apidocs/"; + variables.testRunner = "http://localhost:60299/tests/runner.cfm"; + + // Source Excludes Not Added to final binary + variables.excludes = [ + "build", + "node-modules", + "resources", + "test-harness", + "modules", + "docs", + "(package|package-lock|book).json", + "webpack.config.js", + "server-.*\.json", "docker-compose.yml", - "book.json", - ".DS_Store", - ".git" - ]; - - // Cleanup + Init Build Directories - [ variables.buildDir, variables.artifactsDir ].each( function( item ){ - if( directoryExists( item ) ){ - directoryDelete( item, true ); - } - // Create directories - directoryCreate( item, true, true ); + "^\..*", + "Query Ideas.md" + ]; + + // Cleanup + Init Build Directories + [ + variables.buildDir, + variables.artifactsDir + ].each( function( item ){ + if ( directoryExists( item ) ) { + directoryDelete( item, true ); + } + // Create directories + directoryCreate( item, true, true ); } ); // Create Mappings - fileSystemUtil.createMapping( "coldbox", variables.cwd & "test-harness/coldbox" ); + fileSystemUtil.createMapping( + "coldbox", + variables.cwd & "test-harness/coldbox" + ); - return this; - } + return this; + } - /** - * Run the build process: test, build source, docs, checksums - * - * @projectName The project name used for resources and slugs - * @version The version you are building - * @buldID The build identifier - * @branch The branch you are building - */ - function run( - required projectName, - version="1.0.0", - buildID=createUUID(), - branch="development" - ){ + /** + * Run the build process: test, build source, docs, checksums + * + * @projectName The project name used for resources and slugs + * @version The version you are building + * @buldID The build identifier + * @branch The branch you are building + */ + function run( + required projectName, + version = "1.0.0", + buildID = createUUID(), + branch = "development" + ){ // Create project mapping fileSystemUtil.createMapping( arguments.projectName, variables.cwd ); - // Run the tests - // runTests(); - - // Build the source - buildSource( argumentCollection=arguments ); + // Build the source + buildSource( argumentCollection = arguments ); - // Build Docs - arguments.outputDir = variables.buildDir & "/apidocs"; - docs( argumentCollection=arguments ); + // Build Docs + arguments.outputDir = variables.buildDir & "/apidocs"; + docs( argumentCollection = arguments ); - // checksums + // checksums buildChecksums(); - // Finalize Message - print.line() - .boldMagentaLine( "Build Process is done! Enjoy your build!" ) - .toConsole(); - } - - /** - * Run the test suites - */ - function runTests(){ - // Tests First, if they fail then exit - print.blueLine( "Testing the package, please wait..." ).toConsole(); - - command( 'testbox run' ) - .params( - runner = variables.testRunner, - verbose = true, - outputFile = "build/results.json" - ) - .run(); - - // Check Exit Code? - if( shell.getExitCode() ){ - return error( "Cannot continue building, tests failed!" ); - } - } + // Finalize Message + print + .line() + .boldMagentaLine( "Build Process is done! Enjoy your build!" ) + .toConsole(); + } - /** - * Build the source + /** + * Build the source * * @projectName The project name used for resources and slugs - * @version The version you are building - * @buldID The build identifier - * @branch The branch you are building - */ - function buildSource( - required projectName, - version="1.0.0", - buildID=createUUID(), - branch="development" - ){ - // Build Notice ID - print.line() - .boldMagentaLine( "Building #arguments.projectName# v#arguments.version#+#arguments.buildID# from #cwd# using the #arguments.branch# branch." ) - .toConsole(); - - // Prepare exports directory - variables.exportsDir = variables.artifactsDir & "/#projectName#/#arguments.version#"; - directoryCreate( variables.exportsDir, true, true ); - - // Project Build Dir - variables.projectBuildDir = variables.buildDir & "/#projectName#"; - directoryCreate( variables.projectBuildDir, true, true ); - - // Copy source - print.blueLine( "Copying source to build folder..." ).toConsole(); - copy( variables.cwd, variables.projectBuildDir ); - - // Create build ID - fileWrite( "#variables.projectBuildDir#/#projectName#-#version#+#buildID#", "Built with love on #dateTimeFormat( now(), "full")#" ); - - // Updating Placeholders - print.greenLine( "Updating version identifier to #arguments.version#" ).toConsole(); - command( 'tokenReplace' ) - .params( - path = "/#variables.projectBuildDir#/**.json,/#variables.projectBuildDir#/**.cfc", - token = "@build.version@", - replacement = arguments.version - ) - .run(); - - print.greenLine( "Updating build identifier to #arguments.buildID#" ).toConsole(); - command( 'tokenReplace' ) - .params( - path = "/#variables.projectBuildDir#/**.json,/#variables.projectBuildDir#/**.cfc", - token = ( arguments.branch == "main" ? "@build.number@" : "+@build.number@" ), - replacement = ( arguments.branch == "main" ? arguments.buildID : "-snapshot" ) - ) - .run(); - - // zip up source - var destination = "#variables.exportsDir#/#projectName#-#version#.zip"; - print.greenLine( "Zipping code to #destination#" ).toConsole(); - cfzip( - action="zip", - file="#destination#", - source="#variables.projectBuildDir#", - overwrite=true, - recurse=true - ); + * @version The version you are building + * @buldID The build identifier + * @branch The branch you are building + */ + function buildSource( + required projectName, + version = "1.0.0", + buildID = createUUID(), + branch = "development" + ){ + // Build Notice ID + print + .line() + .boldMagentaLine( + "Building #arguments.projectName# v#arguments.version#+#arguments.buildID# from #cwd# using the #arguments.branch# branch." + ) + .toConsole(); + + // Prepare exports directory + variables.exportsDir = variables.artifactsDir & "/#projectName#/#arguments.version#"; + directoryCreate( variables.exportsDir, true, true ); + + // Project Build Dir + variables.projectBuildDir = variables.buildDir & "/#projectName#"; + directoryCreate( + variables.projectBuildDir, + true, + true + ); + + // Copy source + print.blueLine( "Copying source to build folder..." ).toConsole(); + copy( + variables.cwd, + variables.projectBuildDir + ); + + // Create build ID + fileWrite( + "#variables.projectBuildDir#/#projectName#-#version#+#buildID#", + "Built with love on #dateTimeFormat( now(), "full" )#" + ); + + // Updating Placeholders + print.greenLine( "Updating version identifier to #arguments.version#" ).toConsole(); + command( "tokenReplace" ) + .params( + path = "/#variables.projectBuildDir#/**", + token = "@build.version@", + replacement = arguments.version + ) + .run(); - // Copy box.json for convenience - fileCopy( "#variables.projectBuildDir#/box.json", variables.exportsDir ); - } + print.greenLine( "Updating build identifier to #arguments.buildID#" ).toConsole(); + command( "tokenReplace" ) + .params( + path = "/#variables.projectBuildDir#/**", + token = ( arguments.branch == "main" ? "@build.number@" : "+@build.number@" ), + replacement = ( arguments.branch == "main" ? arguments.buildID : "-snapshot" ) + ) + .run(); - /** - * Produce the API Docs - */ - function docs( required projectName, version="1.0.0", outputDir=".tmp/apidocs" ){ - return; - // Generate Docs - print.greenLine( "Generating API Docs, please wait..." ).toConsole(); - directoryCreate( arguments.outputDir, true, true ); + var fileSuffix = "+" & arguments.buildID; + + if( arguments.branch != "main" ){ + var fileSuffix = "-snapshot" + } + + // zip up source + var destination = "#variables.exportsDir#/#projectName#-#version##fileSuffix#.zip"; + print.greenLine( "Zipping code to #destination#" ).toConsole(); + cfzip( + action = "zip", + file = "#destination#", + source = "#variables.projectBuildDir#", + overwrite = true, + recurse = true + ); + + // Copy box.json for convenience + fileCopy( + "#variables.projectBuildDir#/box.json", + variables.exportsDir + ); + } + /** + * Produce the API Docs + */ + function docs( + required projectName, + version = "1.0.0", + outputDir = ".tmp/apidocs" + ){ // Create project mapping fileSystemUtil.createMapping( arguments.projectName, variables.cwd ); fileSystemUtil.createMapping( "coldbox", variables.cwd & "test-harness/coldbox" ); fileSystemUtil.createMapping( "testbox", variables.cwd & "test-harness/testbox" ); + // Generate Docs + print.greenLine( "Generating API Docs, please wait..." ).toConsole(); + directoryCreate( arguments.outputDir, true, true ); - command( 'docbox generate' ) + command( "docbox generate" ) .params( - "source" = "models", - "mapping" = "models", + "source" = "models", + "mapping" = "models", "strategy-projectTitle" = "#arguments.projectName# v#arguments.version#", - "strategy-outputDir" = arguments.outputDir + "strategy-outputDir" = arguments.outputDir ) .run(); - print.greenLine( "API Docs produced at #arguments.outputDir#" ).toConsole(); - - var destination = "#variables.exportsDir#/#projectName#-docs-#version#.zip"; + print.greenLine( "API Docs produced at #arguments.outputDir#" ).toConsole(); + var destination = "#variables.exportsDir#/#projectName#-docs-#version#.zip"; print.greenLine( "Zipping apidocs to #destination#" ).toConsole(); - - cfzip( - action="zip", - file="#destination#", - source="#arguments.outputDir#", - overwrite=true, - recurse=true - ); + cfzip( + action = "zip", + file = "#destination#", + source = "#arguments.outputDir#", + overwrite = true, + recurse = true + ); } - /********************************************* PRIVATE HELPERS *********************************************/ + /********************************************* PRIVATE HELPERS *********************************************/ - /** - * Build Checksums - */ - private function buildChecksums(){ - print.greenLine( "Building checksums" ).toConsole(); - command( 'checksum' ) - .params( path = '#variables.exportsDir#/*.zip', algorithm = 'SHA-512', extension="sha512", write=true ) - .run(); - command( 'checksum' ) - .params( path = '#variables.exportsDir#/*.zip', algorithm = 'md5', extension="md5", write=true ) - .run(); - } + /** + * Build Checksums + */ + private function buildChecksums(){ + print.greenLine( "Building checksums" ).toConsole(); + command( "checksum" ) + .params( + path = "#variables.exportsDir#/*.zip", + algorithm = "SHA-512", + extension = "sha512", + write = true + ) + .run(); + command( "checksum" ) + .params( + path = "#variables.exportsDir#/*.zip", + algorithm = "md5", + extension = "md5", + write = true + ) + .run(); + } - /** - * DirectoryCopy is broken in lucee - */ - private function copy( src, target, recurse=true ){ - // process paths with excludes - directoryList( src, false, "path", function( path ){ - var isExcluded = false; - variables.excludes.each( function( item ){ - if( path.replaceNoCase( variables.cwd, "", "all" ).findNoCase( item ) ){ - isExcluded = true; - } - } ); - return !isExcluded; - }).each( function( item ){ - // Copy to target - if( fileExists( item ) ){ - print.blueLine( "Copying #item#" ).toConsole(); - fileCopy( item, target ); - } else { - print.greenLine( "Copying directory #item#" ).toConsole(); - directoryCopy( item, target & "/" & item.replace( src, "" ), true ); - } - } ); - } + /** + * DirectoryCopy is broken in lucee + */ + private function copy( src, target, recurse = true ){ + // process paths with excludes + directoryList( + src, + false, + "path", + function( path ){ + var isExcluded = false; + variables.excludes.each( function( item ){ + if ( path.replaceNoCase( variables.cwd, "", "all" ).reFindNoCase( item ) ) { + isExcluded = true; + } + } ); + return !isExcluded; + } + ).each( function( item ){ + // Copy to target + if ( fileExists( item ) ) { + print.blueLine( "Copying #item#" ).toConsole(); + fileCopy( item, target ); + } else { + print.greenLine( "Copying directory #item#" ).toConsole(); + directoryCopy( + item, + target & "/" & item.replace( src, "" ), + true + ); + } + } ); + } - /** + /** * Gets the last Exit code to be used **/ - private function getExitCode() { - return (createObject( 'java', 'java.lang.System' ).getProperty( 'cfml.cli.exitCode' ) ?: 0); - + private function getExitCode(){ + return ( createObject( "java", "java.lang.System" ).getProperty( "cfml.cli.exitCode" ) ?: 0 ); } -} \ No newline at end of file +}