Skip to content

Commit

Permalink
resolving conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
shprink committed Jan 28, 2014
2 parents 118ee99 + 79ee0c3 commit 55f0056
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 530 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
124 changes: 42 additions & 82 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -1,94 +1,54 @@
fs = require 'fs'
CoffeeScript = require 'coffee-script'
{exec} = require 'child_process'
fs = require 'fs'
{exec} = require 'child_process'
flour = require 'flour'

FILE_COFFEE = 'BttrLazyLoading.coffee'
FILE_COMPILED_JS = 'jquery.bttrlazyloading.js'
FILE_COMPILED_CSS = 'bttrlazyloading.css'
FILE_VERSION = 'version'

task 'tag.major', 'Major tag incrementation', ->
tag getIncreasedVersion 'major'

task 'tag.minor', 'Minor tag incrementation', ->
tag getIncreasedVersion 'minor'

task 'tag.patch', 'Patch tag incrementation', ->
tag getIncreasedVersion 'patch'

task 'build', 'Compile and uglify BttrLazyLoading.coffee', ->
compressFiles()

task 'lint', 'Run linting for CoffeeScripts', ->
runLinting()

tag = (version) ->
# Preparing
console.log "Increasing from #{getVersion()} to #{version}..."

# Running
run 'git', ['tag', '-a', '-m', "\"Version #{version}\"", 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 = ->
FILE_CSS = 'bttrlazyloading.css'
FILE_MINIFIED_JS = 'jquery.bttrlazyloading.min.js'
FILE_MINIFIED_CSS = 'bttrlazyloading.min.css'
FILE_VERSION = 'version'

task 'build', 'Compile and minify', ->
invoke 'build:coffee'
invoke 'build:css'

task 'build:coffee', 'Build CoffeeScript', ->
bundle FILE_COFFEE, FILE_MINIFIED_JS, ->
prependCopyright FILE_MINIFIED_JS

task 'build:css', 'Build CSS', ->
minify FILE_CSS, FILE_MINIFIED_CSS, ->
prependCopyright FILE_MINIFIED_CSS

task 'dev', 'Lints, builds and keeps watching for changes', ->
invoke 'build'
invoke 'watch'

task 'lint', 'Run linting for CoffeeScript and JavaScript', ->
lint ['./test/spec.js', FILE_COFFEE, 'Cakefile']

task 'watch', 'Watch for changes', ->
watch 'bttrlazyloading.css', ->
invoke 'build:css'
watch 'BttrLazyLoading.coffee', ->
invoke 'lint'
invoke 'build:coffee'
watch ['Cakefile', './test/spec.js', FILE_COFFEE], ->
invoke 'lint'
invoke 'build'

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 "Copyright added successfully"
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}"

run = (cmd, args, successCallback) ->
# Dump the command on the screen
console.log "command used: #{cmd} #{args.join(' ')}"

# Execute the command
child = exec cmd, args

child.on 'exit', (code) ->
# Success
if !code
successCallback()

# Listen to errors
child.stderr.on 'data', (data) ->
console.log 'Oups something wrong happened: ' + data
console.warn "Failed to prepend copyright"

# Get the current version
getVersion = ->
"#{fs.readFileSync FILE_VERSION}"

# Get the increased version
getIncreasedVersion = (label) ->
v = getVersion()
vSplitted = v.split('.');
switch label
when "major"
vSplitted[0] = parseInt(vSplitted[0]) + 1
vSplitted[1] = 0
vSplitted[2] = 0
when "minor"
vSplitted[1] = parseInt(vSplitted[1]) + 1
vSplitted[2] = 0
when "patch"
vSplitted[2] = parseInt(vSplitted[2]) + 1
vSplitted.join('.');

copyright =
"""
/*
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ $("#yourImageId").bttrlazyloading({
#### Prerequisites
+ [Node JS](http://julienrenaux.fr/2013/05/16/how-to-install-node-js-coffeescript-less-and-uglify-js-on-ubuntu/)
+ [Bower](http://julienrenaux.fr/2013/09/12/bower/)
+ Coffee Script (Global installation, `$ sudo npm install -g coffee-script`, is optional but convenient in the build step)
+ CoffeeScript (Global installation, `$ sudo npm install -g coffee-script`, is optional but convenient in the build step)

#### Clone the repository
`$ git clone https://github.com/shprink/BttrLazyLoading`
Expand All @@ -155,11 +155,17 @@ $ npm install
```

### Build
Compile and uglify BttrLazyLoading.coffee
Compiles and minifies BttrLazyLoading.coffee and bttrlazyloading.css.
```
cake build
```
If Coffe-Script isn't globally installed, use `node_modules/.bin/cake build`
If CoffeeScript isn't globally installed, use `node_modules/.bin/cake build`

### Develop
Builds CoffeeScript and CSS, and runs linting and build steps if any changes occur to important files. This allows you to rerun the tests immidiately after you've changed the CoffeeScript, without having to lint and recompile. Of course, any changes that breaks the CoffeeScript will be prompted on the command line.
```
cake dev
```

### Run tests
Open test/index.html
Expand Down
2 changes: 1 addition & 1 deletion bttrlazyloading.min.css

Large diffs are not rendered by default.

Loading

0 comments on commit 55f0056

Please sign in to comment.