Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 211 lines (176 sloc) 7.441 kB
0b1a192 @assaf Started using Docco for documentation.
authored
1 fs = require("fs")
2 path = require("path")
3 {spawn, exec} = require("child_process")
39a12a8 @assaf Removed CoffeeScript from runtime dependencies.
authored
4 stdout = process.stdout
0b1a192 @assaf Started using Docco for documentation.
authored
5
20f5cc9 @assaf Now using npm bundle to manage runtime/dev dependencies when working …
authored
6 # Use executables installed with npm bundle.
7 process.env["PATH"] = "node_modules/.bin:#{process.env["PATH"]}"
8
0b1a192 @assaf Started using Docco for documentation.
authored
9 # ANSI Terminal Colors.
10 bold = "\033[0;1m"
11 red = "\033[0;31m"
12 green = "\033[0;32m"
13 reset = "\033[0m"
14
15 # Log a message with a color.
16 log = (message, color, explanation) ->
17 console.log color + message + reset + ' ' + (explanation or '')
18
200f4f3 @assaf Brought back callback in runTests but fixed cake test to show vows
authored
19 # Handle error and kill the process.
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
20 onerror = (err)->
21 if err
39a12a8 @assaf Removed CoffeeScript from runtime dependencies.
authored
22 process.stdout.write "#{red}#{err.stack}#{reset}\n"
20f5cc9 @assaf Now using npm bundle to manage runtime/dev dependencies when working …
authored
23 process.exit -1
2f9b7ee @assaf First NPM release.
authored
24
25
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
26 ## Setup ##
2f9b7ee @assaf First NPM release.
authored
27
28 # Setup development dependencies, not part of runtime dependencies.
29 task "setup", "Install development dependencies", ->
30 fs.readFile "package.json", "utf8", (err, package)->
20f5cc9 @assaf Now using npm bundle to manage runtime/dev dependencies when working …
authored
31 log "Need runtime dependencies, installing into node_modules ...", green
32 exec "npm bundle", onerror
33
34 log "Need development dependencies, installing ...", green
35 for name, version of JSON.parse(package).devDependencies
36 log "Installing #{name} #{version}", green
37 exec "npm bundle install \"#{name}@#{version}\"", onerror
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
38
39
40 ## Building ##
41
42 build = (callback)->
503aea8 @assaf Using .npmignore makes life so much easier.
authored
43 log "Compiling CoffeeScript to JavaScript ...", green
a95a1c9 @assaf Cakefile now reports more of what's going on.
authored
44 exec "rm -rf lib && coffee -c -l -b -o lib src", (err, stdout)->
45 callback err
2e14582 @assaf Added `querySelector` and `querySelectorAll` based on the [DOM
authored
46 task "build", "Compile CoffeeScript to JavaScript", -> build onerror
47
48 task "watch", "Continously compile CoffeeScript to JavaScript", ->
49 cmd = spawn("coffee", ["-cw", "-o", "lib", "src"])
39a12a8 @assaf Removed CoffeeScript from runtime dependencies.
authored
50 cmd.stdout.on "data", (data)-> process.stdout.write green + data + reset
a95a1c9 @assaf Cakefile now reports more of what's going on.
authored
51 cmd.on "error", onerror
6feb998 @assaf Fixed cookie spec and upgraded to hTML5 0.2.12.
authored
52
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
53
20f5cc9 @assaf Now using npm bundle to manage runtime/dev dependencies when working …
authored
54 clean = (callback)->
55 exec "rm -rf html lib man7", callback
56 task "clean", "Remove temporary files and such", -> clean onerror
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
57
0b1a192 @assaf Started using Docco for documentation.
authored
58
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
59 ## Testing ##
2f9b7ee @assaf First NPM release.
authored
60
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
61 runTests = (callback)->
62 log "Running test suite ...", green
a95a1c9 @assaf Cakefile now reports more of what's going on.
authored
63 exec "vows --spec", (err, stdout)->
39a12a8 @assaf Removed CoffeeScript from runtime dependencies.
authored
64 process.stdout.write stdout
200f4f3 @assaf Brought back callback in runTests but fixed cake test to show vows
authored
65 callback err if callback
66 task "test", "Run all tests", ->
67 runTests (err)->
68 process.stdout.on "drain", -> process.exit -1 if err
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
69
70
71 ## Documentation ##
2f9b7ee @assaf First NPM release.
authored
72
73 # Markdown to HTML.
2b99178 @assaf Added subtitle to pages, changed tagline.
authored
74 toHTML = (source, callback)->
2f9b7ee @assaf First NPM release.
authored
75 target = "html/#{path.basename(source, ".md").toLowerCase()}.html"
51c0401 @assaf Fixed TOC, PDF header and added require("assert") to examples.
authored
76 fs.readFile "doc/layout/main.html", "utf8", (err, layout)->
92ab434 @assaf Added documentation page for CSS selectors.
authored
77 onerror err
78 fs.readFile source, "utf8", (err, text)->
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
79 onerror err
92ab434 @assaf Added documentation page for CSS selectors.
authored
80 log "Creating #{target}", green
81 exec "ronn --html #{source}", (err, stdout, stderr)->
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
82 onerror err
92ab434 @assaf Added documentation page for CSS selectors.
authored
83 [name, title] = stdout.match(/<h1>(.*)<\/h1>/)[1].split(" -- ")
84 name = name.replace(/\(\d\)/, "")
85 body = stdout.replace(/<h1>.*<\/h1>/, "")
86 html = layout.replace("{{body}}", body).replace(/{{title}}/g, title)
87 fs.writeFile target, html, "utf8", (err)->
88 callback err, target
cf1f734 @assaf Smarted Cakefile.
authored
89
90 documentPages = (callback)->
8f851ca @assaf Added troublehsooting guide.
authored
91 files = fs.readdirSync(".").filter((file)-> path.extname(file) == ".md").
92 concat(fs.readdirSync("doc").filter((file)-> path.extname(file) == ".md").map((file)-> "doc/#{file}"))
92ab434 @assaf Added documentation page for CSS selectors.
authored
93 fs.mkdir "html", 0777, ->
94 convert = ->
95 if file = files.pop()
96 toHTML file, (err)->
97 onerror err
98 convert()
99 else
100 process.stdout.write "\n"
101 fs.readFile "html/readme.html", "utf8", (err, html)->
102 html = html.replace(/<h1>(.*)<\/h1>/, "<h1>Zombie.js</h1><b>$1</b>")
103 fs.writeFile "html/index.html", html, "utf8", onerror
104 fs.unlink "html/readme.html", onerror
51c0401 @assaf Fixed TOC, PDF header and added require("assert") to examples.
authored
105 exec "cp -fr doc/css doc/images html/", callback
92ab434 @assaf Added documentation page for CSS selectors.
authored
106 convert()
cf1f734 @assaf Smarted Cakefile.
authored
107
108 documentSource = (callback)->
2f9b7ee @assaf First NPM release.
authored
109 log "Documenting source files ...", green
a95a1c9 @assaf Cakefile now reports more of what's going on.
authored
110 exec "docco src/*.coffee src/**/*.coffee", (err, stdout, stderr)->
111 log stdout, green
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
112 onerror err
a95a1c9 @assaf Cakefile now reports more of what's going on.
authored
113 log "Copying to html/source", green
650947c @assaf Fixed documentation link.
authored
114 exec "mkdir -p html && cp -rf docs/ html/source && rm -rf docs", callback
406ed04 @assaf Added doc:readme Cake task.
authored
115
c59ef32 @assaf Fixed documentation link.
authored
116 generateMan = (callback)->
8f851ca @assaf Added troublehsooting guide.
authored
117 files = fs.readdirSync(".").filter((file)-> path.extname(file) == ".md").
118 concat(fs.readdirSync("doc").filter((file)-> path.extname(file) == ".md").map((file)-> "doc/#{file}"))
92ab434 @assaf Added documentation page for CSS selectors.
authored
119 fs.mkdir "man7", 0777, (err)->
8f851ca @assaf Added troublehsooting guide.
authored
120 log "Generating man file ...", green
121 convert = ->
122 if file = files.pop()
92ab434 @assaf Added documentation page for CSS selectors.
authored
123 target = "man7/#{path.basename(file, ".md").toLowerCase()}.7"
8f851ca @assaf Added troublehsooting guide.
authored
124 exec "ronn --roff #{file}", (err, stdout, stderr)->
125 onerror err
126 log "Creating #{target}", green
550bb16 @assaf Fixed the cake.
authored
127 fs.writeFile target, stdout, "utf8", onerror
8f851ca @assaf Added troublehsooting guide.
authored
128 convert()
129 else
92ab434 @assaf Added documentation page for CSS selectors.
authored
130 exec "mv man7/readme.7 man7/zombie.7", onerror
8f851ca @assaf Added troublehsooting guide.
authored
131 process.stdout.write "\n"
550bb16 @assaf Fixed the cake.
authored
132 callback()
8f851ca @assaf Added troublehsooting guide.
authored
133 convert()
c59ef32 @assaf Fixed documentation link.
authored
134
71ad9f8 @assaf Added magical zombie girl and PDF.
authored
135 generatePDF = (callback)->
136 log "Generating PDF documentation ...", green
137 files = "index api selectors troubleshoot".split(" ").map((f)-> "html/#{f}.html")
51c0401 @assaf Fixed TOC, PDF header and added require("assert") to examples.
authored
138 options = "--disable-javascript --outline --print-media-type --title Zombie.js --header-html doc/layout/header.html"
139 toc = "--toc --toc-depth 2 --toc-no-dots --cover doc/layout/cover.html --allow doc/images --outline"
8750a5e @assaf Added credits linking to Github contribution page.
authored
140 margins = "--margin-left 30 --margin-right 30 --margin-top 30 --margin-bottom 30 --header-spacing 5"
51c0401 @assaf Fixed TOC, PDF header and added require("assert") to examples.
authored
141 exec "wkhtmltopdf #{options} #{margins} #{toc} #{files.join(" ")} html/zombie.pdf", callback
71ad9f8 @assaf Added magical zombie girl and PDF.
authored
142
cf1f734 @assaf Smarted Cakefile.
authored
143 generateDocs = (callback)->
144 log "Generating documentation ...", green
145 documentPages (err)->
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
146 onerror err
cf1f734 @assaf Smarted Cakefile.
authored
147 documentSource (err)->
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
148 onerror err
71ad9f8 @assaf Added magical zombie girl and PDF.
authored
149 generatePDF (err)->
150 onerror err
151 generateMan callback
152
2e14582 @assaf Added `querySelector` and `querySelectorAll` based on the [DOM
authored
153 task "doc:pages", "Generate documentation for main pages", -> documentPages onerror
154 task "doc:source", "Generate documentation from source files", -> documentSource onerror
155 task "doc:man", "Generate man pages", -> generateMan onerror
8750a5e @assaf Added credits linking to Github contribution page.
authored
156 task "doc:pdf", "Generate PDF documentation", ->
157 documentPages (err)->
158 onerror err
159 generatePDF onerror
2e14582 @assaf Added `querySelector` and `querySelectorAll` based on the [DOM
authored
160 task "doc", "Generate all documentation", -> generateDocs onerror
0b1a192 @assaf Started using Docco for documentation.
authored
161
2f9b7ee @assaf First NPM release.
authored
162
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
163 ## Publishing ##
2f9b7ee @assaf First NPM release.
authored
164
cf1f734 @assaf Smarted Cakefile.
authored
165 publishDocs = (callback)->
550bb16 @assaf Fixed the cake.
authored
166 log "Uploading documentation ...", green
167 exec "rsync -chr --del --stats html/ labnotes.org:/var/www/zombie/", (err, stdout, stderr)->
168 log stdout, green
169 callback err
170 task "doc:publish", "Publish documentation to site", ->
9700c7c @assaf Upgraded to HTLM5 0.2.9.
authored
171 documentPages (err)->
172 onerror err
173 documentSource (err)->
174 onerror err
175 generatePDF (err)->
176 onerror err
177 publishDocs onerror
2f9b7ee @assaf First NPM release.
authored
178
179 task "publish", "Publish new version (Git, NPM, site)", ->
e37f031 @assaf Work around npm publish including all files in the current directory.
authored
180 # Run tests, don't publish unless tests pass.
cf1f734 @assaf Smarted Cakefile.
authored
181 runTests (err)->
e05c3f6 @assaf Fixed lack of JavaScript source code: CoffeeScript moved to src,
authored
182 onerror err
e37f031 @assaf Work around npm publish including all files in the current directory.
authored
183 # Clean up temporary files and such, want to create everything from
184 # scratch, don't want generated files we no longer use, etc.
20f5cc9 @assaf Now using npm bundle to manage runtime/dev dependencies when working …
authored
185 clean (err)->
186 onerror err
187 fs.readFile "package.json", "utf8", (err, package)->
e37f031 @assaf Work around npm publish including all files in the current directory.
authored
188 package = JSON.parse(package)
189
190 # Create a tag for this version and push changes to Github.
191 log "Tagging v#{package.version} ...", green
192 exec "git tag v#{package.version}", (err, stdout, stderr)->
a95a1c9 @assaf Cakefile now reports more of what's going on.
authored
193 log stdout, green
20f5cc9 @assaf Now using npm bundle to manage runtime/dev dependencies when working …
authored
194 exec "git push --tags origin master", (err, stdout, stderr)->
195 log stdout, green
cf1f734 @assaf Smarted Cakefile.
authored
196
550bb16 @assaf Fixed the cake.
authored
197 # Publish documentation, need these first to generate man pages,
198 # inclusion on NPM package.
199 generateDocs (err)->
a95a1c9 @assaf Cakefile now reports more of what's going on.
authored
200 onerror err
550bb16 @assaf Fixed the cake.
authored
201
202 log "Publishing to NPM ...", green
203 build (err)->
20f5cc9 @assaf Now using npm bundle to manage runtime/dev dependencies when working …
authored
204 onerror err
9700c7c @assaf Upgraded to HTLM5 0.2.9.
authored
205 exec "npm publish", (err, stdout, stderr)->
206 log stdout, green
e37f031 @assaf Work around npm publish including all files in the current directory.
authored
207 onerror err
550bb16 @assaf Fixed the cake.
authored
208
209 # We can do this in parallel.
210 publishDocs onerror
Something went wrong with that request. Please try again.