@tinymce/moxiedoc
Advanced tools
Comparing version 0.2.2-rc.20220622065305759.sha4aa7bcb to 0.3.0-feature.20220822040129921.sha302e003
@@ -9,2 +9,7 @@ # Changelog | ||
## 0.3.0 - 2022-07-12 | ||
### Added | ||
- New `structure` option with default `flat` file structure or `legacy` nested folders. | ||
## 0.2.1 - 2022-04-29 | ||
@@ -11,0 +16,0 @@ |
@@ -9,6 +9,7 @@ #! /usr/bin/env node | ||
commander_1.program | ||
.version('0.2.0') | ||
.version('0.3.0') | ||
.usage('[options] <dir ...>') | ||
.option('-o, --out <path>', 'output path, default: out') | ||
.option('-t, --template <template>', 'template name') | ||
.option('-t, --template <template>', 'template name, default: cli') | ||
.option('-s, --structure <type>', 'output file structure') | ||
.option('-v, --verbose', 'verbose output') | ||
@@ -15,0 +16,0 @@ .option('--debug', 'debug output') |
import { Api } from './api'; | ||
export declare type ExportStructure = 'default' | 'legacy'; | ||
export interface ExporterSettings { | ||
readonly template: string; | ||
readonly structure: ExportStructure; | ||
} | ||
@@ -5,0 +7,0 @@ /** |
@@ -21,3 +21,3 @@ "use strict"; | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require(templatePath).template.call(this, types, dirPath); | ||
require(templatePath).template.call(this, types, dirPath, this.settings.structure); | ||
} | ||
@@ -24,0 +24,0 @@ } |
@@ -0,4 +1,6 @@ | ||
import { ExportStructure } from './exporter'; | ||
export interface MoxiedocSettings { | ||
out?: string; | ||
template?: string; | ||
structure?: ExportStructure; | ||
verbose?: boolean; | ||
@@ -5,0 +7,0 @@ debug?: boolean; |
@@ -32,2 +32,3 @@ "use strict"; | ||
settings.template = settings.template || 'cli'; | ||
settings.structure = settings.structure || 'default'; | ||
if (settings.verbose) { | ||
@@ -79,3 +80,4 @@ Reporter.setLevel(2 /* INFO */); | ||
const exporter = new exporter_1.Exporter({ | ||
template: settings.template | ||
template: settings.template, | ||
structure: settings.structure | ||
}); | ||
@@ -82,0 +84,0 @@ exporter.exportTo(builder.api, settings.out); |
@@ -1,8 +0,5 @@ | ||
export interface PageOutput { | ||
readonly type: 'adoc' | 'json'; | ||
readonly filename: string; | ||
readonly content: string; | ||
} | ||
declare const convert: (pages: PageOutput[][]) => PageOutput[][]; | ||
import { ExportStructure } from 'src/lib/exporter'; | ||
import { PageOutput } from './util'; | ||
declare const convert: (pages: PageOutput[][], structure: ExportStructure) => PageOutput[][]; | ||
export { convert }; | ||
//# sourceMappingURL=antora.converter.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.convert = void 0; | ||
// TODO: we can pass this through later | ||
const basePath = 'apis/'; | ||
const Util = require("./util"); | ||
const hasValue = (x) => { | ||
@@ -62,9 +61,2 @@ // empty helper for strings, objects, arrays | ||
}; | ||
const getNameFromFullName = (name) => name.split('.').slice(-1).join(''); | ||
const getFilePathFromFullName = (name) => { | ||
const filename = name.toLowerCase() === 'tinymce' ? 'tinymce.root' : name.toLowerCase(); | ||
return basePath + filename + '.adoc'; | ||
}; | ||
const generateTypeXref = (type) => type.includes('tinymce', 0) ? 'xref:' + getFilePathFromFullName(type) + '[' + getNameFromFullName(type) + ']' : type; | ||
const generateDefinedByXref = (definedBy) => 'xref:' + getFilePathFromFullName(definedBy) + '[' + getNameFromFullName(definedBy) + ']'; | ||
const generateExamples = (examples) => { | ||
@@ -80,18 +72,17 @@ let tmp = '\n==== Examples\n'; | ||
}; | ||
const generateParameters = (params) => { | ||
const generateParameters = (params, structure) => { | ||
let tmp = '\n==== Parameters\n'; | ||
params.forEach((param) => { | ||
tmp += '\n* `' + param.name + ' (' + param.types.map(generateTypeXref).join(' | ') + ')` - ' + cleanup(param.desc); | ||
tmp += '\n* `' + param.name + ' (' + param.types.map((type) => Util.generateTypeXref(type, structure)).join(' | ') + ')` - ' + cleanup(param.desc); | ||
}); | ||
return tmp + '\n'; | ||
}; | ||
const generateReturn = (ret) => { | ||
const generateReturn = (ret, structure) => { | ||
let tmp = '\n==== Return value\n'; | ||
ret.types.forEach((type) => { | ||
tmp += '\n* `' + generateTypeXref(type) + '` - ' + cleanup(ret.desc); | ||
tmp += '\n* `' + Util.generateTypeXref(type, structure) + '` - ' + cleanup(ret.desc); | ||
}); | ||
tmp += '\n'; | ||
return tmp; | ||
return tmp += '\n'; | ||
}; | ||
const buildSummary = (data) => { | ||
const buildSummary = (data, structure) => { | ||
let tmp = ''; | ||
@@ -108,5 +99,5 @@ // settings | ||
tmp += '|' + item.name; | ||
tmp += '|`' + generateTypeXref(item.dataTypes[0]) + '`'; | ||
tmp += '|`' + Util.generateTypeXref(item.dataTypes[0], structure) + '`'; | ||
tmp += '|' + cleanup(item.desc); | ||
tmp += '|`' + generateDefinedByXref(item.definedBy) + '`\n'; | ||
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n'; | ||
}); | ||
@@ -124,5 +115,5 @@ tmp += '|===\n'; | ||
tmp += '|' + item.name; | ||
tmp += '|`' + generateTypeXref(item.dataTypes[0]) + '`'; | ||
tmp += '|`' + Util.generateTypeXref(item.dataTypes[0], structure) + '`'; | ||
tmp += '|' + cleanup(item.desc); | ||
tmp += '|`' + generateDefinedByXref(item.definedBy) + '`\n'; | ||
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n'; | ||
}); | ||
@@ -141,3 +132,3 @@ tmp += '|===\n'; | ||
tmp += '|' + cleanup(item.desc); | ||
tmp += '|`' + generateDefinedByXref(item.definedBy) + '`\n'; | ||
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n'; | ||
}); | ||
@@ -154,3 +145,3 @@ tmp += '|===\n'; | ||
data.methods.forEach((item) => { | ||
tmp += '|xref:#' + item.name + '[' + item.name + '()]|' + cleanup(item.desc) + '|`' + generateDefinedByXref(item.definedBy) + '`\n'; | ||
tmp += '|xref:#' + item.name + '[' + item.name + '()]|' + cleanup(item.desc) + '|`' + Util.generateXref(item.definedBy, structure) + '`\n'; | ||
}); | ||
@@ -170,3 +161,3 @@ tmp += '|===\n'; | ||
tmp += '|' + cleanup(item.desc); | ||
tmp += '|`' + generateDefinedByXref(item.definedBy) + '`\n'; | ||
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n'; | ||
}); | ||
@@ -177,3 +168,3 @@ tmp += '|===\n'; | ||
}; | ||
const buildConstructor = (data) => { | ||
const buildConstructor = (data, structure) => { | ||
let tmp = ''; | ||
@@ -195,6 +186,6 @@ if (hasValue(data.constructors)) { | ||
if (hasValue(constructor.params)) { | ||
tmp += generateParameters(constructor.params); | ||
tmp += generateParameters(constructor.params, structure); | ||
} | ||
if (hasValue(constructor.return) && hasValue(constructor.return.types)) { | ||
tmp += generateReturn(constructor.return); | ||
tmp += generateReturn(constructor.return, structure); | ||
} | ||
@@ -205,3 +196,3 @@ }); | ||
}; | ||
const buildMethods = (data) => { | ||
const buildMethods = (data, structure) => { | ||
let tmp = ''; | ||
@@ -223,6 +214,6 @@ if (hasValue(data.methods)) { | ||
if (hasValue(method.params)) { | ||
tmp += generateParameters(method.params); | ||
tmp += generateParameters(method.params, structure); | ||
} | ||
if (hasValue(method.return) && hasValue(method.return.types)) { | ||
tmp += generateReturn(method.return); | ||
tmp += generateReturn(method.return, structure); | ||
} | ||
@@ -234,3 +225,3 @@ tmp += `\n'''\n`; | ||
}; | ||
const buildEvents = (data) => { | ||
const buildEvents = (data, structure) => { | ||
let tmp = ''; | ||
@@ -246,3 +237,3 @@ // untested snippet, no events data | ||
if (hasValue(event.params)) { | ||
tmp += generateParameters(event.params); | ||
tmp += generateParameters(event.params, structure); | ||
} | ||
@@ -253,3 +244,3 @@ }); | ||
}; | ||
const convert = (pages) => pages.map((page) => { | ||
const convert = (pages, structure) => pages.map((page) => { | ||
// page[0] is json | ||
@@ -284,3 +275,3 @@ // page[1] is adoc | ||
data.borrows.forEach((item) => { | ||
tmp += '\n * xref:' + basePath + item.toLowerCase() + '.adoc[' + item + ']\n'; | ||
tmp += '\n * ' + Util.generateXref(item, structure) + '\n'; | ||
}); | ||
@@ -299,6 +290,6 @@ } | ||
} | ||
tmp += buildSummary(data); | ||
tmp += buildConstructor(data); | ||
tmp += buildMethods(data); | ||
tmp += buildEvents(data); | ||
tmp += buildSummary(data, structure); | ||
tmp += buildConstructor(data, structure); | ||
tmp += buildMethods(data, structure); | ||
tmp += buildEvents(data, structure); | ||
// return the applied antora page mutation | ||
@@ -305,0 +296,0 @@ page[1] = Object.assign(Object.assign({}, page[1]), { content: tmp }); |
@@ -0,1 +1,2 @@ | ||
import { ExportStructure } from 'src/lib/exporter'; | ||
import { Api } from '../../lib/api'; | ||
@@ -6,6 +7,7 @@ /** | ||
* @param {[type]} toPath [description] | ||
* @param {[type]} structure [description] | ||
* @return {[type]} [description] | ||
*/ | ||
declare const template: (root: Api, toPath: string) => void; | ||
declare const template: (root: Api, toPath: string, structure: ExportStructure) => void; | ||
export { template }; | ||
//# sourceMappingURL=template.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.template = void 0; | ||
const fs = require("fs"); | ||
const Handlebars = require("handlebars"); | ||
const YAML = require("js-yaml"); | ||
const moxie_zip_1 = require("moxie-zip"); | ||
const path = require("path"); | ||
const AntoraTemplate = require("./antora.converter"); | ||
const BASE_PATH = process.env.BASE_PATH || '/_data/antora'; | ||
// correlates to tinymce-docs antora path | ||
const AntoraNavBaseDir = 'apis/'; | ||
const navToAdoc = (navyml) => { | ||
// Api index page | ||
const indexPage = navyml[0]; | ||
let adoc = '* ' + indexPage.title + '\n'; | ||
// generate API namespaces | ||
indexPage.pages.forEach((namespace) => { | ||
// main namespace level navigation (namespace index) | ||
adoc += '** ' + namespace.path + '\n'; | ||
namespace.pages.forEach((page) => { | ||
// namespace level pages | ||
adoc += '*** xref:' + AntoraNavBaseDir + page.path + '.adoc' + '[' + page.title + ']\n'; | ||
}); | ||
}); | ||
return adoc; | ||
}; | ||
const getNamespaceFromFullName = (fullName) => fullName.split('.').slice(0, -1).join('.'); | ||
const getNamespacesFromTypes = (types) => { | ||
return types.reduce((namespaces, type) => { | ||
const fullName = type.fullName.toLowerCase(); | ||
const url = getNamespaceFromFullName(fullName); | ||
if (url && !namespaces[url]) { | ||
namespaces[url] = getNamespaceFromFullName(type.fullName); | ||
} | ||
return namespaces; | ||
}, {}); | ||
}; | ||
const Util = require("./util"); | ||
/** | ||
* [getNavFile description] | ||
* @return {[type]} [description] | ||
*/ | ||
const getNavFile = (types) => { | ||
const namespaces = getNamespacesFromTypes(types); | ||
const pages = Object.entries(namespaces).map(([url, title]) => { | ||
const innerPages = types.filter((type) => { | ||
const fullName = type.fullName.toLowerCase(); | ||
return getNamespaceFromFullName(fullName) === url; | ||
}).map((type) => { | ||
return { title: type.fullName, path: type.fullName.toLowerCase() }; | ||
}); | ||
if (url === 'tinymce') { | ||
innerPages.unshift({ | ||
title: 'tinymce', | ||
path: 'tinymce.root' | ||
}); | ||
} | ||
return { | ||
title, | ||
path: url, | ||
pages: innerPages | ||
}; | ||
}); | ||
return [{ | ||
title: 'API Reference', | ||
path: BASE_PATH, | ||
pages | ||
}]; | ||
}; | ||
/** | ||
* [description] | ||
@@ -77,3 +14,3 @@ * @param {[type]} root [description] | ||
*/ | ||
const getMemberPages = (root, templateDelegate, type) => { | ||
const getMemberPages = (root, templateDelegate, structure, type) => { | ||
const members = type.getMembers(true); | ||
@@ -102,24 +39,21 @@ const data = type.toJSON(); | ||
memberData.definedBy = parentType.fullName; | ||
if ('property' === memberData.type) { | ||
data.properties.push(memberData); | ||
return; | ||
switch (memberData.type) { | ||
case 'property': | ||
data.properties.push(memberData); | ||
return; | ||
case 'setting': | ||
data.settings.push(memberData); | ||
return; | ||
case 'constructor': | ||
data.constructors.push(memberData); | ||
memberData.signature = getSyntaxString(memberData); | ||
return; | ||
case 'method': | ||
data.methods.push(memberData); | ||
memberData.signature = getSyntaxString(memberData); | ||
return; | ||
case 'event': | ||
data.events.push(memberData); | ||
return; | ||
} | ||
if ('setting' === memberData.type) { | ||
data.settings.push(memberData); | ||
return; | ||
} | ||
if ('constructor' === memberData.type) { | ||
data.constructors.push(memberData); | ||
memberData.signature = getSyntaxString(memberData); | ||
return; | ||
} | ||
if ('method' === memberData.type) { | ||
data.methods.push(memberData); | ||
memberData.signature = getSyntaxString(memberData); | ||
return; | ||
} | ||
if ('event' === memberData.type) { | ||
data.events.push(memberData); | ||
return; | ||
} | ||
}); | ||
@@ -133,9 +67,11 @@ data.constructors = sortMembers(data.constructors); | ||
data.keywords = data.keywords.join(', '); | ||
const jsonFilePath = Util.getJsonFilePath(data.type, data.fullName); | ||
const adocFilePath = Util.getFilePath(data.fullName, structure); | ||
return [{ | ||
type: 'json', | ||
filename: createFileName(data, 'json'), | ||
filename: jsonFilePath, | ||
content: JSON.stringify(data, null, ' ') | ||
}, { | ||
type: 'adoc', | ||
filename: createFileName(data, 'adoc'), | ||
filename: adocFilePath, | ||
content: templateDelegate(data) | ||
@@ -171,27 +107,2 @@ }]; | ||
/** | ||
* [compileTemplate description] | ||
* @param {[type]} filePath [description] | ||
* @return {[type]} [description] | ||
*/ | ||
const compileTemplate = (filePath) => { | ||
return Handlebars.compile(fs.readFileSync(path.join(__dirname, filePath)).toString()); | ||
}; | ||
/** | ||
* [createFileName description] | ||
* @param {[type]} data [description] | ||
* @param {[type]} ext [description] | ||
* @return {[type]} [description] | ||
*/ | ||
const createFileName = (data, ext) => { | ||
if ('adoc' === ext) { | ||
if (data.fullName === 'tinymce') { | ||
return (BASE_PATH + '/tinymce.root.adoc').toLowerCase(); | ||
} | ||
return (BASE_PATH + '/' + data.fullName + '.adoc').toLowerCase(); | ||
} | ||
else if ('json' === ext) { | ||
return ('_data/api/' + data.type + '_' + data.fullName.replace(/\./g, '_') + '.json').toLowerCase(); | ||
} | ||
}; | ||
/** | ||
* [addPageToArchive description] | ||
@@ -230,7 +141,8 @@ * @param {[type]} page [description] | ||
* @param {[type]} toPath [description] | ||
* @param {[type]} structure [description] | ||
* @return {[type]} [description] | ||
*/ | ||
const template = (root, toPath) => { | ||
const template = (root, toPath, structure) => { | ||
const archive = new moxie_zip_1.ZipWriter(); | ||
const memberTemplate = compileTemplate('member.handlebars'); | ||
const memberTemplate = Util.compileTemplate('member.handlebars'); | ||
// bind new archive to function | ||
@@ -250,15 +162,14 @@ const addPage = addPageToArchive.bind(archive); | ||
}); | ||
const nav = getNavFile(sortedTypes); | ||
const adocNav = navToAdoc(nav); | ||
addPage({ | ||
filename: '_data/nav.yml', | ||
content: YAML.dump(nav) | ||
const indexPage = Util.getNavFile(sortedTypes); | ||
const navPages = Util.generateNavPages(indexPage, structure); | ||
if (structure === 'legacy') { | ||
Util.generateIndexPages(indexPage, sortedTypes, memberTemplate, structure) | ||
.forEach((pageOutput) => navPages.push(pageOutput)); | ||
} | ||
navPages.forEach((page) => { | ||
addPage(page); | ||
}); | ||
addPage({ | ||
filename: '_data/moxiedoc_nav.adoc', | ||
content: adocNav | ||
}); | ||
// create all json and adoc for each item | ||
const pages = sortedTypes.map(getMemberPages.bind(null, root, memberTemplate)); | ||
const convertedPages = AntoraTemplate.convert(pages); | ||
const pages = sortedTypes.map(getMemberPages.bind(null, root, memberTemplate, structure)); | ||
const convertedPages = AntoraTemplate.convert(pages, structure); | ||
flatten(convertedPages).forEach(addPage); | ||
@@ -265,0 +176,0 @@ archive.saveAs(toPath, (err) => { |
{ | ||
"name": "@tinymce/moxiedoc", | ||
"version": "0.2.2-rc.20220622065305759.sha4aa7bcb", | ||
"version": "0.3.0-feature.20220822040129921.sha302e003", | ||
"description": "A tool for generating API documentation", | ||
@@ -5,0 +5,0 @@ "author": "Tiny Technologies, Inc", |
# moxiedoc | ||
## Introduction | ||
This project maintains Moxiedoc, a tool used to build API reference documentation. If you have any modifications you wish to contribute, fork this project, make the changes and submit a pull request. You will need to sign the contributors license agreement, which will be emailed to you upon creating the pull request. | ||
## Using Moxiedoc | ||
To create API reference documentation from a development version of moxiedoc, run: | ||
``` | ||
yarn build | ||
node ./dist/lib/cli.js PATH/TO/API_FILE_FOLDER | ||
``` | ||
## Moxiedoc Options | ||
Moxiedoc provides the following options to customise the format of the output documentation: | ||
``` | ||
-o --out <path>: location of output files, default: 'tmp/out.zip' | ||
-t --template <template>: documentation type: default: 'cli'; 'antora', 'github', 'moxiewiki', 'singlehtml', 'tinymcenext', 'xml' | ||
-s --structure <type>: default: 'flat', 'legacy' | ||
-v --verbose: verbose output | ||
--debug: debug output | ||
--dry: dry run only syntax check | ||
--fail-on-warning: fail if warnings are produced | ||
``` | ||
## Schema | ||
The output JSON takes the form of the following schema: | ||
```json | ||
@@ -4,0 +35,0 @@ { |
@@ -11,6 +11,7 @@ #! /usr/bin/env node | ||
program | ||
.version('0.2.0') | ||
.version('0.3.0') | ||
.usage('[options] <dir ...>') | ||
.option('-o, --out <path>', 'output path, default: out') | ||
.option('-t, --template <template>', 'template name') | ||
.option('-t, --template <template>', 'template name, default: cli') | ||
.option('-s, --structure <type>', 'output file structure') | ||
.option('-v, --verbose', 'verbose output') | ||
@@ -17,0 +18,0 @@ .option('--debug', 'debug output') |
import { Api } from './api'; | ||
export type ExportStructure = 'default' | 'legacy'; | ||
export interface ExporterSettings { | ||
readonly template: string; | ||
readonly structure: ExportStructure; | ||
} | ||
@@ -28,3 +31,3 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require(templatePath).template.call(this, types, dirPath); | ||
require(templatePath).template.call(this, types, dirPath, this.settings.structure); | ||
} | ||
@@ -35,2 +38,2 @@ } | ||
Exporter | ||
}; | ||
}; |
@@ -6,3 +6,3 @@ import * as fs from 'fs'; | ||
import { Builder } from './builder'; | ||
import { Exporter } from './exporter'; | ||
import { Exporter, ExportStructure } from './exporter'; | ||
import * as Reporter from './reporter'; | ||
@@ -16,2 +16,3 @@ | ||
template?: string; | ||
structure?: ExportStructure; | ||
verbose?: boolean; | ||
@@ -49,2 +50,3 @@ debug?: boolean; | ||
settings.template = settings.template || 'cli'; | ||
settings.structure = settings.structure || 'default'; | ||
@@ -105,3 +107,4 @@ if (settings.verbose) { | ||
const exporter = new Exporter({ | ||
template: settings.template | ||
template: settings.template, | ||
structure: settings.structure | ||
}); | ||
@@ -117,2 +120,2 @@ | ||
process | ||
}; | ||
}; |
@@ -0,13 +1,9 @@ | ||
import { ExportStructure } from 'src/lib/exporter'; | ||
import { Return } from '../../lib/member'; | ||
import { Param } from '../../lib/param'; | ||
import { PageOutput } from './util'; | ||
import * as Util from './util'; | ||
export interface PageOutput { | ||
readonly type: 'adoc' | 'json'; | ||
readonly filename: string; | ||
readonly content: string; | ||
} | ||
// TODO: we can pass this through later | ||
const basePath = 'apis/'; | ||
const hasValue = <T>(x: T): x is NonNullable<T> => { | ||
@@ -82,16 +78,2 @@ // empty helper for strings, objects, arrays | ||
const getNameFromFullName = (name: string): string => | ||
name.split('.').slice(-1).join(''); | ||
const getFilePathFromFullName = (name: string): string => { | ||
const filename = name.toLowerCase() === 'tinymce' ? 'tinymce.root' : name.toLowerCase(); | ||
return basePath + filename + '.adoc'; | ||
}; | ||
const generateTypeXref = (type: string): string => | ||
type.includes('tinymce', 0) ? 'xref:' + getFilePathFromFullName(type) + '[' + getNameFromFullName(type) + ']' : type; | ||
const generateDefinedByXref = (definedBy: string): string => | ||
'xref:' + getFilePathFromFullName(definedBy) + '[' + getNameFromFullName(definedBy) + ']'; | ||
const generateExamples = (examples: Array<{ content: string }>): string => { | ||
@@ -108,6 +90,6 @@ let tmp = '\n==== Examples\n'; | ||
const generateParameters = (params: Param[]): string => { | ||
const generateParameters = (params: Param[], structure: ExportStructure): string => { | ||
let tmp = '\n==== Parameters\n'; | ||
params.forEach((param) => { | ||
tmp += '\n* `' + param.name + ' (' + param.types.map(generateTypeXref).join(' | ') + ')` - ' + cleanup(param.desc); | ||
tmp += '\n* `' + param.name + ' (' + param.types.map((type) => Util.generateTypeXref(type, structure)).join(' | ') + ')` - ' + cleanup(param.desc); | ||
}); | ||
@@ -117,12 +99,11 @@ return tmp + '\n'; | ||
const generateReturn = (ret: Return): string => { | ||
const generateReturn = (ret: Return, structure: ExportStructure): string => { | ||
let tmp = '\n==== Return value\n'; | ||
ret.types.forEach((type) => { | ||
tmp += '\n* `' + generateTypeXref(type) + '` - ' + cleanup(ret.desc); | ||
tmp += '\n* `' + Util.generateTypeXref(type, structure) + '` - ' + cleanup(ret.desc); | ||
}); | ||
tmp += '\n'; | ||
return tmp; | ||
return tmp += '\n'; | ||
}; | ||
const buildSummary = (data: Record<string, any>): string => { | ||
const buildSummary = (data: Record<string, any>, structure: ExportStructure): string => { | ||
let tmp = ''; | ||
@@ -142,5 +123,5 @@ | ||
tmp += '|' + item.name; | ||
tmp += '|`' + generateTypeXref(item.dataTypes[0]) + '`'; | ||
tmp += '|`' + Util.generateTypeXref(item.dataTypes[0], structure) + '`'; | ||
tmp += '|' + cleanup(item.desc); | ||
tmp += '|`' + generateDefinedByXref(item.definedBy) + '`\n'; | ||
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n'; | ||
}); | ||
@@ -161,5 +142,5 @@ tmp += '|===\n'; | ||
tmp += '|' + item.name; | ||
tmp += '|`' + generateTypeXref(item.dataTypes[0]) + '`'; | ||
tmp += '|`' + Util.generateTypeXref(item.dataTypes[0], structure) + '`'; | ||
tmp += '|' + cleanup(item.desc); | ||
tmp += '|`' + generateDefinedByXref(item.definedBy) + '`\n'; | ||
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n'; | ||
}); | ||
@@ -181,3 +162,3 @@ tmp += '|===\n'; | ||
tmp += '|' + cleanup(item.desc); | ||
tmp += '|`' + generateDefinedByXref(item.definedBy) + '`\n'; | ||
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n'; | ||
}); | ||
@@ -195,3 +176,3 @@ tmp += '|===\n'; | ||
data.methods.forEach((item) => { | ||
tmp += '|xref:#' + item.name + '[' + item.name + '()]|' + cleanup(item.desc) + '|`' + generateDefinedByXref(item.definedBy) + '`\n'; | ||
tmp += '|xref:#' + item.name + '[' + item.name + '()]|' + cleanup(item.desc) + '|`' + Util.generateXref(item.definedBy, structure) + '`\n'; | ||
}); | ||
@@ -214,3 +195,3 @@ tmp += '|===\n'; | ||
tmp += '|' + cleanup(item.desc); | ||
tmp += '|`' + generateDefinedByXref(item.definedBy) + '`\n'; | ||
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n'; | ||
}); | ||
@@ -223,3 +204,3 @@ tmp += '|===\n'; | ||
const buildConstructor = (data: Record<string, any>): string => { | ||
const buildConstructor = (data: Record<string, any>, structure: ExportStructure): string => { | ||
let tmp = ''; | ||
@@ -245,7 +226,7 @@ | ||
if (hasValue(constructor.params)) { | ||
tmp += generateParameters(constructor.params); | ||
tmp += generateParameters(constructor.params, structure); | ||
} | ||
if (hasValue(constructor.return) && hasValue(constructor.return.types)) { | ||
tmp += generateReturn(constructor.return); | ||
tmp += generateReturn(constructor.return, structure); | ||
} | ||
@@ -258,3 +239,3 @@ }); | ||
const buildMethods = (data: Record<string, any>): string => { | ||
const buildMethods = (data: Record<string, any>, structure: ExportStructure): string => { | ||
let tmp = ''; | ||
@@ -279,7 +260,7 @@ | ||
if (hasValue(method.params)) { | ||
tmp += generateParameters(method.params); | ||
tmp += generateParameters(method.params, structure); | ||
} | ||
if (hasValue(method.return) && hasValue(method.return.types)) { | ||
tmp += generateReturn(method.return); | ||
tmp += generateReturn(method.return, structure); | ||
} | ||
@@ -294,3 +275,3 @@ | ||
const buildEvents = (data: Record<string, any>): string => { | ||
const buildEvents = (data: Record<string, any>, structure: ExportStructure): string => { | ||
let tmp = ''; | ||
@@ -308,3 +289,3 @@ | ||
if (hasValue(event.params)) { | ||
tmp += generateParameters(event.params); | ||
tmp += generateParameters(event.params, structure); | ||
} | ||
@@ -317,3 +298,3 @@ }); | ||
const convert = (pages: PageOutput[][]): PageOutput[][] => pages.map((page) => { | ||
const convert = (pages: PageOutput[][], structure: ExportStructure): PageOutput[][] => pages.map((page) => { | ||
// page[0] is json | ||
@@ -352,3 +333,3 @@ // page[1] is adoc | ||
data.borrows.forEach((item) => { | ||
tmp += '\n * xref:' + basePath + item.toLowerCase() + '.adoc[' + item + ']\n'; | ||
tmp += '\n * ' + Util.generateXref(item, structure) + '\n'; | ||
}); | ||
@@ -369,6 +350,6 @@ } | ||
tmp += buildSummary(data); | ||
tmp += buildConstructor(data); | ||
tmp += buildMethods(data); | ||
tmp += buildEvents(data); | ||
tmp += buildSummary(data, structure); | ||
tmp += buildConstructor(data, structure); | ||
tmp += buildMethods(data, structure); | ||
tmp += buildEvents(data, structure); | ||
@@ -375,0 +356,0 @@ // return the applied antora page mutation |
@@ -1,6 +0,3 @@ | ||
import * as fs from 'fs'; | ||
import * as Handlebars from 'handlebars'; | ||
import * as YAML from 'js-yaml'; | ||
import { ZipWriter } from 'moxie-zip'; | ||
import * as path from 'path'; | ||
import { ExportStructure } from 'src/lib/exporter'; | ||
@@ -10,84 +7,6 @@ import { Api } from '../../lib/api'; | ||
import * as AntoraTemplate from './antora.converter'; | ||
import { PageOutput } from './util'; | ||
import * as Util from './util'; | ||
interface NavFile { | ||
readonly title: string; | ||
readonly path: string; | ||
readonly pages?: NavFile[]; | ||
} | ||
type PageOutput = AntoraTemplate.PageOutput; | ||
const BASE_PATH = process.env.BASE_PATH || '/_data/antora'; | ||
// correlates to tinymce-docs antora path | ||
const AntoraNavBaseDir = 'apis/'; | ||
const navToAdoc = (navyml: NavFile[]): string => { | ||
// Api index page | ||
const indexPage = navyml[0]; | ||
let adoc = '* ' + indexPage.title + '\n'; | ||
// generate API namespaces | ||
indexPage.pages.forEach((namespace) => { | ||
// main namespace level navigation (namespace index) | ||
adoc += '** ' + namespace.path + '\n'; | ||
namespace.pages.forEach((page) => { | ||
// namespace level pages | ||
adoc += '*** xref:' + AntoraNavBaseDir + page.path + '.adoc' + '[' + page.title + ']\n'; | ||
}); | ||
}); | ||
return adoc; | ||
}; | ||
const getNamespaceFromFullName = (fullName: string) => | ||
fullName.split('.').slice(0, -1).join('.'); | ||
const getNamespacesFromTypes = (types: Type[]): Record<string, string> => { | ||
return types.reduce((namespaces: Record<string, string>, type: Type) => { | ||
const fullName = type.fullName.toLowerCase(); | ||
const url = getNamespaceFromFullName(fullName); | ||
if (url && !namespaces[url]) { | ||
namespaces[url] = getNamespaceFromFullName(type.fullName); | ||
} | ||
return namespaces; | ||
}, {}); | ||
}; | ||
/** | ||
* [getNavFile description] | ||
* @return {[type]} [description] | ||
*/ | ||
const getNavFile = (types: Type[]): NavFile[] => { | ||
const namespaces = getNamespacesFromTypes(types); | ||
const pages = Object.entries(namespaces).map(([ url, title ]): NavFile => { | ||
const innerPages = types.filter((type) => { | ||
const fullName = type.fullName.toLowerCase(); | ||
return getNamespaceFromFullName(fullName) === url; | ||
}).map((type): NavFile => { | ||
return { title: type.fullName, path: type.fullName.toLowerCase() }; | ||
}); | ||
if (url === 'tinymce') { | ||
innerPages.unshift({ | ||
title: 'tinymce', | ||
path: 'tinymce.root' | ||
}); | ||
} | ||
return { | ||
title, | ||
path: url, | ||
pages: innerPages | ||
}; | ||
}); | ||
return [{ | ||
title: 'API Reference', | ||
path: BASE_PATH, | ||
pages | ||
}]; | ||
}; | ||
/** | ||
* [description] | ||
@@ -99,3 +18,3 @@ * @param {[type]} root [description] | ||
*/ | ||
const getMemberPages = (root: Api, templateDelegate: HandlebarsTemplateDelegate, type: Type): PageOutput[] => { | ||
const getMemberPages = (root: Api, templateDelegate: HandlebarsTemplateDelegate, structure: ExportStructure, type: Type): PageOutput[] => { | ||
const members = type.getMembers(true); | ||
@@ -124,3 +43,2 @@ const data = type.toJSON(); | ||
const parentType = member.getParentType(); | ||
const memberData = member.toJSON(); | ||
@@ -130,27 +48,24 @@ data.keywords.push(memberData.name); | ||
if ('property' === memberData.type) { | ||
data.properties.push(memberData); | ||
return; | ||
} | ||
switch (memberData.type) { | ||
case 'property': | ||
data.properties.push(memberData); | ||
return; | ||
if ('setting' === memberData.type) { | ||
data.settings.push(memberData); | ||
return; | ||
} | ||
case 'setting': | ||
data.settings.push(memberData); | ||
return; | ||
if ('constructor' === memberData.type) { | ||
data.constructors.push(memberData); | ||
memberData.signature = getSyntaxString(memberData); | ||
return; | ||
} | ||
case 'constructor': | ||
data.constructors.push(memberData); | ||
memberData.signature = getSyntaxString(memberData); | ||
return; | ||
if ('method' === memberData.type) { | ||
data.methods.push(memberData); | ||
memberData.signature = getSyntaxString(memberData); | ||
return; | ||
} | ||
case 'method': | ||
data.methods.push(memberData); | ||
memberData.signature = getSyntaxString(memberData); | ||
return; | ||
if ('event' === memberData.type) { | ||
data.events.push(memberData); | ||
return; | ||
case 'event': | ||
data.events.push(memberData); | ||
return; | ||
} | ||
@@ -167,9 +82,12 @@ }); | ||
data.keywords = data.keywords.join(', '); | ||
const jsonFilePath = Util.getJsonFilePath(data.type, data.fullName); | ||
const adocFilePath = Util.getFilePath(data.fullName, structure); | ||
return [{ | ||
type: 'json', | ||
filename: createFileName(data, 'json'), | ||
filename: jsonFilePath, | ||
content: JSON.stringify(data, null, ' ') | ||
}, { | ||
type: 'adoc', | ||
filename: createFileName(data, 'adoc'), | ||
filename: adocFilePath, | ||
content: templateDelegate(data) | ||
@@ -206,33 +124,6 @@ }]; | ||
/** | ||
* [compileTemplate description] | ||
* @param {[type]} filePath [description] | ||
* @return {[type]} [description] | ||
*/ | ||
const compileTemplate = (filePath: string): HandlebarsTemplateDelegate => { | ||
return Handlebars.compile(fs.readFileSync(path.join(__dirname, filePath)).toString()); | ||
}; | ||
/** | ||
* [createFileName description] | ||
* @param {[type]} data [description] | ||
* @param {[type]} ext [description] | ||
* @return {[type]} [description] | ||
*/ | ||
const createFileName = (data: Record<string, any>, ext: 'adoc' | 'json'): string => { | ||
if ('adoc' === ext) { | ||
if (data.fullName === 'tinymce') { | ||
return (BASE_PATH + '/tinymce.root.adoc').toLowerCase(); | ||
} | ||
return (BASE_PATH + '/' + data.fullName + '.adoc').toLowerCase(); | ||
} else if ('json' === ext) { | ||
return ('_data/api/' + data.type + '_' + data.fullName.replace(/\./g, '_') + '.json').toLowerCase(); | ||
} | ||
}; | ||
/** | ||
* [addPageToArchive description] | ||
* @param {[type]} page [description] | ||
*/ | ||
const addPageToArchive = function (this: ZipWriter, page: { filename: string; content: string }) { | ||
const addPageToArchive = function (this: ZipWriter, page: PageOutput) { | ||
this.addData(page.filename, page.content); | ||
@@ -275,7 +166,8 @@ }; | ||
* @param {[type]} toPath [description] | ||
* @param {[type]} structure [description] | ||
* @return {[type]} [description] | ||
*/ | ||
const template = (root: Api, toPath: string): void => { | ||
const template = (root: Api, toPath: string, structure: ExportStructure): void => { | ||
const archive = new ZipWriter(); | ||
const memberTemplate = compileTemplate('member.handlebars'); | ||
const memberTemplate = Util.compileTemplate('member.handlebars'); | ||
@@ -296,18 +188,19 @@ // bind new archive to function | ||
const nav = getNavFile(sortedTypes); | ||
const adocNav = navToAdoc(nav); | ||
const indexPage = Util.getNavFile(sortedTypes); | ||
addPage({ | ||
filename: '_data/nav.yml', | ||
content: YAML.dump(nav) | ||
}); | ||
const navPages = Util.generateNavPages(indexPage, structure); | ||
addPage({ | ||
filename: '_data/moxiedoc_nav.adoc', | ||
content: adocNav | ||
if (structure === 'legacy') { | ||
Util.generateIndexPages(indexPage, sortedTypes, memberTemplate, structure) | ||
.forEach((pageOutput) => navPages.push(pageOutput)); | ||
} | ||
navPages.forEach((page) => { | ||
addPage(page); | ||
}); | ||
// create all json and adoc for each item | ||
const pages: PageOutput[][] = sortedTypes.map(getMemberPages.bind(null, root, memberTemplate)); | ||
const convertedPages = AntoraTemplate.convert(pages); | ||
const pages: PageOutput[][] = sortedTypes.map(getMemberPages.bind(null, root, memberTemplate, structure)); | ||
const convertedPages = AntoraTemplate.convert(pages, structure); | ||
flatten(convertedPages).forEach(addPage); | ||
@@ -314,0 +207,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
366097
141
6930
65