Created
December 27, 2010 23:45
-
-
Save tswicegood/756704 to your computer and use it in GitHub Desktop.
Fabric file for compiling CoffeeScript for use with CouchApp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This requires a few configuration values to be set in order to know what | |
# parameters to provide to ``couchapp``. | |
# The default value to be sent as ``--docid`` to ``couchapp push`` | |
DEFAULT_DOCID = "_design/awesome" | |
# The default destination to be sent to ``couchapp push`` | |
DEFAULT_DEST = "some_db" | |
# Actual fabfile script | |
# --------------------- | |
# | |
# You shouldn't need to change anything beyond this. | |
# Import fabric specific modules | |
from fabric.api import local | |
from fabric.state import output | |
# Load ``os`` and ``sys`` so we can find files and write to standard out. | |
import os, sys | |
# Turn off Fabric's generated output. There may be a better way to do this, | |
# but this works in the "quick and dirty" way. | |
output["running"] = False | |
# This is a quick convenience method for pushing something to stdout | |
# immediately without adding a new-line. | |
def _out(msg): | |
sys.stdout.write(msg) | |
sys.stdout.flush() | |
# Tasks | |
# ----- | |
# Our first task builds all of the CoffeeScript files. It uses ``find`` to | |
# scan the ``src/`` directory looking for ``*.coffee`` files. With found file, | |
# it compiles it, removing the ``src/`` prefix from the name. | |
# | |
# The ``src/`` directory is meant to be a mirror of the base `CouchApp`_ | |
# directory. I recommend storing *both* the generated ``.js`` and the raw | |
# ``.coffee`` files in version control so your `CouchApp`_ can be deployed | |
# without having to have the entire build chain. | |
# | |
# **Warning**: Calling this command *will* overwrite all JS files with a | |
# ``.coffee`` counterpart. Of course, you have them stored in a VCS, so that's | |
# a none issue, right? | |
def build(): | |
files = local("find src -name '*.coffee'").split("\n") | |
for file in files: | |
dest = os.path.dirname(file[4:]) | |
_out("compiling %s..." % os.path.basename(file)) | |
local("coffee --no-wrap -c --output %s %s" % (dest, file)) | |
print " DONE" | |
# ``push`` provides you with a wrapper around ``couchapp push`` that builds the | |
# CoffeeScript prior to calling push. It's functionally the same as calling:: | |
# | |
# prompt> fab build | |
# ... output | |
# prompt> couchapp push \ | |
# --docid="_design/awesome" \ | |
# some_db | |
def push(docid=DEFAULT_DOCID, server=DEFAULT_DEST): | |
build() | |
print "Pushing changes to Couch..." | |
local('couchapp push --docid="%s" %s' % (docid, server), capture=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment