@tinymce/moxiedoc
Advanced tools
Comparing version 0.2.0-feature.20220218023639432.sha18493e1 to 0.2.0-feature.20220218031537810.sha89a8739
@@ -23,11 +23,11 @@ "use strict"; | ||
// Api index page | ||
let adoc = '* API Reference\n'; | ||
const pages = navyml[0].pages; | ||
const indexPage = navyml[0]; | ||
let adoc = '* ' + indexPage.title + '\n'; | ||
// generate API namespaces | ||
pages.forEach((namespace) => { | ||
indexPage.pages.forEach((namespace) => { | ||
// main namespace level navigation (namespace index) | ||
adoc += '** ' + namespace.url + '\n'; | ||
adoc += '** ' + namespace.path + '\n'; | ||
namespace.pages.forEach((page) => { | ||
// namespace level pages | ||
adoc += '*** xref:' + AntoraNavBaseDir + page.url + '.adoc' + '[' + page.url + ']\n'; | ||
adoc += '*** xref:' + AntoraNavBaseDir + page.path + '.adoc' + '[' + page.title + ']\n'; | ||
}); | ||
@@ -41,5 +41,8 @@ }); | ||
const fullName = type.fullName.toLowerCase(); | ||
const namespace = getNamespaceFromFullName(fullName); | ||
return namespace && namespaces.indexOf(namespace) === -1 ? namespaces.concat(namespace) : namespaces; | ||
}, []); | ||
const url = getNamespaceFromFullName(fullName); | ||
if (url && !namespaces[url]) { | ||
namespaces[url] = getNamespaceFromFullName(type.fullName); | ||
} | ||
return namespaces; | ||
}, {}); | ||
}; | ||
@@ -52,14 +55,18 @@ /** | ||
const namespaces = getNamespacesFromTypes(types); | ||
const pages = namespaces.map((namespace) => { | ||
const pages = Object.entries(namespaces).map(([url, title]) => { | ||
const innerPages = types.filter((type) => { | ||
const fullName = type.fullName.toLowerCase(); | ||
return getNamespaceFromFullName(fullName) === namespace; | ||
}).map((type) => ({ url: type.fullName.toLowerCase() })); | ||
if (namespace === 'tinymce') { | ||
return getNamespaceFromFullName(fullName) === url; | ||
}).map((type) => { | ||
return { title: type.fullName, path: type.fullName.toLowerCase() }; | ||
}); | ||
if (url === 'tinymce') { | ||
innerPages.unshift({ | ||
url: 'tinymce.root' | ||
title: 'tinymce', | ||
path: 'tinymce.root' | ||
}); | ||
} | ||
return { | ||
url: namespace, | ||
title, | ||
path: url, | ||
pages: innerPages | ||
@@ -69,3 +76,4 @@ }; | ||
return [{ | ||
url: BASE_PATH, | ||
title: 'API Reference', | ||
path: BASE_PATH, | ||
pages | ||
@@ -268,10 +276,11 @@ }]; | ||
flatten(convertedPages).forEach(addPage); | ||
getNamespacesFromTypes(sortedTypes).map((namespace) => { | ||
const namespaces = getNamespacesFromTypes(sortedTypes); | ||
Object.entries(namespaces).map(([url, title]) => { | ||
// TODO: flatten FS here for antora if needed. | ||
const fileName = (BASE_PATH + '/' + namespace + '.adoc').toLowerCase(); | ||
const namespaceDescription = (namespace in namespaceDescriptions) ? namespaceDescriptions[namespace] : namespace; | ||
const fileName = (BASE_PATH + '/' + url + '.adoc').toLowerCase(); | ||
const namespaceDescription = (url in namespaceDescriptions) ? namespaceDescriptions[url] : url; | ||
return { | ||
filename: fileName, | ||
content: namespaceTemplate({ | ||
title: namespace, | ||
title, | ||
desc: namespaceDescription | ||
@@ -278,0 +287,0 @@ }) |
{ | ||
"name": "@tinymce/moxiedoc", | ||
"version": "0.2.0-feature.20220218023639432.sha18493e1", | ||
"version": "0.2.0-feature.20220218031537810.sha89a8739", | ||
"description": "A tool for generating API documentation", | ||
@@ -5,0 +5,0 @@ "author": "Tiny Technologies, Inc", |
@@ -12,3 +12,4 @@ import * as fs from 'fs'; | ||
interface NavFile { | ||
readonly url: string; | ||
readonly title: string; | ||
readonly path: string; | ||
readonly pages?: NavFile[]; | ||
@@ -35,12 +36,12 @@ } | ||
// Api index page | ||
let adoc = '* API Reference\n'; | ||
const pages = navyml[0].pages; | ||
const indexPage = navyml[0]; | ||
let adoc = '* ' + indexPage.title + '\n'; | ||
// generate API namespaces | ||
pages.forEach((namespace) => { | ||
indexPage.pages.forEach((namespace) => { | ||
// main namespace level navigation (namespace index) | ||
adoc += '** ' + namespace.url + '\n'; | ||
adoc += '** ' + namespace.path + '\n'; | ||
namespace.pages.forEach((page) => { | ||
// namespace level pages | ||
adoc += '*** xref:' + AntoraNavBaseDir + page.url + '.adoc' + '[' + page.url + ']\n'; | ||
adoc += '*** xref:' + AntoraNavBaseDir + page.path + '.adoc' + '[' + page.title + ']\n'; | ||
}); | ||
@@ -55,8 +56,11 @@ }); | ||
const getNamespacesFromTypes = (types: Type[]): string[] => { | ||
return types.reduce((namespaces: string[], type: Type) => { | ||
const getNamespacesFromTypes = (types: Type[]): Record<string, string> => { | ||
return types.reduce((namespaces: Record<string, string>, type: Type) => { | ||
const fullName = type.fullName.toLowerCase(); | ||
const namespace = getNamespaceFromFullName(fullName); | ||
return namespace && namespaces.indexOf(namespace) === -1 ? namespaces.concat(namespace) : namespaces; | ||
}, []); | ||
const url = getNamespaceFromFullName(fullName); | ||
if (url && !namespaces[url]) { | ||
namespaces[url] = getNamespaceFromFullName(type.fullName); | ||
} | ||
return namespaces; | ||
}, {}); | ||
}; | ||
@@ -70,15 +74,20 @@ | ||
const namespaces = getNamespacesFromTypes(types); | ||
const pages = namespaces.map((namespace) => { | ||
const pages = Object.entries(namespaces).map(([ url, title ]): NavFile => { | ||
const innerPages = types.filter((type) => { | ||
const fullName = type.fullName.toLowerCase(); | ||
return getNamespaceFromFullName(fullName) === namespace; | ||
}).map((type) => ({ url: type.fullName.toLowerCase() })); | ||
return getNamespaceFromFullName(fullName) === url; | ||
}).map((type): NavFile => { | ||
return { title: type.fullName, path: type.fullName.toLowerCase() }; | ||
}); | ||
if (namespace === 'tinymce') { | ||
if (url === 'tinymce') { | ||
innerPages.unshift({ | ||
url: 'tinymce.root' | ||
title: 'tinymce', | ||
path: 'tinymce.root' | ||
}); | ||
} | ||
return { | ||
url: namespace, | ||
title, | ||
path: url, | ||
pages: innerPages | ||
@@ -89,3 +98,4 @@ }; | ||
return [{ | ||
url: BASE_PATH, | ||
title: 'API Reference', | ||
path: BASE_PATH, | ||
pages | ||
@@ -319,10 +329,11 @@ }]; | ||
getNamespacesFromTypes(sortedTypes).map((namespace) => { | ||
const namespaces = getNamespacesFromTypes(sortedTypes); | ||
Object.entries(namespaces).map(([ url, title ]) => { | ||
// TODO: flatten FS here for antora if needed. | ||
const fileName = (BASE_PATH + '/' + namespace + '.adoc').toLowerCase(); | ||
const namespaceDescription = (namespace in namespaceDescriptions) ? namespaceDescriptions[namespace] : namespace; | ||
const fileName = (BASE_PATH + '/' + url + '.adoc').toLowerCase(); | ||
const namespaceDescription = (url in namespaceDescriptions) ? namespaceDescriptions[url] : url; | ||
return { | ||
filename: fileName, | ||
content: namespaceTemplate({ | ||
title: namespace, | ||
title, | ||
desc: namespaceDescription | ||
@@ -329,0 +340,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
351556
6739