pulsar/build/tasks/docs-task.coffee

97 lines
3.3 KiB
CoffeeScript
Raw Normal View History

path = require 'path'
fs = require 'fs'
module.exports = (grunt) ->
cmd = path.join('node_modules', '.bin', 'coffee')
commonArgs = [path.join('build', 'node_modules', '.bin', 'biscotto'), '--']
opts =
stdio: 'inherit'
grunt.registerTask 'build-docs', 'Builds the API docs in src/app', ->
done = @async()
args = [commonArgs..., '--title', 'Atom API Documentation', '-o', 'docs/output/api', 'src/', '../text-buffer/src/range.coffee', '../text-buffer/src/point.coffee', '../text-buffer/src/marker.coffee']
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/']
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/']
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()
fetchTag = (args..., callback) ->
cmd = 'git'
args = ['describe', '--abbrev=0', '--tags']
grunt.util.spawn {cmd, args}, (error, result) ->
if error?
callback(error)
else
callback(null, String(result).trim())
2013-08-20 21:52:18 +04:00
copyDocs = (tag, callback) ->
cmd = 'cp'
args = ['-r', 'docs/output/', "../atom.io/public/docs/api/#{tag}/"]
2013-08-20 21:52:18 +04:00
fs.exists "../atom.io/public/docs/api/", (exists) ->
if exists
grunt.util.spawn {cmd, args}, (error, result) ->
if error?
callback(error)
else
callback(null, tag)
else
grunt.log.error "../atom.io/public/docs/api/ doesn't exist"
return false
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()
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
stageDocs = (tag, callback) ->
cmd = 'git'
args = [docsRepoArgs..., 'add', "public/#{tag}"]
grunt.util.spawn({cmd, args, opts}, callback)
fetchSha = (args..., callback) ->
2013-08-14 19:56:35 +04:00
cmd = 'git'
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
commitChanges = (sha, callback) ->
2013-08-14 19:56:35 +04:00
cmd = 'git'
args = [docsRepoArgs..., 'commit', "-m Update API docs to #{sha}"]
grunt.util.spawn({cmd, args, opts}, callback)
2013-08-14 19:56:35 +04:00
pushOrigin = (args..., callback) ->
2013-08-14 19:56:35 +04:00
cmd = 'git'
args = [docsRepoArgs..., 'push', 'origin', 'master']
grunt.util.spawn({cmd, args, opts}, callback)
2013-08-14 19:56:35 +04:00
pushHeroku = (args..., callback) ->
2013-08-14 19:56:35 +04:00
cmd = 'git'
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