Skip to content

Commit

Permalink
v2.4.1. Improvement.
Browse files Browse the repository at this point in the history
- v2.4.1 January 10, 2014
	- Updated dependencies
	- Repackaged
  • Loading branch information
balupton committed Jan 10, 2014
1 parent 6bf7a7e commit cf1cafc
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 80 deletions.
211 changes: 141 additions & 70 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v1.3.10 December 10, 2013
# v1.3.13 December 19, 2013
# https://github.com/bevry/base


Expand All @@ -12,33 +12,48 @@ pathUtil = require('path')
# =====================================
# Variables

WINDOWS = process.platform.indexOf('win') is 0
NODE = process.execPath
NPM = (if WINDOWS then process.execPath.replace('node.exe', 'npm.cmd') else 'npm')
EXT = (if WINDOWS then '.cmd' else '')
APP_DIR = process.cwd()
PACKAGE_PATH = pathUtil.join(APP_DIR, "package.json")
PACKAGE_DATA = require(PACKAGE_PATH)
DOCS_DIR = pathUtil.join(APP_DIR, "docs")
DOCS_INPUT = pathUtil.join(APP_DIR, "src", "lib", "*")
SRC_DIR = pathUtil.join(APP_DIR, "src")
OUT_DIR = pathUtil.join(APP_DIR, "out")
TEST_DIR = pathUtil.join(APP_DIR, "test")
MODULES_DIR = pathUtil.join(APP_DIR, "node_modules")
DOCPAD_DIR = pathUtil.join(MODULES_DIR, "docpad")
BIN_DIR = pathUtil.join(MODULES_DIR, ".bin")
GIT = "git"
CAKE = pathUtil.join(BIN_DIR, "cake#{EXT}")
COFFEE = pathUtil.join(BIN_DIR, "coffee#{EXT}")
PROJECTZ = pathUtil.join(BIN_DIR, "projectz#{EXT}")
DOCCO = pathUtil.join(BIN_DIR, "docco#{EXT}")
WINDOWS = process.platform.indexOf('win') is 0
NODE = process.execPath
NPM = (if WINDOWS then process.execPath.replace('node.exe', 'npm.cmd') else 'npm')
EXT = (if WINDOWS then '.cmd' else '')
GIT = "git"

APP_PATH = process.cwd()
PACKAGE_PATH = pathUtil.join(APP_PATH, "package.json")
PACKAGE_DATA = require(PACKAGE_PATH)

MODULES_PATH = pathUtil.join(APP_PATH, "node_modules")
DOCPAD_PATH = pathUtil.join(MODULES_PATH, "docpad")
BIN_PATH = pathUtil.join(MODULES_PATH, ".bin")
CAKE = pathUtil.join(BIN_PATH, "cake" + EXT)
COFFEE = pathUtil.join(BIN_PATH, "coffee" + EXT)
PROJECTZ = pathUtil.join(BIN_PATH, "projectz" + EXT)
DOCCO = pathUtil.join(BIN_PATH, "docco" + EXT)
DOCPAD = pathUtil.join(BIN_PATH, "docpad" + EXT)

config = {}
config.TEST_PATH = "test"
config.DOCCO_SRC_PATH = null
config.DOCCO_OUT_PATH = "docs"
config.COFFEE_SRC_PATH = "src" # eventually we'll set this to null, right now it isn't for b/c compat
config.COFFEE_OUT_PATH = "out"
config.DOCPAD_SRC_PATH = null
config.DOCPAD_OUT_PATH = "out"

for own key,value of (PACKAGE_DATA.cakeConfiguration or {})
config[key] = value

for own key,value of config
config[key] = pathUtil.resolve(APP_PATH, value) if value


# =====================================
# Generic

{exec,spawn} = require('child_process')
{spawn, exec} = require('child_process')

safe = (next,fn) ->
next ?= (err) -> console.log(err.stack ? err)
fn ?= next # support only one argument
return (err) ->
# success status code
Expand All @@ -65,9 +80,14 @@ finish = (err) ->

