Skip to content

Instantly share code, notes, and snippets.

@msgre
Created March 8, 2011 13:43

Revisions

  1. msgre revised this gist Mar 8, 2011. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions Cakefile
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # https://gist.github.com/860272
    #
    # Tento Cakefile definuje 2 prikazy:
    #
    # * "build" spoji vice *.coffee souboru do jedineho a zkompiluje jej do vysledneho
    @@ -49,19 +51,17 @@ process = (name) ->


    task 'build', "Zkompiluje #{source}*.coffee soubory do jedineho vystupniho JS", ->
    buffer = {}
    for name, list of appFiles
    buffer[name] = []
    for file, index in list then do (file, index) ->
    fs.readFile "#{source}#{file}.coffee", 'utf8', (err, fileContents) ->
    throw err if err
    buffer[name].push(fileContents)
    buffer[name].push(fs.readFileSync("#{source}#{file}.coffee", 'utf8'))
    process(name)


    task 'watch', "Sleduje zmeny v adresari #{source} a automaticky spousti 'build'", (options) ->
    fs.readdir source, (err, files) ->
    for file in files
    if path.extname(file) is '.coffee'
    fs.watchFile path.join(source, file), {persistent: true, interval: 500}, (curr, prev) ->
    return if curr.size is prev.size and curr.mtime.getTime() is prev.mtime.getTime()
    invoke('build')
    invoke('build')
  2. msgre created this gist Mar 8, 2011.
    67 changes: 67 additions & 0 deletions Cakefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    # Tento Cakefile definuje 2 prikazy:
    #
    # * "build" spoji vice *.coffee souboru do jedineho a zkompiluje jej do vysledneho
    # javascriptu. To, ktere soubory patri k sobe je definovano v hashi appFiles.
    # Klic je nazev vystupniho souboru (ulozi se do adresare `out`), hodnoty nazvy
    # souboru z adresare `source` bez pripony '.coffee'
    # * "watch" sleduje zmeny v adresari `src` a pokud detekuje zmenu v nekterem z
    # .coffee souboru, vyvolava "build"
    #
    # Po pravde, moc tomu nerozumim, ale zrejme to facha.
    #
    # Vice informaci:
    #
    # * https://github.com/jashkenas/coffee-script/wiki/[HowTo]-Compiling-and-Setting-Up-Build-Tools
    # * https://github.com/jashkenas/coffee-script/blob/master/src/command.coffee#L74
    # * https://github.com/jashkenas/coffee-script/blob/master/Cakefile
    # * http://howtonode.org/control-flow
    # * http://jashkenas.github.com/coffee-script/documentation/docs/cake.html

    fs = require 'fs'
    path = require 'path'
    {exec} = require 'child_process'

    # vstupni adresar s *.coffee soubory
    source = 'src/'

    # vystupni adresar, kam se ukladaji zkompilovane javascripty
    out = 'lib/'

    # definuje, ktere soubory z adresare `source` se maji spojit
    appFiles = {
    'app_03': ['common', 'map_03']
    'app_temp': ['common', 'map_02']
    }

    # buffer s nactenymi obsahy souboru
    buffer = {}


    # pomocna fce, ktera zkompiluje soubory z buffer[name] do finalniho JS
    process = (name) ->
    fs.writeFile "#{out}#{name}.coffee", buffer[name].join('\n\n'), 'utf8', (err) ->
    throw err if err
    exec "coffee --compile #{out}#{name}.coffee", (err, stdout, stderr) ->
    throw err if err
    fs.unlink "#{out}#{name}.coffee", (err) ->
    throw err if err
    console.log "Application #{name} compiled."


    task 'build', "Zkompiluje #{source}*.coffee soubory do jedineho vystupniho JS", ->
    for name, list of appFiles
    buffer[name] = []
    for file, index in list then do (file, index) ->
    fs.readFile "#{source}#{file}.coffee", 'utf8', (err, fileContents) ->
    throw err if err
    buffer[name].push(fileContents)
    process(name)


    task 'watch', "Sleduje zmeny v adresari #{source} a automaticky spousti 'build'", (options) ->
    fs.readdir source, (err, files) ->
    for file in files
    if path.extname(file) is '.coffee'
    fs.watchFile path.join(source, file), {persistent: true, interval: 500}, (curr, prev) ->
    return if curr.size is prev.size and curr.mtime.getTime() is prev.mtime.getTime()
    invoke('build')