Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 113 lines (88 sloc) 3.542 kb
5d3bf08 @flosse added cakefile and moved dependencies into lib directory
authored
1 fs = require 'fs'
2 {exec} = require 'child_process'
6ff3897 @flosse updated cakefile for usage with node 0.6
authored
3 coffee = require 'coffee-script'
4 uglify = require 'uglify-js'
2bbe46f @flosse refactored a lot
authored
5
5d4883e @flosse simplified cakefile; changed exports
authored
6 srcDir = 'src'
67bce34 @flosse compile sources into lib directory
authored
7 targetDir = 'lib'
5d3bf08 @flosse added cakefile and moved dependencies into lib directory
authored
8
fb8c98b @flosse moved helper methods into a separate file
authored
9 coreFiles = [ 'Util', 'Mediator', 'Sandbox', 'scaleApp' ]
5d3bf08 @flosse added cakefile and moved dependencies into lib directory
authored
10
2bbe46f @flosse refactored a lot
authored
11 minify = (code, resNames) -> uglify.uglify.gen_code(
12 uglify.uglify.ast_squeeze(
13 uglify.uglify.ast_mangle(
14 uglify.parser.parse(code)
15 ,{ except: resNames }
16 )
17 )
220260f @flosse changed cakefile task 'build:full'
authored
18 )+';'
2bbe46f @flosse refactored a lot
authored
19
5d4883e @flosse simplified cakefile; changed exports
authored
20 concate = (files, type, wrapEach, cb) ->
21 if not cb?
22 cb = wrapEach
23 wrapEach = true
5d3bf08 @flosse added cakefile and moved dependencies into lib directory
authored
24 concateContents = new Array filesRemaining = files.length
25
26 for file, index in files then do (file, index) ->
2bbe46f @flosse refactored a lot
authored
27 fs.readFile "#{file}.#{type}", 'utf8', (err, fileContents) ->
5d4883e @flosse simplified cakefile; changed exports
authored
28 console.log err if err
5d3bf08 @flosse added cakefile and moved dependencies into lib directory
authored
29 concateContents[index] = fileContents
30 if --filesRemaining is 0
5d4883e @flosse simplified cakefile; changed exports
authored
31 if type is 'coffee'
32 if wrapEach
33 cb (coffee.compile c for c in concateContents).join '\n'
34 else
35 cb coffee.compile concateContents.join '\n'
36 else
37 cb concateContents.join '\n'
38
39 checkDir = (d) -> fs.mkdirSync d if not fs.existsSync d
40 checkTargetDir = -> checkDir targetDir
41
4e03178 @flosse added amd support
authored
42 isCoffeeFile = (f) -> (f.indexOf('.coffee') isnt -1) and (f[0] isnt '.')
43
5d4883e @flosse simplified cakefile; changed exports
authored
44 watchDir = (dir) ->
45
46 console.log "Watching for changes in #{dir}"
47 files = fs.readdirSync "#{dir}"
4e03178 @flosse added amd support
authored
48 files = ("#{dir}/#{f}" for f in files when isCoffeeFile f)
5d4883e @flosse simplified cakefile; changed exports
authored
49 for file in files then do (file) ->
50 fs.watchFile file, (curr, prev) ->
5d3bf08 @flosse added cakefile and moved dependencies into lib directory
authored
51 if +curr.mtime isnt +prev.mtime
5d4883e @flosse simplified cakefile; changed exports
authored
52 console.log "Saw change in #{file}"
5d3bf08 @flosse added cakefile and moved dependencies into lib directory
authored
53 invoke 'build'
54
5d4883e @flosse simplified cakefile; changed exports
authored
55 task 'build', 'Build all', ->
56 invoke 'compile'
57 invoke 'bundle'
5d3bf08 @flosse added cakefile and moved dependencies into lib directory
authored
58
5d4883e @flosse simplified cakefile; changed exports
authored
59 option '-p', '--include-plugins [PLUGIN_NAMES]', "bundles scaleApp with defined plugins"
5d3bf08 @flosse added cakefile and moved dependencies into lib directory
authored
60
5d4883e @flosse simplified cakefile; changed exports
authored
61 task 'compile', 'compiles to JS', ->
5d3bf08 @flosse added cakefile and moved dependencies into lib directory
authored
62
5d4883e @flosse simplified cakefile; changed exports
authored
63 exec "coffee -c -o #{targetDir} #{srcDir}", (err, stdout, stderr) ->
64 console.error err if err
65 console.error stderr if stderr
5d3bf08 @flosse added cakefile and moved dependencies into lib directory
authored
66
5d4883e @flosse simplified cakefile; changed exports
authored
67 task 'bundle', 'create browser bundles', (opts) ->
5d3bf08 @flosse added cakefile and moved dependencies into lib directory
authored
68
67bce34 @flosse compile sources into lib directory
authored
69 dir = "bundles"
5d4883e @flosse simplified cakefile; changed exports
authored
70 checkDir dir
71
72 files = ("#{srcDir}/#{f}" for f in coreFiles)
73
74 concate files, "coffee", false, (core) ->
75 targetName = "#{dir}/scaleApp"
76
77 if opts['include-plugins']?
78 plugins = opts['include-plugins'].split ','
79 plugins = ("#{srcDir}/plugins/scaleApp.#{f}" for f in plugins)
80 concate plugins, "coffee", (pluginCode) ->
81 code = core+pluginCode
82 fs.writeFileSync "#{targetName}.custom.js", code, 'utf8'
83 fs.writeFileSync "#{targetName}.custom.min.js", (minify code), 'utf8'
84
85 else
86 fs.writeFile "#{targetName}.js", core, 'utf8', (err) ->
87 console.error err if err
88 fs.writeFile "#{targetName}.min.js",(minify core), 'utf8', (err) ->
89 console.error err if err
90
3e28df6 @flosse ported specs to buster.js; closes #27
authored
91 pluginPath = "#{srcDir}/plugins"
92
93 if fs.existsSync pluginPath
94 fs.readdir pluginPath, (err, files) ->
4e03178 @flosse added amd support
authored
95 pluginFiles = files.filter (s) -> isCoffeeFile s
3e28df6 @flosse ported specs to buster.js; closes #27
authored
96 pluginFiles = ("#{pluginPath}/#{f.split(".coffee")[0]}" for f in pluginFiles)
97 concate pluginFiles, "coffee", (pluginCode) ->
98 code = core+pluginCode
99 fs.writeFile "#{targetName}.full.js", code, 'utf8', (err) ->
100 console.error err if err
101 fs.writeFile "#{targetName}.full.min.js", (minify code), 'utf8', (err) ->
102 console.error err if err
5d4883e @flosse simplified cakefile; changed exports
authored
103
104 task 'watch', 'Watch source files and build changes', ->
6ff3897 @flosse updated cakefile for usage with node 0.6
authored
105
106 invoke "build"
5d4883e @flosse simplified cakefile; changed exports
authored
107 watchDir "#{srcDir}"
108 watchDir "#{srcDir}/plugins"
2bbe46f @flosse refactored a lot
authored
109
dd5beb4 @flosse merged from coffee branch
authored
110 task 'doc', "create docs", ->
5d4883e @flosse simplified cakefile; changed exports
authored
111 exec "docco #{srcDir}/*.coffee #{srcDir}/plugins/*.coffee", (err, stdout) ->
112 console.error err if err
Something went wrong with that request. Please try again.