forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(gatsby): output apis.json for current valid API list (gatsbyjs#…
…16061) * feat(gatsby): output apis.json for current valid API list * chore: do not commit apis.json * chore: use undefined instead of assign * chore: iron out tests * chore: make code self documenting (s/o Pieh)
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,4 @@ dist | |
|
||
# built files | ||
cache-dir/commonjs/ | ||
apis.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const path = require('path') | ||
const documentation = require('documentation') | ||
const fs = require('fs-extra') | ||
|
||
const OUTPUT_FILE_NAME = `apis.json` | ||
|
||
async function outputFile() { | ||
const apis = await Promise.all([ | ||
path.join('cache-dir', 'api-ssr-docs.js'), | ||
path.join('src', 'utils', 'api-browser-docs.js'), | ||
path.join('src', 'utils', 'api-node-docs.js') | ||
] | ||
.map(filePath => { | ||
const resolved = path.resolve(filePath) | ||
const [,api] = path.basename(filePath).split('-') | ||
return documentation.build(resolved, { | ||
shallow: true | ||
}) | ||
.then(contents => { | ||
return [ | ||
contents, | ||
api | ||
] | ||
}) | ||
}) | ||
) | ||
|
||
const output = apis.reduce((merged, [output, api]) => { | ||
merged[api] = output.reduce((mergedOutput, doc) => { | ||
const isAPI = doc.namespace.startsWith('.') | ||
if (isAPI) { | ||
const tags = doc.tags.reduce((mergedTags, tag) => { | ||
mergedTags[tag.title] = tag.description | ||
return mergedTags | ||
}, {}) | ||
mergedOutput[doc.name] = { | ||
deprecated: !!tags.deprecated || undefined, | ||
version: tags.gatsbyVersion | ||
} | ||
} | ||
return mergedOutput | ||
}, {}) | ||
return merged | ||
}, {}) | ||
|
||
return fs.writeFile(path.resolve(OUTPUT_FILE_NAME), JSON.stringify(output, null, 2), 'utf8') | ||
} | ||
|
||
outputFile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters