Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tinymce/moxiedoc

Package Overview
Dependencies
Maintainers
2
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinymce/moxiedoc - npm Package Compare versions

Comparing version 0.2.2-feature.20220719062619425.sha8afdb27 to 0.2.2-feature.20220725071105651.sha5bda993

5

dist/templates/antora/antora.converter.d.ts

@@ -1,4 +0,5 @@

import { Util, PageOutput } from './util';
declare const convert: (pages: PageOutput[][], util: Util) => 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

53

dist/templates/antora/antora.converter.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convert = void 0;
const Util = require("./util");
const hasValue = (x) => {

@@ -70,17 +71,17 @@ // empty helper for strings, objects, arrays

};
const generateParameters = (params, util) => {
const generateParameters = (params, structure) => {
let tmp = '\n==== Parameters\n';
params.forEach((param) => {
tmp += '\n* `' + param.name + ' (' + param.types.map((type) => util.generateTypeXref(type)).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, util) => {
const generateReturn = (ret, structure) => {
let tmp = '\n==== Return value\n';
ret.types.forEach((type) => {
tmp += '\n* `' + util.generateTypeXref(type) + '` - ' + cleanup(ret.desc);
tmp += '\n* `' + Util.generateTypeXref(type, structure) + '` - ' + cleanup(ret.desc);
});
return tmp += '\n';
};
const buildSummary = (data, util) => {
const buildSummary = (data, structure) => {
let tmp = '';

@@ -97,5 +98,5 @@ // settings

tmp += '|' + item.name;
tmp += '|`' + util.generateTypeXref(item.dataTypes[0]) + '`';
tmp += '|`' + Util.generateTypeXref(item.dataTypes[0], structure) + '`';
tmp += '|' + cleanup(item.desc);
tmp += '|`' + util.generateXref(item.definedBy) + '`\n';
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n';
});

@@ -113,5 +114,5 @@ tmp += '|===\n';

tmp += '|' + item.name;
tmp += '|`' + util.generateTypeXref(item.dataTypes[0]) + '`';
tmp += '|`' + Util.generateTypeXref(item.dataTypes[0], structure) + '`';
tmp += '|' + cleanup(item.desc);
tmp += '|`' + util.generateXref(item.definedBy) + '`\n';
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n';
});

@@ -130,3 +131,3 @@ tmp += '|===\n';

tmp += '|' + cleanup(item.desc);
tmp += '|`' + util.generateXref(item.definedBy) + '`\n';
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n';
});

@@ -143,3 +144,3 @@ tmp += '|===\n';

data.methods.forEach((item) => {
tmp += '|xref:#' + item.name + '[' + item.name + '()]|' + cleanup(item.desc) + '|`' + util.generateXref(item.definedBy) + '`\n';
tmp += '|xref:#' + item.name + '[' + item.name + '()]|' + cleanup(item.desc) + '|`' + Util.generateXref(item.definedBy, structure) + '`\n';
});

@@ -159,3 +160,3 @@ tmp += '|===\n';

tmp += '|' + cleanup(item.desc);
tmp += '|`' + util.generateXref(item.definedBy) + '`\n';
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n';
});

