1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | 'use strict'
|
20 |
|
21 | const jsdoc2md = require('jsdoc-to-markdown')
|
22 | const fs = require('fs')
|
23 | const path = require('path')
|
24 | const R = require('ramda')
|
25 |
|
26 | const config = require(`${__dirname}/.jsdoc2md.json`)
|
27 |
|
28 | const outputDir = `${__dirname}/docs`
|
29 | const prefix = /^@aeternity\/aepp-sdk\/es\//
|
30 | const templateData = jsdoc2md.getTemplateDataSync(config)
|
31 |
|
32 | function createDirs (path) {
|
33 | const paths = path.split(/\//).slice(1, -1)
|
34 | .reduce((acc, e) => acc.concat([`${R.last(acc)}/${e}`]), ['']).slice(1)
|
35 |
|
36 | R.forEach(dir => {
|
37 | try {
|
38 | fs.openSync(dir, 'r')
|
39 | } catch (e) {
|
40 | fs.mkdirSync(dir)
|
41 | }
|
42 | }, paths)
|
43 | }
|
44 |
|
45 | const modules = templateData
|
46 | .filter(R.propEq('kind', 'module'))
|
47 | .map(({ name }) => {
|
48 | return { name, out: `api/${name.replace(prefix, '')}` }
|
49 | })
|
50 |
|
51 | R.forEachObjIndexed(({ name, out }) => {
|
52 | const template = `{{#module name="${name}"}}{{>docs}}{{/module}}`
|
53 | console.log(`rendering ${name}`)
|
54 | const dest = path.resolve(outputDir, `${out}.md`)
|
55 | const output = jsdoc2md.renderSync({
|
56 | data: templateData,
|
57 | template,
|
58 | partial: [
|
59 | 'tooling/docs/header.hbs',
|
60 | 'tooling/docs/link.hbs',
|
61 | 'tooling/docs/customTags.hbs'
|
62 | ]
|
63 | })
|
64 | createDirs(dest)
|
65 | fs.writeFileSync(dest, output)
|
66 | }, modules)
|
67 |
|
68 | const output = jsdoc2md.renderSync({
|
69 | data: modules,
|
70 | template: '{{>toc}}',
|
71 | partial: ['tooling/docs/toc.hbs']
|
72 | })
|
73 |
|
74 | fs.writeFileSync(path.resolve(outputDir, 'api.md'), output)
|