diff --git a/docs/versionIndex.md b/docs/versionIndex.md index ff41e6b474..01fc9a418c 100644 --- a/docs/versionIndex.md +++ b/docs/versionIndex.md @@ -33,6 +33,9 @@ backend services have been tested with each released version of ADF. - [Decimal number pipe](core/pipes/decimal-number.pipe.md) +- [Identity group service](core/services/identity-group.service.md) +- [Local preference cloud service](process-services-cloud/services/local-preference-cloud.service.md) +- [User preference cloud service](process-services-cloud/services/user-preference-cloud.service.md) diff --git a/lib/core/userinfo/components/user-info.component.html b/lib/core/userinfo/components/user-info.component.html index 185ebd80a7..91cf4ae4e2 100644 --- a/lib/core/userinfo/components/user-info.component.html +++ b/lib/core/userinfo/components/user-info.component.html @@ -1,5 +1,5 @@ -
+
licenses.txt", @@ -126,10 +127,11 @@ "@angular/compiler-cli": "^7.2.15", "@nrwl/nx": "7.1.1", "@nrwl/schematics": "7.1.1", + "@paperist/types-remark": "^0.1.3", "@types/hammerjs": "2.0.35", "@types/jasmine": "~2.8.3", "@types/jasminewd2": "~2.0.2", - "@types/node": "6.0.90", + "@types/node": "^12.7.3", "@types/selenium-webdriver": "^3.0.8", "ajv-cli": "^3.0.0", "bundlesize": "^0.17.2", @@ -167,6 +169,7 @@ "lite-server": "^2.4.0", "lodash.wrap": "^4.1.1", "markdownlint-cli": "^0.16.0", + "mdast": "^3.0.0", "mdast-util-compact": "^1.0.1", "mdast-util-heading-range": "^2.1.0", "mdast-util-toc": "^2.0.1", diff --git a/tools/doc/docProcessor.js b/tools/doc/docProcessor.js index d4a2599d3e..55fcc902bb 100644 --- a/tools/doc/docProcessor.js +++ b/tools/doc/docProcessor.js @@ -9,7 +9,7 @@ var remark = require("remark"); var frontMatter = require("remark-frontmatter"); var mdCompact = require("mdast-util-compact"); -var si = require("./SourceInfoClasses"); +var si = require("./sourceInfoClasses"); // "Aggregate" data collected over the whole file set. var aggData = {}; diff --git a/tools/doc/mdNav.js b/tools/doc/mdNav.js index 3058e5a6f2..04b0e5c6c9 100644 --- a/tools/doc/mdNav.js +++ b/tools/doc/mdNav.js @@ -51,105 +51,105 @@ var MDNav = /** @class */ (function () { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.find(function (h) { - return h.type === "emphasis" && test(h); + return h.type === 'emphasis' && test(h); }, index); }; MDNav.prototype.heading = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.find(function (h) { - return h.type === "heading" && test(h); + return h.type === 'heading' && test(h); }, index); }; MDNav.prototype.headings = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.findAll(function (h) { - return h.type === "heading" && test(h); + return h.type === 'heading' && test(h); }, index); }; MDNav.prototype.html = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.find(function (h) { - return h.type === "html" && test(h); + return h.type === 'html' && test(h); }, index); }; MDNav.prototype.link = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.find(function (h) { - return h.type === "link" && test(h); + return h.type === 'link' && test(h); }, index); }; MDNav.prototype.links = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.findAll(function (h) { - return h.type === "link" && test(h); + return h.type === 'link' && test(h); }, index); }; MDNav.prototype.list = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.find(function (h) { - return h.type === "list" && test(h); + return h.type === 'list' && test(h); }, index); }; MDNav.prototype.listItem = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.find(function (h) { - return h.type === "listItem" && test(h); + return h.type === 'listItem' && test(h); }, index); }; MDNav.prototype.listItems = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.findAll(function (h) { - return h.type === "listItem" && test(h); + return h.type === 'listItem' && test(h); }, index); }; MDNav.prototype.paragraph = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.find(function (h) { - return h.type === "paragraph" && test(h); + return h.type === 'paragraph' && test(h); }, index); }; MDNav.prototype.strong = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.find(function (h) { - return h.type === "strong" && test(h); + return h.type === 'strong' && test(h); }, index); }; MDNav.prototype.table = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.find(function (h) { - return h.type === "table" && test(h); + return h.type === 'table' && test(h); }, index); }; MDNav.prototype.tableRow = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.find(function (h) { - return h.type === "tableRow" && test(h); + return h.type === 'tableRow' && test(h); }, index); }; MDNav.prototype.tableCell = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.find(function (h) { - return h.type === "tableCell" && test(h); + return h.type === 'tableCell' && test(h); }, index); }; MDNav.prototype.text = function (test, index) { if (test === void 0) { test = function () { return true; }; } if (index === void 0) { index = 0; } return this.find(function (h) { - return h.type === "text" && test(h); + return h.type === 'text' && test(h); }, index); }; Object.defineProperty(MDNav.prototype, "item", { @@ -182,11 +182,11 @@ var MDNav = /** @class */ (function () { }); Object.defineProperty(MDNav.prototype, "value", { get: function () { - if (this.item && this.item["value"]) { + if (this.item && this.item['value']) { return this.item.value; } else { - return ""; + return ''; } }, enumerable: true, @@ -195,20 +195,20 @@ var MDNav = /** @class */ (function () { Object.defineProperty(MDNav.prototype, "textValue", { get: function () { if (this.item) { - if (this.item["value"]) { + if (this.item['value']) { return this.item.value; } else if (this.item.children && (this.item.children.length > 0) && - (this.item.children[0].type === "text")) { + (this.item.children[0].type === 'text')) { return this.item.children[0].value; } else { - return ""; + return ''; } } else { - return ""; + return ''; } }, enumerable: true, diff --git a/tools/doc/mdNav.ts b/tools/doc/mdNav.ts index 2ac4bf7eae..a7a3b2e255 100644 --- a/tools/doc/mdNav.ts +++ b/tools/doc/mdNav.ts @@ -11,7 +11,7 @@ export class MDNav { let currIndex = 0; for (let i = this.pos; i < this.root.children.length; i++) { - let child = this.root.children[i]; + const child = this.root.children[i]; if (test(child)) { if (currIndex === index) { @@ -30,12 +30,12 @@ export class MDNav { return []; } - let result = []; + const result = []; let currIndex = 0; for (let i = this.pos; i < this.root.children.length; i++) { - let child = this.root.children[i]; + const child = this.root.children[i]; if (test(child)) { if (currIndex === index) { @@ -49,107 +49,96 @@ export class MDNav { return result; } - emph(test: (element: any) => boolean = () => true, index: number = 0): MDNav { return this.find((h) => { - return h.type === "emphasis" && test(h); + return h.type === 'emphasis' && test(h); }, index); } - heading(test: (element: any) => boolean = () => true, index: number = 0): MDNav { return this.find((h) => { - return h.type === "heading" && test(h); + return h.type === 'heading' && test(h); }, index); } - headings(test: (element: any) => boolean = () => true, index: number = 0): MDNav[] { return this.findAll((h) => { - return h.type === "heading" && test(h); + return h.type === 'heading' && test(h); }, index); } - html(test: (element: any) => boolean = () => true, index: number = 0): MDNav { return this.find((h) => { - return h.type === "html" && test(h); + return h.type === 'html' && test(h); }, index); } link(test: (element: any) => boolean = () => true, index: number = 0): MDNav { return this.find((h) => { - return h.type === "link" && test(h); + return h.type === 'link' && test(h); }, index); } links(test: (element: any) => boolean = () => true, index: number = 0): MDNav[] { return this.findAll((h) => { - return h.type === "link" && test(h); + return h.type === 'link' && test(h); }, index); } list(test: (element: any) => boolean = () => true, index: number = 0): MDNav { return this.find((h) => { - return h.type === "list" && test(h); + return h.type === 'list' && test(h); }, index); } - listItem(test: (element: any) => boolean = () => true, index: number = 0): MDNav { return this.find((h) => { - return h.type === "listItem" && test(h); + return h.type === 'listItem' && test(h); }, index); } listItems(test: (element: any) => boolean = () => true, index: number = 0): MDNav[] { return this.findAll((h) => { - return h.type === "listItem" && test(h); + return h.type === 'listItem' && test(h); }, index); } paragraph(test: (element: any) => boolean = () => true, index: number = 0): MDNav { return this.find((h) => { - return h.type === "paragraph" && test(h); + return h.type === 'paragraph' && test(h); }, index); } - strong(test: (element: any) => boolean = () => true, index: number = 0): MDNav { return this.find((h) => { - return h.type === "strong" && test(h); + return h.type === 'strong' && test(h); }, index); } - table(test: (element: any) => boolean = () => true, index: number = 0): MDNav { return this.find((h) => { - return h.type === "table" && test(h); + return h.type === 'table' && test(h); }, index); } - tableRow(test: (element: any) => boolean = () => true, index: number = 0): MDNav { return this.find((h) => { - return h.type === "tableRow" && test(h); + return h.type === 'tableRow' && test(h); }, index); } - tableCell(test: (element: any) => boolean = () => true, index: number = 0): MDNav { return this.find((h) => { - return h.type === "tableCell" && test(h); + return h.type === 'tableCell' && test(h); }, index); } - text(test: (element: any) => boolean = () => true, index: number = 0): MDNav { return this.find((h) => { - return h.type === "text" && test(h); + return h.type === 'text' && test(h); }, index); } - get item(): any { if (!this.root || !this.root.children) { return undefined; @@ -164,36 +153,33 @@ export class MDNav { (this.pos >= this.root.children.length); } - get childNav(): MDNav { return new MDNav(this.item); } - get value(): any { - if (this.item && this.item["value"]) { + if (this.item && this.item['value']) { return this.item.value; } else { - return ""; + return ''; } } - - get textValue() : string { + get textValue(): string { if (this.item) { - if (this.item["value"]) { + if (this.item['value']) { return this.item.value; } else if ( this.item.children && (this.item.children.length > 0) && - (this.item.children[0].type === "text") - ){ + (this.item.children[0].type === 'text') + ) { return this.item.children[0].value; } else { - return ""; + return ''; } } else { - return ""; + return ''; } } } diff --git a/tools/doc/mqDefs.ts b/tools/doc/mqDefs.ts index e6070d1ea1..6f43d02540 100644 --- a/tools/doc/mqDefs.ts +++ b/tools/doc/mqDefs.ts @@ -1,7 +1,6 @@ import { MDAST } from 'mdast'; import { UNIST } from 'unist'; import * as mdToString from 'mdast-util-to-string'; - import * as jsyaml from 'js-yaml'; export let schema = ` @@ -107,7 +106,6 @@ export class Node { } } - export class Parent { constructor(protected orig: UNIST.Parent) {} @@ -161,43 +159,43 @@ export class Parent { export class Root extends Parent { _meta: {}; - public id: string + id: string; type(): string { return 'root'; } folder(args): string { - let depth = args['depth']; + const depth = args['depth']; + const relPath = this.id.substring(this.id.indexOf('docs')); + const pathSegments = relPath.split(/[\\\/]/); - let relPath = this.id.substring(this.id.indexOf('docs')); - let pathSegments = relPath.split(/[\\\/]/); return pathSegments[depth]; } metadata(args): string { if (!this._meta) { - let yamlElement: MDAST.YAML = this.orig.children.find( + const yamlElement: any = this.orig.children.find( (ch: UNIST.Node) => (ch.type === 'yaml') ); if (yamlElement) { - this._meta = jsyaml.safeLoad(yamlElement.value) + this._meta = jsyaml.safeLoad(yamlElement.value); } else { this._meta = {}; } } if (this._meta[args['key']]) { - return this._meta[args['key']] + return this._meta[args['key']]; } else { return ''; } } heading(args): Heading { - let depth = args['depth']; - + const depth = args['depth']; + return new Heading( this.orig.children.find( (ch: UNIST.Node) => (ch.type === 'heading') && @@ -205,32 +203,28 @@ export class Root extends Parent { )); } - headings(args): Heading[] { - let depth = args['depth']; + const depth = args['depth']; return this.orig.children.filter( (ch: UNIST.Node) => (ch.type === 'heading') && ((depth === 0) || (depth === ( ch).depth))) .map(ch => new Heading( ch)); - } + } } export class Heading extends Parent { - depth(): number { return ( this.orig).depth; } } - export class Paragraph extends Parent { } - export class Link extends Parent { - + title(): string { return ( this.orig).title; } @@ -248,9 +242,7 @@ export class Text { } } - -let libNamesRegex = /content-services|core|extensions|insights|process-services|process-services-cloud/; - +const libNamesRegex = /content-services|core|extensions|insights|process-services|process-services-cloud/; export class Docset { public docs: Root[]; @@ -258,14 +250,14 @@ export class Docset { constructor(mdCache) { this.docs = []; - let pathnames = Object.keys(mdCache); + const pathnames = Object.keys(mdCache); pathnames.forEach(pathname => { if (!pathname.match(/README/) && pathname.match(libNamesRegex) ) { - let doc = new Root(mdCache[pathname].mdInTree); + const doc = new Root(mdCache[pathname].mdInTree); doc.id = pathname.replace(/\\/g, '/'); this.docs.push(doc); } @@ -283,4 +275,4 @@ export class Docset { size(): number { return this.docs.length; } -} \ No newline at end of file +} diff --git a/tools/doc/remarkGraphQl.js b/tools/doc/remarkGraphQl.js index c914bf512e..1bb52052cc 100644 --- a/tools/doc/remarkGraphQl.js +++ b/tools/doc/remarkGraphQl.js @@ -10,15 +10,15 @@ var MQ = require("./mqDefs"); var docFilePath = path.resolve('..', '..', 'docs', 'core', 'about.component.md'); var docSrc = fs.readFileSync(docFilePath, 'utf8'); var tree = remark() - .use(frontMatter, ["yaml"]) + .use(frontMatter, ['yaml']) .parse(docSrc); tree = removePosInfo(tree); -//console.log(JSON.stringify(tree)); var schema = graphql_1.buildSchema(MQ.schema); var root = { document: function () { return new MQ.Root(tree); } }; var query = "\n {\n document {\n metadata(key: \"Status\")\n heading {\n link {\n text {\n value\n }\n }\n }\n paragraph {\n plaintext\n }\n }\n }\n"; graphql_1.graphql(schema, query, root).then(function (response) { + // tslint:disable-next-line: no-console console.log(JSON.stringify(response)); }); diff --git a/tools/doc/remarkGraphQl.ts b/tools/doc/remarkGraphQl.ts index ec81d5f380..e50b4bc8ad 100644 --- a/tools/doc/remarkGraphQl.ts +++ b/tools/doc/remarkGraphQl.ts @@ -10,25 +10,22 @@ import * as removePosInfo from 'unist-util-remove-position'; import * as MQ from './mqDefs'; -let docFilePath = path.resolve('..', '..', 'docs', 'core', 'about.component.md'); -let docSrc = fs.readFileSync(docFilePath, 'utf8'); +const docFilePath = path.resolve('..', '..', 'docs', 'core', 'about.component.md'); +const docSrc = fs.readFileSync(docFilePath, 'utf8'); let tree: MDAST.Root = remark() -.use(frontMatter, ["yaml"]) -.parse(docSrc); + .use(frontMatter, ['yaml']) + .parse(docSrc); tree = removePosInfo(tree); -//console.log(JSON.stringify(tree)); +const schema = buildSchema(MQ.schema); -let schema = buildSchema(MQ.schema); - -let root = { +const root = { document: () => new MQ.Root(tree) }; - -let query = ` +const query = ` { document { metadata(key: "Status") @@ -47,5 +44,6 @@ let query = ` `; graphql(schema, query, root).then((response) => { + // tslint:disable-next-line: no-console console.log(JSON.stringify(response)); -}); \ No newline at end of file +}); diff --git a/tools/doc/reviewChecker.js b/tools/doc/reviewChecker.js index 70902b718a..f7e081cb05 100644 --- a/tools/doc/reviewChecker.js +++ b/tools/doc/reviewChecker.js @@ -1,4 +1,5 @@ "use strict"; +// tslint:disable: no-console Object.defineProperty(exports, "__esModule", { value: true }); var path = require("path"); var fs = require("fs"); @@ -8,27 +9,20 @@ var remark = require("remark"); var frontMatter = require("remark-frontmatter"); var yaml = require("js-yaml"); var moment = require("moment"); -var Rx_1 = require("rxjs/Rx"); +var rxjs_1 = require("rxjs"); var libsearch = require("./libsearch"); var stoplist_1 = require("./stoplist"); -var adf20StartDate = "2017-11-20"; +var adf20StartDate = '2017-11-20'; var commitWeight = 0.1; var scoreTimeBase = 60; -var libFolder = "lib"; -var stoplistFilePath = path.resolve("tools", "doc", "commitStoplist.json"); +var libFolder = 'lib'; +var stoplistFilePath = path.resolve('tools', 'doc', 'commitStoplist.json'); var angFilePattern = /(component)|(directive)|(model)|(pipe)|(service)|(widget)/; var srcData = {}; var stoplist = new stoplist_1.Stoplist(stoplistFilePath); -var docsFolderPath = path.resolve("docs"); -var libFolders = ["core", "content-services", "extensions", "insights", "process-services", "process-services-cloud"]; +var docsFolderPath = path.resolve('docs'); +var libFolders = ['core', 'content-services', 'extensions', 'insights', 'process-services', 'process-services-cloud']; libsearch(srcData, path.resolve(libFolder)); -/* -let keys = Object.keys(srcData); - -for (let i = 0; i < keys.length; i++) { - console.log(keys[i]); -} -*/ var authToken = process.env.graphAuthToken; var client = new graphql_request_1.GraphQLClient('https://api.github.com/graphql', { headers: { @@ -37,20 +31,21 @@ var client = new graphql_request_1.GraphQLClient('https://api.github.com/graphql }); var query = "query commitHistory($path: String) {\n repository(name: \"alfresco-ng2-components\", owner: \"alfresco\") {\n ref(qualifiedName: \"development\") {\n target {\n ... on Commit {\n history(first: 15, path: $path) {\n nodes {\n pushedDate\n message\n }\n }\n }\n }\n }\n }\n}"; var docFiles = getDocFilePaths(docsFolderPath); -var docNames = Rx_1.Observable.from(docFiles); +var docNames = rxjs_1.of(docFiles); console.log("'Name','Review date','Commits since review','Score'"); docNames.subscribe(function (x) { - var key = path.basename(x, ".md"); - if (!srcData[key]) + var key = path.basename(x, '.md'); + if (!srcData[key]) { return; + } var vars = { - "path": "lib/" + srcData[key].path + 'path': 'lib/' + srcData[key].path }; client.request(query, vars).then(function (data) { - var nodes = data["repository"].ref.target.history.nodes; - var lastReviewDate = getDocReviewDate(x); //(key + ".md"); + var nodes = data['repository'].ref.target.history.nodes; + var lastReviewDate = getDocReviewDate(x); // (key + ".md"); var numUsefulCommits = extractCommitInfo(nodes, lastReviewDate, stoplist); - var dateString = lastReviewDate.format("YYYY-MM-DD"); + var dateString = lastReviewDate.format('YYYY-MM-DD'); var score = priorityScore(lastReviewDate, numUsefulCommits).toPrecision(3); console.log("'" + key + "','" + dateString + "','" + numUsefulCommits + "','" + score + "'"); }); @@ -63,12 +58,13 @@ function priorityScore(reviewDate, numCommits) { function getDocReviewDate(docFileName) { var mdFilePath = path.resolve(docsFolderPath, docFileName); var mdText = fs.readFileSync(mdFilePath); - var tree = remark().use(frontMatter, ["yaml"]).parse(mdText); + var tree = remark().use(frontMatter, ['yaml']).parse(mdText); var lastReviewDate = moment(adf20StartDate); - if (tree.children[0].type == "yaml") { + if (tree.children[0].type === 'yaml') { var metadata = yaml.load(tree.children[0].value); - if (metadata["Last reviewed"]) - lastReviewDate = moment(metadata["Last reviewed"]); + if (metadata['Last reviewed']) { + lastReviewDate = moment(metadata['Last reviewed']); + } } return lastReviewDate; } @@ -76,7 +72,7 @@ function extractCommitInfo(commitNodes, cutOffDate, stoplist) { var numUsefulCommits = 0; commitNodes.forEach(function (element) { if (!stoplist.isRejected(element.message)) { - var abbr = element.message.substr(0, 15); + // const abbr = element.message.substr(0, 15); var commitDate = moment(element.pushedDate); if (commitDate.isAfter(cutOffDate)) { numUsefulCommits++; @@ -90,31 +86,18 @@ function getDocFilePaths(folderPath) { libFolders.forEach(function (element) { var libPath = path.resolve(folderPath, element); addItemsRecursively(libPath, result); - var items = fs.readdirSync(libPath); - /* - - files = files.filter(filename => - (path.extname(filename) === ".md") && - (filename !== "README.md") && - (filename.match(angFilePattern)) - ); - - files.forEach(element => { - result.push(path.join(libPath, element)); - }); - */ }); return result; - function addItemsRecursively(folderPath, resultList) { - var items = fs.readdirSync(folderPath); + function addItemsRecursively(elementPath, resultList) { + var items = fs.readdirSync(elementPath); items.forEach(function (item) { - var fullItemPath = path.resolve(folderPath, item); + var fullItemPath = path.resolve(elementPath, item); var itemInfo = fs.statSync(fullItemPath); if (itemInfo.isDirectory()) { addItemsRecursively(fullItemPath, resultList); } - else if ((path.extname(fullItemPath) === ".md") && - (item !== "README.md") && + else if ((path.extname(fullItemPath) === '.md') && + (item !== 'README.md') && (item.match(angFilePattern))) { resultList.push(fullItemPath); } diff --git a/tools/doc/reviewChecker.ts b/tools/doc/reviewChecker.ts index 0eabace33c..53294f221e 100644 --- a/tools/doc/reviewChecker.ts +++ b/tools/doc/reviewChecker.ts @@ -1,35 +1,35 @@ -import * as path from "path"; -import * as fs from "fs"; -import * as process from "process" +// tslint:disable: no-console -import { GraphQLClient } from "graphql-request"; -import * as remark from "remark"; -import * as frontMatter from "remark-frontmatter"; -import * as yaml from "js-yaml"; -import * as moment from "moment"; -import { Observable } from 'rxjs/Rx'; +import * as path from 'path'; +import * as fs from 'fs'; +import * as process from 'process'; -import * as libsearch from "./libsearch"; -import { Stoplist } from "./stoplist"; -import { last } from "rxjs/operator/last"; +import { GraphQLClient } from 'graphql-request'; +import * as remark from 'remark'; +import * as frontMatter from 'remark-frontmatter'; +import * as yaml from 'js-yaml'; +import * as moment from 'moment'; +import { of } from 'rxjs'; +import * as libsearch from './libsearch'; +import { Stoplist } from './stoplist'; -const adf20StartDate = "2017-11-20"; +const adf20StartDate = '2017-11-20'; const commitWeight = 0.1; const scoreTimeBase = 60; -const libFolder = "lib"; -const stoplistFilePath = path.resolve("tools", "doc", "commitStoplist.json"); +const libFolder = 'lib'; +const stoplistFilePath = path.resolve('tools', 'doc', 'commitStoplist.json'); const angFilePattern = /(component)|(directive)|(model)|(pipe)|(service)|(widget)/; -let srcData = {}; -let stoplist = new Stoplist(stoplistFilePath); +const srcData = {}; +const stoplist = new Stoplist(stoplistFilePath); -let docsFolderPath = path.resolve("docs"); +const docsFolderPath = path.resolve('docs'); -let libFolders = ["core", "content-services", "extensions", "insights", "process-services", "process-services-cloud"]; +const libFolders = ['core', 'content-services', 'extensions', 'insights', 'process-services', 'process-services-cloud']; libsearch(srcData, path.resolve(libFolder)); @@ -58,70 +58,69 @@ const query = `query commitHistory($path: String) { } }`; -let docFiles = getDocFilePaths(docsFolderPath); +const docFiles = getDocFilePaths(docsFolderPath); -let docNames = Observable.from(docFiles); +const docNames = of(docFiles); console.log("'Name','Review date','Commits since review','Score'"); docNames.subscribe(x => { - let key = path.basename(x, ".md"); + const key = path.basename(x, '.md'); - if (!srcData[key]) + if (!srcData[key]) { return; + } - let vars = { - "path": "lib/" + srcData[key].path + const vars = { + 'path': 'lib/' + srcData[key].path }; client.request(query, vars).then(data => { - let nodes = data["repository"].ref.target.history.nodes; + const nodes = data['repository'].ref.target.history.nodes; - let lastReviewDate = getDocReviewDate(x);//(key + ".md"); + const lastReviewDate = getDocReviewDate(x); // (key + ".md"); - let numUsefulCommits = extractCommitInfo(nodes, lastReviewDate, stoplist); - let dateString = lastReviewDate.format("YYYY-MM-DD"); - let score = priorityScore(lastReviewDate, numUsefulCommits).toPrecision(3); + const numUsefulCommits = extractCommitInfo(nodes, lastReviewDate, stoplist); + const dateString = lastReviewDate.format('YYYY-MM-DD'); + const score = priorityScore(lastReviewDate, numUsefulCommits).toPrecision(3); console.log(`'${key}','${dateString}','${numUsefulCommits}','${score}'`); }); }); - function priorityScore(reviewDate, numCommits) { - let daysSinceReview = moment().diff(reviewDate, 'days'); - let commitScore = 2 + numCommits * commitWeight; + const daysSinceReview = moment().diff(reviewDate, 'days'); + const commitScore = 2 + numCommits * commitWeight; return Math.pow(commitScore, daysSinceReview / scoreTimeBase); } - function getDocReviewDate(docFileName) { - let mdFilePath = path.resolve(docsFolderPath, docFileName); + const mdFilePath = path.resolve(docsFolderPath, docFileName); - let mdText = fs.readFileSync(mdFilePath); - let tree = remark().use(frontMatter, ["yaml"]).parse(mdText); + const mdText = fs.readFileSync(mdFilePath); + const tree = remark().use(frontMatter, ['yaml']).parse(mdText); let lastReviewDate = moment(adf20StartDate); - if (tree.children[0].type == "yaml") { - let metadata = yaml.load(tree.children[0].value); + if (tree.children[0].type === 'yaml') { + const metadata = yaml.load(tree.children[0].value); - if (metadata["Last reviewed"]) - lastReviewDate = moment(metadata["Last reviewed"]); + if (metadata['Last reviewed']) { + lastReviewDate = moment(metadata['Last reviewed']); + } } return lastReviewDate; } - function extractCommitInfo(commitNodes, cutOffDate, stoplist) { let numUsefulCommits = 0; commitNodes.forEach(element => { if (!stoplist.isRejected(element.message)) { - let abbr = element.message.substr(0, 15); + // const abbr = element.message.substr(0, 15); - let commitDate = moment(element.pushedDate); + const commitDate = moment(element.pushedDate); if (commitDate.isAfter(cutOffDate)) { numUsefulCommits++; @@ -132,30 +131,28 @@ function extractCommitInfo(commitNodes, cutOffDate, stoplist) { return numUsefulCommits; } - function getDocFilePaths(folderPath) { - let result = []; + const result = []; libFolders.forEach(element => { - let libPath = path.resolve(folderPath, element); + const libPath = path.resolve(folderPath, element); addItemsRecursively(libPath, result); }); - return result; - function addItemsRecursively(folderPath: string, resultList: string[]) { - let items = fs.readdirSync(folderPath); + function addItemsRecursively(elementPath: string, resultList: string[]) { + const items = fs.readdirSync(elementPath); items.forEach(item => { - let fullItemPath = path.resolve(folderPath, item); - let itemInfo = fs.statSync(fullItemPath); + const fullItemPath = path.resolve(elementPath, item); + const itemInfo = fs.statSync(fullItemPath); if (itemInfo.isDirectory()) { addItemsRecursively(fullItemPath, resultList); } else if ( - (path.extname(fullItemPath) === ".md") && - (item !== "README.md") && + (path.extname(fullItemPath) === '.md') && + (item !== 'README.md') && (item.match(angFilePattern)) ) { resultList.push(fullItemPath); diff --git a/tools/doc/SourceInfoClasses.js b/tools/doc/sourceInfoClasses.js similarity index 75% rename from tools/doc/SourceInfoClasses.js rename to tools/doc/sourceInfoClasses.js index e8b9857af4..e50340881b 100644 --- a/tools/doc/SourceInfoClasses.js +++ b/tools/doc/sourceInfoClasses.js @@ -1,44 +1,46 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var undocMethodNames = { - "ngOnChanges": 1 -}; +var skipMethodNames = [ + 'ngOnChanges', + 'ngOnDestroy', + 'ngOnInit' +]; var PropInfo = /** @class */ (function () { function PropInfo(sourceData) { var _this = this; this.errorMessages = []; this.name = sourceData.name; - this.docText = sourceData.summary || ""; - this.docText = this.docText.replace(/[\n\r]+/g, " ").trim(); - var tempDefaultVal = sourceData.syntax["return"].defaultValue; - this.defaultValue = tempDefaultVal ? tempDefaultVal.toString() : ""; - this.defaultValue = this.defaultValue.replace(/\|/, "\\|"); - this.type = sourceData.syntax["return"].type || ""; - this.type = this.type.toString().replace(/\|/, "\\|"); + this.docText = sourceData.summary || ''; + this.docText = this.docText.replace(/[\n\r]+/g, ' ').trim(); + var tempDefaultVal = sourceData.syntax['return'].defaultValue; + this.defaultValue = tempDefaultVal ? tempDefaultVal.toString() : ''; + this.defaultValue = this.defaultValue.replace(/\|/, '\\|'); + this.type = sourceData.syntax['return'].type || ''; + this.type = this.type.toString().replace(/\|/, '\\|'); if (sourceData.tags) { - var depTag = sourceData.tags.find(function (tag) { return tag.name === "deprecated"; }); + var depTag = sourceData.tags.find(function (tag) { return tag.name === 'deprecated'; }); if (depTag) { this.isDeprecated = true; - this.docText = "(**Deprecated:** " + depTag.text.replace(/[\n\r]+/g, " ").trim() + ") " + this.docText; + this.docText = '(**Deprecated:** ' + depTag.text.replace(/[\n\r]+/g, ' ').trim() + ') ' + this.docText; } } this.isInput = false; this.isOutput = false; if (sourceData.decorators) { sourceData.decorators.forEach(function (dec) { - //console.log(dec); - if (dec.name === "Input") { + if (dec.name === 'Input') { _this.isInput = true; if (dec.arguments) { - var bindingName = dec.arguments["bindingPropertyName"]; - if (bindingName && (bindingName !== "")) - _this.name = bindingName.replace(/['"]/g, ""); + var bindingName = dec.arguments['bindingPropertyName']; + if (bindingName && (bindingName !== '')) { + _this.name = bindingName.replace(/['"]/g, ''); + } } if (!_this.docText && !_this.isDeprecated) { _this.errorMessages.push("Warning: Input \"" + sourceData.name + "\" has no doc text."); } } - if (dec.name === "Output") { + if (dec.name === 'Output') { _this.isOutput = true; if (!_this.docText && !_this.isDeprecated) { _this.errorMessages.push("Warning: Output \"" + sourceData.name + "\" has no doc text."); @@ -57,26 +59,27 @@ var PropInfo = /** @class */ (function () { return PropInfo; }()); exports.PropInfo = PropInfo; -; var ParamInfo = /** @class */ (function () { function ParamInfo(sourceData) { this.name = sourceData.id; - this.type = sourceData.type.toString().replace(/\s/g, ""); + this.type = sourceData.type.toString().replace(/\s/g, ''); this.defaultValue = sourceData.defaultValue; - this.docText = sourceData.description.replace(/[\n\r]+/g, " ").trim(); + this.docText = sourceData.description.replace(/[\n\r]+/g, ' ').trim(); this.isOptional = false; if (sourceData.flags) { - var flag = sourceData.flags.find(function (flag) { return flag.name === "isOptional"; }); + var flag = sourceData.flags.find(function (sourceFlag) { return sourceFlag.name === 'isOptional'; }); if (flag) { this.isOptional = true; } } this.combined = this.name; - if (this.isOptional) - this.combined += "?"; + if (this.isOptional) { + this.combined += '?'; + } this.combined += ": `" + this.type + "`"; - if (this.defaultValue !== "") + if (this.defaultValue !== '') { this.combined += " = `" + this.defaultValue + "`"; + } } return ParamInfo; }()); @@ -86,16 +89,16 @@ var MethodSigInfo = /** @class */ (function () { var _this = this; this.errorMessages = []; this.name = sourceData.name; - this.docText = sourceData.summary || ""; - this.docText = this.docText.replace(/[\n\r]+/g, " ").trim(); + this.docText = sourceData.summary || ''; + this.docText = this.docText.replace(/[\n\r]+/g, ' ').trim(); if (!this.docText) { this.errorMessages.push("Warning: method \"" + sourceData.name + "\" has no doc text."); } - this.returnType = sourceData.syntax["return"].type || ""; - this.returnType = this.returnType.toString().replace(/\s/g, ""); - this.returnsSomething = this.returnType && (this.returnType !== "void"); - this.returnDocText = sourceData.syntax["return"].summary || ""; - if (this.returnDocText.toLowerCase() === "nothing") { + this.returnType = sourceData.syntax['return'].type || ''; + this.returnType = this.returnType.toString().replace(/\s/g, ''); + this.returnsSomething = this.returnType && (this.returnType !== 'void'); + this.returnDocText = sourceData.syntax['return'].summary || ''; + if (this.returnDocText.toLowerCase() === 'nothing') { this.returnsSomething = false; } if (this.returnsSomething && !this.returnDocText) { @@ -103,10 +106,10 @@ var MethodSigInfo = /** @class */ (function () { } this.isDeprecated = false; if (sourceData.tags) { - var depTag = sourceData.tags.find(function (tag) { return tag.name === "deprecated"; }); + var depTag = sourceData.tags.find(function (tag) { return tag.name === 'deprecated'; }); if (depTag) { this.isDeprecated = true; - this.docText = "(**Deprecated:** " + depTag.text.replace(/[\n\r]+/g, " ").trim() + ") " + this.docText; + this.docText = '(**Deprecated:** ' + depTag.text.replace(/[\n\r]+/g, ' ').trim() + ') ' + this.docText; } } this.params = []; @@ -121,7 +124,7 @@ var MethodSigInfo = /** @class */ (function () { paramStrings.push(param.combined); }); } - this.signature = "(" + paramStrings.join(", ") + ")"; + this.signature = '(' + paramStrings.join(', ') + ')'; } Object.defineProperty(MethodSigInfo.prototype, "errors", { get: function () { @@ -150,8 +153,8 @@ var ComponentInfo = /** @class */ (function () { this.methods = []; sourceData.items.forEach(function (item) { switch (item.type) { - case "property": - case "accessor": + case 'property': + case 'accessor': var prop = new PropInfo(item); _this.properties.push(prop); if (prop.isInput) { @@ -161,11 +164,11 @@ var ComponentInfo = /** @class */ (function () { _this.hasOutputs = true; } break; - case "method": + case 'method': if (item.flags && (item.flags.length > 0) && - !item.flags.find(function (flag) { return flag.name === "isPrivate"; }) && - !item.flags.find(function (flag) { return flag.name === "isProtected"; }) && - !undocMethodNames[item.name]) { + !item.flags.find(function (flag) { return flag.name === 'isPrivate'; }) && + !item.flags.find(function (flag) { return flag.name === 'isProtected'; }) && + !skipMethodNames.includes(item.name)) { _this.methods.push(new MethodSigInfo(item)); _this.hasMethods = true; } diff --git a/tools/doc/SourceInfoClasses.ts b/tools/doc/sourceInfoClasses.ts similarity index 68% rename from tools/doc/SourceInfoClasses.ts rename to tools/doc/sourceInfoClasses.ts index 37188e2a75..a57e251d4a 100644 --- a/tools/doc/SourceInfoClasses.ts +++ b/tools/doc/sourceInfoClasses.ts @@ -1,8 +1,9 @@ -let undocMethodNames = { - "ngOnChanges": 1 -}; +const skipMethodNames = [ + 'ngOnChanges', + 'ngOnDestroy', + 'ngOnInit' +]; - export class PropInfo { name: string; type: string; @@ -15,26 +16,25 @@ export class PropInfo { errorMessages: string[]; - constructor(sourceData) { this.errorMessages = []; this.name = sourceData.name; - this.docText = sourceData.summary || ""; - this.docText = this.docText.replace(/[\n\r]+/g, " ").trim(); - - let tempDefaultVal = sourceData.syntax["return"].defaultValue; - this.defaultValue = tempDefaultVal ? tempDefaultVal.toString() : ""; - this.defaultValue = this.defaultValue.replace(/\|/, "\\|"); - this.type = sourceData.syntax["return"].type || ""; - this.type = this.type.toString().replace(/\|/, "\\|"); - + this.docText = sourceData.summary || ''; + this.docText = this.docText.replace(/[\n\r]+/g, ' ').trim(); + + const tempDefaultVal = sourceData.syntax['return'].defaultValue; + this.defaultValue = tempDefaultVal ? tempDefaultVal.toString() : ''; + this.defaultValue = this.defaultValue.replace(/\|/, '\\|'); + this.type = sourceData.syntax['return'].type || ''; + this.type = this.type.toString().replace(/\|/, '\\|'); + if (sourceData.tags) { - let depTag = sourceData.tags.find(tag => tag.name === "deprecated"); - + const depTag = sourceData.tags.find(tag => tag.name === 'deprecated'); + if (depTag) { this.isDeprecated = true; - this.docText = "(**Deprecated:** " + depTag.text.replace(/[\n\r]+/g, " ").trim() + ") " + this.docText; + this.docText = '(**Deprecated:** ' + depTag.text.replace(/[\n\r]+/g, ' ').trim() + ') ' + this.docText; } } @@ -43,23 +43,23 @@ export class PropInfo { if (sourceData.decorators) { sourceData.decorators.forEach(dec => { - //console.log(dec); - if (dec.name === "Input") { + if (dec.name === 'Input') { this.isInput = true; - + if (dec.arguments) { - let bindingName = dec.arguments["bindingPropertyName"]; - - if (bindingName && (bindingName !== "")) - this.name = bindingName.replace(/['"]/g, ""); + const bindingName = dec.arguments['bindingPropertyName']; + + if (bindingName && (bindingName !== '')) { + this.name = bindingName.replace(/['"]/g, ''); + } } - + if (!this.docText && !this.isDeprecated) { this.errorMessages.push(`Warning: Input "${sourceData.name}" has no doc text.`); } } - if (dec.name === "Output") { + if (dec.name === 'Output') { this.isOutput = true; if (!this.docText && !this.isDeprecated) { @@ -73,8 +73,7 @@ export class PropInfo { get errors() { return this.errorMessages; } -}; - +} export class ParamInfo { name: string; @@ -84,17 +83,16 @@ export class ParamInfo { combined: string; isOptional: boolean; - constructor(sourceData) { this.name = sourceData.id; - this.type = sourceData.type.toString().replace(/\s/g, ""); + this.type = sourceData.type.toString().replace(/\s/g, ''); this.defaultValue = sourceData.defaultValue; - this.docText = sourceData.description.replace(/[\n\r]+/g, " ").trim(); + this.docText = sourceData.description.replace(/[\n\r]+/g, ' ').trim(); this.isOptional = false; if (sourceData.flags) { - let flag = sourceData.flags.find(flag => flag.name === "isOptional"); + const flag = sourceData.flags.find((sourceFlag: any) => sourceFlag.name === 'isOptional'); if (flag) { this.isOptional = true; @@ -103,17 +101,18 @@ export class ParamInfo { this.combined = this.name; - if (this.isOptional) - this.combined += "?"; + if (this.isOptional) { + this.combined += '?'; + } this.combined += `: \`${this.type}\``; - - if (this.defaultValue !== "") + + if (this.defaultValue !== '') { this.combined += ` = \`${this.defaultValue}\``; + } } } - export class MethodSigInfo { name: string; docText: string; @@ -123,28 +122,26 @@ export class MethodSigInfo { signature: string; params: ParamInfo[]; isDeprecated: boolean; - errorMessages: string[]; - constructor(sourceData) { this.errorMessages = []; this.name = sourceData.name; - this.docText = sourceData.summary || ""; - this.docText = this.docText.replace(/[\n\r]+/g, " ").trim(); + this.docText = sourceData.summary || ''; + this.docText = this.docText.replace(/[\n\r]+/g, ' ').trim(); if (!this.docText) { this.errorMessages.push(`Warning: method "${sourceData.name}" has no doc text.`); } - this.returnType = sourceData.syntax["return"].type || ""; - this.returnType = this.returnType.toString().replace(/\s/g, ""); - this.returnsSomething = this.returnType && (this.returnType !== "void"); - this.returnDocText = sourceData.syntax["return"].summary || ""; + this.returnType = sourceData.syntax['return'].type || ''; + this.returnType = this.returnType.toString().replace(/\s/g, ''); + this.returnsSomething = this.returnType && (this.returnType !== 'void'); + this.returnDocText = sourceData.syntax['return'].summary || ''; - if (this.returnDocText.toLowerCase() === "nothing") { + if (this.returnDocText.toLowerCase() === 'nothing') { this.returnsSomething = false; } @@ -155,16 +152,16 @@ export class MethodSigInfo { this.isDeprecated = false; if (sourceData.tags) { - let depTag = sourceData.tags.find(tag => tag.name === "deprecated"); - + const depTag = sourceData.tags.find(tag => tag.name === 'deprecated'); + if (depTag) { this.isDeprecated = true; - this.docText = "(**Deprecated:** " + depTag.text.replace(/[\n\r]+/g, " ").trim() + ") " + this.docText; + this.docText = '(**Deprecated:** ' + depTag.text.replace(/[\n\r]+/g, ' ').trim() + ') ' + this.docText; } } this.params = []; - let paramStrings = []; + const paramStrings = []; if (sourceData.syntax.parameters) { sourceData.syntax.parameters.forEach(rawParam => { @@ -172,13 +169,13 @@ export class MethodSigInfo { this.errorMessages.push(`Warning: parameter "${rawParam.name}" of method "${sourceData.name}" has no doc text.`); } - let param = new ParamInfo(rawParam); + const param = new ParamInfo(rawParam); this.params.push(param); paramStrings.push(param.combined); }); } - this.signature = "(" + paramStrings.join(", ") + ")"; + this.signature = '(' + paramStrings.join(', ') + ')'; } get errors() { @@ -186,7 +183,6 @@ export class MethodSigInfo { } } - export class ComponentInfo { name: string; itemType: string; @@ -198,7 +194,6 @@ export class ComponentInfo { sourcePath: string; sourceLine: number; - constructor(sourceData) { this.name = sourceData.items[0].name; this.itemType = sourceData.items[0].type; @@ -213,15 +208,15 @@ export class ComponentInfo { if (this.itemType === 'type alias') { return; } - + this.properties = []; this.methods = []; sourceData.items.forEach(item => { - switch(item.type) { - case "property": - case "accessor": - var prop = new PropInfo(item); + switch (item.type) { + case 'property': + case 'accessor': + const prop = new PropInfo(item); this.properties.push(prop); if (prop.isInput) { @@ -232,12 +227,12 @@ export class ComponentInfo { this.hasOutputs = true; } break; - - case "method": + + case 'method': if (item.flags && (item.flags.length > 0) && - !item.flags.find(flag => flag.name === "isPrivate") && - !item.flags.find(flag => flag.name === "isProtected") && - !undocMethodNames[item.name] + !item.flags.find(flag => flag.name === 'isPrivate') && + !item.flags.find(flag => flag.name === 'isProtected') && + !skipMethodNames.includes(item.name) ) { this.methods.push(new MethodSigInfo(item)); this.hasMethods = true; @@ -250,14 +245,13 @@ export class ComponentInfo { }); } - get errors() { - let combinedErrors = []; + const combinedErrors = []; this.methods.forEach(method => { method.errors.forEach(err => { combinedErrors.push(err); - }) + }); }); this.properties.forEach(prop => { diff --git a/tools/doc/stoplist.ts b/tools/doc/stoplist.ts index 84798f315e..5b4802525f 100644 --- a/tools/doc/stoplist.ts +++ b/tools/doc/stoplist.ts @@ -1,15 +1,15 @@ -import * as fs from "fs"; +import * as fs from 'fs'; /* "Stoplist" of regular expressions to match against strings. */ export class Stoplist { regexes: RegExp[]; constructor(slFilePath: string) { - let listExpressions = JSON.parse(fs.readFileSync(slFilePath, 'utf8')); + const listExpressions = JSON.parse(fs.readFileSync(slFilePath, 'utf8')); this.regexes = []; - + if (listExpressions) { - for (var i = 0; i < listExpressions.length; i++) { + for (let i = 0; i < listExpressions.length; i++) { this.regexes.push(new RegExp(listExpressions[i])); } } else { @@ -19,13 +19,13 @@ export class Stoplist { // Check if an item is covered by the stoplist and reject it if so. isRejected(itemName: string) { - for (var i = 0; i < this.regexes.length; i++) { + for (let i = 0; i < this.regexes.length; i++) { if (this.regexes[i].test(itemName)) { return true; } } - + return false; } -} \ No newline at end of file +} diff --git a/tools/doc/tools/fileChecker.js b/tools/doc/tools/fileChecker.js index 96114c7a0f..14427f5631 100644 --- a/tools/doc/tools/fileChecker.js +++ b/tools/doc/tools/fileChecker.js @@ -1,4 +1,5 @@ "use strict"; +// tslint:disable: no-console Object.defineProperty(exports, "__esModule", { value: true }); var path = require("path"); var fs = require("fs"); @@ -16,7 +17,7 @@ function processDocs(mdCache, aggData, errorMessages) { var linkRefs = {}; var imageRefs = {}; var brokenImageRefs = {}; - var filters = makeFilepathFilters(aggData.config["fileCheckerFilter"]); + var filters = makeFilepathFilters(aggData.config['fileCheckerFilter']); pathnames.forEach(function (pathname) { var fileBaseName = path.basename(pathname, '.md'); var tree = mdCache[pathname].mdOutTree; @@ -86,8 +87,8 @@ function getImagePaths(imageFolder) { var files = fs.readdirSync(imageFolder); return files.map(function (f) { return path.resolve(imageFolder, f); }); } -function makeFilepathFilters(regexes) { - return regexes.map(function (r) { return new RegExp(r); }); +function makeFilepathFilters(patterns) { + return patterns.map(function (r) { return new RegExp(r); }); } function filterFilepath(filters, filepath) { for (var i = 0; i < filters.length; i++) { diff --git a/tools/doc/tools/fileChecker.ts b/tools/doc/tools/fileChecker.ts index c4a6231f94..b991fbc90e 100644 --- a/tools/doc/tools/fileChecker.ts +++ b/tools/doc/tools/fileChecker.ts @@ -1,11 +1,10 @@ -import * as path from "path"; -import * as fs from "fs"; +// tslint:disable: no-console -import { select, selectAll } from "unist-util-select"; - -import * as lev from "fast-levenshtein"; - -import * as ngHelpers from "../ngHelpers"; +import * as path from 'path'; +import * as fs from 'fs'; +import { selectAll } from 'unist-util-select'; +import * as lev from 'fast-levenshtein'; +import * as ngHelpers from '../ngHelpers'; const imageFolderPath = path.resolve('docs', 'docassets', 'images'); @@ -15,39 +14,39 @@ const imageFolderPath = path.resolve('docs', 'docassets', 'images'); const maxImagePathLevDistance = 7; export function processDocs(mdCache, aggData, errorMessages) { - var pathnames = Object.keys(mdCache); + const pathnames = Object.keys(mdCache); - let classlessDocs = []; - let linkRefs = {}; - let imageRefs = {}; - let brokenImageRefs = {}; + const classlessDocs = []; + const linkRefs = {}; + const imageRefs = {}; + const brokenImageRefs = {}; - let filters = makeFilepathFilters(aggData.config["fileCheckerFilter"]); + const filters = makeFilepathFilters(aggData.config['fileCheckerFilter']); pathnames.forEach(pathname => { - let fileBaseName = path.basename(pathname, '.md'); - let tree = mdCache[pathname].mdOutTree; - let className = ngHelpers.ngNameToClassName(fileBaseName, aggData.config.typeNameExceptions); - let classInfo = aggData.classInfo[className]; + const fileBaseName = path.basename(pathname, '.md'); + const tree = mdCache[pathname].mdOutTree; + const className = ngHelpers.ngNameToClassName(fileBaseName, aggData.config.typeNameExceptions); + const classInfo = aggData.classInfo[className]; if (!classInfo) { if (!filterFilepath(filters, pathname)) { classlessDocs.push(pathname); } } else { - let linkElems = selectAll('link', tree); + const linkElems = selectAll('link', tree); linkElems.forEach(linkElem => { - let normUrl = normaliseLinkPath(pathname, linkElem.url); + const normUrl = normaliseLinkPath(pathname, linkElem.url); multiSetAdd(linkRefs, normUrl, pathname); }); } - let imageElems = selectAll('image', tree); + const imageElems = selectAll('image', tree); imageElems.forEach(imageElem => { - let normUrl = normaliseLinkPath(pathname, imageElem.url); + const normUrl = normaliseLinkPath(pathname, imageElem.url); multiSetAdd(imageRefs, normUrl, pathname); if (!fs.existsSync(normUrl)) { @@ -57,12 +56,12 @@ export function processDocs(mdCache, aggData, errorMessages) { }); classlessDocs.forEach(docPath => { - let relDocPath = docPath.substring(docPath.indexOf('docs')); + const relDocPath = docPath.substring(docPath.indexOf('docs')); console.group(`Warning: no source class found for "${relDocPath}"`); if (linkRefs[docPath]) { linkRefs[docPath].forEach(linkRef => { - let relLinkPath = linkRef.substring(linkRef.indexOf('docs')); + const relLinkPath = linkRef.substring(linkRef.indexOf('docs')); console.log(`Linked from: "${relLinkPath}"`); }); } @@ -72,28 +71,28 @@ export function processDocs(mdCache, aggData, errorMessages) { console.log(); - let imagePaths = getImagePaths(imageFolderPath); + const imagePaths = getImagePaths(imageFolderPath); imagePaths.forEach(imagePath => { if (!imageRefs[imagePath]) { - let relImagePath = imagePath.substring(imagePath.indexOf('docs')); + const relImagePath = imagePath.substring(imagePath.indexOf('docs')); console.log(`Warning: no links to image file "${relImagePath}"`); } }); console.log(); - let brokenImUrls = Object.keys(brokenImageRefs); + const brokenImUrls = Object.keys(brokenImageRefs); brokenImUrls.forEach(url => { - let relUrl = url.substring(url.indexOf('docs')); - let relDocPath = brokenImageRefs[url].substring(brokenImageRefs[url].indexOf('docs')); + const relUrl = url.substring(url.indexOf('docs')); + const relDocPath = brokenImageRefs[url].substring(brokenImageRefs[url].indexOf('docs')); console.group(`Broken image link "${relUrl}" found in "${relDocPath}`); imagePaths.forEach(imPath => { if (lev.get(imPath, url) <= maxImagePathLevDistance) { - let relImPath = imPath.substring(imPath.indexOf('docs')); - console.log(`Should it be "${relImPath}"?`) + const relImPath = imPath.substring(imPath.indexOf('docs')); + console.log(`Should it be "${relImPath}"?`); } }); @@ -101,34 +100,29 @@ export function processDocs(mdCache, aggData, errorMessages) { }); } - function normaliseLinkPath(homeFilePath, linkUrl) { - let homeFolder = path.dirname(homeFilePath); + const homeFolder = path.dirname(homeFilePath); return path.resolve(homeFolder, linkUrl); } - function getImagePaths(imageFolder) { - let files = fs.readdirSync(imageFolder); + const files = fs.readdirSync(imageFolder); return files.map(f => path.resolve(imageFolder, f)); } - -function makeFilepathFilters(regexes: string[]) { - return regexes.map(r => new RegExp(r)); +function makeFilepathFilters(patterns: string[]) { + return patterns.map(r => new RegExp(r)); } - function filterFilepath(filters: RegExp[], filepath: string): boolean { for (let i = 0; i < filters.length; i++) { if (filters[i].test(filepath)) { - return true + return true; } } return false; } - function multiSetAdd(container: {}, key: string, value: string) { if (container[key]) { container[key].push(value); diff --git a/tools/doc/tools/gqIndex.js b/tools/doc/tools/gqIndex.js index 569cafacb0..0cc8e9fc3a 100644 --- a/tools/doc/tools/gqIndex.js +++ b/tools/doc/tools/gqIndex.js @@ -1,4 +1,5 @@ "use strict"; +// tslint:disable: no-console Object.defineProperty(exports, "__esModule", { value: true }); var fs = require("fs"); var path = require("path"); @@ -21,7 +22,7 @@ function processDocs(mdCache, aggData) { var indexFilePath = path.resolve(aggData['rootFolder'], 'docs', 'README.md'); var indexFileText = fs.readFileSync(indexFilePath, 'utf8'); var indexMD = remark() - .use(frontMatter, ["yaml"]) + .use(frontMatter, ['yaml']) .parse(indexFileText); var schema = graphql_1.buildSchema(MQ.schema); libNamesList.forEach(function (libName) { @@ -31,7 +32,7 @@ function processDocs(mdCache, aggData) { console.log(JSON.stringify(response)); } else { - //console.log(template(response['data'])); + // console.log(template(response['data'])); var newSection_1 = remark().parse(template(response['data'])).children; replaceZone(indexMD, libName, function (start, _oldZone, end) { newSection_1.unshift(start); @@ -40,7 +41,7 @@ function processDocs(mdCache, aggData) { }); var outText = remark() .use(frontMatter, { type: 'yaml', fence: '---' }) - .data("settings", { paddedTable: false, gfm: false }) + .data('settings', { paddedTable: false, gfm: false }) .stringify(indexMD); fs.writeFileSync(indexFilePath, outText); } diff --git a/tools/doc/tools/gqIndex.ts b/tools/doc/tools/gqIndex.ts index 60ea660d7a..d93aa2ec92 100644 --- a/tools/doc/tools/gqIndex.ts +++ b/tools/doc/tools/gqIndex.ts @@ -1,23 +1,20 @@ +// tslint:disable: no-console + import * as fs from 'fs'; import * as path from 'path'; - import * as ejs from 'ejs'; - import * as remark from 'remark'; import * as frontMatter from 'remark-frontmatter'; import * as replaceZone from 'mdast-zone'; - import { graphql, buildSchema } from 'graphql'; - import * as MQ from '../mqDefs'; -let libNamesList = [ +const libNamesList = [ 'content-services', 'core', 'extensions', 'insights', 'process-services', 'process-services-cloud' ]; - -let query = ` +const query = ` query libIndex($libName: String) { documents(idFilter: $libName) { title: metadata(key: "Title") @@ -36,21 +33,20 @@ let query = ` } `; - export function processDocs(mdCache, aggData) { - let docset: MQ.Docset = new MQ.Docset(mdCache); + const docset: MQ.Docset = new MQ.Docset(mdCache); - let templateFilePath = path.resolve(__dirname, '..', 'templates', 'gqIndex.ejs'); - let templateSource = fs.readFileSync(templateFilePath, 'utf8'); - let template = ejs.compile(templateSource); + const templateFilePath = path.resolve(__dirname, '..', 'templates', 'gqIndex.ejs'); + const templateSource = fs.readFileSync(templateFilePath, 'utf8'); + const template = ejs.compile(templateSource); - let indexFilePath = path.resolve(aggData['rootFolder'], 'docs', 'README.md'); - let indexFileText = fs.readFileSync(indexFilePath, 'utf8'); - let indexMD = remark() - .use(frontMatter, ["yaml"]) + const indexFilePath = path.resolve(aggData['rootFolder'], 'docs', 'README.md'); + const indexFileText = fs.readFileSync(indexFilePath, 'utf8'); + const indexMD = remark() + .use(frontMatter, ['yaml']) .parse(indexFileText); - let schema = buildSchema(MQ.schema); + const schema = buildSchema(MQ.schema); libNamesList.forEach(libName => { graphql(schema, query, docset, null, {'libName': libName}) @@ -58,8 +54,8 @@ export function processDocs(mdCache, aggData) { if (!response['data']) { console.log(JSON.stringify(response)); } else { - //console.log(template(response['data'])); - let newSection = remark().parse(template(response['data'])).children; + // console.log(template(response['data'])); + const newSection = remark().parse(template(response['data'])).children; replaceZone(indexMD, libName, (start, _oldZone, end) => { newSection.unshift(start); @@ -67,9 +63,9 @@ export function processDocs(mdCache, aggData) { return newSection; }); - let outText = remark() + const outText = remark() .use(frontMatter, {type: 'yaml', fence: '---'}) - .data("settings", {paddedTable: false, gfm: false}) + .data('settings', {paddedTable: false, gfm: false}) .stringify(indexMD); fs.writeFileSync(indexFilePath, outText); @@ -77,7 +73,4 @@ export function processDocs(mdCache, aggData) { }); }); - } - - diff --git a/tools/doc/tools/linkFixer.js b/tools/doc/tools/linkFixer.js index 34d6230a57..0aba7f1de0 100644 --- a/tools/doc/tools/linkFixer.js +++ b/tools/doc/tools/linkFixer.js @@ -1,4 +1,5 @@ "use strict"; +// tslint:disable: no-console Object.defineProperty(exports, "__esModule", { value: true }); var path = require("path"); var fs = require("fs"); diff --git a/tools/doc/tools/linkFixer.ts b/tools/doc/tools/linkFixer.ts index d1b52ff9bd..5720d571a7 100644 --- a/tools/doc/tools/linkFixer.ts +++ b/tools/doc/tools/linkFixer.ts @@ -1,38 +1,38 @@ +// tslint:disable: no-console + import * as path from 'path'; import * as fs from 'fs'; - import { selectAll } from 'unist-util-select'; import { MDAST } from 'mdast'; const suffixesNotToCheck = /\.ts/; export function processDocs(mdCache, aggData, errorMessages) { - var pathnames = Object.keys(mdCache); + const pathnames = Object.keys(mdCache); - let linkSet = new LinkSet(pathnames); + const linkSet = new LinkSet(pathnames); - let imageFolderPath = path.resolve(aggData['rootFolder'], 'docs', 'docassets', 'images'); + const imageFolderPath = path.resolve(aggData['rootFolder'], 'docs', 'docassets', 'images'); - let imageSet = new LinkSet(getImagePaths(imageFolderPath)); + const imageSet = new LinkSet(getImagePaths(imageFolderPath)); pathnames.forEach(pathname => { - let tree = mdCache[pathname].mdOutTree; + const tree = mdCache[pathname].mdOutTree; fixUrls(tree, pathname, linkSet, 'link'); fixUrls(tree, pathname, imageSet, 'image'); }); } - function fixUrls(tree: MDAST.Root, docFilePath: string, linkSet: LinkSet, selector: string) { - let linksInDoc = selectAll(selector, tree); + const linksInDoc = selectAll(selector, tree); - let errors: string[] = []; + const errors: string[] = []; linksInDoc.forEach(linkElem => { let origFullUrlPath = path.resolve(path.dirname(docFilePath), linkElem.url); - let hashPos = origFullUrlPath.indexOf('#'); + const hashPos = origFullUrlPath.indexOf('#'); let anchor = ''; if (hashPos !== -1) { @@ -45,8 +45,8 @@ function fixUrls(tree: MDAST.Root, docFilePath: string, linkSet: LinkSet, select (origFullUrlPath !== '') && !fs.existsSync(origFullUrlPath) ) { - let newUrl = linkSet.update(origFullUrlPath) || origFullUrlPath; - linkElem.url = path.relative(path.dirname(docFilePath), newUrl).replace(/\\/g,'/') + anchor; + const newUrl = linkSet.update(origFullUrlPath) || origFullUrlPath; + linkElem.url = path.relative(path.dirname(docFilePath), newUrl).replace(/\\/g, '/') + anchor; errors.push(`Bad link: ${origFullUrlPath}\nReplacing with ${linkElem.url}`); } /*else { console.log(`Link OK: ${origFullUrlPath}`); @@ -59,7 +59,6 @@ function fixUrls(tree: MDAST.Root, docFilePath: string, linkSet: LinkSet, select } } - function showMessages(groupName: string, messages: string[]) { console.group(groupName); @@ -75,7 +74,6 @@ function getImagePaths(imageFolderPath: string): string[] { .map(imageFileName => path.resolve(imageFolderPath, imageFileName)); } - class LinkSet { links: Map; @@ -83,10 +81,10 @@ class LinkSet { this.links = new Map(); urls.forEach(url => { - let fileName = path.basename(url); + const fileName = path.basename(url); if (this.links.has(fileName)) { - let item = this.links.get(fileName); + const item = this.links.get(fileName); item.push(url); } else { this.links.set(fileName, [url]); @@ -95,12 +93,12 @@ class LinkSet { } update(oldUrl: string): string { - let oldFileName = path.basename(oldUrl); + const oldFileName = path.basename(oldUrl); if (!this.links.has(oldFileName)) { return ''; } else { - let candidates = this.links.get(oldFileName); + const candidates = this.links.get(oldFileName); if (candidates.length === 1) { return candidates[0]; diff --git a/tools/doc/tools/reducer.ts b/tools/doc/tools/reducer.ts deleted file mode 100644 index 227c1154fb..0000000000 --- a/tools/doc/tools/reducer.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { select, selectAll } from "unist-util-select"; - - -export function processDocs(mdCache, aggData, errorMessages) { -} diff --git a/tools/doc/tools/sourceLinker.js b/tools/doc/tools/sourceLinker.js index 975b729538..2352c846f3 100644 --- a/tools/doc/tools/sourceLinker.js +++ b/tools/doc/tools/sourceLinker.js @@ -1,5 +1,5 @@ "use strict"; -exports.__esModule = true; +Object.defineProperty(exports, "__esModule", { value: true }); var path = require("path"); var unist_util_select_1 = require("unist-util-select"); var ngHelpers = require("../ngHelpers"); @@ -18,7 +18,7 @@ function processDocs(mdCache, aggData) { var titleHeading = unist_util_select_1.select('heading[depth=1]:first-of-type', tree); var relDocPath = pathname.substring(pathname.indexOf('docs')); var srcUrl = fixRelSrcUrl(relDocPath, sourcePath); - if (titleHeading && titleHeading.children[0] && titleHeading.children[0].type === "text") { + if (titleHeading && titleHeading.children[0] && titleHeading.children[0].type === 'text') { var titleText = titleHeading.children[0]; titleHeading.children[0] = { type: 'link', @@ -27,9 +27,9 @@ function processDocs(mdCache, aggData) { children: [titleText] }; } - else if ((titleHeading && titleHeading.children[0].type === "link") && sourcePath) { + else if ((titleHeading && titleHeading.children[0].type === 'link') && sourcePath) { var linkElem = titleHeading.children[0]; - linkElem.url = srcUrl, + linkElem.url = srcUrl, // `../../${sourcePath}`; linkElem.title = "Defined in " + path.basename(sourcePath); } }); diff --git a/tools/doc/tools/sourceLinker.ts b/tools/doc/tools/sourceLinker.ts index fd20072203..b8f6c417cc 100644 --- a/tools/doc/tools/sourceLinker.ts +++ b/tools/doc/tools/sourceLinker.ts @@ -1,48 +1,45 @@ -import * as path from "path"; - -import { select } from "unist-util-select"; - -import * as ngHelpers from "../ngHelpers"; +import * as path from 'path'; +import { select } from 'unist-util-select'; +import * as ngHelpers from '../ngHelpers'; const angFilenameRegex = /([a-zA-Z0-9\-]+)\.((component)|(dialog)|(directive)|(interface)|(model)|(pipe)|(service)|(widget))/; export function processDocs(mdCache, aggData) { - var pathnames = Object.keys(mdCache); + const pathnames = Object.keys(mdCache); pathnames.forEach(pathname => { - let fileBaseName = path.basename(pathname, '.md'); + const fileBaseName = path.basename(pathname, '.md'); if (!fileBaseName.match(angFilenameRegex)) { return; } - let tree = mdCache[pathname].mdOutTree; - let className = ngHelpers.ngNameToClassName(fileBaseName, aggData.config.typeNameExceptions); - let classInfo = aggData.classInfo[className]; - let sourcePath = classInfo ? classInfo.sourcePath : ''; - let titleHeading = select('heading[depth=1]:first-of-type', tree); - let relDocPath = pathname.substring(pathname.indexOf('docs')); - let srcUrl = fixRelSrcUrl(relDocPath, sourcePath); + const tree = mdCache[pathname].mdOutTree; + const className = ngHelpers.ngNameToClassName(fileBaseName, aggData.config.typeNameExceptions); + const classInfo = aggData.classInfo[className]; + const sourcePath = classInfo ? classInfo.sourcePath : ''; + const titleHeading = select('heading[depth=1]:first-of-type', tree); + const relDocPath = pathname.substring(pathname.indexOf('docs')); + const srcUrl = fixRelSrcUrl(relDocPath, sourcePath); - if (titleHeading && titleHeading.children[0] && titleHeading.children[0].type === "text") { - let titleText = titleHeading.children[0]; + if (titleHeading && titleHeading.children[0] && titleHeading.children[0].type === 'text') { + const titleText = titleHeading.children[0]; titleHeading.children[0] = { type: 'link', - url: srcUrl,//`../../${sourcePath}`, + url: srcUrl, // `../../${sourcePath}`, title: `Defined in ${path.basename(sourcePath)}`, children: [titleText] - } - } else if ((titleHeading && titleHeading.children[0].type === "link") && sourcePath) { - let linkElem = titleHeading.children[0]; - linkElem.url = srcUrl, //`../../${sourcePath}`; + }; + } else if ((titleHeading && titleHeading.children[0].type === 'link') && sourcePath) { + const linkElem = titleHeading.children[0]; + linkElem.url = srcUrl, // `../../${sourcePath}`; linkElem.title = `Defined in ${path.basename(sourcePath)}`; } }); } - function fixRelSrcUrl(docPath: string, srcPath: string) { - let docPathSegments = docPath.split(/[\\\/]/); + const docPathSegments = docPath.split(/[\\\/]/); let dotPathPart = ''; for (let i = 0; i < (docPathSegments.length - 1); i++) { diff --git a/tools/doc/tools/tsInfo.js b/tools/doc/tools/tsInfo.js index d0f1984509..43a2fb4a3f 100644 --- a/tools/doc/tools/tsInfo.js +++ b/tools/doc/tools/tsInfo.js @@ -1,22 +1,16 @@ "use strict"; +// tslint:disable: no-console Object.defineProperty(exports, "__esModule", { value: true }); var fs = require("fs"); var path = require("path"); var replaceSection = require("mdast-util-heading-range"); var remark = require("remark"); -// import * as stringify from "remark-stringify"; -// import * as frontMatter from "remark-frontmatter"; var ejs = require("ejs"); var mdNav_1 = require("../mdNav"); var ngHelpers_1 = require("../ngHelpers"); -var libFolders = ["core", "content-services", "process-services", "insights", "process-services-cloud"]; -var templateFolder = path.resolve("tools", "doc", "templates"); -var excludePatterns = [ - "**/*.spec.ts" -]; +var templateFolder = path.resolve('tools', 'doc', 'templates'); var nameExceptions; function processDocs(mdCache, aggData, _errorMessages) { - //initPhase(aggData); nameExceptions = aggData.config.typeNameExceptions; var pathnames = Object.keys(mdCache); var internalErrors; @@ -32,60 +26,31 @@ exports.processDocs = processDocs; function showErrors(filename, errorMessages) { console.log(filename); errorMessages.forEach(function (message) { - console.log(" " + message); + console.log(' ' + message); }); - console.log(""); + console.log(''); } -/* -function initPhase(aggData) { - nameExceptions = aggData.config.typeNameExceptions; - - let app = new Application({ - exclude: excludePatterns, - ignoreCompilerErrors: true, - experimentalDecorators: true, - tsconfig: "tsconfig.json" - }); - - let sources = app.expandInputFiles(libFolders.map(folder => { - return path.resolve("lib", folder); - })); - - aggData.projData = app.convert(sources); -} -*/ function updateFile(tree, pathname, aggData, errorMessages) { - /* - let compName = angNameToClassName(path.basename(pathname, ".md")); - let classRef = aggData.projData.findReflectionByName(compName); - - if (!classRef) { - // A doc file with no corresponding class (eg, Document Library Model). - return false; - } - - let compData = new ComponentInfo(classRef); - */ - var className = ngHelpers_1.ngNameToClassName(path.basename(pathname, ".md"), nameExceptions); + var className = ngHelpers_1.ngNameToClassName(path.basename(pathname, '.md'), nameExceptions); var classTypeMatch = className.match(/component|directive|service/i); var compData = aggData.classInfo[className]; if (classTypeMatch && compData) { var classType = classTypeMatch[0].toLowerCase(); // Copy docs back from the .md file when the JSDocs are empty. - var inputMD = getPropDocsFromMD(tree, "Properties", 3); - var outputMD = getPropDocsFromMD(tree, "Events", 2); + var inputMD = getPropDocsFromMD(tree, 'Properties', 3); + var outputMD = getPropDocsFromMD(tree, 'Events', 2); updatePropDocsFromMD(compData, inputMD, outputMD, errorMessages); - if (classType === "service") { + if (classType === 'service') { var methodMD = getMethodDocsFromMD(tree); updateMethodDocsFromMD(compData, methodMD, errorMessages); } - var templateName = path.resolve(templateFolder, classType + ".ejs"); - var templateSource = fs.readFileSync(templateName, "utf8"); + var templateName = path.resolve(templateFolder, classType + '.ejs'); + var templateSource = fs.readFileSync(templateName, 'utf8'); var template = ejs.compile(templateSource); var mdText = template(compData); - mdText = mdText.replace(/^ +\|/mg, "|"); + mdText = mdText.replace(/^ +\|/mg, '|'); var newSection_1 = remark().parse(mdText.trim()).children; - replaceSection(tree, "Class members", function (before, section, after) { + replaceSection(tree, 'Class members', function (before, section, after) { newSection_1.unshift(before); newSection_1.push(after); return newSection_1; @@ -96,48 +61,16 @@ function updateFile(tree, pathname, aggData, errorMessages) { } return true; } -/* -function initialCap(str: string) { - return str[0].toUpperCase() + str.substr(1); -} - - -function angNameToClassName(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 getPropDocsFromMD(tree, sectionHeading, docsColumn) { var result = {}; var nav = new mdNav_1.MDNav(tree); var classMemHeading = nav .heading(function (h) { - return (h.children[0].type === "text") && (h.children[0].value === "Class members"); + return (h.children[0].type === 'text') && (h.children[0].value === 'Class members'); }); var propsTable = classMemHeading .heading(function (h) { - return (h.children[0].type === "text") && (h.children[0].value === sectionHeading); + return (h.children[0].type === 'text') && (h.children[0].value === sectionHeading); }).table(); var propTableRow = propsTable.childNav .tableRow(function () { return true; }, 1).childNav; @@ -163,11 +96,11 @@ function getMethodDocsFromMD(tree) { var nav = new mdNav_1.MDNav(tree); var classMemHeading = nav .heading(function (h) { - return (h.children[0].type === "text") && (h.children[0].value === "Class members"); + return (h.children[0].type === 'text') && (h.children[0].value === 'Class members'); }); var methListItems = classMemHeading .heading(function (h) { - return (h.children[0].type === "text") && (h.children[0].value === "Methods"); + return (h.children[0].type === 'text') && (h.children[0].value === 'Methods'); }).list().childNav; var methItem = methListItems .listItem(); @@ -186,18 +119,14 @@ function getMethodDocsFromMD(tree) { .text().value; var params = getMDMethodParams(methItem); result[methName] = { - "docText": methDoc.replace(/^\n/, ""), - "params": params + 'docText': methDoc.replace(/^\n/, ''), + 'params': params }; } i++; methItem = methListItems .listItem(function (l) { return true; }, i); } - /* - let newRoot = unist.makeRoot([methList.item]); - console.log(remark().use(frontMatter, {type: 'yaml', fence: '---'}).data("settings", {paddedTable: false, gfm: false}).stringify(tree)); - */ return result; } function getMDMethodParams(methItem) { @@ -211,7 +140,7 @@ function getMDMethodParams(methItem) { .emph().childNav; var paramName; if (!paramNameNode.empty) { - paramName = paramNameNode.text().item.value.replace(/:/, ""); + paramName = paramNameNode.text().item.value.replace(/:/, ''); } else { paramName = paramListItem.childNav @@ -221,8 +150,8 @@ function getMDMethodParams(methItem) { } var paramDoc = paramListItem.childNav .paragraph().childNav - .text(function (t) { return true; }, 1).value; //item.value; - result[paramName] = paramDoc.replace(/^[ -]+/, ""); + .text(function (t) { return true; }, 1).value; // item.value; + result[paramName] = paramDoc.replace(/^[ -]+/, ''); }); return result; } diff --git a/tools/doc/tools/tsInfo.ts b/tools/doc/tools/tsInfo.ts index d2bb613537..8522b68c54 100644 --- a/tools/doc/tools/tsInfo.ts +++ b/tools/doc/tools/tsInfo.ts @@ -1,27 +1,22 @@ -import * as fs from "fs"; -import * as path from "path"; +// tslint:disable: no-console -import * as replaceSection from "mdast-util-heading-range"; -import * as remark from "remark"; +import * as fs from 'fs'; +import * as path from 'path'; +import * as replaceSection from 'mdast-util-heading-range'; +import * as remark from 'remark'; +import * as ejs from 'ejs'; +import { MDNav } from '../mdNav'; +import { ngNameToClassName } from '../ngHelpers'; +import { ComponentInfo } from '../sourceInfoClasses'; -import * as ejs from "ejs"; - -import { MDNav } from "../mdNav"; -import { ngNameToClassName } from "../ngHelpers"; - -import { - ComponentInfo -} from "../SourceInfoClasses" - -let templateFolder = path.resolve("tools", "doc", "templates"); +const templateFolder = path.resolve('tools', 'doc', 'templates'); let nameExceptions; - export function processDocs(mdCache, aggData, _errorMessages) { nameExceptions = aggData.config.typeNameExceptions; - let pathnames = Object.keys(mdCache); + const pathnames = Object.keys(mdCache); let internalErrors; pathnames.forEach(pathname => { @@ -34,47 +29,45 @@ export function processDocs(mdCache, aggData, _errorMessages) { }); } - function showErrors(filename, errorMessages) { console.log(filename); errorMessages.forEach(message => { - console.log(" " + message); + console.log(' ' + message); }); - console.log(""); + console.log(''); } - function updateFile(tree, pathname, aggData, errorMessages) { - let className = ngNameToClassName(path.basename(pathname, ".md"), nameExceptions); - let classTypeMatch = className.match(/component|directive|service/i); - let compData = aggData.classInfo[className]; + const className = ngNameToClassName(path.basename(pathname, '.md'), nameExceptions); + const classTypeMatch = className.match(/component|directive|service/i); + const compData = aggData.classInfo[className]; if (classTypeMatch && compData) { - let classType = classTypeMatch[0].toLowerCase(); + const classType = classTypeMatch[0].toLowerCase(); // Copy docs back from the .md file when the JSDocs are empty. - let inputMD = getPropDocsFromMD(tree, "Properties", 3); - let outputMD = getPropDocsFromMD(tree, "Events", 2); + const inputMD = getPropDocsFromMD(tree, 'Properties', 3); + const outputMD = getPropDocsFromMD(tree, 'Events', 2); updatePropDocsFromMD(compData, inputMD, outputMD, errorMessages); - if (classType === "service") { - let methodMD = getMethodDocsFromMD(tree); + if (classType === 'service') { + const methodMD = getMethodDocsFromMD(tree); updateMethodDocsFromMD(compData, methodMD, errorMessages); } - let templateName = path.resolve(templateFolder, classType + ".ejs"); - let templateSource = fs.readFileSync(templateName, "utf8"); - let template = ejs.compile(templateSource); + const templateName = path.resolve(templateFolder, classType + '.ejs'); + const templateSource = fs.readFileSync(templateName, 'utf8'); + const template = ejs.compile(templateSource); let mdText = template(compData); - mdText = mdText.replace(/^ +\|/mg, "|"); + mdText = mdText.replace(/^ +\|/mg, '|'); - let newSection = remark().parse(mdText.trim()).children; + const newSection = remark().parse(mdText.trim()).children; - replaceSection(tree, "Class members", (before, section, after) => { + replaceSection(tree, 'Class members', (before, section, after) => { newSection.unshift(before); newSection.push(after); return newSection; @@ -82,39 +75,39 @@ function updateFile(tree, pathname, aggData, errorMessages) { compData.errors.forEach(err => { errorMessages.push(err); - }) + }); } return true; } function getPropDocsFromMD(tree, sectionHeading, docsColumn) { - let result = {} + const result = {}; - let nav = new MDNav(tree); + const nav = new MDNav(tree); - let classMemHeading = nav + const classMemHeading = nav .heading(h => { - return (h.children[0].type === "text") && (h.children[0].value === "Class members"); + return (h.children[0].type === 'text') && (h.children[0].value === 'Class members'); }); - let propsTable = classMemHeading + const propsTable = classMemHeading .heading(h => { - return (h.children[0].type === "text") && (h.children[0].value === sectionHeading); + return (h.children[0].type === 'text') && (h.children[0].value === sectionHeading); }).table(); let propTableRow = propsTable.childNav - .tableRow(()=>true, 1).childNav; + .tableRow(() => true, 1).childNav; let i = 1; while (!propTableRow.empty) { - let propName = propTableRow + const propName = propTableRow .tableCell().childNav .text().item.value; - let propDocText = propTableRow - .tableCell(()=>true, docsColumn).childNav + const propDocText = propTableRow + .tableCell(() => true, docsColumn).childNav .text().item; if (propDocText) { @@ -123,26 +116,25 @@ function getPropDocsFromMD(tree, sectionHeading, docsColumn) { i++; propTableRow = propsTable.childNav - .tableRow(()=>true, i).childNav; + .tableRow(() => true, i).childNav; } return result; } - function getMethodDocsFromMD(tree) { - let result = {} + const result = {}; - let nav = new MDNav(tree); + const nav = new MDNav(tree); - let classMemHeading = nav + const classMemHeading = nav .heading(h => { - return (h.children[0].type === "text") && (h.children[0].value === "Class members"); + return (h.children[0].type === 'text') && (h.children[0].value === 'Class members'); }); - let methListItems = classMemHeading + const methListItems = classMemHeading .heading(h => { - return (h.children[0].type === "text") && (h.children[0].value === "Methods"); + return (h.children[0].type === 'text') && (h.children[0].value === 'Methods'); }).list().childNav; let methItem = methListItems @@ -151,7 +143,7 @@ function getMethodDocsFromMD(tree) { let i = 0; while (!methItem.empty) { - let methNameSection = methItem.childNav + const methNameSection = methItem.childNav .paragraph().childNav .strong().childNav; @@ -161,46 +153,45 @@ function getMethodDocsFromMD(tree) { if (!methNameSection.empty) { methName = methNameSection.text().item.value; - let methDoc = methItem.childNav + const methDoc = methItem.childNav .paragraph().childNav .html() .text().value; - let params = getMDMethodParams(methItem); + const params = getMDMethodParams(methItem); result[methName] = { - "docText": methDoc.replace(/^\n/, ""), - "params": params + 'docText': methDoc.replace(/^\n/, ''), + 'params': params }; } i++; methItem = methListItems - .listItem(l=>true, i); + .listItem(l => true, i); } return result; } - function getMDMethodParams(methItem: MDNav) { - let result = {}; + const result = {}; - let paramList = methItem.childNav.list().childNav; + const paramList = methItem.childNav.list().childNav; - let paramListItems = paramList + const paramListItems = paramList .listItems(); paramListItems.forEach(paramListItem => { - let paramNameNode = paramListItem.childNav + const paramNameNode = paramListItem.childNav .paragraph().childNav .emph().childNav; let paramName; if (!paramNameNode.empty) { - paramName = paramNameNode.text().item.value.replace(/:/, ""); + paramName = paramNameNode.text().item.value.replace(/:/, ''); } else { paramName = paramListItem.childNav .paragraph().childNav @@ -208,17 +199,16 @@ function getMDMethodParams(methItem: MDNav) { .text().item.value; } - let paramDoc = paramListItem.childNav + const paramDoc = paramListItem.childNav .paragraph().childNav - .text(t=>true, 1).value; //item.value; + .text(t => true, 1).value; // item.value; - result[paramName] = paramDoc.replace(/^[ -]+/, ""); + result[paramName] = paramDoc.replace(/^[ -]+/, ''); }); return result; } - function updatePropDocsFromMD(comp: ComponentInfo, inputDocs, outputDocs, errorMessages) { comp.properties.forEach(prop => { let propMDDoc: string; @@ -237,10 +227,9 @@ function updatePropDocsFromMD(comp: ComponentInfo, inputDocs, outputDocs, errorM }); } - function updateMethodDocsFromMD(comp: ComponentInfo, methodDocs, errorMessages) { comp.methods.forEach(meth => { - let currMethMD = methodDocs[meth.name] + const currMethMD = methodDocs[meth.name]; // If JSDocs are empty but MD docs aren't then the Markdown is presumably more up-to-date. if (!meth.docText && currMethMD && currMethMD.docText) { @@ -249,8 +238,7 @@ function updateMethodDocsFromMD(comp: ComponentInfo, methodDocs, errorMessages) } meth.params.forEach(param => { - if (!param.docText && currMethMD && currMethMD.params[param.name]) - { + if (!param.docText && currMethMD && currMethMD.params[param.name]) { param.docText = currMethMD.params[param.name]; errorMessages.push(`Warning: empty JSDocs for parameter "${param.name} (${meth.name})" may need sync with the .md file.`); } diff --git a/tools/doc/tools/tutorialIndex.js b/tools/doc/tools/tutorialIndex.js index 43250615b7..9b5caa0a5c 100644 --- a/tools/doc/tools/tutorialIndex.js +++ b/tools/doc/tools/tutorialIndex.js @@ -8,73 +8,73 @@ var frontMatter = require("remark-frontmatter"); var yaml = require("js-yaml"); var ejs = require("ejs"); var unist = require("../unistHelpers"); -var tutFolder = path.resolve("docs", "tutorials"); -var templateFolder = path.resolve("tools", "doc", "templates"); -var userGuideFolder = path.resolve("docs", "user-guide"); -function processDocs(tree, pathname, aggData, errorMessages) { - aggPhase(aggData); +var tutFolder = path.resolve('docs', 'tutorials'); +var templateFolder = path.resolve('tools', 'doc', 'templates'); +var userGuideFolder = path.resolve('docs', 'user-guide'); +function processDocs() { + aggPhase(); } exports.processDocs = processDocs; -function aggPhase(aggData) { +function aggPhase() { var indexDocData = getIndexDocData(); - var templateName = path.resolve(templateFolder, "tutIndex.ejs"); - var templateSource = fs.readFileSync(templateName, "utf8"); + var templateName = path.resolve(templateFolder, 'tutIndex.ejs'); + var templateSource = fs.readFileSync(templateName, 'utf8'); var template = ejs.compile(templateSource); var mdText = template(indexDocData); - mdText = mdText.replace(/^ +\|/mg, "|"); - var newSection = remark().use(frontMatter, ["yaml"]).data("settings", { paddedTable: false, gfm: false }).parse(mdText.trim()).children; - var tutIndexFile = path.resolve(tutFolder, "README.md"); - var tutIndexText = fs.readFileSync(tutIndexFile, "utf8"); - var tutIndexMD = remark().use(frontMatter, ["yaml"]).data("settings", { paddedTable: false, gfm: false }).parse(tutIndexText); - replaceSection(tutIndexMD, "Tutorials", function (before, section, after) { + mdText = mdText.replace(/^ +\|/mg, '|'); + var newSection = remark().use(frontMatter, ['yaml']).data('settings', { paddedTable: false, gfm: false }).parse(mdText.trim()).children; + var tutIndexFile = path.resolve(tutFolder, 'README.md'); + var tutIndexText = fs.readFileSync(tutIndexFile, 'utf8'); + var tutIndexMD = remark().use(frontMatter, ['yaml']).data('settings', { paddedTable: false, gfm: false }).parse(tutIndexText); + replaceSection(tutIndexMD, 'Tutorials', function (before, section, after) { newSection.unshift(before); newSection.push(after); return newSection; }); - fs.writeFileSync(tutIndexFile, remark().use(frontMatter, { type: 'yaml', fence: '---' }).data("settings", { paddedTable: false, gfm: false }).stringify(tutIndexMD)); + fs.writeFileSync(tutIndexFile, remark().use(frontMatter, { type: 'yaml', fence: '---' }).data('settings', { paddedTable: false, gfm: false }).stringify(tutIndexMD)); } function getIndexDocData() { - var indexFile = path.resolve(userGuideFolder, "summary.json"); - var summaryArray = JSON.parse(fs.readFileSync(indexFile, "utf8")); + var indexFile = path.resolve(userGuideFolder, 'summary.json'); + var summaryArray = JSON.parse(fs.readFileSync(indexFile, 'utf8')); var indexArray = []; summaryArray.forEach(function (element) { - if (element["title"] === "Tutorials") { - indexArray = element["children"]; + if (element['title'] === 'Tutorials') { + indexArray = element['children']; } }); var result = { tuts: [] }; indexArray.forEach(function (element) { - var tutData = { link: element["file"] }; - var tutFile = path.resolve(tutFolder, element["file"]); - var tutFileText = fs.readFileSync(tutFile, "utf8"); - var tutMD = remark().use(frontMatter, ["yaml"]).parse(tutFileText); + var tutData = { link: element['file'] }; + var tutFile = path.resolve(tutFolder, element['file']); + var tutFileText = fs.readFileSync(tutFile, 'utf8'); + var tutMD = remark().use(frontMatter, ['yaml']).parse(tutFileText); var metadata = getDocMetadata(tutMD); - if (metadata["Level"]) { - tutData["level"] = metadata["Level"]; + if (metadata['Level']) { + tutData['level'] = metadata['Level']; } else { - tutData["level"] = ""; + tutData['level'] = ''; } var briefDesc = getFirstParagraph(tutMD); var briefDescText = remark() .use(frontMatter, { type: 'yaml', fence: '---' }) - .data("settings", { paddedTable: false, gfm: false }) + .data('settings', { paddedTable: false, gfm: false }) .stringify(briefDesc); - tutData["briefDesc"] = briefDescText; + tutData['briefDesc'] = briefDescText; var title = getFirstHeading(tutMD); var titleText = remark() .use(frontMatter, { type: 'yaml', fence: '---' }) - .data("settings", { paddedTable: false, gfm: false }) + .data('settings', { paddedTable: false, gfm: false }) .stringify(title.children[0]); - tutData["title"] = titleText; + tutData['title'] = titleText; result.tuts.push(tutData); }); return result; } function getDocMetadata(tree) { - if (tree.children[0].type == "yaml") { + if (tree.children[0].type === 'yaml') { return yaml.load(tree.children[0].value); } else { diff --git a/tools/doc/tools/tutorialIndex.ts b/tools/doc/tools/tutorialIndex.ts index b961e615e8..acf628dbca 100644 --- a/tools/doc/tools/tutorialIndex.ts +++ b/tools/doc/tools/tutorialIndex.ts @@ -1,98 +1,92 @@ -import * as fs from "fs"; -import * as path from "path"; - -import * as replaceSection from "mdast-util-heading-range"; -import * as remark from "remark"; -import * as frontMatter from "remark-frontmatter"; -import * as yaml from "js-yaml"; -import * as ejs from "ejs"; - -import * as unist from "../unistHelpers"; - -const tutFolder = path.resolve("docs", "tutorials"); -const templateFolder = path.resolve("tools", "doc", "templates"); -const userGuideFolder = path.resolve("docs", "user-guide"); +import * as fs from 'fs'; +import * as path from 'path'; +import * as replaceSection from 'mdast-util-heading-range'; +import * as remark from 'remark'; +import * as frontMatter from 'remark-frontmatter'; +import * as yaml from 'js-yaml'; +import * as ejs from 'ejs'; +import * as unist from '../unistHelpers'; +const tutFolder = path.resolve('docs', 'tutorials'); +const templateFolder = path.resolve('tools', 'doc', 'templates'); +const userGuideFolder = path.resolve('docs', 'user-guide'); export function processDocs() { aggPhase(); } - function aggPhase() { - let indexDocData = getIndexDocData(); + const indexDocData = getIndexDocData(); - let templateName = path.resolve(templateFolder, "tutIndex.ejs"); - let templateSource = fs.readFileSync(templateName, "utf8"); - let template = ejs.compile(templateSource); + const templateName = path.resolve(templateFolder, 'tutIndex.ejs'); + const templateSource = fs.readFileSync(templateName, 'utf8'); + const template = ejs.compile(templateSource); let mdText = template(indexDocData); - mdText = mdText.replace(/^ +\|/mg, "|"); + mdText = mdText.replace(/^ +\|/mg, '|'); - let newSection = remark().use(frontMatter, ["yaml"]).data("settings", {paddedTable: false, gfm: false}).parse(mdText.trim()).children; + const newSection = remark().use(frontMatter, ['yaml']).data('settings', {paddedTable: false, gfm: false}).parse(mdText.trim()).children; - let tutIndexFile = path.resolve(tutFolder, "README.md"); - let tutIndexText = fs.readFileSync(tutIndexFile, "utf8"); - let tutIndexMD = remark().use(frontMatter, ["yaml"]).data("settings", {paddedTable: false, gfm: false}).parse(tutIndexText); + const tutIndexFile = path.resolve(tutFolder, 'README.md'); + const tutIndexText = fs.readFileSync(tutIndexFile, 'utf8'); + const tutIndexMD = remark().use(frontMatter, ['yaml']).data('settings', {paddedTable: false, gfm: false}).parse(tutIndexText); - replaceSection(tutIndexMD, "Tutorials", (before, section, after) => { + replaceSection(tutIndexMD, 'Tutorials', (before, section, after) => { newSection.unshift(before); newSection.push(after); return newSection; }); - fs.writeFileSync(tutIndexFile, remark().use(frontMatter, {type: 'yaml', fence: '---'}).data("settings", {paddedTable: false, gfm: false}).stringify(tutIndexMD)); + fs.writeFileSync(tutIndexFile, remark().use(frontMatter, {type: 'yaml', fence: '---'}).data('settings', {paddedTable: false, gfm: false}).stringify(tutIndexMD)); } - - function getIndexDocData() { - let indexFile = path.resolve(userGuideFolder, "summary.json"); - let summaryArray = JSON.parse(fs.readFileSync(indexFile, "utf8")); + const indexFile = path.resolve(userGuideFolder, 'summary.json'); + const summaryArray = JSON.parse(fs.readFileSync(indexFile, 'utf8')); let indexArray = []; summaryArray.forEach(element => { - if (element["title"] === "Tutorials") { - indexArray = element["children"]; + if (element['title'] === 'Tutorials') { + indexArray = element['children']; } }); - let result = { + const result = { tuts: [] }; indexArray.forEach(element => { - let tutData = { link: element["file"] }; + const tutData = { link: element['file'] }; - let tutFile = path.resolve(tutFolder, element["file"]); - let tutFileText = fs.readFileSync(tutFile, "utf8"); - let tutMD = remark().use(frontMatter, ["yaml"]).parse(tutFileText); + const tutFile = path.resolve(tutFolder, element['file']); + const tutFileText = fs.readFileSync(tutFile, 'utf8'); + const tutMD = remark().use(frontMatter, ['yaml']).parse(tutFileText); - let metadata = getDocMetadata(tutMD); + const metadata = getDocMetadata(tutMD); - if (metadata["Level"]){ - tutData["level"] = metadata["Level"]; + if (metadata['Level']) { + tutData['level'] = metadata['Level']; } else { - tutData["level"] = ""; + tutData['level'] = ''; } - let briefDesc = getFirstParagraph(tutMD); + const briefDesc = getFirstParagraph(tutMD); - let briefDescText = remark() + const briefDescText = remark() .use(frontMatter, {type: 'yaml', fence: '---'}) - .data("settings", {paddedTable: false, gfm: false}) + .data('settings', {paddedTable: false, gfm: false}) .stringify(briefDesc); - tutData["briefDesc"] = briefDescText; + tutData['briefDesc'] = briefDescText; - let title = getFirstHeading(tutMD); + const title = getFirstHeading(tutMD); - let titleText = remark() + const titleText = remark() .use(frontMatter, {type: 'yaml', fence: '---'}) - .data("settings", {paddedTable: false, gfm: false}) + .data('settings', {paddedTable: false, gfm: false}) .stringify(title.children[0]); - tutData["title"] = titleText; + tutData['title'] = titleText; result.tuts.push(tutData); }); @@ -100,20 +94,18 @@ function getIndexDocData() { return result; } - function getDocMetadata(tree) { - if (tree.children[0].type == "yaml") { + if (tree.children[0].type === 'yaml') { return yaml.load(tree.children[0].value); } else { return {}; } } - function getFirstParagraph(tree) { let s = 0; - for (;(s < tree.children.length) && !unist.isParagraph(tree.children[s]); s++) {} + for (; (s < tree.children.length) && !unist.isParagraph(tree.children[s]); s++) {} if (s < tree.children.length) { return tree.children[s]; @@ -126,7 +118,7 @@ function getFirstParagraph(tree) { function getFirstHeading(tree) { let s = 0; - for (;(s < tree.children.length) && !unist.isHeading(tree.children[s]); s++) {} + for (; (s < tree.children.length) && !unist.isHeading(tree.children[s]); s++) {} if (s < tree.children.length) { return tree.children[s]; diff --git a/tools/doc/tools/typeLinker.js b/tools/doc/tools/typeLinker.js index a7c62f64b6..39bdd8f315 100644 --- a/tools/doc/tools/typeLinker.js +++ b/tools/doc/tools/typeLinker.js @@ -1,12 +1,12 @@ "use strict"; -exports.__esModule = true; +Object.defineProperty(exports, "__esModule", { value: true }); var path = require("path"); var unist = require("../unistHelpers"); var ngHelpers = require("../ngHelpers"); var includedNodeTypes = [ - "root", "paragraph", "inlineCode", "list", "listItem", - "table", "tableRow", "tableCell", "emphasis", "strong", - "link", "text" + 'root', 'paragraph', 'inlineCode', 'list', 'listItem', + 'table', 'tableRow', 'tableCell', 'emphasis', 'strong', + 'link', 'text' ]; var externalNameLinks; var linkOverrides; @@ -28,8 +28,8 @@ function initPhase(aggData, mdCache) { aggData.nameLookup = new SplitNameLookup(); var docFilePaths = Object.keys(mdCache); docFilePaths.forEach(function (docFilePath) { - var relPath = docFilePath.substring(docFilePath.indexOf('docs') + 5).replace(/\\/g, "/"); - var compName = path.basename(relPath, ".md"); + var relPath = docFilePath.substring(docFilePath.indexOf('docs') + 5).replace(/\\/g, '/'); + var compName = path.basename(relPath, '.md'); aggData.docFiles[compName] = relPath; }); var classNames = Object.keys(aggData.classInfo); @@ -46,33 +46,33 @@ function updateFile(tree, pathname, aggData) { if (!includedNodeTypes.includes(node.type)) { return; } - if (node.type === "link") { - if (node.children[0] && ((node.children[0].type === "inlineCode") || - (node.children[0].type === "text"))) { + if (node.type === 'link') { + if (node.children[0] && ((node.children[0].type === 'inlineCode') || + (node.children[0].type === 'text'))) { var link = resolveTypeLink(aggData, pathname, node.children[0].value); if (link) { convertNodeToTypeLink(node, node.children[0].value, link); } } } - else if ((node.children) && (node.type !== "heading")) { + else if ((node.children) && (node.type !== 'heading')) { node.children.forEach(function (child, index) { - if ((child.type === "text") || (child.type === "inlineCode")) { + var _a; + if ((child.type === 'text') || (child.type === 'inlineCode')) { var newNodes = handleLinksInBodyText(aggData, pathname, child.value, child.type === 'inlineCode'); (_a = node.children).splice.apply(_a, [index, 1].concat(newNodes)); } else { traverseMDTree(child); } - var _a; }); } } } -var SplitNameNode = (function () { +var SplitNameNode = /** @class */ (function () { function SplitNameNode(key, value) { - if (key === void 0) { key = ""; } - if (value === void 0) { value = ""; } + if (key === void 0) { key = ''; } + if (value === void 0) { value = ''; } this.key = key; this.value = value; this.children = {}; @@ -82,21 +82,21 @@ var SplitNameNode = (function () { }; return SplitNameNode; }()); -var SplitNameMatchElement = (function () { +var SplitNameMatchElement = /** @class */ (function () { function SplitNameMatchElement(node, textPos) { this.node = node; this.textPos = textPos; } return SplitNameMatchElement; }()); -var SplitNameMatchResult = (function () { +var SplitNameMatchResult = /** @class */ (function () { function SplitNameMatchResult(value, startPos) { this.value = value; this.startPos = startPos; } return SplitNameMatchResult; }()); -var SplitNameMatcher = (function () { +var SplitNameMatcher = /** @class */ (function () { function SplitNameMatcher(root) { this.root = root; this.reset(); @@ -142,17 +142,17 @@ var SplitNameMatcher = (function () { }; return SplitNameMatcher; }()); -var SplitNameLookup = (function () { +var SplitNameLookup = /** @class */ (function () { function SplitNameLookup() { this.root = new SplitNameNode(); } SplitNameLookup.prototype.addName = function (name) { - var spacedName = name.replace(/([A-Z])/g, " $1"); - var segments = spacedName.trim().toLowerCase().split(" "); + var spacedName = name.replace(/([A-Z])/g, ' $1'); + var segments = spacedName.trim().toLowerCase().split(' '); var currNode = this.root; segments.forEach(function (segment, index) { - var value = ""; - if (index == (segments.length - 1)) { + var value = ''; + if (index === (segments.length - 1)) { value = name; } var childNode = currNode.children[segment]; @@ -165,10 +165,10 @@ var SplitNameLookup = (function () { }; return SplitNameLookup; }()); -var WordScanner = (function () { +var WordScanner = /** @class */ (function () { function WordScanner(text) { this.text = text; - this.separators = " \n\r\t.;:<>[]&|"; + this.separators = ' \n\r\t.;:<>[]&|'; this.index = 0; this.nextSeparator = 0; this.next(); @@ -208,9 +208,9 @@ function handleLinksInBodyText(aggData, docFilePath, text, wrapInlineCode) { var matcher = new SplitNameMatcher(aggData.nameLookup.root); for (var scanner = new WordScanner(text); !scanner.finished(); scanner.next()) { var word = scanner.current - .replace(/'s$/, "") - .replace(/^[;:,\."']+/g, "") - .replace(/[;:,\."']+$/g, ""); + .replace(/'s$/, '') + .replace(/^[;:,\."']+/g, '') + .replace(/[;:,\."']+$/g, ''); var link = resolveTypeLink(aggData, docFilePath, word); var matchStart = void 0; if (!link) { @@ -261,13 +261,9 @@ function handleLinksInBodyText(aggData, docFilePath, text, wrapInlineCode) { function resolveTypeLink(aggData, docFilePath, text) { var possTypeName = cleanTypeName(text); if (possTypeName === 'constructor') { - return ""; + return ''; } - /* - let ref: Reflection = aggData.projData.findReflectionByName(possTypeName); -*/ var classInfo = aggData.classInfo[possTypeName]; - //if (ref && isLinkable(ref.kind)) { if (linkOverrides[possTypeName.toLowerCase()]) { return ''; } @@ -277,16 +273,14 @@ function resolveTypeLink(aggData, docFilePath, text) { else if (classInfo) { var kebabName = ngHelpers.kebabifyClassName(possTypeName); var possDocFile = aggData.docFiles[kebabName]; - //let url = "../../" + classInfo.sourcePath; var url = fixRelSrcUrl(docFilePath, classInfo.sourcePath); if (possDocFile) { - //url = "../" + possDocFile; url = fixRelDocUrl(docFilePath, possDocFile); } return url; } else { - return ""; + return ''; } } function fixRelSrcUrl(docPath, srcPath) { @@ -313,13 +307,13 @@ function cleanTypeName(text) { return matches[1]; } else { - return text.replace(/\[\]$/, ""); + return text.replace(/\[\]$/, ''); } } function convertNodeToTypeLink(node, text, url, title) { if (title === void 0) { title = null; } var linkDisplayText = unist.makeInlineCode(text); - node.type = "link"; + node.type = 'link'; node.title = title; node.url = url; node.children = [linkDisplayText]; diff --git a/tools/doc/tools/typeLinker.ts b/tools/doc/tools/typeLinker.ts index a4ba1a67be..69a1183cae 100644 --- a/tools/doc/tools/typeLinker.ts +++ b/tools/doc/tools/typeLinker.ts @@ -1,13 +1,11 @@ -import * as path from "path"; - -import * as unist from "../unistHelpers"; -import * as ngHelpers from "../ngHelpers"; - +import * as path from 'path'; +import * as unist from '../unistHelpers'; +import * as ngHelpers from '../ngHelpers'; const includedNodeTypes = [ - "root", "paragraph", "inlineCode", "list", "listItem", - "table", "tableRow", "tableCell", "emphasis", "strong", - "link", "text" + 'root', 'paragraph', 'inlineCode', 'list', 'listItem', + 'table', 'tableRow', 'tableCell', 'emphasis', 'strong', + 'link', 'text' ]; let externalNameLinks; @@ -16,7 +14,7 @@ let linkOverrides; export function processDocs(mdCache, aggData) { initPhase(aggData, mdCache); - var pathnames = Object.keys(mdCache); + const pathnames = Object.keys(mdCache); pathnames.forEach(pathname => { updateFile(mdCache[pathname].mdOutTree, pathname, aggData); @@ -34,15 +32,15 @@ function initPhase(aggData, mdCache) { aggData.docFiles = {}; aggData.nameLookup = new SplitNameLookup(); - let docFilePaths = Object.keys(mdCache); + const docFilePaths = Object.keys(mdCache); docFilePaths.forEach(docFilePath => { - let relPath = docFilePath.substring(docFilePath.indexOf('docs') + 5).replace(/\\/g, "/"); - let compName = path.basename(relPath, ".md"); + const relPath = docFilePath.substring(docFilePath.indexOf('docs') + 5).replace(/\\/g, '/'); + const compName = path.basename(relPath, '.md'); aggData.docFiles[compName] = relPath; }); - let classNames = Object.keys(aggData.classInfo); + const classNames = Object.keys(aggData.classInfo); classNames.forEach(currClassName => { if (currClassName.match(/(Component|Directive|Interface|Model|Pipe|Service|Widget)$/)) { @@ -55,27 +53,26 @@ function updateFile(tree, pathname, aggData) { traverseMDTree(tree); return true; - function traverseMDTree(node) { if (!includedNodeTypes.includes(node.type)) { return; } - if (node.type === "link") { + if (node.type === 'link') { if (node.children[0] && ( - (node.children[0].type === "inlineCode") || - (node.children[0].type === "text") + (node.children[0].type === 'inlineCode') || + (node.children[0].type === 'text') )) { - let link = resolveTypeLink(aggData, pathname, node.children[0].value); + const link = resolveTypeLink(aggData, pathname, node.children[0].value); if (link) { convertNodeToTypeLink(node, node.children[0].value, link); } } - } else if ((node.children) && (node.type !== "heading")) { + } else if ((node.children) && (node.type !== 'heading')) { node.children.forEach((child, index) => { - if ((child.type === "text") || (child.type === "inlineCode")) { - let newNodes = handleLinksInBodyText(aggData, pathname, child.value, child.type === 'inlineCode'); + if ((child.type === 'text') || (child.type === 'inlineCode')) { + const newNodes = handleLinksInBodyText(aggData, pathname, child.value, child.type === 'inlineCode'); node.children.splice(index, 1, ...newNodes); } else { traverseMDTree(child); @@ -85,11 +82,10 @@ function updateFile(tree, pathname, aggData) { } } - class SplitNameNode { children: {}; - constructor(public key: string = "", public value: string = "") { + constructor(public key: string = '', public value: string = '') { this.children = {}; } @@ -98,17 +94,14 @@ class SplitNameNode { } } - class SplitNameMatchElement { constructor(public node: SplitNameNode, public textPos: number) {} } - class SplitNameMatchResult { constructor(public value: string, public startPos: number) {} } - class SplitNameMatcher { matches: SplitNameMatchElement[]; @@ -118,13 +111,13 @@ class SplitNameMatcher { /* Returns all names that match when this word is added. */ nextWord(word: string, textPos: number): SplitNameMatchResult[] { - let result = []; + const result = []; this.matches.push(new SplitNameMatchElement(this.root, textPos)); for (let i = this.matches.length - 1; i >= 0; i--) { if (this.matches[i].node.children) { - let child = this.matches[i].node.children[word]; + const child = this.matches[i].node.children[word]; if (child) { if (child.value) { @@ -158,7 +151,6 @@ class SplitNameMatcher { } } - class SplitNameLookup { root: SplitNameNode; @@ -167,15 +159,15 @@ class SplitNameLookup { } addName(name: string) { - let spacedName = name.replace(/([A-Z])/g, " $1"); - let segments = spacedName.trim().toLowerCase().split(" "); + const spacedName = name.replace(/([A-Z])/g, ' $1'); + const segments = spacedName.trim().toLowerCase().split(' '); let currNode = this.root; segments.forEach((segment, index) => { - let value = ""; + let value = ''; - if (index == (segments.length - 1)) { + if (index === (segments.length - 1)) { value = name; } @@ -198,7 +190,7 @@ class WordScanner { current: string; constructor(public text: string) { - this.separators = " \n\r\t.;:<>[]&|"; + this.separators = ' \n\r\t.;:<>[]&|'; this.index = 0; this.nextSeparator = 0; this.next(); @@ -238,32 +230,32 @@ class WordScanner { } function handleLinksInBodyText(aggData, docFilePath: string, text: string, wrapInlineCode: boolean = false): Node[] { - let result = []; + const result = []; let currTextStart = 0; - let matcher = new SplitNameMatcher(aggData.nameLookup.root); + const matcher = new SplitNameMatcher(aggData.nameLookup.root); - for (let scanner = new WordScanner(text); !scanner.finished(); scanner.next()) { - let word = scanner.current - .replace(/'s$/, "") - .replace(/^[;:,\."']+/g, "") - .replace(/[;:,\."']+$/g, ""); + for (const scanner = new WordScanner(text); !scanner.finished(); scanner.next()) { + const word = scanner.current + .replace(/'s$/, '') + .replace(/^[;:,\."']+/g, '') + .replace(/[;:,\."']+$/g, ''); let link = resolveTypeLink(aggData, docFilePath, word); let matchStart; if (!link) { - let match = matcher.nextWord(word.toLowerCase(), scanner.index); + const match = matcher.nextWord(word.toLowerCase(), scanner.index); if (match && match[0]) { link = resolveTypeLink(aggData, docFilePath, match[0].value); matchStart = match[0].startPos; } } else { - matchStart = scanner.index + matchStart = scanner.index; } if (link) { - let linkText = text.substring(matchStart, scanner.nextSeparator); + const linkText = text.substring(matchStart, scanner.nextSeparator); let linkTitle; if (wrapInlineCode) { @@ -272,8 +264,8 @@ function handleLinksInBodyText(aggData, docFilePath: string, text: string, wrapI linkTitle = unist.makeText(linkText); } - let linkNode = unist.makeLink(linkTitle, link); - let prevText = text.substring(currTextStart, matchStart); + const linkNode = unist.makeLink(linkTitle, link); + const prevText = text.substring(currTextStart, matchStart); if (prevText) { if (wrapInlineCode) { @@ -289,7 +281,7 @@ function handleLinksInBodyText(aggData, docFilePath: string, text: string, wrapI } } - let remainingText = text.substring(currTextStart, text.length); + const remainingText = text.substring(currTextStart, text.length); if (remainingText) { if (wrapInlineCode) { @@ -302,23 +294,22 @@ function handleLinksInBodyText(aggData, docFilePath: string, text: string, wrapI return result; } - function resolveTypeLink(aggData, docFilePath, text): string { - let possTypeName = cleanTypeName(text); + const possTypeName = cleanTypeName(text); if (possTypeName === 'constructor') { - return ""; + return ''; } - let classInfo = aggData.classInfo[possTypeName]; + const classInfo = aggData.classInfo[possTypeName]; if (linkOverrides[possTypeName.toLowerCase()]) { return ''; } else if (externalNameLinks[possTypeName]) { return externalNameLinks[possTypeName]; } else if (classInfo) { - let kebabName = ngHelpers.kebabifyClassName(possTypeName); - let possDocFile = aggData.docFiles[kebabName]; + const kebabName = ngHelpers.kebabifyClassName(possTypeName); + const possDocFile = aggData.docFiles[kebabName]; let url = fixRelSrcUrl(docFilePath, classInfo.sourcePath); @@ -328,13 +319,13 @@ function resolveTypeLink(aggData, docFilePath, text): string { return url; } else { - return ""; + return ''; } } function fixRelSrcUrl(docPath: string, srcPath: string) { - let relDocPath = docPath.substring(docPath.indexOf('docs')); - let docPathSegments = relDocPath.split(/[\\\/]/); + const relDocPath = docPath.substring(docPath.indexOf('docs')); + const docPathSegments = relDocPath.split(/[\\\/]/); let dotPathPart = ''; for (let i = 0; i < (docPathSegments.length - 1); i++) { @@ -345,8 +336,8 @@ function fixRelSrcUrl(docPath: string, srcPath: string) { } function fixRelDocUrl(docPathFrom: string, docPathTo: string) { - let relDocPathFrom = docPathFrom.substring(docPathFrom.indexOf('docs')); - let docPathSegments = relDocPathFrom.split(/[\\\/]/); + const relDocPathFrom = docPathFrom.substring(docPathFrom.indexOf('docs')); + const docPathSegments = relDocPathFrom.split(/[\\\/]/); let dotPathPart = ''; for (let i = 0; i < (docPathSegments.length - 2); i++) { @@ -357,18 +348,18 @@ function fixRelDocUrl(docPathFrom: string, docPathTo: string) { } function cleanTypeName(text) { - let matches = text.match(/[a-zA-Z0-9_]+<([a-zA-Z0-9_]+)(\[\])?>/); + const matches = text.match(/[a-zA-Z0-9_]+<([a-zA-Z0-9_]+)(\[\])?>/); if (matches) { return matches[1]; } else { - return text.replace(/\[\]$/, ""); + return text.replace(/\[\]$/, ''); } } function convertNodeToTypeLink(node, text, url, title = null) { - let linkDisplayText = unist.makeInlineCode(text); - node.type = "link"; + const linkDisplayText = unist.makeInlineCode(text); + node.type = 'link'; node.title = title; node.url = url; node.children = [linkDisplayText]; diff --git a/tools/doc/tsconfig.json b/tools/doc/tsconfig.json index 283a487953..46fa3fc123 100644 --- a/tools/doc/tsconfig.json +++ b/tools/doc/tsconfig.json @@ -1,19 +1,24 @@ { - "compilerOptions": { - "outDir": ".", - "baseUrl": ".", - "moduleResolution": "node", - "noUnusedLocals": true, - "target": "es5", - "types": ["node", "@paperist/types-remark"], - "lib": [ - "es2015" - ] - }, - "files": [ - "remarkGraphQl.ts", - "mqDefs.ts", - "tools/gqIndex.ts", - "tools/linkFixer.ts" - ] - } \ No newline at end of file + "compilerOptions": { + "outDir": ".", + "baseUrl": ".", + "moduleResolution": "node", + "noUnusedLocals": true, + "target": "es5", + "types": ["node", "@paperist/types-remark"], + "typeRoots": ["node_modules/@types"], + "lib": ["es2018", "dom"] + }, + "files": [ + "remarkGraphQl.ts", + "mqDefs.ts", + "tools/fileChecker.ts", + "tools/gqIndex.ts", + "tools/linkFixer.ts", + "tools/sourceLinker.ts", + "tools/tsInfo.ts", + "tools/tutorialIndex.ts", + "tools/typeLinker.ts" + // "reviewChecker.ts" + ] +}