diff --git a/gatsby-node.js b/gatsby-node.js index eefb490c..c38c0f59 100755 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -153,7 +153,7 @@ exports.createPages = ({ graphql, actions }) => { // Create pages from swagger json files // const apiSwaggerTemplate = path.resolve( - './src/templates/ApiSwagger.jsx' + './src/templates/Swagger/index.jsx' ) const petStoreSlug = '/references/petstore/' @@ -202,7 +202,7 @@ exports.createPages = ({ graphql, actions }) => { // const typeDocSpecs = ['./data/squid-js.json'] const typedocTemplate = path.resolve( - './src/templates/Typedoc.jsx' + './src/templates/Typedoc/index.jsx' ) typeDocSpecs.forEach(spec => { diff --git a/package.json b/package.json index 7db010e5..648b0a09 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "eslint-plugin-prettier": "^3.0.0", "markdownlint-cli": "^0.13.0", "npm-run-all": "^4.1.5", + "ora": "^3.0.0", "prettier": "^1.15.3", "prettier-stylelint": "^0.4.2", "stylelint": "^9.9.0", diff --git a/scripts/typedoc.js b/scripts/typedoc.js index 42443663..1953ddd8 100644 --- a/scripts/typedoc.js +++ b/scripts/typedoc.js @@ -1,10 +1,11 @@ #!/usr/bin/env node -/* eslint-disable no-console, security/detect-child-process */ +/* eslint-disable no-console, security/detect-child-process, security/detect-non-literal-fs-filename */ const fs = require('fs') const typedoc = require('typedoc') const typescript = require('typescript') +const ora = require('ora') const squidJsPackage = require('../external/squid-js/package.json') const { exec } = require('child_process') @@ -21,17 +22,18 @@ const config = typescript.findConfigFile( ) // npm install for squid-js -console.log('Installing submodule dependencies...') +const spinnerNpm = ora('Installing submodule dependencies...').start() const install = exec( 'cd ./external/squid-js && npm i && git checkout package-lock.json' ) install.on('exit', () => { + spinnerNpm.succeed('Installed submodule dependencies.') generateJson() }) const generateJson = () => { - console.log('Generating TypeDoc json...') + const spinnerTypedoc = ora('Generating TypeDoc json...').start() // Setup our TypeDoc app const app = new typedoc.Application({ @@ -45,7 +47,7 @@ const generateJson = () => { app.generateJson(project, outPath) // Parse and modify json output - const jsonOrig = JSON.parse(fs.readFileSync(outPath, 'utf8')) // eslint-disable-line + const jsonOrig = JSON.parse(fs.readFileSync(outPath, 'utf8')) const jsonFinal = { info: { @@ -58,5 +60,7 @@ const generateJson = () => { ...jsonOrig } - fs.writeFileSync(outPath, JSON.stringify(jsonFinal, null, 4)) // eslint-disable-line + fs.writeFileSync(outPath, JSON.stringify(jsonFinal, null, 4)) + + spinnerTypedoc.succeed('Generated TypeDoc json.') } diff --git a/src/templates/ApiSwagger.jsx b/src/templates/ApiSwagger.jsx deleted file mode 100644 index 1635122e..00000000 --- a/src/templates/ApiSwagger.jsx +++ /dev/null @@ -1,321 +0,0 @@ -import React, { Component } from 'react' -import PropTypes from 'prop-types' -import { graphql } from 'gatsby' -import Helmet from 'react-helmet' -import slugify from 'slugify' -import Layout from '../components/Layout' -import Content from '../components/Content' -import HeaderSection from '../components/HeaderSection' -import Sidebar from '../components/Sidebar' -import DocHeader from '../components/DocHeader' -import DocFooter from '../components/DocFooter' -import SEO from '../components/Seo' -import stylesDoc from './Doc.module.scss' -import styles from './ApiSwagger.module.scss' - -const cleanKey = key => { - let keyCleaned = key - - if (key.includes('aquarius')) { - keyCleaned = key.replace(/\/api\/v1\/aquarius/gi, '') - } - - if (key.includes('brizo')) { - keyCleaned = key.replace(/\/api\/v1\/brizo/gi, '') - } - - return keyCleaned -} - -const toc = api => { - const items = Object.keys(api.paths).map( - key => `
${cleanKey(
- key
- )}
-
-
- {'{'}
- {properties &&
- Object.keys(properties).map(key => (
-
- {` "${key}"`}
- {`: `}
- {properties[key].type === 'string' && (
- {`"${
- properties[key].example
- }"`}
- )}
- {(properties[key].type === 'integer' ||
- properties[key].type === 'number') && (
-
- {`${properties[key].example}`}
-
- )}
- {(properties[key].type === 'array' ||
- properties[key].type === 'object') &&
- JSON.stringify(properties[key].example, null, 2)}
- ,
-
- ))}
- {'}'}
-
-
-)
-
-ParameterExample.propTypes = {
- properties: PropTypes.object
-}
-
-const Parameters = ({ parameters }) => (
- <>
- {name}
- {required && (
-
- *
-
- )}
- {type}
- {description}
- - {schema && ( -{key}
{responses[key].description}
- {summary}
- - {description &&{description}
} - - {/* - {consumes && - consumes.map((item, i) => ( -{item}
- {cleanKey(key)}
-
- {host}
- {basePath}
-
-
+
+ {'{'}
+ {properties &&
+ Object.keys(properties).map(key => (
+
+ {` "${key}"`}
+ {`: `}
+ {properties[key].type === 'string' && (
+ {`"${
+ properties[key].example
+ }"`}
+ )}
+ {(properties[key].type === 'integer' ||
+ properties[key].type === 'number') && (
+
+ {`${properties[key].example}`}
+
+ )}
+ {(properties[key].type === 'array' ||
+ properties[key].type === 'object') &&
+ JSON.stringify(properties[key].example, null, 2)}
+ ,
+
+ ))}
+ {'}'}
+
+
+)
+
+ParameterExample.propTypes = {
+ properties: PropTypes.object
+}
+
+const Parameters = ({ parameters }) => (
+ <>
+ {name}
+ {required && (
+
+ *
+
+ )}
+ {type}
+ {description}
+ + {schema && ( +{key}
{responses[key].description}
+ {summary}
+ + {description &&{description}
} + + {/* + {consumes && + consumes.map((item, i) => ( +{item}
+ {cleanPathKey(key)}
+ ${cleanPathKey(key)}
+
+
+ {host}
+ {basePath}
+
+
- ${name}
-
- ${name}
-
- ${name}
+
+ ${name}
+
+