Skip to content

Commit

Permalink
indention to tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardPosselt committed Dec 27, 2012
1 parent 03f7222 commit dd2ec52
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 76 deletions.
129 changes: 64 additions & 65 deletions apptemplate_advanced/coffee/Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ util = require 'util'
### Configuration ###

# path that contains your coffee files relative to this script
# leave empty for current directory
sourceDirectory = __dirname

# path and name of the compiled js file relative to this script without .js suffix
compileToFile = '../js/app'

# These files will be compiled in order before any other files
compileFirst = [
'lib/owncloud.coffee'
'app.coffee'
'lib/owncloud.coffee'
'app.coffee'
]


Expand All @@ -37,99 +36,99 @@ compileFirst = [
# @param string path: the path to search for coffee files
# @param array coffeeFiles: a hashmap with existing files that will be ignored
getCoffeeFiles = (path, coffeeFiles) ->
entries = fs.readdirSync(path)
entries = fs.readdirSync(path)

for entry in entries
do (entry) ->
entryPath = path + '/' + entry
entryStats = fs.statSync(entryPath)
for entry in entries
do (entry) ->
entryPath = path + '/' + entry
entryStats = fs.statSync(entryPath)

if entryStats.isFile()
if entryPath.indexOf('.coffee') > 1 and coffeeFiles[entryPath] == undefined
coffeeFiles[entryPath] = true
if entryStats.isFile()
if entryPath.indexOf('.coffee') > 1 and coffeeFiles[entryPath] == undefined
coffeeFiles[entryPath] = true

else if entryStats.isDirectory()
getCoffeeFiles(entryPath, coffeeFiles)
else if entryStats.isDirectory()
getCoffeeFiles(entryPath, coffeeFiles)


# returns an array with all coffeefiles in order
getOrderedCoffeeFiles = (directory) ->
unorderedFiles = {}
getCoffeeFiles(directory, unorderedFiles)
unorderedFiles = {}
getCoffeeFiles(directory, unorderedFiles)

# create data structures for quick prioritized files lookup
orderedFilesHashMap = {}
for file in compileFirst
filePath = directory + '/' + file
orderedFilesHashMap[filePath] = true
# create data structures for quick prioritized files lookup
orderedFilesHashMap = {}
for file in compileFirst
filePath = directory + '/' + file
orderedFilesHashMap[filePath] = true

# prepend prioritized files
orderedFiles = []
for file in compileFirst
orderedFiles.push(directory + '/' + file)
# prepend prioritized files
orderedFiles = []
for file in compileFirst
orderedFiles.push(directory + '/' + file)

# order files
for file, exists of unorderedFiles
if orderedFilesHashMap[file] == undefined
orderedFiles.push(file)
# order files
for file, exists of unorderedFiles
if orderedFilesHashMap[file] == undefined
orderedFiles.push(file)

util.log "#{orderedFiles.length} coffee files found."
return orderedFiles
util.log "#{orderedFiles.length} coffee files found."
return orderedFiles


# compiles an array with file content to a js file
compile = (content, toFile) ->
toFile += '.coffee'
toFile += '.coffee'

fs.writeFile toFile, content.join('\n\n'), 'utf8', (error) ->
if error
throw error
fs.writeFile toFile, content.join('\n\n'), 'utf8', (error) ->
if error
throw error

exec 'coffee --compile ' + toFile, (error, stdout, stderr) ->
if error
util.log 'Error compiling coffee file.'
util.error error
else
fs.unlink toFile, (error) ->
if error
util.log 'Couldn\'t delete the compile cache file ' + toFile
util.log 'Finished building coffee file.'
exec 'coffee --compile ' + toFile, (error, stdout, stderr) ->
if error
util.log 'Error compiling coffee file.'
util.error error
else
fs.unlink toFile, (error) ->
if error
util.log 'Couldn\'t delete the compile cache file ' + toFile
util.log 'Finished building coffee file.'


# register a callback on an array of files and remove already bound ones
watchFiles = (files, callback) ->
for file in files
fs.unwatchFile(file)
fs.watchFile(file, callback)
for file in files
fs.unwatchFile(file)
fs.watchFile(file, callback)


### Tasks ###

task 'watch', 'Watch and rebuild on changes', ->
invoke 'build'
util.log "Watching for changes"
invoke 'build'
util.log "Watching for changes"

watchFiles getOrderedCoffeeFiles(sourceDirectory), ->
invoke 'build'
watchFiles getOrderedCoffeeFiles(sourceDirectory), ->
invoke 'build'

fs.watchFile sourceDirectory, (current, previous) ->
watchFiles getOrderedCoffeeFiles(sourceDirectory), ->
invoke 'build'
fs.watchFile sourceDirectory, (current, previous) ->
watchFiles getOrderedCoffeeFiles(sourceDirectory), ->
invoke 'build'


task 'build', 'Build and compress CoffeeScript into single JavaScript file', ->
files = getOrderedCoffeeFiles(sourceDirectory)
content = []
remaining = files.length
files = getOrderedCoffeeFiles(sourceDirectory)
content = []
remaining = files.length

# read out content of files and compile them afterwards
for file, index in files then do (file, index) ->
fs.readFile file, 'utf8', (error, fileContent) ->
if error
throw error
# read out content of files and compile them afterwards
for file, index in files then do (file, index) ->
fs.readFile file, 'utf8', (error, fileContent) ->
if error
throw error

content[index] = fileContent
remaining -= 1
content[index] = fileContent
remaining -= 1

if remaining <= 0
compile(content, compileToFile)
if remaining <= 0
compile(content, compileToFile)
22 changes: 11 additions & 11 deletions apptemplate_advanced/coffee/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

angular.module('AppTemplateAdvanced', ['OC']).config ['$provide', ($provide) ->

# Use this for configuration values
Config =
myParam: 'test'
# Use this for configuration values
Config =
myParam: 'test'

# declare your routes here
# Hint: angularjs comes with an own route system with which you can
# build HTML5 apps with enabled history access, meaning: you can go
# forward and backward and change the state of your app
# http:#docs.angularjs.org/api/ng.$route
Config.routes =
saveNameRoute: 'apptemplate_advanced_ajax_setsystemvalue'
# declare your routes here
# Hint: angularjs comes with an own route system with which you can
# build HTML5 apps with enabled history access, meaning: you can go
# forward and backward and change the state of your app
# http:#docs.angularjs.org/api/ng.$route
Config.routes =
saveNameRoute: 'apptemplate_advanced_ajax_setsystemvalue'

return $provide.value('Config', Config)
return $provide.value('Config', Config)
]

0 comments on commit dd2ec52

Please sign in to comment.