1 |
|
2 | fs = require 'fs'
|
3 | mecano = require '..'
|
4 |
|
5 | date = -> d = (new Date).toISOString()
|
6 |
|
7 | source = "#{__dirname}/mecano.coffee"
|
8 | destination = "#{__dirname}/../doc/index.md"
|
9 | docs = """
|
10 | ---
|
11 | language: en
|
12 | layout: page
|
13 | title: "Node Mecano: Common functions for system deployment"
|
14 | date: #{date()}
|
15 | comments: false
|
16 | sharing: false
|
17 | footer: false
|
18 | github: https://github.com/wdavidw/node-mecano
|
19 | ---
|
20 | """
|
21 |
|
22 | fs.readFile source, 'ascii', (err, content) ->
|
23 | re = /###\n([\s\S]*?)\n( *)###/g
|
24 | re_code = /\n(\s{4}\s*?\w[\s\S]*?)\n(?!\s)/g
|
25 | match = re.exec content
|
26 | docs += match[1]
|
27 | while match = re.exec content
|
28 | match[1] = match[1].split('\n').map((line)->line.substr(2)).join('\n')
|
29 | match[1] = match[1].replace re_code, (str, code) ->
|
30 | code = code.split('\n').map((line)->line.substr(4)).join('\n')
|
31 | "\n```coffeescript\n#{code}\n```"
|
32 | docs += match[1]
|
33 | fs.writeFile destination, docs, (err) ->
|
34 | return console.log err.message if err
|
35 | console.log 'Documentation generated'
|
36 | destination = process.argv[2]
|
37 | return unless destination
|
38 | mecano.copy
|
39 | source: "#{__dirname}/../doc/index.md"
|
40 | destination: destination
|
41 | force: true
|
42 | , (err, copied) ->
|
43 | console.log "Documentation published: #{destination}" |
\ | No newline at end of file |