mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[ADF-3150] Moved all doc tool config settings to doctool.config.json (#3455)
* [ADF-3150] Moved undoc stoplist to doc config file * [ADF-3150] Moved config to doctools.config.json and removed obsolete scripts
This commit is contained in:
parent
30826500e5
commit
beeb7bd369
@ -1,57 +0,0 @@
|
||||
[
|
||||
"model",
|
||||
"context-menu-holder",
|
||||
"data-column-list",
|
||||
"card-view-[a-z]+item",
|
||||
"card-view-item-dispatcher",
|
||||
"content-column",
|
||||
"content-action-list",
|
||||
"empty-folder-content",
|
||||
"empty-list",
|
||||
"loading-template",
|
||||
"no-content-template",
|
||||
"card-view-content-proxy",
|
||||
"login-footer\\.directive",
|
||||
"login-header\\.directive",
|
||||
"no-task-detail-template",
|
||||
"diagram",
|
||||
"raphael",
|
||||
"context-menu",
|
||||
"alfresco-settings",
|
||||
"\\.widget",
|
||||
"[vV]iewer",
|
||||
"translate-loader",
|
||||
"search\\.service",
|
||||
"mediaPlayer",
|
||||
"unknown-format",
|
||||
"cell",
|
||||
"error.component",
|
||||
"no-permission",
|
||||
"form-custom",
|
||||
"widget-visibility",
|
||||
"card-item-types",
|
||||
"dynamic-component",
|
||||
"settings",
|
||||
"file-uploading",
|
||||
"version-upload",
|
||||
"search-trigger",
|
||||
"node-actions",
|
||||
"content-node-selector.service",
|
||||
"analytics",
|
||||
"process-upload",
|
||||
"properties-loader",
|
||||
"property-descriptors",
|
||||
"attach-file",
|
||||
"attach-folder",
|
||||
"task-upload",
|
||||
"aspect-whitelist",
|
||||
"basic-properties",
|
||||
"content-metadata",
|
||||
"empty-search-result",
|
||||
"property-group",
|
||||
"people-search-",
|
||||
"people-selector",
|
||||
"sidenav-layout-",
|
||||
"layout-container",
|
||||
"search-"
|
||||
]
|
@ -1,240 +0,0 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var angFilenameRegex = /([a-zA-Z0-9\-]+)\.((component)|(directive)|(model)|(pipe)|(service)|(widget))\.ts/;
|
||||
var searchFolderOmitRegex = /(mock)|(i18n)|(assets)|(styles)/;
|
||||
var libFolderOmitRegex = /config/;
|
||||
|
||||
var indexFileName = path.resolve('..', 'docs', 'README.md');
|
||||
var summaryFileName = path.resolve('..', 'docs', 'summary.json');
|
||||
var undocStoplistFileName = path.resolve('..', 'docs', 'undocStoplist.json');
|
||||
|
||||
|
||||
// Search source folders for .ts files to discover all components, directives, etc,
|
||||
// that are in the supplied library.
|
||||
function searchLibraryRecursive(libData, folderPath) {
|
||||
var items = fs.readdirSync(folderPath);
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var itemPath = path.resolve(folderPath, items[i]);
|
||||
var info = fs.statSync(itemPath);
|
||||
|
||||
if (info.isFile() && (items[i].match(angFilenameRegex))) {
|
||||
var nameNoSuffix = path.basename(items[i], '.ts');
|
||||
|
||||
var itemCategory = nameNoSuffix.split('.')[1];
|
||||
|
||||
if(nameNoSuffix in docDict) {
|
||||
switch (itemCategory) {
|
||||
case "component":
|
||||
libData.componentsWithDocs.push(itemPath);
|
||||
break;
|
||||
|
||||
case "directive":
|
||||
libData.directivesWithDocs.push(itemPath);
|
||||
break;
|
||||
|
||||
case "model":
|
||||
libData.modelsWithDocs.push(itemPath);
|
||||
break;
|
||||
|
||||
case "pipe":
|
||||
libData.pipesWithDocs.push(itemPath);
|
||||
break;
|
||||
|
||||
case "service":
|
||||
libData.servicesWithDocs.push(itemPath);
|
||||
break;
|
||||
|
||||
case "widget":
|
||||
libData.widgetsWithDocs.push(itemPath);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (!rejectItemViaStoplist(undocStoplist, items[i])) {
|
||||
switch (itemCategory) {
|
||||
case "component":
|
||||
libData.componentsWithoutDocs.push(itemPath);
|
||||
break;
|
||||
|
||||
case "directive":
|
||||
libData.directivesWithoutDocs.push(itemPath);
|
||||
break;
|
||||
|
||||
case "model":
|
||||
libData.modelsWithoutDocs.push(itemPath);
|
||||
break;
|
||||
|
||||
case "pipe":
|
||||
libData.pipesWithoutDocs.push(itemPath);
|
||||
break;
|
||||
|
||||
case "service":
|
||||
libData.servicesWithoutDocs.push(itemPath);
|
||||
break;
|
||||
|
||||
case "widget":
|
||||
libData.widgetsWithoutDocs.push(itemPath);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (info.isDirectory() && !items[i].match(searchFolderOmitRegex)) {
|
||||
searchLibraryRecursive(libData, itemPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get a list of all items that have a file in the docs folder.
|
||||
function getDocFolderItems(docFolderPath) {
|
||||
var result = {};
|
||||
var items = fs.readdirSync(path.resolve(docFolderPath));
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
if (items[i].endsWith('.md')) {
|
||||
var nameNoSuffix = path.basename(items[i], '.md');
|
||||
result[nameNoSuffix] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Convert an Angular-style name (eg, "card-view") into one with correct spaces and uppercase (eg, "Card View").
|
||||
function tidyName(name) {
|
||||
var result = name.replace(/-/g, " ");
|
||||
result = result.substr(0, 1).toUpperCase() + result.substr(1);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Generate the Markdown index for the files from the guide summary.
|
||||
function makeSummaryIndex() {
|
||||
var summaryJson = fs.readFileSync(summaryFileName, 'utf8');
|
||||
var summary = JSON.parse(summaryJson);
|
||||
|
||||
var result = '';
|
||||
|
||||
for (var i = 0; i < summary.length; i++) {
|
||||
var item = summary[i];
|
||||
result += '- [' + item.title + '](' + item.file + ')\n';
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Create a stoplist of regular expressions.
|
||||
function makeStoplist(slFilePath) {
|
||||
var listExpressions = JSON.parse(fs.readFileSync(slFilePath, 'utf8'));
|
||||
|
||||
var result = [];
|
||||
|
||||
for (var i = 0; i < listExpressions.length; i++) {
|
||||
result.push(new RegExp(listExpressions[i]));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Check if an item is covered by the stoplist and reject it if so.
|
||||
function rejectItemViaStoplist(stoplist, itemName) {
|
||||
for (var i = 0; i < stoplist.length; i++) {
|
||||
if (stoplist[i].test(itemName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function buildIndexSection(name, documented, undocumented) {
|
||||
var listItems = [];
|
||||
|
||||
if ((documented.length > 0) || (undocumented.length > 0)) {
|
||||
listItems.push('\n### ' + name + '\n');
|
||||
}
|
||||
|
||||
for (var i = 0; i < documented.length; i++) {
|
||||
var libFilePath = documented[i];
|
||||
var libFileName = path.basename(libFilePath, '.ts');
|
||||
var nameSections = libFileName.split('.');
|
||||
var visibleName = tidyName(nameSections[0]) + ' ' + nameSections[1];
|
||||
var mdListItem = '- [' + visibleName + '](' + libFileName + '.md)';
|
||||
listItems.push(mdListItem);
|
||||
}
|
||||
|
||||
for (var i = 0; i < undocumented.length; i++) {
|
||||
var libFilePath = undocumented[i].replace(/\\/g, '/');
|
||||
var libFileName = path.basename(libFilePath, '.ts');
|
||||
var nameSections = libFileName.split('.');
|
||||
var visibleName = tidyName(nameSections[0]) + ' ' + nameSections[1];
|
||||
var relPath = libFilePath.substr(libFilePath.indexOf('/lib'));
|
||||
var mdListItem = '- [*' + visibleName + '](..' + relPath + ')';
|
||||
listItems.push(mdListItem);
|
||||
}
|
||||
|
||||
return listItems;
|
||||
}
|
||||
|
||||
|
||||
var undocStoplist = makeStoplist(undocStoplistFileName);
|
||||
|
||||
var docDict = getDocFolderItems(path.resolve('..', 'docs'));
|
||||
|
||||
var rootItems = fs.readdirSync(path.resolve('.'));
|
||||
|
||||
var libs = {}
|
||||
|
||||
for (var i = 0; i < rootItems.length; i++) {
|
||||
var itemPath = path.resolve(rootItems[i]);
|
||||
var info = fs.statSync(itemPath);
|
||||
|
||||
if (info.isDirectory() && !rootItems[i].match(libFolderOmitRegex)) {
|
||||
libs[rootItems[i]] = {
|
||||
componentsWithDocs: [], componentsWithoutDocs: [],
|
||||
directivesWithDocs: [], directivesWithoutDocs: [],
|
||||
modelsWithDocs: [], modelsWithoutDocs: [],
|
||||
pipesWithDocs: [], pipesWithoutDocs: [],
|
||||
servicesWithDocs: [], servicesWithoutDocs: [],
|
||||
widgetsWithDocs: [], widgetsWithoutDocs: [],
|
||||
};
|
||||
|
||||
searchLibraryRecursive(libs[rootItems[i]], path.resolve(itemPath));
|
||||
}
|
||||
}
|
||||
|
||||
var indexFileText = fs.readFileSync(indexFileName, 'utf8');
|
||||
|
||||
var libNames = Object.keys(libs);
|
||||
|
||||
for (var i = 0; i < libNames.length; i++) {
|
||||
var libName = libNames[i];
|
||||
var libData = libs[libName];
|
||||
|
||||
var listItems = buildIndexSection('Components', libData.componentsWithDocs, libData.componentsWithoutDocs);
|
||||
listItems = listItems.concat(buildIndexSection('Directives', libData.directivesWithDocs, libData.directivesWithoutDocs));
|
||||
listItems = listItems.concat(buildIndexSection('Models', libData.modelsWithDocs, libData.modelsWithoutDocs));
|
||||
listItems = listItems.concat(buildIndexSection('Pipes', libData.pipesWithDocs, libData.pipesWithoutDocs));
|
||||
listItems = listItems.concat(buildIndexSection('Services', libData.servicesWithDocs, libData.servicesWithoutDocs));
|
||||
listItems = listItems.concat(buildIndexSection('Widgets', libData.widgetsWithDocs, libData.widgetsWithoutDocs));
|
||||
|
||||
var libText = listItems.join('\n');
|
||||
var libStartMarker = '<!-- ' + libName + ' start -->';
|
||||
var libEndMarker = '<!-- ' + libName + ' end -->';
|
||||
var contentRegex = new RegExp('(?:' + libStartMarker + ')([\\s\\S]*)(?:' + libEndMarker + ')');
|
||||
indexFileText = indexFileText.replace(contentRegex, libStartMarker + '\n' + libText + '\n' + libEndMarker);
|
||||
}
|
||||
|
||||
var guideStartMarker = '<!-- guide start -->';
|
||||
var guideEndMarker = '<!-- guide end -->';
|
||||
var contentRegex = new RegExp('(?:' + guideStartMarker + ')([\\s\\S]*)(?:' + guideEndMarker + ')');
|
||||
indexFileText = indexFileText.replace(contentRegex, guideStartMarker + '\n' + makeSummaryIndex() + '\n' + guideEndMarker);
|
||||
|
||||
fs.writeFileSync(indexFileName, indexFileText, 'utf-8');
|
@ -1,96 +0,0 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var docFolderPath = path.resolve("..", "docs");
|
||||
var graphFileName = path.resolve(docFolderPath, "seeAlsoGraph.json");
|
||||
|
||||
|
||||
// Get a list of all items that have a file in the docs folder.
|
||||
function getDocFolderItems(docFolderPath) {
|
||||
var result = {};
|
||||
var items = fs.readdirSync(path.resolve(docFolderPath));
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
if (items[i].endsWith('.md')) {
|
||||
var nameNoSuffix = path.basename(items[i], '.md');
|
||||
result[nameNoSuffix] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Convert an Angular-style name (eg, "card-view") into one with correct spaces and uppercase (eg, "Card view").
|
||||
function tidyName(name) {
|
||||
var result = name.replace(/-/g, " ");
|
||||
result = result.substr(0, 1).toUpperCase() + result.substr(1);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
function buildSeeAlsoList(arcs) {
|
||||
var listItems = [];
|
||||
|
||||
for (var i = 0; i < arcs.length; i++) {
|
||||
var parts = arcs[i].split('.');
|
||||
var itemName = tidyName(parts[0]);
|
||||
|
||||
if (parts[1]) {
|
||||
itemName += ' ' + parts[1];
|
||||
}
|
||||
|
||||
listItems.push('- [' + itemName + '](' + arcs[i] + '.md)');
|
||||
}
|
||||
|
||||
return listItems.join('\n');
|
||||
}
|
||||
|
||||
|
||||
// If item is not in the arcs array then add it at
|
||||
// the end.
|
||||
function fixArcs(arcsArray, item) {
|
||||
if (arcsArray.indexOf(item) == -1) {
|
||||
arcsArray.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Makes link symmetrical between items (ie, if A links to B but not the other way
|
||||
// around then it adds the missing link).
|
||||
function tidyGraph(graph) {
|
||||
var nodeNames = Object.keys(graph);
|
||||
|
||||
for (var n = 0; n < nodeNames.length; n++) {
|
||||
var currNodeName = nodeNames[n];
|
||||
|
||||
var currNodeArcs = graph[currNodeName];
|
||||
|
||||
for (var a = 0; a < currNodeArcs.length; a++) {
|
||||
var linkedNode = graph[currNodeArcs[a]];
|
||||
fixArcs(linkedNode, currNodeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var graphJson = fs.readFileSync(graphFileName, 'utf8');
|
||||
var graph = JSON.parse(graphJson);
|
||||
tidyGraph(graph);
|
||||
|
||||
var nodeNames = Object.keys(graph);
|
||||
|
||||
for (var i = 0; i < nodeNames.length; i++) {
|
||||
var seeAlsoText = '## See also\n\n' + buildSeeAlsoList(graph[nodeNames[i]]);
|
||||
|
||||
var docFileName = path.resolve(docFolderPath, nodeNames[i] + '.md');
|
||||
var docFileText = fs.readFileSync(docFileName, 'utf8');
|
||||
|
||||
var seeAlsoStartMarker = '<!-- seealso start -->';
|
||||
var seeAlsoEndMarker = '<!-- seealso end -->';
|
||||
|
||||
var seeAlsoRegex = new RegExp('(?:' + seeAlsoStartMarker + ')([\\s\\S]*)(?:' + seeAlsoEndMarker + ')');
|
||||
docFileText = docFileText.replace(seeAlsoRegex, seeAlsoStartMarker + '\n' + seeAlsoText + '\n' + seeAlsoEndMarker);
|
||||
|
||||
fs.writeFileSync(docFileName, docFileText, 'utf-8');
|
||||
}
|
@ -147,6 +147,7 @@ var sourceInfo = fs.statSync(sourcePath);
|
||||
var toolModules = loadToolModules();
|
||||
|
||||
var config = loadConfig();
|
||||
aggData['config'] = config;
|
||||
|
||||
var toolList;
|
||||
|
||||
|
@ -19,8 +19,88 @@
|
||||
"toc"
|
||||
],
|
||||
"dev": [
|
||||
"tsInfo",
|
||||
"typeLinker"
|
||||
"index"
|
||||
]
|
||||
},
|
||||
"externalNameLinks": {
|
||||
"Blob": "https://developer.mozilla.org/en-US/docs/Web/API/Blob",
|
||||
"EventEmitter": "https://angular.io/api/core/EventEmitter",
|
||||
"MatSnackBarRef": "https://material.angular.io/components/snack-bar/overview",
|
||||
"TemplateRef": "https://angular.io/api/core/TemplateRef",
|
||||
"Observable": "http://reactivex.io/documentation/observable.html",
|
||||
"Subject": "http://reactivex.io/documentation/subject.html",
|
||||
"AppDefinitionRepresentation": "https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-activiti-rest-api/docs/AppDefinitionRepresentation.md",
|
||||
"DeletedNodesPaging": "https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/DeletedNodesPaging.md",
|
||||
"MinimalNodeEntity": "../content-services/document-library.model.md",
|
||||
"MinimalNodeEntryEntity": "../content-services/document-library.model.md",
|
||||
"NodeEntry": "https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md",
|
||||
"RelatedContentRepresentation": "https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-activiti-rest-api/docs/RelatedContentRepresentation.md",
|
||||
"SiteEntry": "https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/SiteEntry.md",
|
||||
"SitePaging": "https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/SitePaging.md"
|
||||
},
|
||||
"typeNameExceptions": {
|
||||
"datatable.component": "DataTableComponent",
|
||||
"tasklist.service": "TaskListService",
|
||||
"text-mask.component": "InputMaskDirective",
|
||||
"card-item-types.service": "CardItemTypeService",
|
||||
"create-task-attachment.component": "AttachmentComponent",
|
||||
"process-list.component": "ProcessInstanceListComponent"
|
||||
},
|
||||
"undocStoplist": [
|
||||
"model",
|
||||
"context-menu-holder",
|
||||
"data-column-list",
|
||||
"card-view-[a-z]+item",
|
||||
"card-view-item-dispatcher",
|
||||
"content-column",
|
||||
"content-action-list",
|
||||
"empty-folder-content",
|
||||
"empty-list",
|
||||
"loading-template",
|
||||
"no-content-template",
|
||||
"card-view-content-proxy",
|
||||
"login-footer\\.directive",
|
||||
"login-header\\.directive",
|
||||
"no-task-detail-template",
|
||||
"diagram",
|
||||
"raphael",
|
||||
"context-menu",
|
||||
"alfresco-settings",
|
||||
"\\.widget",
|
||||
"[vV]iewer",
|
||||
"translate-loader",
|
||||
"search\\.service",
|
||||
"mediaPlayer",
|
||||
"unknown-format",
|
||||
"cell",
|
||||
"error.component",
|
||||
"no-permission",
|
||||
"form-custom",
|
||||
"widget-visibility",
|
||||
"card-item-types",
|
||||
"dynamic-component",
|
||||
"settings",
|
||||
"file-uploading",
|
||||
"version-upload",
|
||||
"search-trigger",
|
||||
"node-actions",
|
||||
"content-node-selector.service",
|
||||
"analytics",
|
||||
"process-upload",
|
||||
"properties-loader",
|
||||
"property-descriptors",
|
||||
"attach-file",
|
||||
"attach-folder",
|
||||
"task-upload",
|
||||
"aspect-whitelist",
|
||||
"basic-properties",
|
||||
"content-metadata",
|
||||
"empty-search-result",
|
||||
"property-group",
|
||||
"people-search-",
|
||||
"people-selector",
|
||||
"sidenav-layout-",
|
||||
"layout-container",
|
||||
"search-"
|
||||
]
|
||||
}
|
||||
}
|
@ -21,7 +21,6 @@ var angFilenameRegex = /([a-zA-Z0-9\-]+)\.((component)|(directive)|(model)|(pipe
|
||||
var searchFolderOmitRegex = /(config)|(mock)|(i18n)|(assets)|(styles)/;
|
||||
|
||||
var docsFolderPath = path.resolve("docs");
|
||||
var undocStoplistFileName = path.resolve(docsFolderPath, "undocStoplist.json");
|
||||
var rootFolder = "lib";
|
||||
var indexMdFilePath = path.resolve(docsFolderPath, "README.md");
|
||||
|
||||
@ -37,7 +36,7 @@ var experimentalIconURL = "docassets/images/ExperimentalIcon.png";
|
||||
|
||||
|
||||
function initPhase(aggData) {
|
||||
aggData.stoplist = makeStoplist(undocStoplistFileName);
|
||||
aggData.stoplist = makeStoplist(aggData.config);
|
||||
aggData.srcData = {};
|
||||
aggData.mdFileDesc = [];
|
||||
aggData.mdFileStatus = [];
|
||||
@ -159,9 +158,8 @@ function updatePhase(tree, pathname, aggData) {
|
||||
|
||||
|
||||
// Create a stoplist of regular expressions.
|
||||
function makeStoplist(slFilePath) {
|
||||
var listExpressions = JSON.parse(fs.readFileSync(slFilePath, 'utf8'));
|
||||
|
||||
function makeStoplist(config) {
|
||||
var listExpressions = config.undocStoplist;
|
||||
var result = [];
|
||||
|
||||
for (var i = 0; i < listExpressions.length; i++) {
|
||||
|
@ -12,14 +12,7 @@ var templateFolder = path.resolve("tools", "doc", "templates");
|
||||
var excludePatterns = [
|
||||
"**/*.spec.ts"
|
||||
];
|
||||
var nameExceptions = {
|
||||
"datatable.component": "DataTableComponent",
|
||||
"tasklist.service": "TaskListService",
|
||||
"text-mask.component": "InputMaskDirective",
|
||||
"card-item-types.service": "CardItemTypeService",
|
||||
"create-task-attachment.component": "AttachmentComponent",
|
||||
"process-list.component": "ProcessInstanceListComponent"
|
||||
};
|
||||
var nameExceptions;
|
||||
var undocMethodNames = {
|
||||
"ngOnChanges": 1
|
||||
};
|
||||
@ -182,6 +175,7 @@ var ComponentInfo = /** @class */ (function () {
|
||||
return ComponentInfo;
|
||||
}());
|
||||
function initPhase(aggData) {
|
||||
nameExceptions = aggData.config.typeNameExceptions;
|
||||
var app = new typedoc_1.Application({
|
||||
exclude: excludePatterns,
|
||||
ignoreCompilerErrors: true,
|
||||
|
@ -34,15 +34,7 @@ let excludePatterns = [
|
||||
];
|
||||
|
||||
|
||||
let nameExceptions = {
|
||||
"datatable.component": "DataTableComponent",
|
||||
"tasklist.service": "TaskListService",
|
||||
"text-mask.component": "InputMaskDirective",
|
||||
"card-item-types.service": "CardItemTypeService",
|
||||
"create-task-attachment.component": "AttachmentComponent",
|
||||
"process-list.component": "ProcessInstanceListComponent"
|
||||
}
|
||||
|
||||
let nameExceptions;
|
||||
|
||||
let undocMethodNames = {
|
||||
"ngOnChanges": 1
|
||||
@ -268,6 +260,8 @@ class ComponentInfo {
|
||||
|
||||
|
||||
export function initPhase(aggData) {
|
||||
nameExceptions = aggData.config.typeNameExceptions;
|
||||
|
||||
let app = new Application({
|
||||
exclude: excludePatterns,
|
||||
ignoreCompilerErrors: true,
|
||||
|
@ -1,357 +0,0 @@
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var ts = require("typescript");
|
||||
var path = require("path");
|
||||
var heading = require("mdast-util-heading-range");
|
||||
var remark = require("remark");
|
||||
var unist = require("../unistHelpers");
|
||||
var typescript_1 = require("typescript");
|
||||
// Max number of characters in the text for the default value column.
|
||||
var maxDefaultTextLength = 20;
|
||||
var nameExceptions = {
|
||||
"datatable.component": "DataTableComponent",
|
||||
"tasklist.service": "TaskListService"
|
||||
};
|
||||
function initPhase(aggData) {
|
||||
}
|
||||
exports.initPhase = initPhase;
|
||||
function readPhase(tree, pathname, aggData) {
|
||||
}
|
||||
exports.readPhase = readPhase;
|
||||
function aggPhase(aggData) {
|
||||
}
|
||||
exports.aggPhase = aggPhase;
|
||||
var PropData = /** @class */ (function () {
|
||||
function PropData() {
|
||||
}
|
||||
return PropData;
|
||||
}());
|
||||
var ParamData = /** @class */ (function () {
|
||||
function ParamData() {
|
||||
}
|
||||
ParamData.prototype.getSignature = function () {
|
||||
var sig = this.name;
|
||||
if (this.optional)
|
||||
sig += "?";
|
||||
if (this.type)
|
||||
sig += ": " + this.type;
|
||||
if (this.initializer)
|
||||
sig += " = " + this.initializer;
|
||||
return sig;
|
||||
};
|
||||
return ParamData;
|
||||
}());
|
||||
var MethodData = /** @class */ (function () {
|
||||
function MethodData() {
|
||||
this.params = [];
|
||||
}
|
||||
MethodData.prototype.getSignature = function () {
|
||||
var sig = this.name + "(";
|
||||
if (this.params.length > 0) {
|
||||
sig += this.params[0].getSignature();
|
||||
}
|
||||
for (var i = 1; i < this.params.length; i++) {
|
||||
sig += ", " + this.params[i].getSignature();
|
||||
}
|
||||
sig += ")";
|
||||
if (this.returnType !== "void") {
|
||||
sig += ": " + this.returnType;
|
||||
}
|
||||
return sig;
|
||||
};
|
||||
return MethodData;
|
||||
}());
|
||||
var ComponentDocAutoContent = /** @class */ (function () {
|
||||
function ComponentDocAutoContent() {
|
||||
this.inputs = [];
|
||||
this.outputs = [];
|
||||
}
|
||||
ComponentDocAutoContent.prototype.extractClassInfoFromSource = function (checker, classDec) {
|
||||
var sourceFile = classDec.getSourceFile();
|
||||
for (var i = 0; i < classDec.members.length; i++) {
|
||||
var member = classDec.members[i];
|
||||
if (ts.isPropertyDeclaration(member) ||
|
||||
ts.isGetAccessorDeclaration(member) ||
|
||||
ts.isSetAccessorDeclaration(member)) {
|
||||
var prop = member;
|
||||
var mods = ts.getCombinedModifierFlags(prop);
|
||||
var nonPrivate = (mods & ts.ModifierFlags.Private) === 0;
|
||||
var memSymbol = checker.getSymbolAtLocation(prop.name);
|
||||
if (nonPrivate && memSymbol && prop.decorators) {
|
||||
var name_1 = memSymbol.getName();
|
||||
var initializer = "";
|
||||
if (prop.initializer) {
|
||||
initializer = prop.initializer.getText(sourceFile);
|
||||
}
|
||||
var doc = ts.displayPartsToString(memSymbol.getDocumentationComment(checker));
|
||||
doc = doc.replace(/\r\n/g, " ");
|
||||
var propType = checker.typeToString(checker.getTypeOfSymbolAtLocation(memSymbol, memSymbol.valueDeclaration));
|
||||
var dec = prop.decorators[0].getText(sourceFile);
|
||||
if (dec.match(/@Input/)) {
|
||||
this.inputs.push({
|
||||
"name": name_1,
|
||||
"type": propType,
|
||||
"initializer": initializer,
|
||||
"docText": doc
|
||||
});
|
||||
}
|
||||
else if (dec.match(/@Output/)) {
|
||||
this.outputs.push({
|
||||
"name": name_1,
|
||||
"type": propType,
|
||||
"initializer": "",
|
||||
"docText": doc
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
ComponentDocAutoContent.prototype.addContentToDoc = function (tree) {
|
||||
var inTable = buildPropsTable(this.inputs);
|
||||
var outTable = buildPropsTable(this.outputs, false);
|
||||
if (inTable) {
|
||||
heading(tree, "Properties", function (before, section, after) {
|
||||
return [before, inTable, after];
|
||||
});
|
||||
}
|
||||
if (outTable) {
|
||||
heading(tree, "Events", function (before, section, after) {
|
||||
return [before, outTable, after];
|
||||
});
|
||||
}
|
||||
};
|
||||
return ComponentDocAutoContent;
|
||||
}());
|
||||
var ServiceDocAutoContent = /** @class */ (function () {
|
||||
function ServiceDocAutoContent() {
|
||||
this.props = [];
|
||||
this.methods = [];
|
||||
}
|
||||
ServiceDocAutoContent.prototype.extractClassInfoFromSource = function (checker, classDec) {
|
||||
var sourceFile = classDec.getSourceFile();
|
||||
for (var i = 0; i < classDec.members.length; i++) {
|
||||
var member = classDec.members[i];
|
||||
if (ts.isMethodDeclaration(member)) {
|
||||
var method = member;
|
||||
var mods = ts.getCombinedModifierFlags(method);
|
||||
var nonPrivate = (mods & ts.ModifierFlags.Private) === 0;
|
||||
var memSymbol = checker.getSymbolAtLocation(method.name);
|
||||
if (nonPrivate && memSymbol) {
|
||||
var methData = new MethodData();
|
||||
methData.name = memSymbol.getName();
|
||||
var doc = ts.displayPartsToString(memSymbol.getDocumentationComment());
|
||||
if (!doc)
|
||||
console.log("Warning: Method " + classDec.name.escapedText + "." + methData.name + " is not documented");
|
||||
methData.docText = doc.replace(/\r\n/g, " ");
|
||||
var sig = checker.getSignatureFromDeclaration(method);
|
||||
var returnType = sig.getReturnType();
|
||||
methData.returnType = checker.typeToString(returnType);
|
||||
var returnSymbol = returnType.getSymbol();
|
||||
var params = method.parameters;
|
||||
for (var p = 0; p < params.length; p++) {
|
||||
var pData = new ParamData();
|
||||
pData.name = params[p].name.getText();
|
||||
if (params[p].type)
|
||||
pData.type = params[p].type.getText();
|
||||
else
|
||||
pData.type = "";
|
||||
var paramSymbol = checker.getSymbolAtLocation(params[p].name);
|
||||
pData.docText = ts.displayPartsToString(paramSymbol.getDocumentationComment());
|
||||
if (!pData.docText)
|
||||
console.log("Warning: Parameter \"" + pData.name + "\" of " + classDec.name.escapedText + "." + methData.name + " is not documented");
|
||||
pData.optional = params[p].questionToken ? true : false;
|
||||
if (params[p].initializer) {
|
||||
var initText = params[p].initializer.getText();
|
||||
if (initText !== "undefined")
|
||||
pData.initializer = initText;
|
||||
}
|
||||
methData.params.push(pData);
|
||||
}
|
||||
this.methods.push(methData);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
ServiceDocAutoContent.prototype.addContentToDoc = function (tree) {
|
||||
var propsTable = buildPropsTable(this.props);
|
||||
var methodsList = buildMethodsList(this.methods);
|
||||
if (propsTable) {
|
||||
heading(tree, "Properties", function (before, section, after) {
|
||||
return [before, propsTable, after];
|
||||
});
|
||||
}
|
||||
if (methodsList) {
|
||||
heading(tree, "Methods", function (before, section, after) {
|
||||
return [before, methodsList, after];
|
||||
});
|
||||
}
|
||||
};
|
||||
return ServiceDocAutoContent;
|
||||
}());
|
||||
function updatePhase(tree, pathname, aggData) {
|
||||
var fileNameNoSuffix = path.basename(pathname, ".md");
|
||||
var itemType = fileNameNoSuffix.match(/component|directive|service/);
|
||||
if (itemType) {
|
||||
var srcData = aggData.srcData[fileNameNoSuffix];
|
||||
if (srcData) {
|
||||
var srcPath = srcData.path;
|
||||
var className = fixAngularFilename(fileNameNoSuffix);
|
||||
var classData = void 0;
|
||||
if ((itemType[0] === "component") || (itemType[0] === "directive")) {
|
||||
classData = new ComponentDocAutoContent();
|
||||
}
|
||||
else if (itemType[0] === "service") {
|
||||
classData = new ServiceDocAutoContent();
|
||||
}
|
||||
getDocSourceData(path.resolve(".", srcPath), className, classData);
|
||||
classData.addContentToDoc(tree);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.updatePhase = updatePhase;
|
||||
function initialCap(str) {
|
||||
return str[0].toUpperCase() + str.substr(1);
|
||||
}
|
||||
function fixAngularFilename(rawName) {
|
||||
if (nameExceptions[rawName])
|
||||
return nameExceptions[rawName];
|
||||
var name = rawName.replace(/\]|\(|\)/g, '');
|
||||
var fileNameSections = name.split('.');
|
||||
var compNameSections = fileNameSections[0].split('-');
|
||||
var outCompName = '';
|
||||
for (var i = 0; i < compNameSections.length; i++) {
|
||||
outCompName = outCompName + initialCap(compNameSections[i]);
|
||||
}
|
||||
var itemTypeIndicator = '';
|
||||
if (fileNameSections.length > 1) {
|
||||
itemTypeIndicator = initialCap(fileNameSections[1]);
|
||||
}
|
||||
var finalName = outCompName + itemTypeIndicator;
|
||||
return finalName;
|
||||
}
|
||||
function getDocSourceData(srcPath, docClassName, classData) {
|
||||
var prog = ts.createProgram([srcPath], {
|
||||
target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS
|
||||
});
|
||||
var sourceFiles = prog.getSourceFiles();
|
||||
var checker = prog.getTypeChecker();
|
||||
for (var i = 0; i < sourceFiles.length; i++) {
|
||||
if (!sourceFiles[i].isDeclarationFile)
|
||||
ts.forEachChild(sourceFiles[i], visit);
|
||||
}
|
||||
function visit(node) {
|
||||
if (!isNodeExported(node))
|
||||
return;
|
||||
if (ts.isClassDeclaration(node) && node.name) {
|
||||
var classDec = node;
|
||||
var sourceFile = classDec.getSourceFile();
|
||||
if (classDec.name.escapedText === docClassName) {
|
||||
getPropDataFromClassChain(checker, classDec, classData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Get properties/events from main class and all inherited classes.
|
||||
function getPropDataFromClassChain(checker, classDec, classData) {
|
||||
// Main class
|
||||
classData.extractClassInfoFromSource(checker, classDec);
|
||||
// Inherited classes
|
||||
if (classDec.heritageClauses) {
|
||||
for (var _i = 0, _a = classDec.heritageClauses; _i < _a.length; _i++) {
|
||||
var hc = _a[_i];
|
||||
var hcType = checker.getTypeFromTypeNode(hc.types[0]);
|
||||
for (var _b = 0, _c = hcType.symbol.declarations; _b < _c.length; _b++) {
|
||||
var dec = _c[_b];
|
||||
if (typescript_1.isClassDeclaration(dec)) {
|
||||
getPropDataFromClassChain(checker, dec, classData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function buildPropsTable(props, includeInitializer) {
|
||||
if (includeInitializer === void 0) { includeInitializer = true; }
|
||||
if (props.length === 0) {
|
||||
return null;
|
||||
}
|
||||
var headerCells = [
|
||||
unist.makeTableCell([unist.makeText("Name")]),
|
||||
unist.makeTableCell([unist.makeText("Type")])
|
||||
];
|
||||
if (includeInitializer)
|
||||
headerCells.push(unist.makeTableCell([unist.makeText("Default value")]));
|
||||
headerCells.push(unist.makeTableCell([unist.makeText("Description")]));
|
||||
var rows = [
|
||||
unist.makeTableRow(headerCells)
|
||||
];
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var pName = props[i].name;
|
||||
var pType = props[i].type;
|
||||
var pDesc = props[i].docText || "";
|
||||
if (pDesc) {
|
||||
pDesc = pDesc.replace(/[\n\r]+/, " ");
|
||||
}
|
||||
var descCellContent = remark().parse(pDesc).children;
|
||||
var pDefault = props[i].initializer || "";
|
||||
var defaultCellContent;
|
||||
if (pDefault) {
|
||||
if (pDefault.length > maxDefaultTextLength) {
|
||||
defaultCellContent = unist.makeText("See description");
|
||||
console.log("Warning: property \"" + pName + "\" default value substituted (> " + maxDefaultTextLength + " chars)");
|
||||
}
|
||||
else
|
||||
defaultCellContent = unist.makeInlineCode(pDefault);
|
||||
}
|
||||
else {
|
||||
defaultCellContent = unist.makeText("");
|
||||
}
|
||||
var cells = [
|
||||
unist.makeTableCell([unist.makeText(pName)]),
|
||||
unist.makeTableCell([unist.makeInlineCode(pType)])
|
||||
];
|
||||
if (includeInitializer)
|
||||
cells.push(unist.makeTableCell([defaultCellContent]));
|
||||
cells.push(unist.makeTableCell(descCellContent));
|
||||
rows.push(unist.makeTableRow(cells));
|
||||
}
|
||||
var spacers = [null, null, null];
|
||||
if (includeInitializer)
|
||||
spacers.push(null);
|
||||
return unist.makeTable(spacers, rows);
|
||||
}
|
||||
function buildMethodsList(methods) {
|
||||
if (methods.length === 0)
|
||||
return null;
|
||||
var listItems = [];
|
||||
for (var _i = 0, methods_1 = methods; _i < methods_1.length; _i++) {
|
||||
var method = methods_1[_i];
|
||||
var itemLines = [];
|
||||
itemLines.push(unist.makeInlineCode(method.getSignature()));
|
||||
itemLines.push(unist.makeBreak());
|
||||
itemLines.push(unist.makeParagraph(remark().parse(method.docText).children));
|
||||
itemLines.push(unist.makeBreak());
|
||||
var paramListItems = [];
|
||||
for (var _a = 0, _b = method.params; _a < _b.length; _a++) {
|
||||
var param = _b[_a];
|
||||
var currParamSections = [];
|
||||
if (param.docText !== "") {
|
||||
currParamSections.push(unist.makeInlineCode(param.name));
|
||||
var optionalPart = param.optional ? "(Optional) " : "";
|
||||
currParamSections.push(unist.makeText(" - " + optionalPart + param.docText));
|
||||
//currParamSections.push(unist.makeBreak());
|
||||
paramListItems.push(unist.makeListItem(unist.makeParagraph(currParamSections)));
|
||||
}
|
||||
}
|
||||
itemLines.push(unist.makeListUnordered(paramListItems));
|
||||
listItems.push(unist.makeListItem(unist.makeParagraph(itemLines)));
|
||||
}
|
||||
return unist.makeListUnordered(listItems);
|
||||
}
|
||||
function isNodeExported(node) {
|
||||
return (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Export) !== 0 || (!!node.parent && node.parent.kind === ts.SyntaxKind.SourceFile);
|
||||
}
|
@ -1,498 +0,0 @@
|
||||
import * as ts from "typescript";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
import * as heading from "mdast-util-heading-range";
|
||||
import * as remark from "remark";
|
||||
|
||||
import * as unist from "../unistHelpers";
|
||||
import { JsxEmit, isClassDeclaration, PropertyDeclaration } from "typescript";
|
||||
|
||||
|
||||
// Max number of characters in the text for the default value column.
|
||||
const maxDefaultTextLength = 20;
|
||||
|
||||
let nameExceptions = {
|
||||
"datatable.component": "DataTableComponent",
|
||||
"tasklist.service": "TaskListService"
|
||||
}
|
||||
|
||||
|
||||
export function initPhase(aggData) {
|
||||
}
|
||||
|
||||
export function readPhase(tree, pathname, aggData) {
|
||||
}
|
||||
|
||||
export function aggPhase(aggData) {
|
||||
}
|
||||
|
||||
|
||||
interface NgDocAutoContent {
|
||||
extractClassInfoFromSource(checker: ts.TypeChecker, classDec: ts.ClassDeclaration);
|
||||
addContentToDoc(tree);
|
||||
}
|
||||
|
||||
class PropData {
|
||||
name: string;
|
||||
type: string;
|
||||
initializer: string;
|
||||
docText: string;
|
||||
}
|
||||
|
||||
class ParamData {
|
||||
name: string;
|
||||
type: string;
|
||||
docText: string;
|
||||
initializer: string;
|
||||
optional: boolean;
|
||||
|
||||
getSignature() {
|
||||
let sig = this.name;
|
||||
|
||||
if (this.optional)
|
||||
sig += "?";
|
||||
|
||||
if (this.type)
|
||||
sig += ": " + this.type;
|
||||
|
||||
if (this.initializer)
|
||||
sig += " = " + this.initializer;
|
||||
|
||||
return sig;
|
||||
}
|
||||
}
|
||||
|
||||
class MethodData {
|
||||
name: string;
|
||||
docText: string;
|
||||
params: ParamData[];
|
||||
returnType: string;
|
||||
|
||||
constructor() {
|
||||
this.params = [];
|
||||
}
|
||||
|
||||
getSignature() {
|
||||
let sig = this.name + "(";
|
||||
|
||||
if (this.params.length > 0) {
|
||||
sig += this.params[0].getSignature();
|
||||
}
|
||||
|
||||
for (let i = 1; i < this.params.length; i++) {
|
||||
sig += ", " + this.params[i].getSignature();
|
||||
}
|
||||
|
||||
sig += ")";
|
||||
|
||||
if (this.returnType !== "void") {
|
||||
sig += ": " + this.returnType;
|
||||
}
|
||||
|
||||
return sig;
|
||||
}
|
||||
}
|
||||
|
||||
class ComponentDocAutoContent implements NgDocAutoContent {
|
||||
inputs: PropData[];
|
||||
outputs: PropData[];
|
||||
|
||||
constructor() {
|
||||
this.inputs = [];
|
||||
this.outputs = [];
|
||||
}
|
||||
|
||||
|
||||
extractClassInfoFromSource(checker: ts.TypeChecker, classDec: ts.ClassDeclaration) {
|
||||
let sourceFile = classDec.getSourceFile();
|
||||
|
||||
for (var i = 0; i < classDec.members.length; i++) {
|
||||
let member = classDec.members[i];
|
||||
|
||||
if (ts.isPropertyDeclaration(member) ||
|
||||
ts.isGetAccessorDeclaration(member) ||
|
||||
ts.isSetAccessorDeclaration(member)) {
|
||||
let prop: ts.PropertyDeclaration = member;
|
||||
|
||||
let mods = ts.getCombinedModifierFlags(prop);
|
||||
let nonPrivate = (mods & ts.ModifierFlags.Private) === 0;
|
||||
let memSymbol = checker.getSymbolAtLocation(prop.name);
|
||||
|
||||
if (nonPrivate && memSymbol && prop.decorators) {
|
||||
let name = memSymbol.getName();
|
||||
let initializer = "";
|
||||
|
||||
if (prop.initializer) {
|
||||
initializer = prop.initializer.getText(sourceFile);
|
||||
}
|
||||
|
||||
let doc = ts.displayPartsToString(memSymbol.getDocumentationComment(checker));
|
||||
doc = doc.replace(/\r\n/g, " ");
|
||||
|
||||
let propType = checker.typeToString(checker.getTypeOfSymbolAtLocation(memSymbol, memSymbol.valueDeclaration!));
|
||||
|
||||
let dec = prop.decorators[0].getText(sourceFile);
|
||||
|
||||
if (dec.match(/@Input/)) {
|
||||
this.inputs.push({
|
||||
"name": name,
|
||||
"type": propType,
|
||||
"initializer": initializer,
|
||||
"docText": doc
|
||||
});
|
||||
} else if (dec.match(/@Output/)) {
|
||||
this.outputs.push({
|
||||
"name": name,
|
||||
"type": propType,
|
||||
"initializer": "",
|
||||
"docText": doc
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
addContentToDoc(tree) {
|
||||
let inTable = buildPropsTable(this.inputs);
|
||||
let outTable = buildPropsTable(this.outputs, false);
|
||||
|
||||
if (inTable) {
|
||||
heading(tree, "Properties", (before, section, after) => {
|
||||
return [before, inTable, after];
|
||||
});
|
||||
}
|
||||
|
||||
if (outTable) {
|
||||
heading(tree, "Events", (before, section, after) => {
|
||||
return [before, outTable, after];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ServiceDocAutoContent implements NgDocAutoContent {
|
||||
props: PropData[];
|
||||
methods: MethodData[];
|
||||
|
||||
constructor() {
|
||||
this.props = [];
|
||||
this.methods = [];
|
||||
}
|
||||
|
||||
|
||||
extractClassInfoFromSource(checker: ts.TypeChecker, classDec: ts.ClassDeclaration) {
|
||||
let sourceFile = classDec.getSourceFile();
|
||||
|
||||
for (var i = 0; i < classDec.members.length; i++) {
|
||||
let member = classDec.members[i];
|
||||
|
||||
if (ts.isMethodDeclaration(member)) {
|
||||
let method: ts.MethodDeclaration = member;
|
||||
|
||||
let mods = ts.getCombinedModifierFlags(method);
|
||||
let nonPrivate = (mods & ts.ModifierFlags.Private) === 0;
|
||||
let memSymbol = checker.getSymbolAtLocation(method.name);
|
||||
|
||||
if (nonPrivate && memSymbol) {
|
||||
let methData = new MethodData();
|
||||
|
||||
methData.name = memSymbol.getName();
|
||||
let doc = ts.displayPartsToString(memSymbol.getDocumentationComment());
|
||||
|
||||
if (!doc)
|
||||
console.log(`Warning: Method ${classDec.name.escapedText}.${methData.name} is not documented`);
|
||||
|
||||
methData.docText = doc.replace(/\r\n/g, " ");
|
||||
let sig = checker.getSignatureFromDeclaration(method);
|
||||
let returnType = sig.getReturnType();
|
||||
methData.returnType = checker.typeToString(returnType);
|
||||
let returnSymbol = returnType.getSymbol();
|
||||
|
||||
let params = method.parameters;
|
||||
|
||||
for (let p = 0; p < params.length; p++){
|
||||
let pData = new ParamData();
|
||||
pData.name = params[p].name.getText();
|
||||
|
||||
if (params[p].type)
|
||||
pData.type = params[p].type.getText();
|
||||
else
|
||||
pData.type = "";
|
||||
|
||||
let paramSymbol = checker.getSymbolAtLocation(params[p].name);
|
||||
pData.docText = ts.displayPartsToString(paramSymbol.getDocumentationComment());
|
||||
|
||||
if (!pData.docText)
|
||||
console.log(`Warning: Parameter "${pData.name}" of ${classDec.name.escapedText}.${methData.name} is not documented`);
|
||||
|
||||
pData.optional = params[p].questionToken ? true : false;
|
||||
|
||||
if (params[p].initializer) {
|
||||
let initText = params[p].initializer.getText();
|
||||
|
||||
if (initText !== "undefined")
|
||||
pData.initializer = initText;
|
||||
}
|
||||
|
||||
methData.params.push(pData);
|
||||
}
|
||||
|
||||
this.methods.push(methData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
addContentToDoc(tree) {
|
||||
let propsTable = buildPropsTable(this.props);
|
||||
let methodsList = buildMethodsList(this.methods);
|
||||
|
||||
if (propsTable) {
|
||||
heading(tree, "Properties", (before, section, after) => {
|
||||
return [before, propsTable, after];
|
||||
});
|
||||
}
|
||||
|
||||
if (methodsList) {
|
||||
heading(tree, "Methods", (before, section, after) => {
|
||||
return [before, methodsList, after];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function updatePhase(tree, pathname, aggData) {
|
||||
let fileNameNoSuffix = path.basename(pathname, ".md");
|
||||
|
||||
let itemType = fileNameNoSuffix.match(/component|directive|service/);
|
||||
|
||||
if (itemType) {
|
||||
let srcData = aggData.srcData[fileNameNoSuffix];
|
||||
|
||||
if (srcData) {
|
||||
let srcPath = srcData.path;
|
||||
let className = fixAngularFilename(fileNameNoSuffix);
|
||||
|
||||
let classData: NgDocAutoContent;
|
||||
|
||||
if ((itemType[0] === "component") || (itemType[0] === "directive")) {
|
||||
classData = new ComponentDocAutoContent();
|
||||
} else if (itemType[0] === "service") {
|
||||
classData = new ServiceDocAutoContent();
|
||||
}
|
||||
|
||||
getDocSourceData(path.resolve(".", srcPath), className, classData);
|
||||
classData.addContentToDoc(tree);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function initialCap(str: string) {
|
||||
return str[0].toUpperCase() + str.substr(1);
|
||||
}
|
||||
|
||||
|
||||
function fixAngularFilename(rawName: string) {
|
||||
if (nameExceptions[rawName])
|
||||
return nameExceptions[rawName];
|
||||
|
||||
var name = rawName.replace(/\]|\(|\)/g, '');
|
||||
|
||||
var fileNameSections = name.split('.');
|
||||
var compNameSections = fileNameSections[0].split('-');
|
||||
|
||||
var outCompName = '';
|
||||
|
||||
for (var i = 0; i < compNameSections.length; i++) {
|
||||
outCompName = outCompName + initialCap(compNameSections[i]);
|
||||
}
|
||||
|
||||
var itemTypeIndicator = '';
|
||||
|
||||
if (fileNameSections.length > 1) {
|
||||
itemTypeIndicator = initialCap(fileNameSections[1]);
|
||||
}
|
||||
|
||||
var finalName = outCompName + itemTypeIndicator;
|
||||
|
||||
return finalName;
|
||||
}
|
||||
|
||||
|
||||
function getDocSourceData(srcPath: string, docClassName: string, classData: NgDocAutoContent) {
|
||||
let prog = ts.createProgram([srcPath], {
|
||||
target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS
|
||||
});
|
||||
|
||||
let sourceFiles = prog.getSourceFiles();
|
||||
let checker = prog.getTypeChecker();
|
||||
|
||||
for (var i = 0; i < sourceFiles.length; i++) {
|
||||
if (!sourceFiles[i].isDeclarationFile)
|
||||
ts.forEachChild(sourceFiles[i], visit);
|
||||
}
|
||||
|
||||
function visit(node: ts.Node) {
|
||||
if (!isNodeExported(node))
|
||||
return;
|
||||
|
||||
if (ts.isClassDeclaration(node) && node.name) {
|
||||
let classDec: ts.ClassDeclaration = node;
|
||||
let sourceFile = classDec.getSourceFile();
|
||||
|
||||
if (classDec.name.escapedText === docClassName) {
|
||||
getPropDataFromClassChain(checker, classDec, classData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get properties/events from main class and all inherited classes.
|
||||
function getPropDataFromClassChain(
|
||||
checker: ts.TypeChecker,
|
||||
classDec: ts.ClassDeclaration,
|
||||
classData: NgDocAutoContent
|
||||
){
|
||||
// Main class
|
||||
classData.extractClassInfoFromSource(checker, classDec);
|
||||
|
||||
// Inherited classes
|
||||
if (classDec.heritageClauses) {
|
||||
for(const hc of classDec.heritageClauses) {
|
||||
let hcType = checker.getTypeFromTypeNode(hc.types[0]);
|
||||
|
||||
for (const dec of hcType.symbol.declarations) {
|
||||
if (isClassDeclaration(dec)) {
|
||||
getPropDataFromClassChain(checker, dec, classData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function buildPropsTable(props: PropData[], includeInitializer: boolean = true) {
|
||||
if (props.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var headerCells = [
|
||||
unist.makeTableCell([unist.makeText("Name")]),
|
||||
unist.makeTableCell([unist.makeText("Type")])
|
||||
];
|
||||
|
||||
if (includeInitializer)
|
||||
headerCells.push(unist.makeTableCell([unist.makeText("Default value")]));
|
||||
|
||||
headerCells.push(unist.makeTableCell([unist.makeText("Description")]));
|
||||
|
||||
var rows = [
|
||||
unist.makeTableRow(headerCells)
|
||||
];
|
||||
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var pName = props[i].name;
|
||||
var pType = props[i].type;
|
||||
var pDesc = props[i].docText || "";
|
||||
|
||||
if (pDesc) {
|
||||
pDesc = pDesc.replace(/[\n\r]+/, " ");
|
||||
}
|
||||
|
||||
var descCellContent = remark().parse(pDesc).children;
|
||||
|
||||
var pDefault = props[i].initializer || "";
|
||||
|
||||
var defaultCellContent;
|
||||
|
||||
if (pDefault) {
|
||||
if (pDefault.length > maxDefaultTextLength) {
|
||||
defaultCellContent = unist.makeText("See description");
|
||||
console.log(`Warning: property "${pName}" default value substituted (> ${maxDefaultTextLength} chars)`);
|
||||
} else
|
||||
defaultCellContent = unist.makeInlineCode(pDefault);
|
||||
} else {
|
||||
defaultCellContent = unist.makeText("");
|
||||
}
|
||||
|
||||
var cells = [
|
||||
unist.makeTableCell([unist.makeText(pName)]),
|
||||
unist.makeTableCell([unist.makeInlineCode(pType)])
|
||||
];
|
||||
|
||||
if (includeInitializer)
|
||||
cells.push(unist.makeTableCell([defaultCellContent]));
|
||||
|
||||
cells.push(unist.makeTableCell(descCellContent));
|
||||
|
||||
rows.push(unist.makeTableRow(cells));
|
||||
}
|
||||
|
||||
let spacers = [null, null, null];
|
||||
|
||||
if (includeInitializer)
|
||||
spacers.push(null);
|
||||
|
||||
return unist.makeTable(spacers, rows);
|
||||
}
|
||||
|
||||
|
||||
function buildMethodsList(methods: MethodData[]) {
|
||||
if (methods.length === 0)
|
||||
return null;
|
||||
|
||||
let listItems = [];
|
||||
|
||||
for (let method of methods) {
|
||||
let itemLines = [];
|
||||
|
||||
itemLines.push(unist.makeInlineCode(method.getSignature()));
|
||||
itemLines.push(unist.makeBreak());
|
||||
itemLines.push(unist.makeParagraph(remark().parse(method.docText).children));
|
||||
itemLines.push(unist.makeBreak());
|
||||
|
||||
let paramListItems = [];
|
||||
|
||||
for (let param of method.params) {
|
||||
let currParamSections = [];
|
||||
|
||||
if (param.docText !== "") {
|
||||
currParamSections.push(unist.makeInlineCode(param.name));
|
||||
|
||||
let optionalPart = param.optional ? "(Optional) " : "";
|
||||
|
||||
currParamSections.push(unist.makeText(" - " + optionalPart + param.docText));
|
||||
//currParamSections.push(unist.makeBreak());
|
||||
paramListItems.push(unist.makeListItem(unist.makeParagraph(currParamSections)));
|
||||
}
|
||||
}
|
||||
|
||||
itemLines.push(unist.makeListUnordered(paramListItems));
|
||||
|
||||
|
||||
listItems.push(unist.makeListItem(unist.makeParagraph(itemLines)));
|
||||
}
|
||||
|
||||
return unist.makeListUnordered(listItems);
|
||||
}
|
||||
|
||||
|
||||
function isNodeExported(node: ts.Node): boolean {
|
||||
return (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Export) !== 0 || (!!node.parent && node.parent.kind === ts.SyntaxKind.SourceFile);
|
||||
}
|
@ -12,24 +12,9 @@ var includedNodeTypes = [
|
||||
];
|
||||
var docFolder = path.resolve("docs");
|
||||
var adfLibNames = ["core", "content-services", "insights", "process-services"];
|
||||
var externalTypes = {
|
||||
'Blob': 'https://developer.mozilla.org/en-US/docs/Web/API/Blob',
|
||||
'EventEmitter': 'https://angular.io/api/core/EventEmitter',
|
||||
'MatSnackBarRef': 'https://material.angular.io/components/snack-bar/overview',
|
||||
'TemplateRef': 'https://angular.io/api/core/TemplateRef',
|
||||
'Observable': 'http://reactivex.io/documentation/observable.html',
|
||||
'Subject': 'http://reactivex.io/documentation/subject.html',
|
||||
'AppDefinitionRepresentation': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-activiti-rest-api/docs/AppDefinitionRepresentation.md',
|
||||
'DeletedNodesPaging': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/DeletedNodesPaging.md',
|
||||
'MinimalNodeEntity': '../content-services/document-library.model.md',
|
||||
'MinimalNodeEntryEntity': '../content-services/document-library.model.md',
|
||||
'NodeEntry': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md',
|
||||
'ProcessInstanceFilterRepresentation': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-activiti-rest-api/docs/ProcessInstanceFilterRepresentation.md',
|
||||
'RelatedContentRepresentation': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-activiti-rest-api/docs/RelatedContentRepresentation.md',
|
||||
'SiteEntry': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/SiteEntry.md',
|
||||
'SitePaging': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/SitePaging.md'
|
||||
};
|
||||
var externalNameLinks;
|
||||
function initPhase(aggData) {
|
||||
externalNameLinks = aggData.config.externalNameLinks;
|
||||
aggData.docFiles = {};
|
||||
aggData.nameLookup = new SplitNameLookup();
|
||||
adfLibNames.forEach(function (libName) {
|
||||
@ -303,8 +288,8 @@ function resolveTypeLink(aggData, text) {
|
||||
}
|
||||
return url;
|
||||
}
|
||||
else if (externalTypes[possTypeName]) {
|
||||
return externalTypes[possTypeName];
|
||||
else if (externalNameLinks[possTypeName]) {
|
||||
return externalNameLinks[possTypeName];
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
|
@ -33,6 +33,7 @@ const docFolder = path.resolve("docs");
|
||||
const adfLibNames = ["core", "content-services", "insights", "process-services"];
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
const externalTypes = {
|
||||
'Blob': 'https://developer.mozilla.org/en-US/docs/Web/API/Blob',
|
||||
'EventEmitter': 'https://angular.io/api/core/EventEmitter',
|
||||
@ -51,8 +52,12 @@ const externalTypes = {
|
||||
'SitePaging': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/SitePaging.md'
|
||||
};
|
||||
|
||||
=======
|
||||
let externalNameLinks;
|
||||
>>>>>>> [ADF-3150] Moved config to doctools.config.json and removed obsolete scripts
|
||||
|
||||
export function initPhase(aggData) {
|
||||
externalNameLinks = aggData.config.externalNameLinks;
|
||||
aggData.docFiles = {};
|
||||
aggData.nameLookup = new SplitNameLookup();
|
||||
|
||||
@ -373,8 +378,8 @@ function resolveTypeLink(aggData, text): string {
|
||||
}
|
||||
|
||||
return url;
|
||||
} else if (externalTypes[possTypeName]) {
|
||||
return externalTypes[possTypeName];
|
||||
} else if (externalNameLinks[possTypeName]) {
|
||||
return externalNameLinks[possTypeName];
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user