2018-11-28 12:19:11 +01:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
2018-11-07 16:13:20 +01:00
|
|
|
const path = require('path')
|
|
|
|
const { createFilePath } = require('gatsby-source-filesystem')
|
2018-11-28 12:19:11 +01:00
|
|
|
const Swagger = require('swagger-client')
|
2018-11-29 10:47:42 +01:00
|
|
|
const { redirects } = require('./config')
|
2018-11-07 12:24:53 +01:00
|
|
|
|
2018-11-07 16:13:20 +01:00
|
|
|
exports.onCreateNode = ({ node, getNode, actions }) => {
|
|
|
|
const { createNodeField } = actions
|
|
|
|
|
2018-11-08 16:03:16 +01:00
|
|
|
if (node.internal.type === 'MarkdownRemark') {
|
2018-11-07 16:13:20 +01:00
|
|
|
const fileNode = getNode(node.parent)
|
|
|
|
const parsedFilePath = path.parse(fileNode.relativePath)
|
2018-11-14 15:17:19 +01:00
|
|
|
|
|
|
|
let slug = createFilePath({ node, getNode, basePath: 'content' })
|
|
|
|
let section = parsedFilePath.dir
|
|
|
|
|
|
|
|
if (node.frontmatter.slug) {
|
|
|
|
;({ slug } = node.frontmatter)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.frontmatter.section) {
|
|
|
|
;({ section } = node.frontmatter)
|
|
|
|
}
|
2018-11-07 16:13:20 +01:00
|
|
|
|
|
|
|
createNodeField({
|
|
|
|
node,
|
|
|
|
name: 'slug',
|
|
|
|
value: slug
|
|
|
|
})
|
|
|
|
|
|
|
|
createNodeField({
|
|
|
|
node,
|
|
|
|
name: 'section',
|
|
|
|
value: section
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.createPages = ({ graphql, actions }) => {
|
2018-11-29 10:47:42 +01:00
|
|
|
const { createPage, createRedirect } = actions
|
2018-11-07 16:13:20 +01:00
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
resolve(
|
|
|
|
graphql(
|
|
|
|
`
|
2018-11-27 13:54:00 +01:00
|
|
|
query {
|
2018-11-09 22:10:35 +01:00
|
|
|
allMarkdownRemark(
|
|
|
|
filter: { fileAbsolutePath: { regex: "/content/" } }
|
|
|
|
) {
|
2018-11-07 16:13:20 +01:00
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
fields {
|
|
|
|
slug
|
|
|
|
section
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-14 13:00:32 +01:00
|
|
|
|
2018-11-16 14:52:42 +01:00
|
|
|
devOceanDocs: allMarkdownRemark(
|
2018-11-14 15:17:19 +01:00
|
|
|
filter: {
|
2018-11-15 14:46:20 +01:00
|
|
|
fileAbsolutePath: { regex: "/dev-ocean/doc/" }
|
2018-11-14 15:17:19 +01:00
|
|
|
}
|
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
fields {
|
|
|
|
slug
|
|
|
|
section
|
2018-11-14 13:00:32 +01:00
|
|
|
}
|
2018-11-14 17:02:31 +01:00
|
|
|
frontmatter {
|
|
|
|
slug
|
|
|
|
title
|
|
|
|
description
|
|
|
|
section
|
|
|
|
}
|
2018-11-14 13:00:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-24 20:48:45 +02:00
|
|
|
|
|
|
|
squidJs: github {
|
|
|
|
repository(
|
|
|
|
name: "squid-js"
|
|
|
|
owner: "oceanprotocol"
|
|
|
|
) {
|
|
|
|
name
|
|
|
|
releases(
|
2019-11-21 16:31:11 +01:00
|
|
|
first: 30
|
2019-06-24 20:48:45 +02:00
|
|
|
orderBy: {
|
|
|
|
field: CREATED_AT
|
|
|
|
direction: DESC
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
2019-11-21 16:31:11 +01:00
|
|
|
isPrerelease
|
|
|
|
isDraft
|
2019-06-24 20:48:45 +02:00
|
|
|
releaseAssets(
|
|
|
|
first: 1
|
|
|
|
name: "squid-js.json"
|
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
name
|
|
|
|
downloadUrl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-07 16:13:20 +01:00
|
|
|
}
|
|
|
|
`
|
2018-11-28 12:19:11 +01:00
|
|
|
).then(async result => {
|
2018-11-07 16:13:20 +01:00
|
|
|
if (result.errors) {
|
|
|
|
console.log(result.errors)
|
|
|
|
reject(result.errors)
|
|
|
|
}
|
|
|
|
|
|
|
|
const docTemplate = path.resolve('./src/templates/Doc.jsx')
|
2018-11-14 13:00:32 +01:00
|
|
|
const posts = result.data.allMarkdownRemark.edges
|
2018-11-07 16:13:20 +01:00
|
|
|
|
2018-11-28 12:19:11 +01:00
|
|
|
//
|
2018-11-07 16:13:20 +01:00
|
|
|
// Create Doc pages
|
2018-11-28 12:19:11 +01:00
|
|
|
//
|
2018-11-07 16:13:20 +01:00
|
|
|
posts.forEach(post => {
|
|
|
|
createPage({
|
|
|
|
path: `${post.node.fields.slug}`,
|
|
|
|
component: docTemplate,
|
|
|
|
context: {
|
|
|
|
slug: post.node.fields.slug,
|
|
|
|
section: post.node.fields.section
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-11-28 12:19:11 +01:00
|
|
|
//
|
2018-11-16 14:52:42 +01:00
|
|
|
// Create pages from dev-ocean contents
|
2018-11-28 12:19:11 +01:00
|
|
|
//
|
2018-11-16 14:52:42 +01:00
|
|
|
const postsDevOcean = result.data.devOceanDocs.edges
|
2018-11-14 13:00:32 +01:00
|
|
|
|
2018-11-16 14:52:42 +01:00
|
|
|
postsDevOcean
|
2018-11-14 17:02:31 +01:00
|
|
|
// only grab files with required frontmatter defined
|
|
|
|
.filter(
|
|
|
|
post =>
|
2018-11-16 14:52:42 +01:00
|
|
|
post.node.frontmatter &&
|
2018-11-14 17:02:31 +01:00
|
|
|
post.node.frontmatter.slug &&
|
|
|
|
post.node.frontmatter.title &&
|
|
|
|
post.node.frontmatter.description &&
|
|
|
|
post.node.frontmatter.section
|
|
|
|
)
|
|
|
|
.forEach(post => {
|
|
|
|
createPage({
|
|
|
|
path: `${post.node.fields.slug}`,
|
|
|
|
component: docTemplate,
|
|
|
|
context: {
|
|
|
|
slug: post.node.fields.slug,
|
|
|
|
section: post.node.fields.section
|
|
|
|
}
|
|
|
|
})
|
2018-11-14 15:17:19 +01:00
|
|
|
})
|
|
|
|
|
2019-06-24 20:48:45 +02:00
|
|
|
// API: brizo, aquarius
|
|
|
|
await createSwaggerPages(createPage)
|
2018-11-27 13:54:00 +01:00
|
|
|
|
2019-06-24 20:48:45 +02:00
|
|
|
// API: squid-js
|
2019-11-21 16:31:11 +01:00
|
|
|
const lastRelease = result.data.squidJs.repository.releases.edges.filter(
|
|
|
|
({ node }) => !node.isPrerelease && !node.isDraft
|
|
|
|
)[0].node.releaseAssets.edges[0].node
|
2019-06-24 20:48:45 +02:00
|
|
|
await createTypeDocPage(
|
|
|
|
createPage,
|
|
|
|
result.data.squidJs.repository.name,
|
2019-11-21 16:31:11 +01:00
|
|
|
lastRelease.downloadUrl
|
2019-01-18 17:35:04 +01:00
|
|
|
)
|
|
|
|
|
2018-11-29 10:53:35 +01:00
|
|
|
//
|
|
|
|
// create redirects
|
|
|
|
//
|
|
|
|
redirects.forEach(({ from, to }) => {
|
|
|
|
createRedirect({
|
|
|
|
fromPath: from,
|
|
|
|
redirectInBrowser: true,
|
|
|
|
toPath: to
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log('Create redirect: ' + from + ' --> ' + to)
|
2018-11-28 13:20:03 +01:00
|
|
|
})
|
2018-11-27 12:01:44 +01:00
|
|
|
|
2018-11-07 16:13:20 +01:00
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
2019-06-24 20:48:45 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Create pages from TypeDoc json files
|
|
|
|
//
|
|
|
|
const createTypeDocPage = async (createPage, name, downloadUrl) => {
|
|
|
|
try {
|
|
|
|
const typedoc = await fetch(downloadUrl)
|
|
|
|
const typedocTemplate = path.resolve(
|
|
|
|
'./src/templates/Typedoc/index.jsx'
|
|
|
|
)
|
|
|
|
const slug = `/references/${name}/`
|
|
|
|
|
|
|
|
createPage({
|
|
|
|
path: slug,
|
|
|
|
component: typedocTemplate,
|
|
|
|
context: {
|
|
|
|
slug,
|
|
|
|
typedoc: await typedoc.json(),
|
|
|
|
// We define the classes here so the data object passed as page context
|
|
|
|
// is as small as possible.
|
|
|
|
// Caveat: no live update during development when these values are changed.
|
|
|
|
//
|
|
|
|
// TODO: defining these classes for inclusion
|
|
|
|
// needs to be handled somewhere else to keep
|
|
|
|
// it generic for all TypeDoc specs
|
|
|
|
classes: [
|
|
|
|
'ocean/Ocean',
|
|
|
|
'ocean/OceanAccounts',
|
|
|
|
'ocean/OceanAssets',
|
|
|
|
'ocean/OceanAgreements',
|
2019-11-06 12:30:44 +01:00
|
|
|
'ocean/OceanAgreementsConditions',
|
|
|
|
'ocean/OceanSecretStore',
|
2019-06-24 20:48:45 +02:00
|
|
|
'ocean/OceanVersions',
|
|
|
|
'ocean/Account',
|
|
|
|
'ocean/DID',
|
|
|
|
'ddo/DDO',
|
|
|
|
'ddo/Service',
|
|
|
|
'aquarius/Aquarius',
|
|
|
|
'brizo/Brizo',
|
|
|
|
'keeper/Keeper',
|
2019-11-06 12:30:44 +01:00
|
|
|
'keeper/ContractHandler',
|
|
|
|
'keeper/EventHandler',
|
2019-06-24 20:48:45 +02:00
|
|
|
'keeper/Web3Provider',
|
|
|
|
'models/Config',
|
2019-11-06 12:30:44 +01:00
|
|
|
'models/Balance',
|
|
|
|
'ocean/utils/OceanUtils',
|
|
|
|
'ocean/utils/ServiceAgreement',
|
|
|
|
'ocean/utils/WebServiceConnector',
|
|
|
|
'utils/Logger'
|
2019-06-24 20:48:45 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create pages from swagger json files
|
|
|
|
//
|
|
|
|
// https://github.com/swagger-api/swagger-js
|
|
|
|
const fetchSwaggerSpec = async name => {
|
|
|
|
try {
|
2019-07-08 16:51:02 +02:00
|
|
|
const client = await Swagger(
|
2019-10-31 14:06:23 +01:00
|
|
|
`https://${name}.commons.oceanprotocol.com/spec`
|
2019-07-08 16:51:02 +02:00
|
|
|
)
|
2019-06-24 20:48:45 +02:00
|
|
|
return client.spec // The resolved spec
|
|
|
|
|
|
|
|
// client.originalSpec // In case you need it
|
|
|
|
// client.errors // Any resolver errors
|
|
|
|
|
|
|
|
// Tags interface
|
|
|
|
// client.apis.pet.addPet({id: 1, name: "bobby"}).then(...)
|
|
|
|
|
|
|
|
// TryItOut Executor, with the `spec` already provided
|
|
|
|
// client.execute({operationId: 'addPet', parameters: {id: 1, name: "bobby") }).then(...)
|
|
|
|
} catch (error) {
|
2019-10-31 14:06:23 +01:00
|
|
|
console.error(error.message)
|
2019-06-24 20:48:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const createSwaggerPages = async createPage => {
|
|
|
|
const swaggerComponents = ['aquarius', 'brizo']
|
|
|
|
const apiSwaggerTemplate = path.resolve('./src/templates/Swagger/index.jsx')
|
|
|
|
|
|
|
|
const getSlug = name => {
|
|
|
|
const slug = `/references/${name}/`
|
|
|
|
return slug
|
|
|
|
}
|
|
|
|
|
|
|
|
const specAquarius = await fetchSwaggerSpec(swaggerComponents[0])
|
|
|
|
const slugAquarius = getSlug(swaggerComponents[0])
|
|
|
|
|
|
|
|
createPage({
|
|
|
|
path: slugAquarius,
|
|
|
|
component: apiSwaggerTemplate,
|
|
|
|
context: {
|
|
|
|
slug: slugAquarius,
|
|
|
|
name: swaggerComponents[0],
|
|
|
|
api: specAquarius
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const specBrizo = await fetchSwaggerSpec(swaggerComponents[1])
|
|
|
|
const slugBrizo = getSlug(swaggerComponents[1])
|
|
|
|
|
|
|
|
createPage({
|
|
|
|
path: slugBrizo,
|
|
|
|
component: apiSwaggerTemplate,
|
|
|
|
context: {
|
|
|
|
slug: slugBrizo,
|
|
|
|
name: swaggerComponents[1],
|
|
|
|
api: specBrizo
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Swagger Pet Store example
|
|
|
|
const petStoreSlug = '/references/petstore/'
|
|
|
|
|
|
|
|
try {
|
|
|
|
const client = await Swagger(
|
|
|
|
`http://petstore.swagger.io/v2/swagger.json`
|
|
|
|
)
|
|
|
|
|
|
|
|
createPage({
|
|
|
|
path: petStoreSlug,
|
|
|
|
component: apiSwaggerTemplate,
|
|
|
|
context: {
|
|
|
|
slug: petStoreSlug,
|
|
|
|
api: client.spec
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} catch (error) {
|
2019-10-31 14:06:23 +01:00
|
|
|
console.error(error.message)
|
2019-06-24 20:48:45 +02:00
|
|
|
}
|
|
|
|
}
|