Skip to content

Instantly share code, notes, and snippets.

@azenla
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save azenla/3723670638c6967fd8dd to your computer and use it in GitHub Desktop.

Select an option

Save azenla/3723670638c6967fd8dd to your computer and use it in GitHub Desktop.
Testly Build File - Uses CoffeeScript and ShellJS

Build Script

This Build Script is completely written in Literate CoffeeScript with ShellJS's Make System

--version target

Adds support for the make --version flag

target "--version", ->
    # Print Version Information
    echo "testly v#{pkginfo.version} make script (shelljs v#{pkginfo["dependencies"].shelljs.substr(1)})"
    # Exit so no other targets are executed
    exit 0

Main Target

target "all", ->
    # Run Tests
    runTarget "test"

Test Target

Runs the tests using testly

target "test", ->
    # Create Arguments List
    args = ["bin/testly", "--testdir=tests/", "--json=test-report.json"]
    # Add --teamcity if TeamCity was detected
    if teamcity
        args.push "--teamcity"
    # Execute Tests
    node args.join " "

CI Target

Target for Continuous Integration

target "ci", ->
    # Run Tests
    runTarget "test"

Update Version Target

Updates Testly's Version using the 'semver' module. Also creates a git tag, pushes the tag, and pushes the update version commit.

target "update-version", ->
    # Get Next Patch Version
    next = semver.inc pkginfo.version, "patch"
    # Update Version
    echo "Updating Version to v#{next}"
    pkginfo.version = next
    # Write version to package.json
    json(pkginfo).to "package.json"
    # Create a Git Tag
    git "tag v#{pkginfo.version}"
    # Push the Created Tag
    git "push --tags"
    # Add Updated Files
    git "add ."
    # Commit Update
    git "commit -m 'Update Version to v#{next}'"
    # Push Commit
    git "push origin master"

Publish Target

Publishes testly to NPM

target "publish", ->
    # Run Tests to Ensure Release Works
    runTarget "test"
    # Update Version
    runTarget "update-version"
    npm "publish"
@azenla

azenla commented Jun 1, 2014

Copy link
Copy Markdown
Author

This of course is an extension of ShellJS's Make System. Here is the code for the invoker for the build script

#!node_modules/coffee-script/bin/coffee
global[moduleName] = require moduleName for moduleName in [
    "colors" # Fancy Colors
    "shelljs/make" # Make in JavaScript
    "semver" # Semantic Versions
]

global.__target = global.target

global.target = (name, func) ->
    __target[name] = func

global.teamcity = no

if process.env.TEAMCITY_VERSION
    global.teamcity = yes

global.pkginfo = require "../package.json"

global.cmdline = (executable, args) ->
    line = [ executable ]
    type = typeof args
    if type is "array"
        for arg in args
            line.push arg
    else
        line.push args
    exec line.join(' ')

global.npm = (args...) ->
    cmdline "npm", args

global.node = (args...) ->
    cmdline "node", args

global.git = (args...) ->
    cmdline "git", args

global.json = (obj) ->
    JSON.stringify obj, null, 4

global.runTarget = (target) ->
    __target[target]()

require "./build.litcoffee"

global.target = __target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment