Adding buildScript
This commit is contained in:
parent
12e44c3e00
commit
27aab78ca3
@ -16,6 +16,9 @@ dependencies {
|
|||||||
/**
|
/**
|
||||||
* Logging
|
* Logging
|
||||||
*/
|
*/
|
||||||
|
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
|
||||||
|
implementation 'org.slf4j:slf4j-api:1.7.36'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl
|
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl
|
||||||
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'
|
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.jessebrault.ssg
|
package com.jessebrault.ssg
|
||||||
|
|
||||||
|
import com.jessebrault.ssg.buildscript.GroovyBuildScriptRunner
|
||||||
import com.jessebrault.ssg.part.GspPartRenderer
|
import com.jessebrault.ssg.part.GspPartRenderer
|
||||||
import com.jessebrault.ssg.part.PartFilePartsProvider
|
import com.jessebrault.ssg.part.PartFilePartsProvider
|
||||||
import com.jessebrault.ssg.part.PartType
|
import com.jessebrault.ssg.part.PartType
|
||||||
@ -13,9 +14,13 @@ import com.jessebrault.ssg.text.MarkdownFrontMatterGetter
|
|||||||
import com.jessebrault.ssg.text.MarkdownTextRenderer
|
import com.jessebrault.ssg.text.MarkdownTextRenderer
|
||||||
import com.jessebrault.ssg.text.TextType
|
import com.jessebrault.ssg.text.TextType
|
||||||
import com.jessebrault.ssg.text.TextFileTextsProvider
|
import com.jessebrault.ssg.text.TextFileTextsProvider
|
||||||
|
import org.slf4j.Logger
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
class StaticSiteGeneratorCli {
|
class StaticSiteGeneratorCli {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(StaticSiteGeneratorCli)
|
||||||
|
|
||||||
static void main(String[] args) {
|
static void main(String[] args) {
|
||||||
def markdownText = new TextType(['.md'], new MarkdownTextRenderer(), new MarkdownFrontMatterGetter())
|
def markdownText = new TextType(['.md'], new MarkdownTextRenderer(), new MarkdownFrontMatterGetter())
|
||||||
def gspTemplate = new TemplateType(['.gsp'], new GspTemplateRenderer())
|
def gspTemplate = new TemplateType(['.gsp'], new GspTemplateRenderer())
|
||||||
@ -39,6 +44,16 @@ class StaticSiteGeneratorCli {
|
|||||||
specialPagesProviderGetter: { Config config -> new SpecialPageFileSpecialPagesProvider(config.specialPageTypes, config.specialPagesDir) }
|
specialPagesProviderGetter: { Config config -> new SpecialPageFileSpecialPagesProvider(config.specialPageTypes, config.specialPagesDir) }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def globals = [:]
|
||||||
|
|
||||||
|
if (new File('build.groovy').exists()) {
|
||||||
|
logger.info('found buildScript: build.groovy')
|
||||||
|
def buildScriptRunner = new GroovyBuildScriptRunner()
|
||||||
|
buildScriptRunner.runBuildScript(config, globals)
|
||||||
|
logger.info('after running buildScript, config: {}', config)
|
||||||
|
logger.info('after running buildScript, globals: {}', globals)
|
||||||
|
}
|
||||||
|
|
||||||
def ssg = new SimpleStaticSiteGenerator(config)
|
def ssg = new SimpleStaticSiteGenerator(config)
|
||||||
ssg.generate(new File('build'))
|
ssg.generate(new File('build'))
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,9 @@ dependencies {
|
|||||||
// https://mvnrepository.com/artifact/org.apache.groovy/groovy-templates
|
// https://mvnrepository.com/artifact/org.apache.groovy/groovy-templates
|
||||||
implementation 'org.apache.groovy:groovy-templates:4.0.7'
|
implementation 'org.apache.groovy:groovy-templates:4.0.7'
|
||||||
|
|
||||||
|
// https://mvnrepository.com/artifact/org.apache.groovy/groovy-yaml
|
||||||
|
implementation 'org.apache.groovy:groovy-yaml:4.0.7'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/org.commonmark/commonmark
|
// https://mvnrepository.com/artifact/org.commonmark/commonmark
|
||||||
implementation 'org.commonmark:commonmark:0.21.0'
|
implementation 'org.commonmark:commonmark:0.21.0'
|
||||||
|
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.jessebrault.ssg.buildscript
|
||||||
|
|
||||||
|
import com.jessebrault.ssg.Config
|
||||||
|
import groovy.transform.TupleConstructor
|
||||||
|
|
||||||
|
abstract class BuildScriptBase extends Script {
|
||||||
|
|
||||||
|
@TupleConstructor(includeFields = true, defaults = false)
|
||||||
|
static class GlobalsConfigurator {
|
||||||
|
|
||||||
|
private final Map globals
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Object getProperty(String propertyName) {
|
||||||
|
this.globals[propertyName]
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void setProperty(String propertyName, Object newValue) {
|
||||||
|
this.globals.put(propertyName, newValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Config config
|
||||||
|
Map globals
|
||||||
|
|
||||||
|
void config(
|
||||||
|
@DelegatesTo(value = Config, strategy = Closure.DELEGATE_FIRST)
|
||||||
|
Closure configClosure
|
||||||
|
) {
|
||||||
|
configClosure.setDelegate(this.config)
|
||||||
|
configClosure.setResolveStrategy(Closure.DELEGATE_FIRST)
|
||||||
|
configClosure.run()
|
||||||
|
}
|
||||||
|
|
||||||
|
void globals(
|
||||||
|
@DelegatesTo(value = GlobalsConfigurator, strategy = Closure.DELEGATE_FIRST)
|
||||||
|
Closure globalsClosure
|
||||||
|
) {
|
||||||
|
def globalsConfigurator = new GlobalsConfigurator(this.globals)
|
||||||
|
globalsClosure.setDelegate(globalsConfigurator)
|
||||||
|
globalsClosure.setResolveStrategy(Closure.DELEGATE_FIRST)
|
||||||
|
globalsClosure.run()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.jessebrault.ssg.buildscript
|
||||||
|
|
||||||
|
import com.jessebrault.ssg.Config
|
||||||
|
|
||||||
|
interface BuildScriptRunner {
|
||||||
|
void runBuildScript(Config config, Map globals)
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.jessebrault.ssg.buildscript
|
||||||
|
|
||||||
|
import com.jessebrault.ssg.Config
|
||||||
|
import org.codehaus.groovy.control.CompilerConfiguration
|
||||||
|
|
||||||
|
class GroovyBuildScriptRunner implements BuildScriptRunner {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void runBuildScript(Config config, Map globals) {
|
||||||
|
Objects.requireNonNull(config)
|
||||||
|
Objects.requireNonNull(globals)
|
||||||
|
def engine = new GroovyScriptEngine([new File('.').toURI().toURL()] as URL[])
|
||||||
|
engine.config = new CompilerConfiguration().tap {
|
||||||
|
scriptBaseClass = 'com.jessebrault.ssg.buildscript.BuildScriptBase'
|
||||||
|
}
|
||||||
|
def buildScript = engine.createScript('build.groovy', new Binding())
|
||||||
|
assert buildScript instanceof BuildScriptBase
|
||||||
|
buildScript.config = config
|
||||||
|
buildScript.globals = globals
|
||||||
|
buildScript.run()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user