Skip to content
This repository
Browse code

Use Cakefile to build pure JavaScript.

  • Loading branch information...
commit 135b1466c8d2f959c2b4bd71509d917b0794dba9 1 parent 0442473
Brandon Ramirez authored October 27, 2012
4  .gitignore
... ...
@@ -0,0 +1,4 @@
  1
+node_modules/
  2
+bin/buildr.js
  3
+lib/buildr.js
  4
+buildr-*.tgz
6  .npmignore
... ...
@@ -0,0 +1,6 @@
  1
+node_modules/
  2
+bin/buildr.coffee
  3
+lib/buildr.coffee
  4
+.gitignore
  5
+Cakefile
  6
+buildr-*.tgz
21  Cakefile
... ...
@@ -0,0 +1,21 @@
  1
+fs = require 'fs'
  2
+CoffeeScript = require 'coffee-script'
  3
+
  4
+task 'build', 'compile source files to javascript', (options) ->
  5
+  compile 'lib/buildr.coffee', false
  6
+  compile 'bin/buildr.coffee', true
  7
+
  8
+task 'clean', 'delete compiled output', (options) ->
  9
+  fs.unlink 'lib/buildr.js'
  10
+  fs.unlink 'bin/buildr.js'
  11
+
  12
+compile = (sourceFile, needShebang) ->
  13
+  fs.readFile sourceFile, 'utf8', (error, coffeeCode) ->
  14
+    throw error if error
  15
+
  16
+    javaScript = CoffeeScript.compile(coffeeCode)
  17
+    javaScript = '#!/usr/bin/env node\n' + javaScript if needShebang
  18
+
  19
+    outFile = sourceFile.replace '\.coffee', '.js'
  20
+    fs.writeFile outFile, javaScript, 'utf8', () ->
  21
+      console.log 'built ' + outFile + ' successfully.'
7  package.json
@@ -65,11 +65,14 @@
65 65
 	"engines" : {
66 66
 		"node": ">=0.4.0"
67 67
 	},
  68
+	"scripts": {
  69
+		"prepublish": "cake clean build"
  70
+	},
68 71
 	"directories": {
69 72
 		"lib": "lib"
70 73
 	},
71 74
 	"bin": {
72  
-		"buildr": "./bin/buildr.coffee"
  75
+		"buildr": "./bin/buildr.js"
73 76
 	},
74  
-	"main": "./lib/buildr.coffee"
  77
+	"main": "./lib/buildr.js"
75 78
 }

0 notes on commit 135b146

Please sign in to comment.
Something went wrong with that request. Please try again.