Bjorn Tipling

unapologetically uninformed, unthoughtful and unimaginative

Scons Scanner for Dojo

Comments

Omg! It’s not a post about something political! :o

Anyhow, I wrote a Scons Scanner for Dojo.

Scons is a python based build tool like Make and Ant, only it rocks and those others suck. A scanner is a neat feature of scons that allows you to create a way to follow #include foo.h like statements that Scons doesn’t understand, like Dojo’s dojo.require(”foo.js”); to create a list of dependencies. The list of files scanned will be examined for changes and if a change has been found it will trigger a build. Dojo is a JavaScript framework like prototype or JQuery only it rocks and those others suck.

I am making this scanner available to you at the low low cost of free! With an MIT License.

Here it be (I assume an understanding of Scons):

import re
import os

include_re = re.compile(r'^dojo.require\("(.*)"\).*$', re.M)

cwd = os.getcwd()

def DojoScan(node, env, path):
  contents = node.get_contents()
  includes = include_re.findall(contents)
  return [env.File("%s/%s" % (cwd,"/".join(n.split(".")) + ".js")) for n in includes]

scan = env.Scanner(function=DojoScan, skeys=['.js'], recursive=True)
env.Append(SCANNERS = scan)



Note this wont yet detect changes in Dijit templates. :/
My implementation as a Sconscript file in a js directory that has dojo, dijit, etc:

import re
import os

Import('env')

include_re = re.compile(r'^dojo.require\("(.*)"\).*$', re.M)

cwd = os.getcwd()

def DojoScan(node, env, path):
  contents = node.get_contents()
  includes = include_re.findall(contents)
  return [env.File("%s/%s" % (cwd,"/".join(n.split(".")) + ".js")) for n in includes]

def JSMin(target, source, env):
  cwd = os.getcwd()
  os.chdir("static/js/util/buildscripts")
  cmd_ = "./build.sh profile=karmerd action=release"
  r = os.system(cmd_)
  os.chdir(cwd)
  return r

minifier = Builder(action = JSMin, src_suffix=".js", suffix=".js")
env.Append(BUILDERS = {'JSMinifier' : minifier})
scan = env.Scanner(function=DojoScan, skeys=['.js'], recursive=True)
env.Append(SCANNERS = scan)
JSBuild = env.JSMinifier(env.File("release/dojo/karmerd/karmerd.js"), env.File("karmerd/karmerd.js"))
env.Depends(JSBuild, env.Glob("karmerd/templates/*.html"))
env.Install("%s/%s" % (env["releaseDir"],"static/js/karmerd/"), JSBuild)
dojo = env.InstallAs(target = "%s/%s" % (env["releaseDir"],"static/js/dojo/dojo.js"), source=env.File("release/dojo/dojo/dojo.js"))
resources = env.Command(env.Dir("%s/%s" % (env["releaseDir"], "static/js/dojo/resources")), env.Dir("release/dojo/dojo/resources"), [Delete('$TARGET'),Copy('$TARGET','$SOURCE')])
env.Depends(dojo, JSBuild)
env.Depends(resources, dojo)

Updated:
Updated my implementation to include a dijit template directory and an installation of dojo’s resources directory. It still doesn’t trigger a build if Dijit templates in Dojo’s trunk are modified. I will investigate that some more.

Written by Bjorn

September 25th, 2008 at 6:56 pm

Posted in programming, python

Tagged with ,

Viewing 2 Comments

 
close Reblog this comment
blog comments powered by Disqus