actions =
clean: (opts,next) ->
# Prepare
(next = opts; opts = {}) unless next?
args = ['-Rf', OUT_DIR]
for path in [APP_DIR, TEST_DIR]

# Add compilation paths
args = ['-Rf', config.COFFEE_OUT_PATH, config.DOCPAD_OUT_PATH, config.DOCCO_OUT_PATH]

# Add common ignore paths
for path in [APP_PATH, config.TEST_PATH]
args.push(
pathUtil.join(path, 'build')
pathUtil.join(path, 'components')
Expand All @@ -76,89 +96,140 @@ actions =
pathUtil.join(path, '*out')
pathUtil.join(path, '*log')
)

# rm
spawn('rm', args, {stdio:'inherit', cwd:APP_DIR}).on('close', safe next)
console.log('clean')
spawn('rm', args, {stdio:'inherit', cwd:APP_PATH}).on('close', safe next)

install: (opts,next) ->
# Prepare
(next = opts; opts = {}) unless next?

# Steps
step1 = ->
# npm install (for app)
spawn(NPM, ['install'], {stdio:'inherit', cwd:APP_DIR}).on('close', safe next, step2)
console.log('npm install (for app)')
spawn(NPM, ['install'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step2)
step2 = ->
fsUtil.exists TEST_DIR, (exists) ->
return next() unless exists
# npm install (for test)
spawn(NPM, ['install'], {stdio:'inherit', cwd:TEST_DIR}).on('close', safe next, step3)
return step3() if !config.TEST_PATH or !fsUtil.existsSync(config.TEST_PATH)
console.log('npm install (for test)')
spawn(NPM, ['install'], {stdio:'inherit', cwd:config.TEST_PATH}).on('close', safe next, step3)
step3 = ->
fsUtil.exists DOCPAD_DIR, (exists) ->
return next() unless exists
# npm install (for test)
spawn(NPM, ['install'], {stdio:'inherit', cwd:DOCPAD_DIR}).on('close', safe next)
return step4() if !fsUtil.existsSync(DOCPAD_PATH)
console.log('npm install (for docpad tests)')
spawn(NPM, ['install'], {stdio:'inherit', cwd:DOCPAD_PATH}).on('close', safe next, step4)
step4 = next

# Start
step1()

compile: (opts,next) ->
# Prepare
(next = opts; opts = {}) unless next?

# Steps
step1 = ->
# cake install
console.log('cake install')
actions.install(opts, safe next, step2)
step2 = ->
# coffee compile
fsUtil.exists COFFEE, (exists) ->
return next() unless exists
spawn(COFFEE, ['-co', OUT_DIR, SRC_DIR], {stdio:'inherit', cwd:APP_DIR}).on('close', safe next)
return step3() if !config.COFFEE_SRC_PATH or !fsUtil.existsSync(COFFEE)
console.log('coffee compile')
spawn(COFFEE, ['-co', config.COFFEE_OUT_PATH, config.COFFEE_SRC_PATH], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step3)
step3 = ->
return step4() if !config.DOCPAD_SRC_PATH or !fsUtil.existsSync(DOCPAD)
console.log('docpad generate')
spawn(DOCPAD, ['generate'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step4)
step4 = next

# Start
step1()

watch: (opts,next) ->
# Prepare
(next = opts; opts = {}) unless next?

# Steps
step1 = ->
# cake install
console.log('cake install')
actions.install(opts, safe next, step2)
step2 = ->
# coffee watch
fsUtil.exists COFFEE, (exists) ->
return next() unless exists
spawn(COFFEE, ['-wco', OUT_DIR, SRC_DIR], {stdio:'inherit', cwd:APP_DIR}).on('close', safe next)
return step3() if !config.COFFEE_SRC_PATH or !fsUtil.existsSync(COFFEE)
console.log('coffee watch')
spawn(COFFEE, ['-wco', config.COFFEE_OUT_PATH, config.COFFEE_SRC_PATH], {stdio:'inherit', cwd:APP_PATH}).on('close', safe) # background
step3() # continue while coffee runs in background
step3 = ->
return step4() if !config.DOCPAD_SRC_PATH or !fsUtil.existsSync(DOCPAD)
console.log('docpad run')
spawn(DOCPAD, ['run'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe) # background
step4() # continue while docpad runs in background
step4 = next

# Start
step1()

test: (opts,next) ->
# Prepare
(next = opts; opts = {}) unless next?
# cake compile
actions.compile opts, safe next, ->
# npm test
spawn(NPM, ['test'], {stdio:'inherit', cwd:APP_DIR}).on('close', safe next)

# Steps
step1 = ->
console.log('cake compile')
actions.compile(opts, safe next, step2)
step2 = ->
console.log('npm test')
spawn(NPM, ['test'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step3)
step3 = next

# Start
step1()

prepublish: (opts,next) ->
# Prepare
(next = opts; opts = {}) unless next?

# Steps
step1 = ->
# cake compile
console.log('cake compile')
actions.compile(opts, safe next, step2)
step2 = ->
# project compile
fsUtil.exists PROJECTZ, (exists) ->
return step3() unless exists
spawn(PROJECTZ, ['compile'], {stdio:'inherit', cwd:APP_DIR}).on('close', safe next, step3)
return step3() if !fsUtil.existsSync(PROJECTZ)
console.log('projectz compile')
spawn(PROJECTZ, ['compile'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step3)
step3 = ->
# docco compile
fsUtil.exists DOCCO, (exists) ->
return step4() unless exists
exec("#{DOCCO} -o #{DOCS_DIR} #{DOCS_INPUT}", {stdio:'inherit', cwd:APP_DIR}, safe next, step4)
return step4() if !config.DOCCO_SRC_PATH or !fsUtil.existsSync(DOCCO)
console.log('docco compile')
exec("#{DOCCO} -o #{config.DOCCO_OUT_PATH} #{config.DOCCO_SRC_PATH}", {stdio:'inherit', cwd:APP_PATH}, safe next, step4)
step4 = ->
# npm test
actions.test(opts, safe next)
console.log('cake test')
actions.test(opts, safe next, step5)
step5 = next

# Start
step1()

publish: (opts,next) ->
# Prepare
(next = opts; opts = {}) unless next?
# cake prepublish
actions.prepublish opts, safe next, ->
# npm publish
spawn(NPM, ['publish'], {stdio:'inherit', cwd:APP_DIR}).on 'close', safe next, ->
# git tag
spawn(GIT, ['tag', 'v'+PACKAGE_DATA.version, '-a'], {stdio:'inherit', cwd:APP_DIR}).on 'close', safe next, ->
# git push origin master
spawn(GIT, ['push', 'origin', 'master'], {stdio:'inherit', cwd:APP_DIR}).on 'close', safe next, ->
# git push tags
spawn(GIT, ['push', 'origin', '--tags'], {stdio:'inherit', cwd:APP_DIR}).on('close', safe next)

# Steps
step1 = ->
console.log('cake prepublish')
actions.prepublish(opts, safe next, step2)
step2 = ->
console.log('npm publish')
spawn(NPM, ['publish'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step3)
step3 = ->
console.log('git tag')
spawn(GIT, ['tag', 'v'+PACKAGE_DATA.version, '-a'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step4)
step4 = ->
console.log('git push origin master')
spawn(GIT, ['push', 'origin', 'master'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step5)
step5 = ->
console.log('git push tags')
spawn(GIT, ['push', 'origin', '--tags'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step6)
step6 = next

# Start
step1()


# =====================================
Expand Down
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# History

- v2.4.1 January 10, 2014
- Updated dependencies
- Repackaged

- v2.4.0 December 10, 2013
- `balUtilPaths` changes:
- Added `resolveCaseSensitivePath(path, next)`
Expand Down
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

[![Build Status](http://img.shields.io/travis-ci/balupton/bal-util.png?branch=master)](http://travis-ci.org/balupton/bal-util "Check this project's build status on TravisCI")
[![NPM version](http://badge.fury.io/js/bal-util.png)](https://npmjs.org/package/bal-util "View this project on NPM")
[![Dependency Status](https://david-dm.org/balupton/bal-util.png?theme=shields.io)](https://david-dm.org/balupton/bal-util)
[![Development Dependency Status](https://david-dm.org/balupton/bal-util/dev-status.png?theme=shields.io)](https://david-dm.org/balupton/bal-util#info=devDependencies)<br/>
[![Gittip donate button](http://img.shields.io/gittip/balupton.png)](https://www.gittip.com/balupton/ "Donate weekly to this project using Gittip")
[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")
[![BitCoin donate button](http://img.shields.io/bitcoin/donate.png?color=yellow)](https://coinbase.com/checkouts/9ef59f5479eec1d97d63382c9ebcb93a "Donate once-off to this project using BitCoin")

<!-- /BADGES -->

Expand All @@ -28,10 +31,15 @@ Common utility functions for Node.js used and maintained by Benjamin Lupton

## Install

### [Node](http://nodejs.org/), [Browserify](http://browserify.org/)
### [Node](http://nodejs.org/)
- Use: `require('bal-util')`
- Install: `npm install --save bal-util`

### [Browserify](http://browserify.org/)
- Use: `require('bal-util')`
- Install: `npm install --save bal-util`
- CDN URL: `//wzrd.in/bundle/bal-util@2.4.1`

### [Ender](http://ender.jit.su/)
- Use: `require('bal-util')`
- Install: `ender add bal-util`
Expand Down Expand Up @@ -69,15 +77,15 @@ We're in the process of abstracting the pieces of bal-util out into their own mo

## Contribute

[Discover how you can contribute by heading on over to the `Contributing.md` file.](https://github.com/balupton/bal-util/blob/master/Contributing.md#files)
[Discover how you can contribute by heading on over to the `CONTRIBUTING.md` file.](https://github.com/balupton/bal-util/blob/master/CONTRIBUTING.md#files)

<!-- /CONTRIBUTE -->


<!-- HISTORY/ -->

## History
[Discover the change history by heading on over to the `History.md` file.](https://github.com/balupton/bal-util/blob/master/History.md#files)
[Discover the change history by heading on over to the `HISTORY.md` file.](https://github.com/balupton/bal-util/blob/master/HISTORY.md#files)

<!-- /HISTORY -->

Expand All @@ -99,15 +107,16 @@ No sponsors yet! Will you be the first?
[![Gittip donate button](http://img.shields.io/gittip/balupton.png)](https://www.gittip.com/balupton/ "Donate weekly to this project using Gittip")
[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")
[![BitCoin donate button](http://img.shields.io/bitcoin/donate.png?color=yellow)](https://coinbase.com/checkouts/9ef59f5479eec1d97d63382c9ebcb93a "Donate once-off to this project using BitCoin")

### Contributors

These amazing people have contributed code to this project:

- Benjamin Lupton <b@lupton.cc> (https://github.com/balupton) - [view contributions](https://github.com/balupton/bal-util/commits?author=balupton)
- Sean Fridman <fridman@mail.sfsu.edu> (https://github.com/sfrdmn) - [view contributions](https://github.com/balupton/bal-util/commits?author=sfrdmn)
- [Benjamin Lupton](https://github.com/balupton) <b@lupton.cc> [view contributions](https://github.com/balupton/bal-util/commits?author=balupton)
- [Sean Fridman](https://github.com/sfrdmn) <fridman@mail.sfsu.edu> [view contributions](https://github.com/balupton/bal-util/commits?author=sfrdmn)

[Become a contributor!](https://github.com/balupton/bal-util/blob/master/Contributing.md#files)
[Become a contributor!](https://github.com/balupton/bal-util/blob/master/CONTRIBUTING.md#files)

<!-- /BACKERS -->

Expand Down

0 comments on commit cf1cafc

Please sign in to comment.