Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 97 lines (78 sloc) 2.404 kb
d8fe4e3 @DrPheltRight Initial commit.
authored
1 fs = require 'fs'
2 {exec} = require 'child_process'
3 {parser, uglify} = require 'uglify-js'
4
5 src = './src'
6 tmp = './tmp'
7 dist = './dist'
63199d4 @DrPheltRight Move todo example to subfolder in preparation for more examples. Update ...
authored
8 eg = './examples'
2b78921 @DrPheltRight Add tests and build mocks via Cakefile.
authored
9 test = './test'
ef3633e @DrPheltRight Todo example gets it's own version of Uniform.
authored
10
60abdb5 @DrPheltRight Add version to built header.
authored
11 version = JSON.parse(fs.readFileSync('./package.json')).version
d8fe4e3 @DrPheltRight Initial commit.
authored
12
13 header = """
60abdb5 @DrPheltRight Add version to built header.
authored
14 // Uniform v#{version}
d8fe4e3 @DrPheltRight Initial commit.
authored
15 // Written by Luke Morton, MIT licensed.
16 // https://github.com/DrPheltRight/uniform
17 """
18
19 task 'build', 'Build Uniform', ->
20 invoke 'clean'
21 exec [
22 "mkdir -p #{tmp}"
23 "coffee -b -o #{tmp} #{src}/*.coffee"
24 ].join(' && ')
25 , ->
26
27 code = ''
28
29 for name in ['uniform']
30 code += """
31 #{fs.readFileSync "#{tmp}/#{name}.js"}
32 """
33 exec "rm -rf #{tmp}"
34
35 code = """
36 !function (definition) {
e2b1cd9 @DrPheltRight Add Uniform.noConflict() in global mode.
authored
37 var context = this,
38 old = context.Uniform;
39
eaa84c7 @DrPheltRight Add braces for clarity.
authored
40 if (typeof define == 'function' && typeof define.amd == 'object') {
949d6a4 @DrPheltRight Require jQuery via require() method. If no AMD we grab from global.
authored
41 define(['require'], definition);
eaa84c7 @DrPheltRight Add braces for clarity.
authored
42 } else {
e2b1cd9 @DrPheltRight Add Uniform.noConflict() in global mode.
authored
43 context.Uniform = definition(function (path) {
eb7e4e9 @DrPheltRight Get require for global environment working. Always assumes jQuery.
authored
44 // This is a fake require for jQuery
e2b1cd9 @DrPheltRight Add Uniform.noConflict() in global mode.
authored
45 return context['jQuery'];
eb7e4e9 @DrPheltRight Get require for global environment working. Always assumes jQuery.
authored
46 });
e2b1cd9 @DrPheltRight Add Uniform.noConflict() in global mode.
authored
47
48 context.Uniform.noConflict = function () {
49 context.Uniform = old;
50 return this;
51 };
eaa84c7 @DrPheltRight Add braces for clarity.
authored
52 }
eb7e4e9 @DrPheltRight Get require for global environment working. Always assumes jQuery.
authored
53 }(function(require) {
d8fe4e3 @DrPheltRight Initial commit.
authored
54 #{code}
55 return Uniform;
56 });
57 """
58
59 console.log "Building Uniform #{version}"
60
61 exec "mkdir -p #{dist}", ->
63199d4 @DrPheltRight Move todo example to subfolder in preparation for more examples. Update ...
authored
62 fs.writeFileSync path, header + '\n' + code for path in [
63 "#{dist}/uniform-#{version}.js"
64 "#{eg}/lib/uniform.js"
65 ]
d8fe4e3 @DrPheltRight Initial commit.
authored
66
67 code = uglify.gen_code uglify.ast_squeeze uglify.ast_mangle parser.parse code
63199d4 @DrPheltRight Move todo example to subfolder in preparation for more examples. Update ...
authored
68
69 fs.writeFileSync path, header + '\n' + code for path in [
70 "#{dist}/uniform-#{version}.min.js"
71 "#{eg}/lib/uniform.min.js"
72 ]
ef3633e @DrPheltRight Todo example gets it's own version of Uniform.
authored
73
1d94d17 @DrPheltRight cake build now invokes "build:example".
authored
74 invoke 'build:example'
2b78921 @DrPheltRight Add tests and build mocks via Cakefile.
authored
75 invoke 'build:mocks'
d8fe4e3 @DrPheltRight Initial commit.
authored
76
deed194 @DrPheltRight Add watch task to Cakefile.
authored
77 task 'watch', 'Build on modification', ->
78 waiting = false
79 fs.watch src, (event, filename) ->
80 return unless filename.indexOf('.coffee') > -1
81
82 if waiting
83 console.log('Waiting')
84 else
85 waiting = setTimeout((-> waiting = false), 2000)
86 invoke('build')
87
d8fe4e3 @DrPheltRight Initial commit.
authored
88 task 'clean', 'Delete distribution folder', ->
4b61019 @DrPheltRight Add a todo example.
authored
89 exec "rm -rf #{dist}"
90
91 task 'build:example', 'Build example', ->
63199d4 @DrPheltRight Move todo example to subfolder in preparation for more examples. Update ...
authored
92 console.log 'Building examples'
2b78921 @DrPheltRight Add tests and build mocks via Cakefile.
authored
93 exec "coffee -c #{eg}/*/*.coffee"
94
95 task 'build:mocks', 'Build mock', ->
96 console.log 'Building mocks'
97 exec "coffee -c #{test}/mocks/*.coffee"
Something went wrong with that request. Please try again.