Skip to content

Commit

Permalink
Using Flour to do linting for both CoffeeScript and JS. Reimplementin…
Browse files Browse the repository at this point in the history
…g build task.
  • Loading branch information
thelinmichael committed Jan 27, 2014
1 parent 597e305 commit 72a83e6
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 469 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/node_modules
/demo/js/analytics.js
*.log
/.idea
2 changes: 1 addition & 1 deletion BttrLazyLoading.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ $.fn.extend
return this.each () ->
$this = $(this)
data = $this.data('bttrlazyloading')
# Already instanciated?
# Already instantiated?
if typeof data is 'undefined'
data = new BttrLazyLoading this, options
$this.data 'bttrlazyloading', data
Expand Down
41 changes: 15 additions & 26 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
fs = require 'fs'
CoffeeScript = require 'coffee-script'
{exec} = require 'child_process'
{exec} = require 'child_process'
flour = require 'flour'

FILE_COFFEE = 'BttrLazyLoading.coffee'
FILE_COMPILED_JS = 'jquery.bttrlazyloading.js'
FILE_COMPILED_CSS = 'bttrlazyloading.css'
FILE_CSS = 'bttrlazyloading.css'
FILE_MINIFIED_JS = 'jquery.bttrlazyloading.min.js'
FILE_MINIFIED_CSS = 'bttrlazyloading.min.css'
FILE_VERSION = 'version'

task 'tag.major', 'Major tag incrementation', ->
Expand All @@ -16,11 +17,13 @@ task 'tag.minor', 'Minor tag incrementation', ->
task 'tag.patch', 'Patch tag incrementation', ->
tag getIncreasedVersion 'patch'

task 'build', 'Compile and uglify BttrLazyLoading.coffee', ->
compressFiles()
task 'build', 'Compile and minify', ->
bundle FILE_COFFEE, FILE_MINIFIED_JS, ->
prependCopyright FILE_MINIFIED_JS
minify FILE_CSS, FILE_MINIFIED_CSS

task 'lint', 'Run linting for CoffeeScripts', ->
runLinting()
lint ['./test/spec.js', FILE_COFFEE, 'Cakefile']

tag = (version) ->
# Preparing
Expand All @@ -31,27 +34,13 @@ tag = (version) ->
# Save the new version within the version file if success
fs.writeFileSync FILE_VERSION, version

runLinting = ->
exec './node_modules/.bin/coffeelint -f coffeelint.json ' + [FILE_COFFEE], (err, stdout, stderr) ->
console.log stderr
console.log stdout

compressFiles = ->
prependCopyright = (file) ->
try
fs.writeFileSync FILE_COMPILED_JS, copyright + CoffeeScript.compile "#{fs.readFileSync FILE_COFFEE}"
unless process.env.MINIFY is 'false'
minifyJs FILE_COMPILED_JS
minifyCss FILE_COMPILED_CSS
minifiedJs = fs.readFileSync(file, { "encoding" : "utf8" })
fs.writeFile file, copyright + minifiedJs, () ->
console.log "Prepended copyright"
catch e
console.log e.message

minifyJs = (file) ->
Uglify = require 'uglify-js'
fs.writeFileSync file.replace(/\.js$/,'.min.js'), copyright + (Uglify.minify "#{fs.readFileSync file}", {fromString: true}).code

minifyCss = (file) ->
CleanCSS = require 'clean-css'
fs.writeFileSync file.replace(/\.css$/,'.min.css'), copyright + CleanCSS.process "#{fs.readFileSync file}"
console.warn "Failed to prepend copyright"

run = (cmd, args, successCallback) ->
# Dump the command on the screen
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Compile and uglify BttrLazyLoading.coffee
```
cake build
```
If Coffe-Script isn't globally installed, use `node_modules/.bin/cake build`
If Coffee Script isn't globally installed, use `node_modules/.bin/cake build`

### Run tests
Open test/index.html
Expand Down
11 changes: 1 addition & 10 deletions bttrlazyloading.min.css

Large diffs are not rendered by default.

Loading

0 comments on commit 72a83e6

Please sign in to comment.