2019-01-22 13:52:44 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2019-01-22 22:06:06 +01:00
|
|
|
/* eslint-disable no-console, security/detect-child-process, security/detect-non-literal-fs-filename */
|
2019-01-22 13:52:44 +01:00
|
|
|
|
|
|
|
const fs = require('fs')
|
|
|
|
const typedoc = require('typedoc')
|
|
|
|
const typescript = require('typescript')
|
2019-01-22 22:06:06 +01:00
|
|
|
const ora = require('ora')
|
2019-01-22 13:52:44 +01:00
|
|
|
const squidJsPackage = require('../external/squid-js/package.json')
|
|
|
|
const { exec } = require('child_process')
|
|
|
|
|
|
|
|
const { description, version } = squidJsPackage
|
|
|
|
|
|
|
|
// Setup our paths, relative to project root
|
|
|
|
const outPath = './data/squid-js.json'
|
|
|
|
const files = ['./external/squid-js/src/squid.ts']
|
|
|
|
|
|
|
|
// specifically point to tsconfig, otherwise TypeDoc fails
|
|
|
|
const config = typescript.findConfigFile(
|
|
|
|
'./external/squid-js',
|
|
|
|
typescript.sys.fileExists
|
|
|
|
)
|
|
|
|
|
|
|
|
// npm install for squid-js
|
2019-01-22 22:06:06 +01:00
|
|
|
const spinnerNpm = ora('Installing submodule dependencies...').start()
|
2019-01-22 13:52:44 +01:00
|
|
|
const install = exec(
|
|
|
|
'cd ./external/squid-js && npm i && git checkout package-lock.json'
|
|
|
|
)
|
|
|
|
|
|
|
|
install.on('exit', () => {
|
2019-01-22 22:06:06 +01:00
|
|
|
spinnerNpm.succeed('Installed submodule dependencies.')
|
2019-01-22 13:52:44 +01:00
|
|
|
generateJson()
|
|
|
|
})
|
|
|
|
|
|
|
|
const generateJson = () => {
|
2019-01-22 22:06:06 +01:00
|
|
|
const spinnerTypedoc = ora('Generating TypeDoc json...').start()
|
2019-01-22 13:52:44 +01:00
|
|
|
|
|
|
|
// Setup our TypeDoc app
|
|
|
|
const app = new typedoc.Application({
|
|
|
|
tsconfig: config
|
|
|
|
})
|
|
|
|
|
|
|
|
const src = app.expandInputFiles(files)
|
|
|
|
const project = app.convert(src)
|
|
|
|
|
|
|
|
// Generate the JSON file
|
|
|
|
app.generateJson(project, outPath)
|
|
|
|
|
|
|
|
// Parse and modify json output
|
2019-01-22 22:06:06 +01:00
|
|
|
const jsonOrig = JSON.parse(fs.readFileSync(outPath, 'utf8'))
|
2019-01-22 13:52:44 +01:00
|
|
|
|
|
|
|
const jsonFinal = {
|
|
|
|
info: {
|
|
|
|
title: 'Squid-js',
|
|
|
|
description,
|
|
|
|
version,
|
|
|
|
sourceUrl:
|
|
|
|
'https://github.com/oceanprotocol/squid-js/tree/develop/src/'
|
|
|
|
},
|
|
|
|
...jsonOrig
|
|
|
|
}
|
|
|
|
|
2019-01-22 22:06:06 +01:00
|
|
|
fs.writeFileSync(outPath, JSON.stringify(jsonFinal, null, 4))
|
|
|
|
|
|
|
|
spinnerTypedoc.succeed('Generated TypeDoc json.')
|
2019-01-22 13:52:44 +01:00
|
|
|
}
|