Skip to content

Commit

Permalink
Fixed readme, tweaked how commands are called and how/when the config…
Browse files Browse the repository at this point in the history
… file is opened
  • Loading branch information
mikemurray committed Dec 14, 2011
1 parent abfe812 commit 2bcabec
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 94 deletions.
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -4,15 +4,15 @@ Sew is a simple build/dev tool for your web based projects using CoffeeScript, L


# Installation # Installation


npm install -g sew npm install -g sew


# Usage # Usage


Commands: Commands:
new Create new config file, this is required new Create new config file, this is required
build Build your project build Build your project
watch Wacth and rebuild your project watch Wacth and rebuild your project
serve Start a simple HTTP server on port 3000, watch and build your project serve Start a simple HTTP server on port 3000, watch and build your project


Options: Options:
-p [default: 3000] -p [default: 3000]
96 changes: 47 additions & 49 deletions lib/sew.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "sew", "name": "sew",
"description": "Test, and build your CoffeeScript, LESS, Eco projects.", "description": "Test, and build your CoffeeScript, LESS, Eco projects.",
"author": "Mike Murray", "author": "Mike Murray",
"version": "0.1.2", "version": "0.1.3",
"licenses": [ "licenses": [
{ {
"type": "MIT", "type": "MIT",
Expand Down
69 changes: 33 additions & 36 deletions src/sew.coffee
Expand Up @@ -25,80 +25,77 @@ argv = opti.usage('''


class Worker class Worker


configFile: './config.json' configFile: 'config.json'
options: defaults:
public: './public' public: 'public'
jsPath: './app' scripts: 'app'
cssPath: './app/css/style.less' scriptsOutput: 'public/js/app.js'
outputJs: './public/js/scripts.js' styles: 'css/style.less'
outputCss: './public/css/styles.css' stylesOutput: 'public/css/app.css'


constructor: -> constructor: ->
if not @readConfig() and argv._[0] isnt 'new' action = @['_' + argv._[0]]
opti.showHelp() if action then action.call(@) else @_help()
return 0

@package = stitch.createPackage { paths: [@options.jsPath] }

switch argv._[0]
when 'new' then @new()
when 'build' then @compile()
when 'watch' then @watch()
when 'serve' then @serve()
when 'help' then opti.showHelp()
else opti.showHelp()


# Actions # Actions
new: -> _new: ->
if true and (!fpath.existsSync(@configFile) or argv.force) if true and (!fpath.existsSync(@configFile) or argv.force)
util.log 'Creating config file' util.log 'Creating config file'
fs.writeFileSync @configFile, JSON.stringify(@options, null, 2) fs.writeFileSync @configFile, JSON.stringify(@defaults, null, 2)
else else
util.log 'Config file already exists use --force to override' util.log 'Config file already exists use --force to override'


compile: -> _build: ->
@compileScriptsAndTemplates() @readConfig()
@compileScripts()
@compileStyles() @compileStyles()


watch: -> _watch: ->
@compile() @_build()
@walk './', (file) => @walk './', (file) =>
fs.watchFile file, (curr, prev) => fs.watchFile file, (curr, prev) =>
if curr and (curr.nlink is 0 or +curr.mtime isnt +prev.mtime) if curr and (curr.nlink is 0 or +curr.mtime isnt +prev.mtime)
switch fpath.extname file switch fpath.extname file
when '.coffee', '.eco' then @compileScriptsAndTemplates() when '.coffee', '.eco' then @compileScripts()
when '.less' then @compileStyles() when '.less' then @compileStyles()


serve: -> _serve: ->
@watch() @_watch()
app = new strata.Builder app = new strata.Builder
app.use strata.commonLogger app.use strata.commonLogger
app.use strata.static, @options.public, ['index.html', 'index.htm'] app.use strata.static, @options.public, ['index.html', 'index.htm']
strata.run app, { port: argv.p } strata.run app, { port: argv.p }


_help: ->
opti.showHelp()

# Compilers # Compilers
compileScriptsAndTemplates: -> compileScripts: ->
util.log 'Building scripts...' util.log 'Building scripts...'
@package = stitch.createPackage { paths: [@options.scripts] } if not @package
@package.compile (err, source) => @package.compile (err, source) =>
fs.writeFile @options.outputJs, source, (err) -> fs.writeFile @options.scriptsOutput, source, (err) ->
util.log err.message if err util.log err.message if err


compileStyles: -> compileStyles: ->
util.log 'Building styles...' util.log 'Building styles...'
if fpath.existsSync @options.cssPath if fpath.existsSync @options.styles
less.render fs.readFileSync(@options.cssPath, 'utf8'), (e, css) => less.render fs.readFileSync(@options.styles, 'utf8'), (e, css) =>
util.log "LESS - #{e.name} | #{e.message} | #{e.extract}" if e util.log "LESS - #{e.name} | #{e.message} | #{e.extract}" if e
fs.writeFile @options.outputCss, css, (err) -> fs.writeFile @options.stylesOutput, css, (err) ->
util.log err.message if err util.log err.message if err


# Utiliity # Utiliity
readConfig: -> readConfig: ->
return if @options
if fpath.existsSync @configFile if fpath.existsSync @configFile
config = fs.readFileSync @configFile config = fs.readFileSync @configFile
config = JSON.parse config config = JSON.parse config
@options = {}
@options[key] = value for key, value of @defaults
@options[key] = value for key, value of config @options[key] = value for key, value of config
return true return true
false process.exit(1)


walk: (path, callback) -> walk: (path, callback) ->
for f in fs.readdirSync(path) for f in fs.readdirSync(path)
Expand Down

0 comments on commit 2bcabec

Please sign in to comment.