Macro preprocessor #15

merged 1 commit into from Oct 28, 2012


None yet

2 participants



I have just coded and tested small patch for bin/,
that allows to define and expand macro constants in buildr.cson
like ##def PROJ_NAME "jascuti"
before it would be converted to object and passed into core buildr.

Macro syntax is masked in comments, so should not harm anything

motivation: e.g. have project name constant populated across whole config file


    ##def PROJ_NAME "jascuti"

    # Options
    log: true # (log status updates to console?) true or false
    watch: false # (automatically rebuild on file change?) true or false

    # Handlers
    buildHandler: (err) -> # (fired when build completed) function or false
        if err
            console.log err
            throw err
        console.log 'Building completed\n'
    rebuildHandler: (err) -> # (fired when rebuild completed) function or false
        if err
            console.log err
            throw err
        console.log 'ReBuilding completed\n'

    # Paths
    srcPath: 'src' # String
    outPath: 'build' # String or false

    # Checking
    checkScripts: false # Array or true or false
    checkStyles: false # Array or true or false
    jshintOptions: false # Object or false
    csslintOptions: false # Object or false

    # Compression (requires outPath)
    compressScripts: true # Array or true or false
    compressStyles: false # Array or true or false
    compressImages: false # Array or true or false

    # Order
    scriptsOrder: ['common.js', 'namespaces.js']
    stylesOrder: false # Array or false

    # Bundling (requires Order)
    bundleScriptPath: "build/PROJ_NAME.min.js" # String or false
    bundleStylePath: false # String or false
    deleteBundledFiles: true # (requires outPath) true or false

    # Loaders (requires Order) - for debug purpose. in production use bundled minified
    srcLoaderHeader: '''
        # Prepare
        myprojectEl = document.getElementById('buildr_debug_loader')
        myprojectBaseUrl = myprojectEl.src.replace(/\\?.*$/,'').replace(/loader\\.js$/, '').replace(/\\/+$/, '')+'/'

        # Load in with Buildr
        myprojectBuildr = new window.Buildr {
            baseUrl: myprojectBaseUrl
            beforeEl: myprojectEl
            serverCompilation: window.serverCompilation or false
            scripts: scripts
            styles: styles
        ''' # note, all \ in this are escaped due to it being in a string
    srcLoaderPath: 'build/PROJ_NAME.loader.js' # String or false
    # use something like this in HTML: <script id="buildr_debug_loader" src="PROJ_NAME.loader.js"></script>

I'm going to use your awesome Buildr with this patch in my projects :),
so it would be nice have this in the upstream.


@rotaryden rotaryden Added simple define-like constants macro preprocessor for buildr.cson…
… to keep DRY, it expands macros before CSON converted into object

This is an awesome idea. I am holding off on merging because I have had issues getting cson to work correctly and JSON may be a better approach. It has been months since I looked at it, however, so I would like to revisit cson.


After upgrading to the latest cson module, everything works, so cson is a safe option. Accepting merge...

@brandonramirez brandonramirez merged commit 6a9aa1e into balupton:master Oct 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment