@tinymce/moxiedoc
Advanced tools
Comparing version 0.2.2-feature.20220708015625385.sha44d977d to 0.2.2-feature.20220711080318333.sha1e32633
@@ -13,2 +13,3 @@ #! /usr/bin/env node | ||
.option('-t, --template <template>', 'template name') | ||
.option('-s, --structure <type>', 'output file structure, default: flat') | ||
.option('-v, --verbose', 'verbose output') | ||
@@ -18,3 +19,2 @@ .option('--debug', 'debug output') | ||
.option('--fail-on-warning', 'fail if warnings are produced') | ||
.option('-l, <name>/--legacy', 'output file structure, default: flat') | ||
.parse(process.argv); | ||
@@ -21,0 +21,0 @@ commander_1.program.on('--help', () => { |
export interface MoxiedocSettings { | ||
out?: string; | ||
template?: string; | ||
structure?: string; | ||
verbose?: boolean; | ||
@@ -9,3 +10,2 @@ debug?: boolean; | ||
failOnWarning?: boolean; | ||
legacy?: string; | ||
} | ||
@@ -12,0 +12,0 @@ export interface MoxiedocResult { |
@@ -32,3 +32,3 @@ "use strict"; | ||
settings.template = settings.template || 'cli'; | ||
settings.legacy = settings.legacy || 'flat'; | ||
settings.structure = settings.structure || 'flat'; | ||
if (settings.verbose) { | ||
@@ -77,3 +77,3 @@ Reporter.setLevel(2 /* INFO */); | ||
}); | ||
builder.api.setStructure(settings.legacy); | ||
builder.api.setStructure(settings.structure); | ||
builder.api.removePrivates(); | ||
@@ -80,0 +80,0 @@ if (!settings.dry) { |
@@ -7,5 +7,4 @@ export interface PageOutput { | ||
declare const getFilePath: (structure: string) => Function; | ||
declare const generateXref: (name: string, structure: string) => string; | ||
declare const convert: (pages: PageOutput[][], structure: string) => PageOutput[][]; | ||
export { getFilePath, generateXref, convert }; | ||
export { getFilePath, convert }; | ||
//# sourceMappingURL=antora.converter.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.convert = exports.generateXref = exports.getFilePath = void 0; | ||
exports.convert = exports.getFilePath = void 0; | ||
const hasValue = (x) => { | ||
@@ -60,3 +60,2 @@ // empty helper for strings, objects, arrays | ||
}; | ||
const getNameFromFullName = (name) => name.split('.').slice(-1).join(''); | ||
const getFilePathFromFullName = (name) => { | ||
@@ -67,19 +66,12 @@ const filename = name.toLowerCase() === 'tinymce' ? 'tinymce.root' : name.toLowerCase(); | ||
const getFilePathFromFullNameLegacy = (name) => { | ||
const folder = getNameFromFullName(name) + '/'; | ||
const filename = name.toLowerCase() === 'tinymce' ? 'root_tinymce' : name.toLowerCase(); | ||
const folder = name.split('.').slice(0, -1).join('.') + '/'; | ||
const filename = name.toLowerCase() === 'tinymce' ? 'tinymce/root_tinymce' : name.toLowerCase(); | ||
return 'api/' + folder + filename + '.adoc'; | ||
}; | ||
const getFilePath = (structure) => { | ||
switch (structure) { | ||
case 'flat': | ||
return getFilePathFromFullName; | ||
case 'legacy': | ||
return getFilePathFromFullNameLegacy; | ||
default: | ||
return getFilePathFromFullName; | ||
} | ||
const getFilePath = (structure) => structure === 'legacy' ? getFilePathFromFullNameLegacy : getFilePathFromFullName; | ||
exports.getFilePath = getFilePath; | ||
const generateXref = (name, structure, title) => { | ||
title = title || name.split('.').slice(-1).join(''); | ||
return 'xref:' + getFilePath(structure)(name) + '[' + title + ']'; | ||
}; | ||
exports.getFilePath = getFilePath; | ||
const generateXref = (name, structure) => 'xref:' + getFilePath(structure)(name) + '[' + getNameFromFullName(name) + ']'; | ||
exports.generateXref = generateXref; | ||
const generateTypeXref = (type, structure) => type.includes('tinymce', 0) ? generateXref(type, structure) : type; | ||
@@ -86,0 +78,0 @@ const generateExamples = (examples) => { |
@@ -10,16 +10,31 @@ "use strict"; | ||
const AntoraTemplate = require("./antora.converter"); | ||
const BASE_PATH = process.env.BASE_PATH || '/_data/antora'; | ||
const generateXref = (basePath, filename, title) => 'xref:' + basePath + '/' + filename + '[' + title + ']'; | ||
const navLine = (name, level) => '*'.repeat(level) + ' ' + name + '\n'; | ||
const navToAdoc = (indexPage, structure, depth, level) => { | ||
level = level || 1; | ||
// Api index page top level or blank | ||
let adoc = level === 1 ? navLine(indexPage.title, level) : ''; | ||
indexPage.pages.forEach((namespace) => { | ||
adoc += navLine(AntoraTemplate.generateXref(namespace.path, structure), level + 1); | ||
if (level < depth) { | ||
adoc += navToAdoc(namespace, structure, depth, level + 1); | ||
} | ||
}); | ||
const navToAdoc = (indexPage, structure) => { | ||
// Api index nav page top level | ||
let adoc = navLine(indexPage.title, 1); | ||
if (indexPage.pages) { | ||
indexPage.pages.forEach((namespace) => { | ||
const namespaceLine = structure === 'legacy' ? generateXref('api/' + namespace.path, namespace.path + '_nav.adoc', namespace.title) : namespace.title; | ||
adoc += navLine(namespaceLine, 2); | ||
if (namespace.pages) { | ||
namespace.pages.forEach((pageFile) => { | ||
const pagePath = structure === 'legacy' ? 'api/' + namespace.path : 'apis'; | ||
adoc += navLine(generateXref(pagePath, pageFile.path + '.adoc', pageFile.title), 3); | ||
}); | ||
} | ||
}); | ||
} | ||
return adoc; | ||
}; | ||
const namespaceNavToAdoc = (namespace) => { | ||
let adoc = navLine(namespace.title, 1); | ||
if (namespace.pages) { | ||
namespace.pages.forEach((pageFile) => { | ||
const namespaceLine = generateXref('api/' + namespace.path, pageFile.path + '.adoc', pageFile.title); | ||
adoc += navLine(namespaceLine, 2); | ||
}); | ||
} | ||
return adoc; | ||
}; | ||
const getNamespaceFromFullName = (fullName) => fullName.split('.').slice(0, -1).join('.'); | ||
@@ -64,3 +79,3 @@ const getNamespacesFromTypes = (types) => { | ||
title: 'API Reference', | ||
path: BASE_PATH, | ||
path: '/_data/antora', | ||
pages | ||
@@ -227,3 +242,3 @@ }]; | ||
const indexPage = nav[0]; | ||
const adocNav = navToAdoc(indexPage, structure, 3); | ||
const adocNav = navToAdoc(indexPage, structure); | ||
addPage({ | ||
@@ -239,6 +254,5 @@ filename: '_data/nav.yml', | ||
indexPage.pages.forEach((namespace) => { | ||
const indexNav = navToAdoc(namespace, structure, 2); | ||
addPage({ | ||
filename: '_data/' + namespace.title + '_nav.adoc', | ||
content: indexNav | ||
filename: 'api/' + namespace.path + '/' + namespace.path + '_nav.adoc', | ||
content: namespaceNavToAdoc(namespace) | ||
}); | ||
@@ -245,0 +259,0 @@ }); |
{ | ||
"name": "@tinymce/moxiedoc", | ||
"version": "0.2.2-feature.20220708015625385.sha44d977d", | ||
"version": "0.2.2-feature.20220711080318333.sha1e32633", | ||
"description": "A tool for generating API documentation", | ||
@@ -5,0 +5,0 @@ "author": "Tiny Technologies, Inc", |
@@ -15,2 +15,3 @@ #! /usr/bin/env node | ||
.option('-t, --template <template>', 'template name') | ||
.option('-s, --structure <type>', 'output file structure, default: flat') | ||
.option('-v, --verbose', 'verbose output') | ||
@@ -20,3 +21,2 @@ .option('--debug', 'debug output') | ||
.option('--fail-on-warning', 'fail if warnings are produced') | ||
.option('-l, <name>/--legacy', 'output file structure, default: flat') | ||
.parse(process.argv); | ||
@@ -23,0 +23,0 @@ |
@@ -15,2 +15,3 @@ import * as fs from 'fs'; | ||
template?: string; | ||
structure?: string; | ||
verbose?: boolean; | ||
@@ -21,3 +22,2 @@ debug?: boolean; | ||
failOnWarning?: boolean; | ||
legacy?: string; | ||
} | ||
@@ -50,3 +50,3 @@ | ||
settings.template = settings.template || 'cli'; | ||
settings.legacy = settings.legacy || 'flat'; | ||
settings.structure = settings.structure || 'flat'; | ||
@@ -103,3 +103,3 @@ if (settings.verbose) { | ||
builder.api.setStructure(settings.legacy); | ||
builder.api.setStructure(settings.structure); | ||
@@ -106,0 +106,0 @@ builder.api.removePrivates(); |
@@ -79,5 +79,2 @@ import { Return } from '../../lib/member'; | ||
const getNameFromFullName = (name: string): string => | ||
name.split('.').slice(-1).join(''); | ||
const getFilePathFromFullName = (name: string): string => { | ||
@@ -89,23 +86,15 @@ const filename = name.toLowerCase() === 'tinymce' ? 'tinymce.root' : name.toLowerCase(); | ||
const getFilePathFromFullNameLegacy = (name: string): string => { | ||
const folder = getNameFromFullName(name) + '/'; | ||
const filename = name.toLowerCase() === 'tinymce' ? 'root_tinymce' : name.toLowerCase(); | ||
const folder = name.split('.').slice(0, -1).join('.') + '/'; | ||
const filename = name.toLowerCase() === 'tinymce' ? 'tinymce/root_tinymce' : name.toLowerCase(); | ||
return 'api/' + folder + filename + '.adoc'; | ||
}; | ||
const getFilePath = (structure: string): Function => { | ||
switch (structure) { | ||
case 'flat': | ||
return getFilePathFromFullName; | ||
const getFilePath = (structure: string): Function => | ||
structure === 'legacy' ? getFilePathFromFullNameLegacy : getFilePathFromFullName; | ||
case 'legacy': | ||
return getFilePathFromFullNameLegacy; | ||
default: | ||
return getFilePathFromFullName; | ||
} | ||
const generateXref = (name: string, structure: string, title?: string): string => { | ||
title = title || name.split('.').slice(-1).join(''); | ||
return 'xref:' + getFilePath(structure)(name) + '[' + title + ']'; | ||
}; | ||
const generateXref = (name: string, structure: string): string => | ||
'xref:' + getFilePath(structure)(name) + '[' + getNameFromFullName(name) + ']'; | ||
const generateTypeXref = (type: string, structure: string): string => | ||
@@ -385,4 +374,3 @@ type.includes('tinymce', 0) ? generateXref(type, structure) : type; | ||
getFilePath, | ||
generateXref, | ||
convert | ||
}; |
@@ -19,3 +19,4 @@ import * as fs from 'fs'; | ||
const BASE_PATH = process.env.BASE_PATH || '/_data/antora'; | ||
const generateXref = (basePath: string, filename: string, title: string) => | ||
'xref:' + basePath + '/' + filename + '[' + title + ']'; | ||
@@ -25,13 +26,28 @@ const navLine = (name: string, level: number): string => | ||
const navToAdoc = (indexPage: NavFile, structure: string, depth: number, level?: number): string => { | ||
level = level || 1; | ||
// Api index page top level or blank | ||
let adoc = level === 1 ? navLine(indexPage.title, level) : ''; | ||
const navToAdoc = (indexPage: NavFile, structure: string): string => { | ||
// Api index nav page top level | ||
let adoc = navLine(indexPage.title, 1); | ||
if (indexPage.pages) { | ||
indexPage.pages.forEach((namespace) => { | ||
const namespaceLine = structure === 'legacy' ? generateXref('api/' + namespace.path, namespace.path + '_nav.adoc', namespace.title) : namespace.title; | ||
adoc += navLine(namespaceLine, 2); | ||
if (namespace.pages) { | ||
namespace.pages.forEach((pageFile) => { | ||
const pagePath = structure === 'legacy' ? 'api/' + namespace.path : 'apis'; | ||
adoc += navLine(generateXref(pagePath, pageFile.path + '.adoc', pageFile.title), 3); | ||
}); | ||
} | ||
}); | ||
} | ||
return adoc; | ||
}; | ||
indexPage.pages.forEach((namespace) => { | ||
adoc += navLine(AntoraTemplate.generateXref(namespace.path, structure), level + 1); | ||
if (level < depth) { | ||
adoc += navToAdoc(namespace, structure, depth, level + 1); | ||
} | ||
}); | ||
const namespaceNavToAdoc = (namespace: NavFile): string => { | ||
let adoc = navLine(namespace.title, 1); | ||
if (namespace.pages) { | ||
namespace.pages.forEach((pageFile) => { | ||
const namespaceLine = generateXref('api/' + namespace.path, pageFile.path + '.adoc', pageFile.title); | ||
adoc += navLine(namespaceLine, 2); | ||
}); | ||
} | ||
return adoc; | ||
@@ -85,3 +101,3 @@ }; | ||
title: 'API Reference', | ||
path: BASE_PATH, | ||
path: '/_data/antora', | ||
pages | ||
@@ -270,3 +286,3 @@ }]; | ||
const indexPage = nav[0]; | ||
const adocNav = navToAdoc(indexPage, structure, 3); | ||
const adocNav = navToAdoc(indexPage, structure); | ||
@@ -285,6 +301,5 @@ addPage({ | ||
indexPage.pages.forEach((namespace) => { | ||
const indexNav = navToAdoc(namespace, structure, 2); | ||
addPage({ | ||
filename: '_data/' + namespace.title + '_nav.adoc', | ||
content: indexNav | ||
filename: 'api/' + namespace.path + '/' + namespace.path + '_nav.adoc', | ||
content: namespaceNavToAdoc(namespace) | ||
}); | ||
@@ -291,0 +306,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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
351739
6731
15