@@ -166,3 +167,3 @@ tmp += '|===\n';

};
const buildConstructor = (data, util) => {
const buildConstructor = (data, structure) => {
let tmp = '';

@@ -184,6 +185,6 @@ if (hasValue(data.constructors)) {

if (hasValue(constructor.params)) {
tmp += generateParameters(constructor.params, util);
tmp += generateParameters(constructor.params, structure);
}
if (hasValue(constructor.return) && hasValue(constructor.return.types)) {
tmp += generateReturn(constructor.return, util);
tmp += generateReturn(constructor.return, structure);
}

@@ -194,3 +195,3 @@ });

};
const buildMethods = (data, util) => {
const buildMethods = (data, structure) => {
let tmp = '';

@@ -212,6 +213,6 @@ if (hasValue(data.methods)) {

if (hasValue(method.params)) {
tmp += generateParameters(method.params, util);
tmp += generateParameters(method.params, structure);
}
if (hasValue(method.return) && hasValue(method.return.types)) {
tmp += generateReturn(method.return, util);
tmp += generateReturn(method.return, structure);
}

@@ -223,3 +224,3 @@ tmp += `\n'''\n`;

};
const buildEvents = (data, util) => {
const buildEvents = (data, structure) => {
let tmp = '';

@@ -235,3 +236,3 @@ // untested snippet, no events data

if (hasValue(event.params)) {
tmp += generateParameters(event.params, util);
tmp += generateParameters(event.params, structure);
}

@@ -242,3 +243,3 @@ });

};
const convert = (pages, util) => pages.map((page) => {
const convert = (pages, structure) => pages.map((page) => {
// page[0] is json

@@ -273,3 +274,3 @@ // page[1] is adoc

data.borrows.forEach((item) => {
tmp += '\n * ' + util.generateXref(item) + '\n';
tmp += '\n * ' + Util.generateXref(item, structure) + '\n';
});

@@ -288,6 +289,6 @@ }

}
tmp += buildSummary(data, util);
tmp += buildConstructor(data, util);
tmp += buildMethods(data, util);
tmp += buildEvents(data, util);
tmp += buildSummary(data, structure);
tmp += buildConstructor(data, structure);
tmp += buildMethods(data, structure);
tmp += buildEvents(data, structure);
// return the applied antora page mutation

@@ -294,0 +295,0 @@ page[1] = Object.assign(Object.assign({}, page[1]), { content: tmp });

@@ -9,3 +9,3 @@ "use strict";

const AntoraTemplate = require("./antora.converter");
const util_1 = require("./util");
const Util = require("./util");
/**

@@ -18,3 +18,3 @@ * [description]

*/
const getMemberPages = (root, templateDelegate, util, type) => {
const getMemberPages = (root, templateDelegate, structure, type) => {
const members = type.getMembers(true);

@@ -70,4 +70,4 @@ const data = type.toJSON();

data.keywords = data.keywords.join(', ');
const jsonFilePath = util.getJsonFilePath(data.type, data.fullName);
const adocFilePath = util.getFilePath(data.fullName);
const jsonFilePath = Util.getJsonFilePath(data.type, data.fullName);
const adocFilePath = Util.getFilePath(data.fullName, structure);
return [{

@@ -155,3 +155,2 @@ type: 'json',

const template = (root, toPath, structure) => {
const util = new util_1.Util(structure);
const archive = new moxie_zip_1.ZipWriter();

@@ -173,3 +172,3 @@ const memberTemplate = compileTemplate('member.handlebars');

});
const navPages = util.generateNavPages(sortedTypes);
const navPages = Util.generateNavPages(sortedTypes, structure);
navPages.forEach((page) => {

@@ -179,4 +178,4 @@ addPage(page);

// create all json and adoc for each item
const pages = sortedTypes.map(getMemberPages.bind(null, root, memberTemplate, util));
const convertedPages = AntoraTemplate.convert(pages, util);
const pages = sortedTypes.map(getMemberPages.bind(null, root, memberTemplate, structure));
const convertedPages = AntoraTemplate.convert(pages, structure);
flatten(convertedPages).forEach(addPage);

@@ -183,0 +182,0 @@ archive.saveAs(toPath, (err) => {

@@ -8,36 +8,8 @@ import { ExportStructure } from '../../lib/exporter';

}
/**
* Utility for organising file structure within the antora template.
*
* @class moxiedoc.antora.Util
*/
declare class Util {
private structure;
private BASE_PATH;
/**
* Constructs a new Util instance.
*
* @param
* @constructor
*/
constructor(structure: ExportStructure);
generateNavPages: (sortedTypes: Type[]) => PageOutput[];
getFilePath: (name: string) => string;
getJsonFilePath: (type: string, fullName: string) => string;
generateXref: (name: string) => string;
generateTypeXref: (type: string) => string;
private getNavFile;
private navToAdoc;
private generateIndexPages;
private indexToAdoc;
private getNamespacesFromTypes;
private getRootPath;
private namespaceLine;
private pageFileLine;
private getNamespaceFromFullName;
private getTitleFromFullName;
private generateNavXref;
private navLine;
}
export { Util };
declare const generateNavPages: (sortedTypes: Type[], structure: ExportStructure) => PageOutput[];
declare const getFilePath: (name: string, structure: ExportStructure) => string;
declare const getJsonFilePath: (type: string, fullName: string) => string;
declare const generateXref: (name: string, structure: ExportStructure) => string;
declare const generateTypeXref: (type: string, structure: ExportStructure) => string;
export { generateNavPages, getFilePath, getJsonFilePath, generateXref, generateTypeXref };
//# sourceMappingURL=util.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Util = void 0;
exports.generateTypeXref = exports.generateXref = exports.getJsonFilePath = exports.getFilePath = exports.generateNavPages = void 0;
const YAML = require("js-yaml");
/**
* Utility for organising file structure within the antora template.
*
* @class moxiedoc.antora.Util
*/
class Util {
/**
* Constructs a new Util instance.
*
* @param
* @constructor
*/
constructor(structure) {
this.generateNavPages = (sortedTypes) => {
const nav = this.getNavFile(sortedTypes);
const indexPage = nav[0];
const adocNav = this.navToAdoc(indexPage);
const newNavPages = [];
newNavPages.push({
type: 'adoc',
filename: '_data/nav.yml',
content: YAML.dump(nav)
const BASE_PATH = process.env.BASE_PATH || '/_data/antora';
const generateNavPages = (sortedTypes, structure) => {
const nav = getNavFile(sortedTypes, structure);
const indexPage = nav[0];
const adocNav = navToAdoc(indexPage, structure);
const newNavPages = [];
newNavPages.push({
type: 'adoc',
filename: '_data/nav.yml',
content: YAML.dump(nav)
});
newNavPages.push({
type: 'adoc',
filename: '_data/moxiedoc_nav.adoc',
content: adocNav
});
switch (structure) {
case 'legacy':
return generateIndexPages(newNavPages, indexPage, structure);
case 'default':
return newNavPages;
}
};
exports.generateNavPages = generateNavPages;
const getFilePath = (name, structure) => {
const fileName = name.toLowerCase() === 'tinymce' ? getRootPath(structure) : name.toLowerCase();
switch (structure) {
case 'legacy':
const folder = getNamespaceFromFullName(name) + '/';
return BASE_PATH + '/api/' + folder + '/' + fileName + '.adoc';
case 'default':
return BASE_PATH + '/apis/' + fileName + '.adoc';
}
};
exports.getFilePath = getFilePath;
const getJsonFilePath = (type, fullName) => (BASE_PATH + '/api/json/' + type + '_' + fullName.replace(/\./g, '_') + '.json').toLowerCase();
exports.getJsonFilePath = getJsonFilePath;
const getNavFile = (types, structure) => {
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: getRootPath(structure)
});
newNavPages.push({
type: 'adoc',
filename: '_data/moxiedoc_nav.adoc',
content: adocNav
});
switch (this.structure) {
case 'legacy':
return this.generateIndexPages(newNavPages, indexPage);
case 'default':
return newNavPages;
}
}
return {
title,
path: url,
pages: innerPages
};
this.getFilePath = (name) => {
const fileName = name.toLowerCase() === 'tinymce' ? this.getRootPath() : name.toLowerCase();
switch (this.structure) {
case 'legacy':
const folder = this.getNamespaceFromFullName(name) + '/';
return this.BASE_PATH + '/api/' + folder + '/' + fileName + '.adoc';
case 'default':
return this.BASE_PATH + '/apis/' + fileName + '.adoc';
}
};
this.getJsonFilePath = (type, fullName) => (this.BASE_PATH + '/api/' + type + '_' + fullName.replace(/\./g, '_') + '.json').toLowerCase();
this.generateXref = (name) => {
const title = this.getTitleFromFullName(name);
return 'xref:' + this.getFilePath(name) + '[' + title + ']';
};
this.generateTypeXref = (type) => {
return type.includes('tinymce', 0) ? this.generateXref(type) : type;
};
this.getNamespaceFromFullName = (fullName) => fullName.split('.').slice(0, -1).join('.');
this.getTitleFromFullName = (fullName) => fullName.split('.').slice(-1).join('');
this.generateNavXref = (basePath, filename, title) => 'xref:' + basePath + '/' + filename + '[' + title + ']';
this.navLine = (name, level) => '*'.repeat(level) + ' ' + name + '\n';
this.structure = structure;
this.BASE_PATH = process.env.BASE_PATH || '/_data/antora';
}
getNavFile(types) {
const namespaces = this.getNamespacesFromTypes(types);
const pages = Object.entries(namespaces).map(([url, title]) => {
const innerPages = types.filter((type) => {
const fullName = type.fullName.toLowerCase();
return this.getNamespaceFromFullName(fullName) === url;
}).map((type) => {
return { title: type.fullName, path: type.fullName.toLowerCase() };
});
if (url === 'tinymce') {
innerPages.unshift({
title: 'tinymce',
path: this.getRootPath()
});
return [{
title: 'API Reference',
path: BASE_PATH,
pages
}];
};
const navToAdoc = (indexPage, structure) => {
// Api index nav page top level
let adoc = navLine(indexPage.title, 1);
if (indexPage.pages) {
indexPage.pages.forEach((namespace) => {
adoc += navLine(namespaceLine(namespace, structure), 2);
if (namespace.pages) {
namespace.pages.forEach((pageFile) => {
adoc += navLine(pageFileLine(pageFile, structure), 3);
});
}
return {
title,
path: url,
pages: innerPages
};
});
return [{
title: 'API Reference',
path: this.BASE_PATH,
pages
}];
}
navToAdoc(indexPage) {
// Api index nav page top level
let adoc = this.navLine(indexPage.title, 1);
if (indexPage.pages) {
indexPage.pages.forEach((namespace) => {
adoc += this.navLine(this.namespaceLine(namespace), 2);
if (namespace.pages) {
namespace.pages.forEach((pageFile) => {
adoc += this.navLine(this.pageFileLine(pageFile), 3);
});
}
});
}
return adoc;
}
generateIndexPages(newNavPages, indexPage) {
indexPage.pages.forEach((namespace) => {
newNavPages.push({
type: 'adoc',
filename: this.BASE_PATH + '/api/' + namespace.path + '/index.adoc',
content: this.indexToAdoc(namespace)
});
return adoc;
};
const generateIndexPages = (newNavPages, indexPage, structure) => {
indexPage.pages.forEach((namespace) => {
newNavPages.push({
type: 'adoc',
filename: BASE_PATH + '/api/' + namespace.path + '/index.adoc',
content: indexToAdoc(namespace, structure)
});
return newNavPages;
});
return newNavPages;
};
const indexToAdoc = (namespace, structure) => {
let adoc = '= ' + namespace.title + '\n\n';
adoc += '[cols="1,1"]\n';
adoc += '|===\n\n';
if (namespace.pages) {
namespace.pages.forEach((pageFile) => {
adoc += 'a|\n';
adoc += '[.lead]\n';
adoc += pageFileLine(pageFile, structure) + '\n\n';
});
}
indexToAdoc(namespace) {
let adoc = '= ' + namespace.title + '\n\n';
adoc += '[cols="1,1"]\n';
adoc += '|===\n\n';
if (namespace.pages) {
namespace.pages.forEach((pageFile) => {
adoc += 'a|\n';
adoc += '[.lead]\n';
adoc += this.generateNavXref('api/' + this.getNamespaceFromFullName(namespace.path), pageFile.path + '.adoc', pageFile.title) + '\n\n';
});
adoc += 'a|\n\n';
adoc += '|===';
return adoc;
};
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);
}
adoc += 'a|\n\n';
adoc += '|===';
return adoc;
return namespaces;
}, {});
};
const getRootPath = (structure) => {
switch (structure) {
case 'legacy':
return 'root_tinymce';
case 'default':
return 'tinymce.root';
}
getNamespacesFromTypes(types) {
return types.reduce((namespaces, type) => {
const fullName = type.fullName.toLowerCase();
const url = this.getNamespaceFromFullName(fullName);
if (url && !namespaces[url]) {
namespaces[url] = this.getNamespaceFromFullName(type.fullName);
}
return namespaces;
}, {});
};
const namespaceLine = (namespace, structure) => {
switch (structure) {
case 'legacy':
return generateNavXref('api/' + namespace.path, 'index.adoc', namespace.title);
case 'default':
return namespace.title;
}
getRootPath() {
switch (this.structure) {
case 'legacy':
return 'tinymce.root_tinymce';
case 'default':
return 'tinymce.root';
}
};
const pageFileLine = (pageFile, structure) => {
switch (structure) {
case 'legacy':
return generateNavXref('api/' + getNamespaceFromFullName(pageFile.path), pageFile.path + '.adoc', pageFile.title);
case 'default':
return generateNavXref('apis', pageFile.path + '.adoc', pageFile.title);
}
namespaceLine(namespace) {
switch (this.structure) {
case 'legacy':
return this.generateNavXref('api/' + namespace.path, 'index.adoc', namespace.title);
case 'default':
return namespace.title;
}
};
const generateXref = (name, structure) => {
const title = getTitleFromFullName(name);
const fileName = name.toLowerCase() + '.adoc';
switch (structure) {
case 'legacy':
return generateNavXref('api/' + getNamespaceFromFullName(name.toLowerCase()), fileName, title);
case 'default':
return generateNavXref('apis/', fileName, title);
}
pageFileLine(pageFile) {
switch (this.structure) {
case 'legacy':
return this.generateNavXref('api/' + this.getNamespaceFromFullName(pageFile.path), pageFile.path + '.adoc', pageFile.title);
case 'default':
return this.generateNavXref('apis', pageFile.path + '.adoc', pageFile.title);
}
}
}
exports.Util = Util;
};
exports.generateXref = generateXref;
const generateTypeXref = (type, structure) => {
return type.includes('tinymce', 0) ? generateXref(type, structure) : type;
};
exports.generateTypeXref = generateTypeXref;
const generateNavXref = (basePath, filename, title) => 'xref:' + basePath + '/' + filename + '[' + title + ']';
const getNamespaceFromFullName = (fullName) => fullName === 'tinymce' ? fullName : fullName.split('.').slice(0, -1).join('.');
const getTitleFromFullName = (fullName) => fullName.split('.').slice(-1).join('');
const navLine = (name, level) => '*'.repeat(level) + ' ' + name + '\n';
//# sourceMappingURL=util.js.map
{
"name": "@tinymce/moxiedoc",
"version": "0.2.2-feature.20220719062619425.sha8afdb27",
"version": "0.2.2-feature.20220725071105651.sha5bda993",
"description": "A tool for generating API documentation",

@@ -5,0 +5,0 @@ "author": "Tiny Technologies, Inc",

@@ -0,4 +1,8 @@

import { ExportStructure } from 'src/lib/exporter';
import { Return } from '../../lib/member';
import { Param } from '../../lib/param';
import { Util, PageOutput } from './util';
import { PageOutput } from './util';
import * as Util from './util';

@@ -85,6 +89,6 @@ const hasValue = <T>(x: T): x is NonNullable<T> => {

const generateParameters = (params: Param[], util: Util): string => {
const generateParameters = (params: Param[], structure: ExportStructure): string => {
let tmp = '\n==== Parameters\n';
params.forEach((param) => {
tmp += '\n* `' + param.name + ' (' + param.types.map((type) => util.generateTypeXref(type)).join(' | ') + ')` - ' + cleanup(param.desc);
tmp += '\n* `' + param.name + ' (' + param.types.map((type) => Util.generateTypeXref(type, structure)).join(' | ') + ')` - ' + cleanup(param.desc);
});

@@ -94,6 +98,6 @@ return tmp + '\n';

const generateReturn = (ret: Return, util: Util): string => {
const generateReturn = (ret: Return, structure: ExportStructure): string => {
let tmp = '\n==== Return value\n';
ret.types.forEach((type) => {
tmp += '\n* `' + util.generateTypeXref(type) + '` - ' + cleanup(ret.desc);
tmp += '\n* `' + Util.generateTypeXref(type, structure) + '` - ' + cleanup(ret.desc);
});

@@ -103,3 +107,3 @@ return tmp += '\n';

const buildSummary = (data: Record<string, any>, util: Util): string => {
const buildSummary = (data: Record<string, any>, structure: ExportStructure): string => {
let tmp = '';

@@ -119,5 +123,5 @@

tmp += '|' + item.name;
tmp += '|`' + util.generateTypeXref(item.dataTypes[0]) + '`';
tmp += '|`' + Util.generateTypeXref(item.dataTypes[0], structure) + '`';
tmp += '|' + cleanup(item.desc);
tmp += '|`' + util.generateXref(item.definedBy) + '`\n';
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n';
});

@@ -138,5 +142,5 @@ tmp += '|===\n';

tmp += '|' + item.name;
tmp += '|`' + util.generateTypeXref(item.dataTypes[0]) + '`';
tmp += '|`' + Util.generateTypeXref(item.dataTypes[0], structure) + '`';
tmp += '|' + cleanup(item.desc);
tmp += '|`' + util.generateXref(item.definedBy) + '`\n';
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n';
});

@@ -158,3 +162,3 @@ tmp += '|===\n';

tmp += '|' + cleanup(item.desc);
tmp += '|`' + util.generateXref(item.definedBy) + '`\n';
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n';
});

@@ -172,3 +176,3 @@ tmp += '|===\n';

data.methods.forEach((item) => {
tmp += '|xref:#' + item.name + '[' + item.name + '()]|' + cleanup(item.desc) + '|`' + util.generateXref(item.definedBy) + '`\n';
tmp += '|xref:#' + item.name + '[' + item.name + '()]|' + cleanup(item.desc) + '|`' + Util.generateXref(item.definedBy, structure) + '`\n';
});

@@ -191,3 +195,3 @@ tmp += '|===\n';

tmp += '|' + cleanup(item.desc);
tmp += '|`' + util.generateXref(item.definedBy) + '`\n';
tmp += '|`' + Util.generateXref(item.definedBy, structure) + '`\n';
});

@@ -200,3 +204,3 @@ tmp += '|===\n';

const buildConstructor = (data: Record<string, any>, util: Util): string => {
const buildConstructor = (data: Record<string, any>, structure: ExportStructure): string => {
let tmp = '';

@@ -222,7 +226,7 @@

if (hasValue(constructor.params)) {
tmp += generateParameters(constructor.params, util);
tmp += generateParameters(constructor.params, structure);
}
if (hasValue(constructor.return) && hasValue(constructor.return.types)) {
tmp += generateReturn(constructor.return, util);
tmp += generateReturn(constructor.return, structure);
}

@@ -235,3 +239,3 @@ });

const buildMethods = (data: Record<string, any>, util: Util): string => {
const buildMethods = (data: Record<string, any>, structure: ExportStructure): string => {
let tmp = '';

@@ -256,7 +260,7 @@

if (hasValue(method.params)) {
tmp += generateParameters(method.params, util);
tmp += generateParameters(method.params, structure);
}
if (hasValue(method.return) && hasValue(method.return.types)) {
tmp += generateReturn(method.return, util);
tmp += generateReturn(method.return, structure);
}

@@ -271,3 +275,3 @@

const buildEvents = (data: Record<string, any>, util: Util): string => {
const buildEvents = (data: Record<string, any>, structure: ExportStructure): string => {
let tmp = '';

@@ -285,3 +289,3 @@

if (hasValue(event.params)) {
tmp += generateParameters(event.params, util);
tmp += generateParameters(event.params, structure);
}

@@ -294,3 +298,3 @@ });

const convert = (pages: PageOutput[][], util: Util): PageOutput[][] => pages.map((page) => {
const convert = (pages: PageOutput[][], structure: ExportStructure): PageOutput[][] => pages.map((page) => {
// page[0] is json

@@ -329,3 +333,3 @@ // page[1] is adoc

data.borrows.forEach((item) => {
tmp += '\n * ' + util.generateXref(item) + '\n';
tmp += '\n * ' + Util.generateXref(item, structure) + '\n';
});

@@ -346,6 +350,6 @@ }

tmp += buildSummary(data, util);
tmp += buildConstructor(data, util);
tmp += buildMethods(data, util);
tmp += buildEvents(data, util);
tmp += buildSummary(data, structure);
tmp += buildConstructor(data, structure);
tmp += buildMethods(data, structure);
tmp += buildEvents(data, structure);

@@ -352,0 +356,0 @@ // return the applied antora page mutation

@@ -10,3 +10,4 @@ import * as fs from 'fs';

import * as AntoraTemplate from './antora.converter';
import { Util, PageOutput } from './util';
import { PageOutput } from './util';
import * as Util from './util';

@@ -20,3 +21,3 @@ /**

*/
const getMemberPages = (root: Api, templateDelegate: HandlebarsTemplateDelegate, util: Util, type: Type): PageOutput[] => {
const getMemberPages = (root: Api, templateDelegate: HandlebarsTemplateDelegate, structure: ExportStructure, type: Type): PageOutput[] => {
const members = type.getMembers(true);

@@ -83,4 +84,4 @@ const data = type.toJSON();

const jsonFilePath = util.getJsonFilePath(data.type, data.fullName);
const adocFilePath = util.getFilePath(data.fullName);
const jsonFilePath = Util.getJsonFilePath(data.type, data.fullName);
const adocFilePath = Util.getFilePath(data.fullName, structure);
return [{

@@ -178,3 +179,2 @@ type: 'json',

const template = (root: Api, toPath: string, structure: ExportStructure): void => {
const util = new Util(structure);
const archive = new ZipWriter();

@@ -197,3 +197,3 @@ const memberTemplate = compileTemplate('member.handlebars');

const navPages = util.generateNavPages(sortedTypes);
const navPages = Util.generateNavPages(sortedTypes, structure);

@@ -205,5 +205,5 @@ navPages.forEach((page) => {

// create all json and adoc for each item
const pages: PageOutput[][] = sortedTypes.map(getMemberPages.bind(null, root, memberTemplate, util));
const pages: PageOutput[][] = sortedTypes.map(getMemberPages.bind(null, root, memberTemplate, structure));
const convertedPages = AntoraTemplate.convert(pages, util);
const convertedPages = AntoraTemplate.convert(pages, structure);
flatten(convertedPages).forEach(addPage);

@@ -210,0 +210,0 @@

@@ -18,203 +18,195 @@ import * as YAML from 'js-yaml';

/**
* Utility for organising file structure within the antora template.
*
* @class moxiedoc.antora.Util
*/
class Util {
private structure: ExportStructure;
private BASE_PATH: string;
const BASE_PATH: string = process.env.BASE_PATH || '/_data/antora';
/**
* Constructs a new Util instance.
*
* @param
* @constructor
*/
public constructor(structure: ExportStructure) {
this.structure = structure;
this.BASE_PATH = process.env.BASE_PATH || '/_data/antora';
}
const generateNavPages = (sortedTypes: Type[], structure: ExportStructure): PageOutput[] => {
const nav = getNavFile(sortedTypes, structure);
const indexPage = nav[0];
const adocNav = navToAdoc(indexPage, structure);
public generateNavPages = (sortedTypes: Type[]): PageOutput[] => {
const nav = this.getNavFile(sortedTypes);
const indexPage = nav[0];
const adocNav = this.navToAdoc(indexPage);
const newNavPages = [] as PageOutput[];
newNavPages.push({
type: 'adoc',
filename: '_data/nav.yml',
content: YAML.dump(nav)
});
const newNavPages = [] as PageOutput[];
newNavPages.push({
type: 'adoc',
filename: '_data/nav.yml',
content: YAML.dump(nav)
});
newNavPages.push({
type: 'adoc',
filename: '_data/moxiedoc_nav.adoc',
content: adocNav
});
newNavPages.push({
type: 'adoc',
filename: '_data/moxiedoc_nav.adoc',
content: adocNav
});
switch (structure) {
case 'legacy':
return generateIndexPages(newNavPages, indexPage, structure);
switch (this.structure) {
case 'legacy':
return this.generateIndexPages(newNavPages, indexPage);
case 'default':
return newNavPages;
}
};
case 'default':
return newNavPages;
}
};
const getFilePath = (name: string, structure: ExportStructure): string => {
const fileName = name.toLowerCase() === 'tinymce' ? getRootPath(structure) : name.toLowerCase();
switch (structure) {
case 'legacy':
const folder = getNamespaceFromFullName(name) + '/';
return BASE_PATH + '/api/' + folder + '/' + fileName + '.adoc';
public getFilePath = (name: string): string => {
const fileName = name.toLowerCase() === 'tinymce' ? this.getRootPath() : name.toLowerCase();
switch (this.structure) {
case 'legacy':
const folder = this.getNamespaceFromFullName(name) + '/';
return this.BASE_PATH + '/api/' + folder + '/' + fileName + '.adoc';
case 'default':
return BASE_PATH + '/apis/' + fileName + '.adoc';
}
};
case 'default':
return this.BASE_PATH + '/apis/' + fileName + '.adoc';
}
};
const getJsonFilePath = (type: string, fullName: string): string =>
(BASE_PATH + '/api/json/' + type + '_' + fullName.replace(/\./g, '_') + '.json').toLowerCase();
public getJsonFilePath = (type: string, fullName: string): string =>
(this.BASE_PATH + '/api/' + type + '_' + fullName.replace(/\./g, '_') + '.json').toLowerCase();
const getNavFile = (types: Type[], structure: ExportStructure): 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() };
});
public generateXref = (name: string): string => {
const title = this.getTitleFromFullName(name);
return 'xref:' + this.getFilePath(name) + '[' + title + ']';
};
if (url === 'tinymce') {
innerPages.unshift({
title: 'tinymce',
path: getRootPath(structure)
});
}
public generateTypeXref = (type: string): string => {
return type.includes('tinymce', 0) ? this.generateXref(type) : type;
};
return {
title,
path: url,
pages: innerPages
};
});
private getNavFile(types: Type[]): NavFile[] {
const namespaces = this.getNamespacesFromTypes(types);
const pages = Object.entries(namespaces).map(([ url, title ]): NavFile => {
const innerPages = types.filter((type) => {
const fullName = type.fullName.toLowerCase();
return this.getNamespaceFromFullName(fullName) === url;
}).map((type): NavFile => {
return { title: type.fullName, path: type.fullName.toLowerCase() };
});
return [{
title: 'API Reference',
path: BASE_PATH,
pages
}];
};
if (url === 'tinymce') {
innerPages.unshift({
title: 'tinymce',
path: this.getRootPath()
const navToAdoc = (indexPage: NavFile, structure: ExportStructure): string => {
// Api index nav page top level
let adoc = navLine(indexPage.title, 1);
if (indexPage.pages) {
indexPage.pages.forEach((namespace) => {
adoc += navLine(namespaceLine(namespace, structure), 2);
if (namespace.pages) {
namespace.pages.forEach((pageFile) => {
adoc += navLine(pageFileLine(pageFile, structure), 3);
});
}
return {
title,
path: url,
pages: innerPages
};
});
return [{
title: 'API Reference',
path: this.BASE_PATH,
pages
}];
}
return adoc;
};
private navToAdoc(indexPage: NavFile): string {
// Api index nav page top level
let adoc = this.navLine(indexPage.title, 1);
if (indexPage.pages) {
indexPage.pages.forEach((namespace) => {
adoc += this.navLine(this.namespaceLine(namespace), 2);
if (namespace.pages) {
namespace.pages.forEach((pageFile) => {
adoc += this.navLine(this.pageFileLine(pageFile), 3);
});
}
});
}
return adoc;
}
const generateIndexPages = (newNavPages: PageOutput[], indexPage: NavFile, structure: ExportStructure): PageOutput[] => {
indexPage.pages.forEach((namespace) => {
newNavPages.push({
type: 'adoc',
filename: BASE_PATH + '/api/' + namespace.path + '/index.adoc',
content: indexToAdoc(namespace, structure)
});
});
return newNavPages;
};
private generateIndexPages(newNavPages: PageOutput[], indexPage: NavFile): PageOutput[] {
indexPage.pages.forEach((namespace) => {
newNavPages.push({
type: 'adoc',
filename: this.BASE_PATH + '/api/' + namespace.path + '/index.adoc',
content: this.indexToAdoc(namespace)
});
const indexToAdoc = (namespace: NavFile, structure: ExportStructure): string => {
let adoc = '= ' + namespace.title + '\n\n';
adoc += '[cols="1,1"]\n';
adoc += '|===\n\n';
if (namespace.pages) {
namespace.pages.forEach((pageFile) => {
adoc += 'a|\n';
adoc += '[.lead]\n';
adoc += pageFileLine(pageFile, structure) + '\n\n';
});
return newNavPages;
}
adoc += 'a|\n\n';
adoc += '|===';
return adoc;
};
private indexToAdoc(namespace: NavFile): string {
let adoc = '= ' + namespace.title + '\n\n';
adoc += '[cols="1,1"]\n';
adoc += '|===\n\n';
if (namespace.pages) {
namespace.pages.forEach((pageFile) => {
adoc += 'a|\n';
adoc += '[.lead]\n';
adoc += this.generateNavXref('api/' + this.getNamespaceFromFullName(namespace.path), pageFile.path + '.adoc', pageFile.title) + '\n\n';
});
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);
}
adoc += 'a|\n\n';
adoc += '|===';
return adoc;
}
return namespaces;
}, {});
};
private getNamespacesFromTypes(types: Type[]): Record<string, string> {
return types.reduce((namespaces: Record<string, string>, type: Type) => {
const fullName = type.fullName.toLowerCase();
const url = this.getNamespaceFromFullName(fullName);
if (url && !namespaces[url]) {
namespaces[url] = this.getNamespaceFromFullName(type.fullName);
}
return namespaces;
}, {});
const getRootPath = (structure: ExportStructure): string => {
switch (structure) {
case 'legacy':
return 'root_tinymce';
case 'default':
return 'tinymce.root';
}
};
private getRootPath(): string {
switch (this.structure) {
case 'legacy':
return 'tinymce.root_tinymce';
const namespaceLine = (namespace: NavFile, structure: ExportStructure): string => {
switch (structure) {
case 'legacy':
return generateNavXref('api/' + namespace.path, 'index.adoc', namespace.title);
case 'default':
return 'tinymce.root';
}
case 'default':
return namespace.title;
}
};
private namespaceLine(namespace: NavFile): string {
switch (this.structure) {
case 'legacy':
return this.generateNavXref('api/' + namespace.path, 'index.adoc', namespace.title);
const pageFileLine = (pageFile: NavFile, structure: ExportStructure): string => {
switch (structure) {
case 'legacy':
return generateNavXref('api/' + getNamespaceFromFullName(pageFile.path), pageFile.path + '.adoc', pageFile.title);
case 'default':
return namespace.title;
}
case 'default':
return generateNavXref('apis', pageFile.path + '.adoc', pageFile.title);
}
};
private pageFileLine(pageFile: NavFile): string {
switch (this.structure) {
case 'legacy':
return this.generateNavXref('api/' + this.getNamespaceFromFullName(pageFile.path), pageFile.path + '.adoc', pageFile.title);
const generateXref = (name: string, structure: ExportStructure): string => {
const title = getTitleFromFullName(name);
const fileName = name.toLowerCase() + '.adoc';
switch (structure) {
case 'legacy':
return generateNavXref('api/' + getNamespaceFromFullName(name.toLowerCase()), fileName, title);
case 'default':
return this.generateNavXref('apis', pageFile.path + '.adoc', pageFile.title);
}
case 'default':
return generateNavXref('apis/', fileName, title);
}
};
private getNamespaceFromFullName = (fullName: string): string =>
fullName.split('.').slice(0, -1).join('.');
const generateTypeXref = (type: string, structure: ExportStructure): string => {
return type.includes('tinymce', 0) ? generateXref(type, structure) : type;
};
private getTitleFromFullName = (fullName: string): string =>
fullName.split('.').slice(-1).join('');
const generateNavXref = (basePath: string, filename: string, title: string): string =>
'xref:' + basePath + '/' + filename + '[' + title + ']';
private generateNavXref = (basePath: string, filename: string, title: string): string =>
'xref:' + basePath + '/' + filename + '[' + title + ']';
const getNamespaceFromFullName = (fullName: string): string =>
fullName === 'tinymce' ? fullName : fullName.split('.').slice(0, -1).join('.');
private navLine = (name: string, level: number): string =>
'*'.repeat(level) + ' ' + name + '\n';
}
const getTitleFromFullName = (fullName: string): string =>
fullName.split('.').slice(-1).join('');
const navLine = (name: string, level: number): string =>
'*'.repeat(level) + ' ' + name + '\n';
export {
Util
generateNavPages,
getFilePath,
getJsonFilePath,
generateXref,
generateTypeXref
};

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc