2013-06-27 06:25:50 +04:00
path = require ' path '
module.exports = (grunt) ->
cmd = path . join ( ' node_modules ' , ' .bin ' , ' coffee ' )
commonArgs = [ path . join ( ' node_modules ' , ' .bin ' , ' biscotto ' ) , ' -- ' ]
opts =
stdio: ' inherit '
grunt . registerTask ' build-docs ' , ' Builds the API docs in src/app ' , ->
2013-08-20 21:52:18 +04:00
grunt . task . run ( ' markdown:guides ' )
2013-06-27 06:25:50 +04:00
done = @ async ( )
2013-08-24 02:56:48 +04:00
args = [ commonArgs . . . , ' --title ' , ' Atom API Documentation ' , ' -o ' , ' docs/output/api ' , ' src/ ' , ' vendor/telepath/lib/range.coffee ' , ' vendor/telepath/lib/point.coffee ' ]
2013-06-27 06:25:50 +04:00
grunt . util . spawn ( { cmd , args , opts } , done )
grunt . registerTask ' lint-docs ' , ' Generate stats about the doc coverage ' , ->
done = @ async ( )
2013-08-14 21:48:16 +04:00
args = [ commonArgs . . . , ' --noOutput ' , ' src/ ' ]
2013-06-27 06:25:50 +04:00
grunt . util . spawn ( { cmd , args , opts } , done )
grunt . registerTask ' missing-docs ' , ' Generate stats about the doc coverage ' , ->
done = @ async ( )
2013-08-14 21:48:16 +04:00
args = [ commonArgs . . . , ' --noOutput ' , ' --missing ' , ' src/ ' ]
2013-06-27 06:25:50 +04:00
grunt . util . spawn ( { cmd , args , opts } , done )
2013-08-14 19:56:35 +04:00
2013-08-20 21:52:18 +04:00
grunt . registerTask ' copy-docs ' , ' Copies over latest API docs to atom-docs ' , ->
2013-08-14 19:56:35 +04:00
done = @ async ( )
2013-08-20 03:56:42 +04:00
fetchTag = (args..., callback) ->
cmd = ' git '
args = [ ' describe ' , ' --abbrev=0 ' , ' --tags ' ]
grunt . util . spawn { cmd , args } , (error, result) ->
if error ?
callback ( error )
else
2013-09-10 22:59:46 +04:00
callback ( null , String ( result ) . trim ( ) . split ( ' . ' ) [ 0 . . 1 ] . join ( ' . ' ) )
2013-08-20 03:56:42 +04:00
2013-08-20 21:52:18 +04:00
copyDocs = (tag, callback) ->
2013-08-20 03:56:42 +04:00
cmd = ' cp '
2013-08-20 19:53:06 +04:00
args = [ ' -r ' , ' docs/output/ ' , " ../atom-docs/public/ #{ tag } / " ]
2013-08-20 21:52:18 +04:00
2013-08-20 03:56:42 +04:00
grunt . util . spawn { cmd , args } , (error, result) ->
if error ?
callback ( error )
else
callback ( null , tag )
2013-08-20 21:52:18 +04:00
grunt . util . async . waterfall [ fetchTag , copyDocs ] , done
grunt . registerTask ' deploy-docs ' , ' Publishes latest API docs to atom-docs.githubapp.com ' , ->
done = @ async ( )
2013-08-20 03:56:42 +04:00
docsRepoArgs = [ ' --work-tree=../atom-docs/ ' , ' --git-dir=../atom-docs/.git/ ' ]
2013-08-20 21:52:18 +04:00
fetchTag = (args..., callback) ->
cmd = ' git '
args = [ ' describe ' , ' --abbrev=0 ' , ' --tags ' ]
grunt . util . spawn { cmd , args } , (error, result) ->
if error ?
callback ( error )
else
2013-09-10 22:59:46 +04:00
callback ( null , String ( result ) . trim ( ) . split ( ' . ' ) [ 0 . . 1 ] . join ( ' . ' ) )
2013-08-20 21:52:18 +04:00
2013-08-20 03:56:42 +04:00
stageDocs = (tag, callback) ->
cmd = ' git '
args = [ docsRepoArgs . . . , ' add ' , " public/ #{ tag } " ]
2013-08-14 23:11:09 +04:00
grunt . util . spawn ( { cmd , args , opts } , callback )
fetchSha = (args..., callback) ->
2013-08-14 19:56:35 +04:00
cmd = ' git '
2013-08-14 23:11:09 +04:00
args = [ ' rev-parse ' , ' HEAD ' ]
grunt . util . spawn { cmd , args } , (error, result) ->
if error ?
callback ( error )
else
callback ( null , String ( result ) . trim ( ) )
2013-08-14 19:56:35 +04:00
2013-08-14 23:11:09 +04:00
commitChanges = (sha, callback) ->
2013-08-14 19:56:35 +04:00
cmd = ' git '
2013-08-20 03:56:42 +04:00
args = [ docsRepoArgs . . . , ' commit ' , " -m Update API docs to #{ sha } " ]
2013-08-14 23:11:09 +04:00
grunt . util . spawn ( { cmd , args , opts } , callback )
2013-08-14 19:56:35 +04:00
2013-08-14 23:11:09 +04:00
pushOrigin = (args..., callback) ->
2013-08-14 19:56:35 +04:00
cmd = ' git '
2013-08-14 23:11:09 +04:00
args = [ docsRepoArgs . . . , ' push ' , ' origin ' , ' master ' ]
grunt . util . spawn ( { cmd , args , opts } , callback )
2013-08-14 19:56:35 +04:00
2013-08-14 23:11:09 +04:00
pushHeroku = (args..., callback) ->
2013-08-14 19:56:35 +04:00
cmd = ' git '
2013-08-14 23:11:09 +04:00
args = [ docsRepoArgs . . . , ' push ' , ' heroku ' , ' master ' ]
grunt . util . spawn ( { cmd , args , opts } , callback )
2013-08-14 19:56:35 +04:00
2013-08-20 21:52:18 +04:00
grunt . util . async . waterfall [ fetchTag , stageDocs , fetchSha , commitChanges , pushOrigin , pushHeroku ] , done