UNPKG

2.25 kBJavaScriptView Raw
1#!/usr/bin/env node
2/*
3 * ISC License (ISC)
4 * Copyright (c) 2018 aeternity developers
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19'use strict'
20
21const jsdoc2md = require('jsdoc-to-markdown')
22const fs = require('fs')
23const path = require('path')
24const R = require('ramda')
25
26const config = require(`${__dirname}/.jsdoc2md.json`)
27
28const outputDir = `${__dirname}/docs`
29const prefix = /^@aeternity\/aepp-sdk\/es\//
30const templateData = jsdoc2md.getTemplateDataSync(config)
31
32function 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
45const modules = templateData
46 .filter(R.propEq('kind', 'module'))
47 .map(({ name }) => {
48 return { name, out: `api/${name.replace(prefix, '')}` }
49 })
50
51R.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
68const output = jsdoc2md.renderSync({
69 data: modules,
70 template: '{{>toc}}',
71 partial: ['tooling/docs/toc.hbs']
72})
73
74fs.writeFileSync(path.resolve(outputDir, 'api.md'), output)