[ACS-6659] cleanup unused docs utils (#9274)

* remove unused scripts

* remove unused scripts

* remove unused scripts

* remove unused libs

* remove unused code

* remove unused code and libs, fix linting issues

* code cleanup

* linting fixes

* linting fixes
This commit is contained in:
Denys Vuika 2024-01-25 10:22:05 -05:00 committed by GitHub
parent 69f24a17ff
commit 5ec8228504
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 1102 additions and 1949 deletions

View File

@ -77,7 +77,6 @@
"lastname",
"listgrid",
"mapitem",
"markdownlint",
"mimetype",
"mincount",
"minlength",

41
package-lock.json generated
View File

@ -111,7 +111,6 @@
"eslint-plugin-unicorn": "^49.0.0",
"github-api": "^3.4.0",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"husky": "^7.0.4",
"jasmine-ajax": "4.0.0",
"jasmine-core": "4.6.0",
@ -28792,33 +28791,6 @@
"version": "1.5.13",
"license": "MIT"
},
"node_modules/cross-fetch": {
"version": "3.1.5",
"dev": true,
"license": "MIT",
"dependencies": {
"node-fetch": "2.6.7"
}
},
"node_modules/cross-fetch/node_modules/node-fetch": {
"version": "2.6.7",
"dev": true,
"license": "MIT",
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
}
},
"node_modules/cross-spawn": {
"version": "7.0.3",
"license": "MIT",
@ -33448,19 +33420,6 @@
"node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0"
}
},
"node_modules/graphql-request": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/graphql-request/-/graphql-request-6.1.0.tgz",
"integrity": "sha512-p+XPfS4q7aIpKVcgmnZKhMNqhltk20hfXtkaIkTfjjmiKMJ5xrt5c743cL03y/K7y1rg3WrIC49xGiEQ4mxdNw==",
"dev": true,
"dependencies": {
"@graphql-typed-document-node/core": "^3.2.0",
"cross-fetch": "^3.1.5"
},
"peerDependencies": {
"graphql": "14 - 16"
}
},
"node_modules/graphql-tag": {
"version": "2.12.6",
"license": "MIT",

View File

@ -9,16 +9,10 @@
"ng": "nx",
"00": "echo -------------------------------------------- DOC -----------------------------------------------",
"build-doc-tools": "tsc -p ./tools/doc/tsconfig.json",
"markdownlint": "markdownlint ./docs",
"docbuild": "(cd ./tools/doc; npm i) && node tools/doc/node_modules/typedoc/bin/typedoc --tsconfig lib/tsconfig.doc.json && node tools/doc/buildYamlSourceInfo.js docs/docs.json && node ./tools/doc/docProcessor.js",
"review-checker": "node ./tools/doc/reviewChecker.js",
"01": "echo -------------------------------------------- Build Lib -----------------------------------------------",
"affected:libs": "nx affected:libs",
"coverage": "./lib/config/create-coverage-index.sh && lite-server -c ./lib/config/proxy-coverage.json",
"print-affected:build": "nx print-affected --target=build --select=tasks.target.project",
"print-affected:test": "nx print-affected --target=test --select=tasks.target.project",
"print-affected:e2e": "nx print-affected --target=e2e --select=tasks.target.project",
"print-affected:lint": "nx print-affected --target=lint --select=tasks.target.project",
"03": "echo -------------------------------------------- Lint -----------------------------------------------",
"affected:lint": "nx affected:lint",
"04": "echo -------------------------------------------- Demo Shell -----------------------------------------------",
@ -161,7 +155,6 @@
"eslint-plugin-unicorn": "^49.0.0",
"github-api": "^3.4.0",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"husky": "^7.0.4",
"jasmine-ajax": "4.0.0",
"jasmine-core": "4.6.0",

View File

@ -1,33 +0,0 @@
# Review checker guide
The review checker tool queries the Github repo to look for recent
commits to the component source files. The dates of these commits
are compared against against a review date stored in the Markdown doc
file for each component. The time and the number of commits since the
last review are then combined into a "score" that gives an indication
of how urgently the doc file needs a review.
## Review date metadata
The review date is kept in the YAML metadata section at the top of each
Markdown file. The key is "Last reviewed" and the date is in the form
YYYY-MM-DD.
## Commit message stoplist
The checker will ignore any commits that match regular expressions stored
in the `commitStoplist.json` file in the `DocProcessor` folder. You could
use this, for example, to filter out JIRA tasks that don't involve any
changes in functionality (and therefore don't need documenting).
## Output format
The script sends comma-separated text to the command line. You can copy/paste
this into a spreadsheet or redirect the output to a text file with a ".csv"
suffix.
To use this tool you need before to set graphAuthToken variable with you github access token:
export graphAuthToken=GITHUB_TOKEN
npm run review-checker

View File

@ -1,12 +1,12 @@
var fs = require("fs");
var path = require("path");
var ejs = require("ejs");
const fs = require('fs');
const path = require('path');
const ejs = require('ejs');
var templateFolder = path.resolve("tools", "doc", "yamlTemplates");
var outputFolder = path.resolve("docs", "sourceinfo");
const templateFolder = path.resolve('tools', 'doc', 'yamlTemplates');
const outputFolder = path.resolve('docs', 'sourceinfo');
if (process.argv.length < 3) {
console.log("Error: Source filename required");
console.log('Error: Source filename required');
process.exit();
}
@ -16,41 +16,36 @@ if (!fs.existsSync(outputFolder)) {
fs.mkdirSync(outputFolder);
}
var docData = JSON.parse(fs.readFileSync(path.resolve(process.argv[2]), "utf8"));
var tempFilename = path.resolve(templateFolder, "template.ejs");
var tempSource = fs.readFileSync(tempFilename, "utf8");
var template = ejs.compile(
tempSource,
{
filename: tempFilename,
cache: true
}
);
const docData = JSON.parse(fs.readFileSync(path.resolve(process.argv[2]), 'utf8'));
const tempFilename = path.resolve(templateFolder, 'template.ejs');
const tempSource = fs.readFileSync(tempFilename, 'utf8');
const template = ejs.compile(tempSource, {
filename: tempFilename,
cache: true
});
searchItemsRecursively(docData);
function searchItemsRecursively(item) {
if (interestedIn(item.kind)) {
processItem(item);
} else if (item.children) {
item.children.forEach(child => {
item.children.forEach((child) => {
searchItemsRecursively(child);
});
}
}
function interestedIn(itemKind) {
return (itemKind === 128) || (itemKind === 256) || (itemKind === 4194304);
return itemKind === 128 || itemKind === 256 || itemKind === 4194304;
}
function processItem(item) {
var docText = template(item);
const docText = template(item);
if( item.name === 'Widget'){
console.log('item ' + JSON.stringify(item.name ));
if (item.name === 'Widget') {
console.log('item ' + JSON.stringify(item.name));
}
fs.writeFileSync(path.resolve(outputFolder, item.name + ".yml"), docText);
fs.writeFileSync(path.resolve(outputFolder, item.name + '.yml'), docText);
}

View File

@ -1 +0,0 @@
["ADF-1769"]

View File

@ -1,25 +1,22 @@
var fs = require("fs");
var path = require("path");
const fs = require('fs');
const path = require('path');
const program = require('commander');
const lodash = require('lodash');
const jsyaml = require('js-yaml');
const remark = require('remark');
const frontMatter = require('remark-frontmatter');
const mdCompact = require('mdast-util-compact');
const minimatch = require('minimatch');
var program = require("commander");
var lodash = require("lodash");
var jsyaml = require("js-yaml");
var remark = require("remark");
var frontMatter = require("remark-frontmatter");
var mdCompact = require("mdast-util-compact");
var minimatch = require("minimatch");
var si = require("./sourceInfoClasses");
const si = require('./sourceInfoClasses');
// "Aggregate" data collected over the whole file set.
var aggData = {};
var toolsFolderName = "tools";
var configFileName = "doctool.config.json";
var defaultFolder = path.resolve("docs");
var sourceInfoFolder = path.resolve("docs", "sourceinfo");
const aggData = {};
const toolsFolderName = 'tools';
const configFileName = 'doctool.config.json';
const defaultFolder = path.resolve('docs');
const sourceInfoFolder = path.resolve('docs', 'sourceinfo');
function filterFiles(filePath) {
let isAllowed = true;
@ -27,31 +24,33 @@ function filterFiles(filePath) {
this.excludedFileList = aggData['config'].exclude;
if (this.excludedFileList) {
isAllowed = this.excludedFileList.filter((pattern) => {
return minimatch(filePath, pattern.toString(), {
nocase: true
});
}).length === 0;
isAllowed =
this.excludedFileList.filter((pattern) => {
return minimatch(filePath, pattern.toString(), {
nocase: true
});
}).length === 0;
}
return isAllowed;
}
const toolModules = loadToolModules();
let toolList;
function updatePhase(mdCache, aggData) {
toolList.forEach(toolName => {
toolList.forEach((toolName) => {
console.log(`Tool: ${toolName}`);
toolModules[toolName].processDocs(mdCache, aggData);
});
var filenames = Object.keys(mdCache);
const filenames = Object.keys(mdCache);
for (var i = 0; i < filenames.length; i++) {
var pathname = filenames[i];
var tree = mdCache[pathname].mdOutTree;
var original = mdCache[pathname].mdInTree;
for (let i = 0; i < filenames.length; i++) {
const pathname = filenames[i];
const tree = mdCache[pathname].mdOutTree;
const original = mdCache[pathname].mdInTree;
if (program.json) {
let filename = path.basename(pathname);
@ -67,30 +66,36 @@ function updatePhase(mdCache, aggData) {
console.log(`Modified: ${pathname}`);
}
fs.writeFileSync(filenames[i], remark().use(frontMatter, {
type: 'yaml',
fence: '---'
}).data("settings", {paddedTable: false, gfm: false}).stringify(tree));
fs.writeFileSync(
filenames[i],
remark()
.use(frontMatter, {
type: 'yaml',
fence: '---'
})
.data('settings', { paddedTable: false, gfm: false })
.stringify(tree)
);
}
}
}
function minimiseTree(tree) {
let minPropsTree = JSON.parse(JSON.stringify(tree, (key, value) => key === "position" ? undefined : value));
let minPropsTree = JSON.parse(JSON.stringify(tree, (key, value) => (key === 'position' ? undefined : value)));
mdCompact(minPropsTree);
return minPropsTree;
}
function loadToolModules() {
var mods = {};
var toolsFolderPath = path.resolve(__dirname, toolsFolderName);
var modFiles = fs.readdirSync(toolsFolderPath);
const mods = {};
const toolsFolderPath = path.resolve(__dirname, toolsFolderName);
const modFiles = fs.readdirSync(toolsFolderPath);
for (var i = 0; i < modFiles.length; i++) {
var modPath = path.resolve(toolsFolderPath, modFiles[i])
for (let i = 0; i < modFiles.length; i++) {
const modPath = path.resolve(toolsFolderPath, modFiles[i]);
if (path.extname(modPath) === ".js") {
var toolName = path.basename(modPath, ".js");
if (path.extname(modPath) === '.js') {
const toolName = path.basename(modPath, '.js');
mods[toolName] = require(modPath);
}
}
@ -98,19 +103,17 @@ function loadToolModules() {
return mods;
}
function loadConfig() {
var configFilePath = path.resolve(__dirname, configFileName)
const configFilePath = path.resolve(__dirname, configFileName);
return JSON.parse(fs.readFileSync(configFilePath));
}
function getAllDocFilePaths(docFolder, files) {
var items = fs.readdirSync(docFolder);
const items = fs.readdirSync(docFolder);
for (var i = 0; i < items.length; i++) {
var itemPath = path.resolve(docFolder, items[i]);
var itemInfo = fs.statSync(itemPath);
for (let i = 0; i < items.length; i++) {
const itemPath = path.resolve(docFolder, items[i]);
const itemInfo = fs.statSync(itemPath);
if (itemInfo.isFile()) {
files.push(itemPath);
@ -120,16 +123,15 @@ function getAllDocFilePaths(docFolder, files) {
}
}
function initMdCache(filenames) {
var mdCache = {};
const mdCache = {};
for (var i = 0; i < filenames.length; i++) {
var pathname = filenames[i];
for (let i = 0; i < filenames.length; i++) {
const pathname = filenames[i];
mdCache[pathname] = {};
var src = fs.readFileSync(pathname);
var tree = remark().use(frontMatter, ["yaml"]).parse(src);
const src = fs.readFileSync(pathname);
const tree = remark().use(frontMatter, ['yaml']).parse(src);
mdCache[pathname].mdInTree = minimiseTree(tree);
mdCache[pathname].mdOutTree = minimiseTree(tree);
}
@ -138,13 +140,13 @@ function initMdCache(filenames) {
}
function initClassInfo(aggData) {
var yamlFilenames = fs.readdirSync(path.resolve(sourceInfoFolder));
const yamlFilenames = fs.readdirSync(path.resolve(sourceInfoFolder));
aggData.classInfo = {};
yamlFilenames.forEach(yamlFilename => {
var classYamlText = fs.readFileSync(path.resolve(sourceInfoFolder, yamlFilename), "utf8");
var classYaml = jsyaml.safeLoad(classYamlText);
yamlFilenames.forEach((yamlFilename) => {
const classYamlText = fs.readFileSync(path.resolve(sourceInfoFolder, yamlFilename), 'utf8');
const classYaml = jsyaml.safeLoad(classYamlText);
if (program.verbose) {
console.log(classYaml.items[0].name);
@ -155,20 +157,20 @@ function initClassInfo(aggData) {
}
program
.usage("[options] <source>")
.option("-p, --profile [profileName]", "Select named config profile", "default")
.option("-j, --json", "Output JSON data for Markdown syntax tree")
.option("-v, --verbose", "Log doc files as they are processed")
.option("-t, --timing", "Output time taken for run")
.usage('[options] <source>')
.option('-p, --profile [profileName]', 'Select named config profile', 'default')
.option('-j, --json', 'Output JSON data for Markdown syntax tree')
.option('-v, --verbose', 'Log doc files as they are processed')
.option('-t, --timing', 'Output time taken for run')
.parse(process.argv);
var startTime;
let startTime;
if (program.timing) {
startTime = process.hrtime();
}
var sourcePath;
let sourcePath;
if (program.args.length === 0) {
sourcePath = defaultFolder;
@ -176,25 +178,20 @@ if (program.args.length === 0) {
sourcePath = path.resolve(program.args[0]);
}
var sourceInfo = fs.statSync(sourcePath);
var toolModules = loadToolModules();
var config = loadConfig();
const sourceInfo = fs.statSync(sourcePath);
const config = loadConfig();
aggData['config'] = config;
var toolList;
if (config.profiles[program.profile]) {
toolList = config.profiles[program.profile];
var toolListText = toolList.join(", ");
var toolListText = toolList.join(', ');
console.log(`Using '${program.profile}' profile: ${toolListText}`);
} else {
console.log(`Aborting: unknown profile '${program.profile}`);
return 0;
}
var files = [];
let files = [];
if (sourceInfo.isDirectory()) {
getAllDocFilePaths(sourcePath, files);
@ -203,22 +200,18 @@ if (sourceInfo.isDirectory()) {
files = [sourcePath];
}
files = files.filter(filename =>
(filename !== undefined) &&
(path.extname(filename) === ".md") &&
(filename !== "README.md") && filterFiles(filename)
);
files = files.filter((filename) => filename !== undefined && path.extname(filename) === '.md' && filename !== 'README.md' && filterFiles(filename));
var mdCache = initMdCache(files);
const mdCache = initMdCache(files);
console.log("Loading source data...");
console.log('Loading source data...');
initClassInfo(aggData);
console.log("Updating Markdown files...");
console.log('Updating Markdown files...');
updatePhase(mdCache, aggData);
if (program.timing) {
var endTime = process.hrtime(startTime);
const endTime = process.hrtime(startTime);
console.log(`Run complete in ${endTime[0]} sec`);
}

View File

@ -1,31 +1,31 @@
var fs = require("fs");
var path = require("path");
const fs = require('fs');
const path = require('path');
module.exports = searchLibraryRecursive;
var angFilenameRegex = /([a-zA-Z0-9\-]+)\.((component)|(dialog)|(directive)|(model)|(pipe)|(service)|(widget))\.ts/;
var searchFolderOmitRegex = /(config)|(mock)|(i18n)|(assets)|(styles)/;
const angFilenameRegex = /([a-zA-Z0-9\-]+)\.((component)|(dialog)|(directive)|(model)|(pipe)|(service)|(widget))\.ts/;
const searchFolderOmitRegex = /(config)|(mock)|(i18n)|(assets)|(styles)/;
// Search source folders for .ts files to discover all components, directives, etc.
function searchLibraryRecursive(srcData, folderPath) {
var items = fs.readdirSync(folderPath);
for (var i = 0; i < items.length; i++) {
var itemPath = path.resolve(folderPath, items[i]);
var info = fs.statSync(itemPath);
if (info.isFile() && (items[i].match(angFilenameRegex))) {
var nameNoSuffix = path.basename(items[i], '.ts');
var displayPath = itemPath.replace(/\\/g, '/');
displayPath = displayPath.substr(displayPath.indexOf("lib") + 4);
const items = fs.readdirSync(folderPath);
for (let i = 0; i < items.length; i++) {
const itemPath = path.resolve(folderPath, items[i]);
const info = fs.statSync(itemPath);
if (info.isFile() && items[i].match(angFilenameRegex)) {
const nameNoSuffix = path.basename(items[i], '.ts');
let displayPath = itemPath.replace(/\\/g, '/');
displayPath = displayPath.substring(displayPath.indexOf('lib') + 4);
// Type == "component", "directive", etc.
var itemType = nameNoSuffix.split('.')[1];
srcData[nameNoSuffix] = { "path": displayPath, "type": itemType };
const itemType = nameNoSuffix.split('.')[1];
srcData[nameNoSuffix] = { path: displayPath, type: itemType };
} else if (info.isDirectory() && !items[i].match(searchFolderOmitRegex)) {
searchLibraryRecursive(srcData, itemPath);
}
}
}
}
module.exports = searchLibraryRecursive;

View File

@ -17,7 +17,7 @@
import { MDAST } from 'mdast';
import { UNIST } from 'unist';
import * as mdToString from 'mdast-util-to-string';
import { toString } from 'mdast-util-to-string';
import * as jsyaml from 'js-yaml';
export const schema = `
@ -116,7 +116,7 @@ export class Node {
children(): Node[] {
if (this.orig['children']) {
return this.orig['children'].map(x => new Node(x));
return this.orig['children'].map((x) => new Node(x));
} else {
return null;
}
@ -124,53 +124,34 @@ export class Node {
}
export class Parent {
constructor(protected orig: UNIST.Parent) {}
plaintext(): string {
return mdToString(this.orig);
return toString(this.orig);
}
paragraph(): Paragraph {
return new Paragraph(<MDAST.Paragraph> this.orig.children.find(
(ch: UNIST.Node) => (ch.type === 'paragraph')
));
return new Paragraph(<MDAST.Paragraph>this.orig.children.find((ch: UNIST.Node) => ch.type === 'paragraph'));
}
paragraphs(): Paragraph[] {
return this.orig.children.filter(
(ch: UNIST.Node) =>
(ch.type === 'paragraph')
)
.map(ch => new Paragraph(<MDAST.Paragraph> ch));
return this.orig.children.filter((ch: UNIST.Node) => ch.type === 'paragraph').map((ch) => new Paragraph(<MDAST.Paragraph>ch));
}
link(): Link {
return new Link(<MDAST.Link> this.orig.children.find(
(ch: UNIST.Node) => (ch.type === 'link')
));
return new Link(<MDAST.Link>this.orig.children.find((ch: UNIST.Node) => ch.type === 'link'));
}
links(): Link[] {
return this.orig.children.filter(
(ch: UNIST.Node) =>
(ch.type === 'link')
)
.map(ch => new Link(<MDAST.Link> ch));
return this.orig.children.filter((ch: UNIST.Node) => ch.type === 'link').map((ch) => new Link(<MDAST.Link>ch));
}
text(): Text {
return new Text(<MDAST.TextNode> this.orig.children.find(
(ch: UNIST.Node) => (ch.type === 'text')
));
return new Text(<MDAST.TextNode>this.orig.children.find((ch: UNIST.Node) => ch.type === 'text'));
}
texts(): Text[] {
return this.orig.children.filter(
(ch: UNIST.Node) =>
(ch.type === 'text')
)
.map(ch => new Text(<MDAST.TextNode> ch));
return this.orig.children.filter((ch: UNIST.Node) => ch.type === 'text').map((ch) => new Text(<MDAST.TextNode>ch));
}
}
@ -192,9 +173,7 @@ export class Root extends Parent {
metadata(args): string {
if (!this._meta) {
const yamlElement: any = this.orig.children.find(
(ch: UNIST.Node) => (ch.type === 'yaml')
);
const yamlElement: any = this.orig.children.find((ch: UNIST.Node) => ch.type === 'yaml');
if (yamlElement) {
this._meta = jsyaml.safeLoad(yamlElement.value);
@ -213,41 +192,35 @@ export class Root extends Parent {
heading(args): Heading {
const depth = args['depth'];
return new Heading(<MDAST.Heading> this.orig.children.find(
(ch: UNIST.Node) =>
(ch.type === 'heading') &&
((depth === 0) || (depth === (<MDAST.Heading> ch).depth))
));
return new Heading(
<MDAST.Heading>this.orig.children.find((ch: UNIST.Node) => ch.type === 'heading' && (depth === 0 || depth === (<MDAST.Heading>ch).depth))
);
}
headings(args): Heading[] {
const depth = args['depth'];
return this.orig.children.filter(
(ch: UNIST.Node) =>
(ch.type === 'heading') &&
((depth === 0) || (depth === (<MDAST.Heading> ch).depth)))
.map(ch => new Heading(<MDAST.Heading> ch));
return this.orig.children
.filter((ch: UNIST.Node) => ch.type === 'heading' && (depth === 0 || depth === (<MDAST.Heading>ch).depth))
.map((ch) => new Heading(<MDAST.Heading>ch));
}
}
export class Heading extends Parent {
depth(): number {
return (<MDAST.Heading> this.orig).depth;
return (<MDAST.Heading>this.orig).depth;
}
}
export class Paragraph extends Parent {
}
export class Paragraph extends Parent {}
export class Link extends Parent {
title(): string {
return (<MDAST.Link> this.orig).title;
return (<MDAST.Link>this.orig).title;
}
url(): string {
return (<MDAST.Link> this.orig).url;
return (<MDAST.Link>this.orig).url;
}
}
@ -269,11 +242,8 @@ export class Docset {
const pathnames = Object.keys(mdCache);
pathnames.forEach(pathname => {
if (!pathname.match(/README/) &&
pathname.match(libNamesRegex)
) {
pathnames.forEach((pathname) => {
if (!pathname.match(/README/) && pathname.match(libNamesRegex)) {
const doc = new Root(mdCache[pathname].mdInTree);
doc.id = pathname.replace(/\\/g, '/');
this.docs.push(doc);
@ -285,7 +255,7 @@ export class Docset {
if (args['idFilter'] === '') {
return this.docs;
} else {
return this.docs.filter(doc => doc.id.indexOf(args['idFilter'] + '/') !== -1);
return this.docs.filter((doc) => doc.id.indexOf(args['idFilter'] + '/') !== -1);
}
}

View File

@ -1,67 +1,55 @@
module.exports = {
"ngNameToDisplayName": ngNameToDisplayName,
"ngNameToClassName": ngNameToClassName,
"dekebabifyName": dekebabifyName,
"kebabifyClassName": kebabifyClassName,
"classTypes": ["component", "dialog", "directive", "model", "pipe", "service", "widget"]
}
ngNameToDisplayName: ngNameToDisplayName,
ngNameToClassName: ngNameToClassName,
dekebabifyName: dekebabifyName,
kebabifyClassName: kebabifyClassName,
classTypes: ['component', 'dialog', 'directive', 'model', 'pipe', 'service', 'widget']
};
function ngNameToDisplayName(ngName) {
var mainSections = ngName.split(".");
const mainSections = ngName.split('.');
mainSections[0] = dekebabifyName(mainSections[0]);
return mainSections.join(" ");
return mainSections.join(' ');
}
function initialCap(str) {
return str[0].toUpperCase() + str.substr(1);
}
function ngNameToClassName(rawName, nameExceptions) {
if (nameExceptions[rawName])
return nameExceptions[rawName];
if (nameExceptions[rawName]) return nameExceptions[rawName];
var name = rawName.replace(/\]|\(|\)/g, '');
var fileNameSections = name.split('.');
var compNameSections = fileNameSections[0].split('-');
var outCompName = '';
for (var i = 0; i < compNameSections.length; i++) {
const name = rawName.replace(/\]|\(|\)/g, '');
const fileNameSections = name.split('.');
const compNameSections = fileNameSections[0].split('-');
let outCompName = '';
for (let i = 0; i < compNameSections.length; i++) {
outCompName = outCompName + initialCap(compNameSections[i]);
}
var itemTypeIndicator = '';
let itemTypeIndicator = '';
if (fileNameSections.length > 1) {
itemTypeIndicator = initialCap(fileNameSections[1]);
}
var finalName = outCompName + itemTypeIndicator;
return finalName;
}
function displayNameToNgName(name) {
var noSpaceName = ngName.replace(/ ([a-zA-Z])/, "$1".toUpperCase());
return noSpaceName.substr(0, 1).toUpperCase() + noSpaceName.substr(1);
return outCompName + itemTypeIndicator;
}
function dekebabifyName(name) {
var result = name.replace(/-/g, " ");
let result = name.replace(/-/g, ' ');
result = result.substr(0, 1).toUpperCase() + result.substr(1);
return result;
}
function kebabifyClassName(name) {
var result = name.replace(/(Component|Directive|Interface|Model|Pipe|Service|Widget)$/, match => {
return "." + match.toLowerCase();
let result = name.replace(/(Component|Directive|Interface|Model|Pipe|Service|Widget)$/, (match) => {
return '.' + match.toLowerCase();
});
result = result.replace(/([A-Z])/g, "-$1");
result = result.replace(/([A-Z])/g, '-$1');
return result.substr(1).toLowerCase();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -9,15 +9,13 @@
"ejs": "^3.1.6",
"fast-levenshtein": "^3.0.0",
"graphql": "^15.4.0",
"graphql-request": "^3.1.0",
"js-yaml": "3.14.1",
"markdownlint-cli": "^0.34.0",
"mdast": "3.0.0",
"mdast-util-compact": "1.0.3",
"mdast-util-heading-range": "2.1.3",
"mdast-util-to-string": "^4.0.0",
"mdast-util-toc": "2.1.0",
"mdast-zone": "3.0.4",
"moment": "2.29.2",
"remark": "^9.0.0",
"remark-frontmatter": "^1.2.0",
"rxjs": "^6.6.6",

View File

@ -1,23 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var fs = require("fs");
var path = require("path");
var graphql_1 = require("graphql");
var remark = require("remark");
var frontMatter = require("remark-frontmatter");
var removePosInfo = require("unist-util-remove-position");
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'])
.parse(docSrc);
tree = removePosInfo(tree);
var schema = (0, 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";
(0, graphql_1.graphql)(schema, query, root).then(function (response) {
console.log(JSON.stringify(response));
});

View File

@ -1,65 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as fs from 'fs';
import * as path from 'path';
import { graphql, buildSchema } from 'graphql';
import * as remark from 'remark';
import * as frontMatter from 'remark-frontmatter';
import { MDAST } from 'mdast';
import * as removePosInfo from 'unist-util-remove-position';
import * as MQ from './mqDefs';
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);
tree = removePosInfo(tree);
const schema = buildSchema(MQ.schema);
const root = {
document: () => new MQ.Root(tree)
};
const query = `
{
document {
metadata(key: "Status")
heading {
link {
text {
value
}
}
}
paragraph {
plaintext
}
}
}
`;
graphql(schema, query, root).then((response) => {
console.log(JSON.stringify(response));
});

View File

@ -1,109 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var path = require("path");
var fs = require("fs");
var process = require("process");
var graphql_request_1 = require("graphql-request");
var remark = require("remark");
var frontMatter = require("remark-frontmatter");
var yaml = require("js-yaml");
var moment = require("moment");
var rxjs_1 = require("rxjs");
var libsearch = require("./libsearch");
var stoplist_1 = require("./stoplist");
var adf20StartDate = '2017-11-20';
var commitWeight = 0.1;
var scoreTimeBase = 60;
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'];
libsearch(srcData, path.resolve(libFolder));
var authToken = process.env.graphAuthToken;
var client = new graphql_request_1.GraphQLClient('https://api.github.com/graphql', {
headers: {
Authorization: 'Bearer ' + authToken
}
});
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 = (0, rxjs_1.of)(docFiles);
console.log("'Name','Review date','Commits since review','Score'");
docNames.subscribe(function (docs) {
docs.forEach(function (x) {
var key = path.basename(x, '.md');
if (!srcData[key]) {
return;
}
var vars = {
'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 numUsefulCommits = extractCommitInfo(nodes, lastReviewDate, stoplist);
if (numUsefulCommits > 0) {
var dateString = lastReviewDate.format('YYYY-MM-DD');
var score = priorityScore(lastReviewDate, numUsefulCommits).toPrecision(3);
console.log("'".concat(key, "','").concat(dateString, "','").concat(numUsefulCommits, "','").concat(score, "'"));
}
});
});
});
function priorityScore(reviewDate, numCommits) {
var daysSinceReview = moment().diff(reviewDate, 'days');
var commitScore = 2 + numCommits * commitWeight;
return Math.pow(commitScore, daysSinceReview / scoreTimeBase);
}
function getDocReviewDate(docFileName) {
var mdFilePath = path.resolve(docsFolderPath, docFileName);
var mdText = fs.readFileSync(mdFilePath);
var tree = remark().use(frontMatter, ['yaml']).parse(mdText);
var lastReviewDate = moment(adf20StartDate);
if (tree.children[0].type === 'yaml') {
var metadata = yaml.load(tree.children[0].value);
if (metadata['Last reviewed']) {
lastReviewDate = moment(metadata['Last reviewed']);
}
}
return lastReviewDate;
}
function extractCommitInfo(commitNodes, cutOffDate, stoplist) {
var numUsefulCommits = 0;
commitNodes.forEach(function (element) {
if (!stoplist.isRejected(element.message)) {
// const abbr = element.message.substr(0, 15);
var commitDate = moment(element.pushedDate);
if (commitDate.isAfter(cutOffDate)) {
numUsefulCommits++;
}
}
});
return numUsefulCommits;
}
function getDocFilePaths(folderPath) {
var result = [];
libFolders.forEach(function (element) {
var libPath = path.resolve(folderPath, element);
addItemsRecursively(libPath, result);
});
return result;
function addItemsRecursively(elementPath, resultList) {
var items = fs.readdirSync(elementPath);
items.forEach(function (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') &&
(item.match(angFilePattern))) {
resultList.push(fullItemPath);
}
});
}
}

View File

@ -1,182 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as path from 'path';
import * as fs from 'fs';
import * as process from 'process';
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 commitWeight = 0.1;
const scoreTimeBase = 60;
const libFolder = 'lib';
const stoplistFilePath = path.resolve('tools', 'doc', 'commitStoplist.json');
const angFilePattern = /(component)|(directive)|(model)|(pipe)|(service)|(widget)/;
const srcData = {};
const stoplist = new Stoplist(stoplistFilePath);
const docsFolderPath = path.resolve('docs');
const libFolders = ['core', 'content-services', 'extensions', 'insights', 'process-services', 'process-services-cloud'];
libsearch(srcData, path.resolve(libFolder));
const authToken = process.env.graphAuthToken;
const client = new GraphQLClient('https://api.github.com/graphql', {
headers: {
Authorization: 'Bearer ' + authToken
}
});
const query = `query commitHistory($path: String) {
repository(name: "alfresco-ng2-components", owner: "alfresco") {
ref(qualifiedName: "development") {
target {
... on Commit {
history(first: 15, path: $path) {
nodes {
pushedDate
message
}
}
}
}
}
}
}`;
const docFiles = getDocFilePaths(docsFolderPath);
const docNames = of(docFiles);
console.log('\'Name\',\'Review date\',\'Commits since review\',\'Score\'');
docNames.subscribe(docs => {
docs.forEach(x => {
const key = path.basename(x, '.md');
if (!srcData[key]) {
return;
}
const vars = {
path: 'lib/' + srcData[key].path
};
client.request(query, vars).then(data => {
const nodes = data['repository'].ref.target.history.nodes;
const lastReviewDate = getDocReviewDate(x); // (key + ".md");
const numUsefulCommits = extractCommitInfo(nodes, lastReviewDate, stoplist);
if (numUsefulCommits > 0) {
const dateString = lastReviewDate.format('YYYY-MM-DD');
const score = priorityScore(lastReviewDate, numUsefulCommits).toPrecision(3);
console.log(`'${key}','${dateString}','${numUsefulCommits}','${score}'`);
}
});
});
});
function priorityScore(reviewDate, numCommits) {
const daysSinceReview = moment().diff(reviewDate, 'days');
const commitScore = 2 + numCommits * commitWeight;
return Math.pow(commitScore, daysSinceReview / scoreTimeBase);
}
function getDocReviewDate(docFileName) {
const mdFilePath = path.resolve(docsFolderPath, docFileName);
const mdText = fs.readFileSync(mdFilePath);
const tree = remark().use(frontMatter, ['yaml']).parse(mdText);
let lastReviewDate = moment(adf20StartDate);
if (tree.children[0].type === 'yaml') {
const metadata = yaml.load(tree.children[0].value);
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)) {
// const abbr = element.message.substr(0, 15);
const commitDate = moment(element.pushedDate);
if (commitDate.isAfter(cutOffDate)) {
numUsefulCommits++;
}
}
});
return numUsefulCommits;
}
function getDocFilePaths(folderPath) {
const result = [];
libFolders.forEach(element => {
const libPath = path.resolve(folderPath, element);
addItemsRecursively(libPath, result);
});
return result;
function addItemsRecursively(elementPath: string, resultList: string[]) {
const items = fs.readdirSync(elementPath);
items.forEach(item => {
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') &&
(item.match(angFilePattern))
) {
resultList.push(fullItemPath);
}
});
}
}

View File

@ -1,30 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Stoplist = void 0;
var fs = require("fs");
/* "Stoplist" of regular expressions to match against strings. */
var Stoplist = /** @class */ (function () {
function Stoplist(slFilePath) {
var listExpressions = JSON.parse(fs.readFileSync(slFilePath, 'utf8'));
this.regexes = [];
if (listExpressions) {
for (var i = 0; i < listExpressions.length; i++) {
this.regexes.push(new RegExp(listExpressions[i]));
}
}
else {
this.regexes = [];
}
}
// Check if an item is covered by the stoplist and reject it if so.
Stoplist.prototype.isRejected = function (itemName) {
for (var i = 0; i < this.regexes.length; i++) {
if (this.regexes[i].test(itemName)) {
return true;
}
}
return false;
};
return Stoplist;
}());
exports.Stoplist = Stoplist;

View File

@ -1,48 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as fs from 'fs';
/* "Stoplist" of regular expressions to match against strings. */
export class Stoplist {
regexes: RegExp[];
constructor(slFilePath: string) {
const listExpressions = JSON.parse(fs.readFileSync(slFilePath, 'utf8'));
this.regexes = [];
if (listExpressions) {
for (let i = 0; i < listExpressions.length; i++) {
this.regexes.push(new RegExp(listExpressions[i]));
}
} else {
this.regexes = [];
}
}
// Check if an item is covered by the stoplist and reject it if so.
isRejected(itemName: string) {
for (let i = 0; i < this.regexes.length; i++) {
if (this.regexes[i].test(itemName)) {
return true;
}
}
return false;
}
}

View File

@ -1,23 +1,19 @@
var path = require("path");
var unist = require("../unistHelpers");
var seeAlsoHeading = "See Also";
const path = require('path');
const unist = require('../unistHelpers');
const seeAlsoHeading = 'See Also';
module.exports = {
"initPhase": initPhase,
"readPhase": readPhase,
"aggPhase": aggPhase,
"updatePhase": updatePhase
}
initPhase: initPhase,
readPhase: readPhase,
aggPhase: aggPhase,
updatePhase: updatePhase
};
function initPhase(aggData) {
aggData.saGraph = {};
aggData.saUpdateGraph = {};
}
function readPhase(tree, pathname, aggData) {
var saHeadingOffset = findSeeAlsoSection(tree);
@ -27,13 +23,9 @@ function readPhase(tree, pathname, aggData) {
// Skip over non-list parts.
var s;
for (
s = saHeadingOffset;
(s < tree.children.length) && !unist.isListUnordered(tree.children[s]);
s++
);
for (s = saHeadingOffset; s < tree.children.length && !unist.isListUnordered(tree.children[s]); s++);
if ((s < tree.children.length) && unist.isListUnordered(tree.children[s])) {
if (s < tree.children.length && unist.isListUnordered(tree.children[s])) {
var list = tree.children[s];
for (var i = 0; i < list.children.length; i++) {
@ -46,17 +38,15 @@ function readPhase(tree, pathname, aggData) {
}
}
aggData.saGraph[path.basename(pathname, ".md")] = saNode;
aggData.saGraph[path.basename(pathname, '.md')] = saNode;
}
function aggPhase(aggData) {
aggData.saUpdateGraph = tidyGraph(aggData.saGraph);
}
function updatePhase(tree, pathname, aggData) {
var currNodeName = path.basename(pathname, ".md");
var currNodeName = path.basename(pathname, '.md');
var currNodeArcs = aggData.saUpdateGraph[currNodeName];
if (currNodeArcs.length > 0) {
@ -64,7 +54,7 @@ function updatePhase(tree, pathname, aggData) {
for (var i = 0; i < currNodeArcs.length; i++) {
var linkText = graphKeyToLinkName(currNodeArcs[i]);
var linkTarget = currNodeArcs[i] + ".md";
var linkTarget = currNodeArcs[i] + '.md';
var link = unist.makeLink(unist.makeText(linkText), linkTarget);
saListItems.push(unist.makeListItem(link));
}
@ -75,11 +65,7 @@ function updatePhase(tree, pathname, aggData) {
// Skip over non-list parts.
var s;
for (
s = saHeadingOffset;
(s < tree.children.length) && !unist.isListUnordered(tree.children[s]);
s++
);
for (s = saHeadingOffset; s < tree.children.length && !unist.isListUnordered(tree.children[s]); s++);
// Push all elements of the items array as if they were separate elements.
Array.prototype.push.apply(tree.children[s].children, saListItems);
@ -93,39 +79,30 @@ function updatePhase(tree, pathname, aggData) {
return true;
}
function graphKeyToLinkName(key) {
var mainSections = key.split(".");
mainSections[0] = tidyName(mainSections[0]);
return mainSections.join(" ");
var mainSections = key.split('.');
mainSections[0] = tidyName(mainSections[0]);
return mainSections.join(' ');
}
// Convert an Angular-style name (eg, "card-view") into one with correct spaces and uppercase (eg, "Card view").
function tidyName(name) {
var result = name.replace(/-/g, " ");
var result = name.replace(/-/g, ' ');
result = result.substr(0, 1).toUpperCase() + result.substr(1);
return result;
}
function makeEmptySAList() {
var result = [];
}
// Makes link symmetrical between items (ie, if A links to B but not the other way
// around then it adds the missing link).
function tidyGraph(graph) {
var nodeNames = Object.keys(graph);
var result = {};
for (var n = 0; n < nodeNames.length; n++) {
for (let n = 0; n < nodeNames.length; n++) {
result[nodeNames[n]] = [];
}
for (var n = 0; n < nodeNames.length; n++) {
for (let n = 0; n < nodeNames.length; n++) {
var currNodeName = nodeNames[n];
var currNodeArcs = graph[currNodeName];
@ -146,29 +123,21 @@ function tidyGraph(graph) {
return result;
}
function findSeeAlsoSection(tree) {
var i;
for (i = 0; i < tree.children.length; i++) {
var child = tree.children[i];
if (unist.isHeading(child) && (child.children[0].value.toLowerCase() === seeAlsoHeading.toLowerCase()))
return i;
if (unist.isHeading(child) && child.children[0].value.toLowerCase() === seeAlsoHeading.toLowerCase()) return i;
}
return -1;
}
function getItemLinkInfo(listItem) {
var linkTarget = listItem.children[0].children[0].url;
if (linkTarget.startsWith("http:") ||
linkTarget.startsWith("#") ||
!linkTarget.endsWith(".md"))
return null;
else
return path.basename(linkTarget, ".md");
if (linkTarget.startsWith('http:') || linkTarget.startsWith('#') || !linkTarget.endsWith('.md')) return null;
else return path.basename(linkTarget, '.md');
}

View File

@ -1,51 +1,43 @@
var path = require("path");
var fs = require("fs");
const path = require('path');
const fs = require('fs');
const remark = require('remark');
const replaceSection = require('mdast-util-heading-range');
const { toString } = require('mdast-util-to-string');
const ejs = require('ejs');
const unist = require('../unistHelpers');
const mdNav = require('../mdNav');
var remark = require("remark");
//var tocGenerator = require("mdast-util-toc");
var replaceSection = require("mdast-util-heading-range");
var tostring = require("mdast-util-to-string");
var ejs = require("ejs");
var unist = require("../unistHelpers");
var mdNav = require("../mdNav");
const contentsHeading = "Contents";
const contentsHeading = 'Contents';
const minHeadingsForToc = 8;
const maxTocHeadingDepth = 3;
var templateFolder = path.resolve("tools", "doc", "templates");
const templateFolder = path.resolve('tools', 'doc', 'templates');
module.exports = {
"processDocs": processDocs
}
processDocs: processDocs
};
function processDocs(mdCache, aggData, errorMessages) {
var pathnames = Object.keys(mdCache);
const pathNames = Object.keys(mdCache);
pathnames.forEach(pathname => {
pathNames.forEach((pathname) => {
updateFile(mdCache[pathname].mdOutTree, pathname, aggData, errorMessages);
});
}
// Find an existing Contents section or add a new empty one if needed.
// Returns true if section is present/needed, false if not needed.
function establishContentsSection(mdTree) {
var firstL2HeadingPos = -1;
var numTocHeadings = 0;
var foundContentsHeading = false;
let firstL2HeadingPos = -1;
let numTocHeadings = 0;
let foundContentsHeading = false;
for (let i = 0; i < mdTree.children.length; i++) {
const child = mdTree.children[i];
for (var i = 0; i < mdTree.children.length; i++) {
var child = mdTree.children[i];
// Look through all headings.
if (child.type === "heading") {
if ((child.depth > 1) && (child.depth <= maxTocHeadingDepth)) {
if (child.type === 'heading') {
if (child.depth > 1 && child.depth <= maxTocHeadingDepth) {
numTocHeadings++;
}
@ -57,7 +49,7 @@ function establishContentsSection(mdTree) {
// If it is also a Contents heading then we're done. We don't include the
// Contents heading itself within the ToC, so decrement the count for that.
if ((child.children[0].value === contentsHeading) && !foundContentsHeading) {
if (child.children[0].value === contentsHeading && !foundContentsHeading) {
foundContentsHeading = true;
numTocHeadings--;
}
@ -69,42 +61,38 @@ function establishContentsSection(mdTree) {
// If there are enough headings for a ToC to be necessary then
// add one in the right place.
if (!foundContentsHeading) {
var newContsHeading = unist.makeHeading(unist.makeText(contentsHeading), 2);
const newHeading = unist.makeHeading(unist.makeText(contentsHeading), 2);
// If we found another L2 heading then add the Contents in just before it.
if (firstL2HeadingPos != -1) {
mdTree.children.splice(firstL2HeadingPos, 0, newContsHeading);
if (firstL2HeadingPos !== -1) {
mdTree.children.splice(firstL2HeadingPos, 0, newHeading);
} else {
// Otherwise, the unlikely situation where a ToC is required but there
// are no L2 headings! Add it as the second element in the document.
mdTree.children.splice(1, 0, newContsHeading);
mdTree.children.splice(1, 0, newHeading);
}
}
return numTocHeadings;
}
function updateFile(tree, pathname, _aggData, _errorMessages) {
if (path.basename(pathname, ".md").match(/README|versionIndex/)) {
if (path.basename(pathname, '.md').match(/README|versionIndex/)) {
return false;
}
// If we need a contents section then add one or update the existing one.
var numTocHeadings = establishContentsSection(tree);
// If we need a contents section then add one or update the existing one.
const numTocHeadings = establishContentsSection(tree);
if (numTocHeadings >= minHeadingsForToc) {
var newToc = makeToc(tree); //tocGenerator(tree, {heading: contentsHeading, maxDepth: 3});
const newToc = makeToc(tree);
replaceSection(tree, contentsHeading, function(before, oldSection, after) {
replaceSection(tree, contentsHeading, function (before, oldSection, after) {
return [before, newToc, after];
});
} else {
// Otherwise, we don't need one, so remove any existing one.
replaceSection(tree, contentsHeading, function(before, oldSection, after) {
replaceSection(tree, contentsHeading, function (before, oldSection, after) {
return [after];
});
}
@ -112,44 +100,39 @@ function updateFile(tree, pathname, _aggData, _errorMessages) {
return true;
}
function makeToc(tree) {
var nav = new mdNav.MDNav(tree);
const nav = new mdNav.MDNav(tree);
const headings = nav.headings((h) => h.depth > 1 && h.depth <= maxTocHeadingDepth);
const context = { headings: [] };
var headings = nav.headings(h =>
(h.depth > 1) &&
(h.depth <= maxTocHeadingDepth) //&&
//!((h.children[0].type === "text") && (h.children[0].value === "Contents"))
);
headings.forEach((heading) => {
let linkTitle = '';
var context = {headings: []};
headings.forEach(heading => {
var linkTitle = "";
if (!((heading.item.children.length > 0) && (heading.item.children[0].type === "text") && (heading.item.children[0].value === "Contents"))) {
linkTitle = tostring(heading.item).trim();
if (!(heading.item.children.length > 0 && heading.item.children[0].type === 'text' && heading.item.children[0].value === 'Contents')) {
linkTitle = toString(heading.item).trim();
}
if (linkTitle !== "") {
if (linkTitle !== '') {
context.headings.push({
"level": heading.item.depth - 2,
"title": linkTitle,
//"anchor": "#" + linkTitle.toLowerCase().replace(/ /g, "-").replace(/[:;@\.,'"`$\(\)\/]/g ,"")
"anchor": "#" + linkTitle.toLowerCase()
.replace(/[^a-z0-9\s\-_]/g, '')
.replace(/\s/g ,"-")
.replace(/\-+$/, '')
})
};
level: heading.item.depth - 2,
title: linkTitle,
anchor:
'#' +
linkTitle
.toLowerCase()
.replace(/[^a-z0-9\s\-_]/g, '')
.replace(/\s/g, '-')
.replace(/-+$/, '')
});
}
});
var templateName = path.resolve(templateFolder, "toc.ejs");
var templateSource = fs.readFileSync(templateName, "utf8");
var template = ejs.compile(templateSource);
const templateName = path.resolve(templateFolder, 'toc.ejs');
const templateSource = fs.readFileSync(templateName, 'utf8');
const template = ejs.compile(templateSource);
var mdText = template(context);
var newMD = remark().parse(mdText);
const mdText = template(context);
const newMD = remark().parse(mdText);
return newMD.children[0];
}
}

View File

@ -31,10 +31,10 @@ let nameExceptions;
export function processDocs(mdCache, aggData) {
nameExceptions = aggData.config.typeNameExceptions;
const pathnames = Object.keys(mdCache);
const pathNames = Object.keys(mdCache);
let internalErrors;
pathnames.forEach(pathname => {
pathNames.forEach((pathname) => {
internalErrors = [];
updateFile(mdCache[pathname].mdOutTree, pathname, aggData, internalErrors);
@ -47,7 +47,7 @@ export function processDocs(mdCache, aggData) {
function showErrors(filename, errorMessages) {
console.log(filename);
errorMessages.forEach(message => {
errorMessages.forEach((message) => {
console.log(' ' + message);
});
@ -55,7 +55,6 @@ function showErrors(filename, errorMessages) {
}
function updateFile(tree, pathname, aggData, errorMessages) {
const className = ngNameToClassName(path.basename(pathname, '.md'), nameExceptions);
const classTypeMatch = className.match(/component|directive|service/i);
const compData = aggData.classInfo[className];
@ -67,8 +66,6 @@ function updateFile(tree, pathname, aggData, errorMessages) {
const inputMD = getPropDocsFromMD(tree, 'Properties', 3);
const outputMD = getPropDocsFromMD(tree, 'Events', 2);
updatePropDocsFromMD(compData, inputMD, outputMD, errorMessages);
if (classType === 'service') {
@ -81,7 +78,7 @@ function updateFile(tree, pathname, aggData, errorMessages) {
const template = ejs.compile(templateSource);
let mdText = template(compData);
mdText = mdText.replace(/^ +\|/mg, '|');
mdText = mdText.replace(/^ +\|/gm, '|');
const newSection = remark().parse(mdText.trim()).children;
@ -91,7 +88,7 @@ function updateFile(tree, pathname, aggData, errorMessages) {
return newSection;
});
compData.errors.forEach(err => {
compData.errors.forEach((err) => {
errorMessages.push(err);
});
}
@ -104,37 +101,31 @@ function getPropDocsFromMD(tree, sectionHeading, docsColumn) {
const nav = new MDNav(tree);
const classMemHeading = nav
.heading(h => {
return (h.children[0].type === 'text') && (h.children[0].value === 'Class members');
});
const classMemHeading = nav.heading((h) => {
return h.children[0].type === 'text' && h.children[0].value === 'Class members';
});
const propsTable = classMemHeading
.heading(h => {
return (h.children[0].type === 'text') && (h.children[0].value === sectionHeading);
}).table();
.heading((h) => {
return h.children[0].type === 'text' && h.children[0].value === sectionHeading;
})
.table();
let propTableRow = propsTable.childNav
.tableRow(() => true, 1).childNav;
let propTableRow = propsTable.childNav.tableRow(() => true, 1).childNav;
let i = 1;
while (!propTableRow.empty) {
const propName = propTableRow
.tableCell().childNav
.text().item.value;
const propName = propTableRow.tableCell().childNav.text().item.value;
const propDocText = propTableRow
.tableCell(() => true, docsColumn).childNav
.text().item;
const propDocText = propTableRow.tableCell(() => true, docsColumn).childNav.text().item;
if (propDocText) {
result[propName] = propDocText.value;
}
i++;
propTableRow = propsTable.childNav
.tableRow(() => true, i).childNav;
propTableRow = propsTable.childNav.tableRow(() => true, i).childNav;
}
return result;
@ -145,25 +136,22 @@ function getMethodDocsFromMD(tree) {
const nav = new MDNav(tree);
const classMemHeading = nav
.heading(h => {
return (h.children[0].type === 'text') && (h.children[0].value === 'Class members');
});
const classMemHeading = nav.heading((h) => {
return h.children[0].type === 'text' && h.children[0].value === 'Class members';
});
const methListItems = classMemHeading
.heading(h => {
return (h.children[0].type === 'text') && (h.children[0].value === 'Methods');
}).list().childNav;
.heading((h) => {
return h.children[0].type === 'text' && h.children[0].value === 'Methods';
})
.list().childNav;
let methItem = methListItems
.listItem();
let methItem = methListItems.listItem();
let i = 0;
while (!methItem.empty) {
const methNameSection = methItem.childNav
.paragraph().childNav
.strong().childNav;
const methNameSection = methItem.childNav.paragraph().childNav.strong().childNav;
let methName = '';
@ -171,23 +159,19 @@ function getMethodDocsFromMD(tree) {
if (!methNameSection.empty) {
methName = methNameSection.text().item.value;
const methDoc = methItem.childNav
.paragraph().childNav
.html()
.text().value;
const methDoc = methItem.childNav.paragraph().childNav.html().text().value;
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);
methItem = methListItems.listItem((l) => true, i);
}
return result;
@ -198,31 +182,24 @@ function getMDMethodParams(methItem: MDNav) {
const paramList = methItem.childNav.list().childNav;
const paramListItems = paramList
.listItems();
const paramListItems = paramList.listItems();
paramListItems.forEach(paramListItem => {
const paramNameNode = paramListItem.childNav
.paragraph().childNav
.emph().childNav;
paramListItems.forEach((paramListItem) => {
const paramNameNode = paramListItem.childNav.paragraph().childNav.emph().childNav;
let paramName;
if (!paramNameNode.empty) {
paramName = paramNameNode.text().item.value.replace(/:/, '');
} else {
let item = paramListItem.childNav.paragraph().childNav
.strong().childNav.text();
let item = paramListItem.childNav.paragraph().childNav.strong().childNav.text();
if (paramName) {
paramName = item.value;
}
}
const paramDoc = paramListItem.childNav
.paragraph().childNav
.text(t => true, 1).value; // item.value;
const paramDoc = paramListItem.childNav.paragraph().childNav.text((t) => true, 1).value; // item.value;
result[paramName] = paramDoc.replace(/^[ -]+/, '');
});
@ -231,7 +208,7 @@ function getMDMethodParams(methItem: MDNav) {
}
function updatePropDocsFromMD(comp: ComponentInfo, inputDocs, outputDocs, errorMessages) {
comp.properties.forEach(prop => {
comp.properties.forEach((prop) => {
let propMDDoc: string;
if (prop.isInput) {
@ -249,7 +226,7 @@ function updatePropDocsFromMD(comp: ComponentInfo, inputDocs, outputDocs, errorM
}
function updateMethodDocsFromMD(comp: ComponentInfo, methodDocs, errorMessages) {
comp.methods.forEach(meth => {
comp.methods.forEach((meth) => {
const currMethMD = methodDocs[meth.name];
// If JSDocs are empty but MD docs aren't then the Markdown is presumably more up-to-date.
@ -258,7 +235,7 @@ function updateMethodDocsFromMD(comp: ComponentInfo, methodDocs, errorMessages)
errorMessages.push(`Warning: empty JSDocs for method sig "${meth.name}" may need sync with the .md file.`);
}
meth.params.forEach(param => {
meth.params.forEach((param) => {
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.`);

View File

@ -40,13 +40,13 @@ function aggPhase() {
const template = ejs.compile(templateSource);
let mdText = template(indexDocData);
mdText = mdText.replace(/^ +\|/mg, '|');
mdText = mdText.replace(/^ +\|/gm, '|');
const 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;
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);
const tutIndexMD = remark().use(frontMatter, ['yaml']).data('settings', { paddedTable: false, gfm: false }).parse(tutIndexText);
replaceSection(tutIndexMD, 'Tutorials', (before, section, after) => {
newSection.unshift(before);
@ -54,7 +54,10 @@ function aggPhase() {
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() {
@ -62,7 +65,7 @@ function getIndexDocData() {
const summaryArray = JSON.parse(fs.readFileSync(indexFile, 'utf8'));
let indexArray = [];
summaryArray.forEach(element => {
summaryArray.forEach((element) => {
if (element['title'] === 'Tutorials') {
indexArray = element['children'];
}
@ -72,7 +75,7 @@ function getIndexDocData() {
tuts: []
};
indexArray.forEach(element => {
indexArray.forEach((element) => {
const tutData = { link: element['file'] };
const tutFile = path.resolve(tutFolder, element['file']);
@ -89,21 +92,16 @@ function getIndexDocData() {
const briefDesc = getFirstParagraph(tutMD);
const briefDescText = remark()
.use(frontMatter, {type: 'yaml', fence: '---'})
.data('settings', {paddedTable: false, gfm: false})
.stringify(briefDesc);
tutData['briefDesc'] = briefDescText;
tutData['briefDesc'] = remark()
.use(frontMatter, { type: 'yaml', fence: '---' })
.data('settings', { paddedTable: false, gfm: false })
.stringify(briefDesc);
const title = getFirstHeading(tutMD);
const titleText = remark()
.use(frontMatter, {type: 'yaml', fence: '---'})
.data('settings', {paddedTable: false, gfm: false})
.stringify(title.children[0]);
tutData['title'] = titleText;
tutData['title'] = remark()
.use(frontMatter, { type: 'yaml', fence: '---' })
.data('settings', { paddedTable: false, gfm: false })
.stringify(title.children[0]);
result.tuts.push(tutData);
});
@ -122,11 +120,10 @@ function getDocMetadata(tree) {
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];
} else {
return null;
}
@ -135,11 +132,10 @@ 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];
} else {
return null;
}

View File

@ -1,30 +1,20 @@
var fs = require("fs");
var path = require("path");
var yaml = require("js-yaml");
var remark = require("remark");
var stringify = require("remark-stringify");
var zone = require("mdast-zone");
var frontMatter = require("remark-frontmatter");
var ejs = require("ejs");
var unist = require("../unistHelpers");
var ngHelpers = require("../ngHelpers");
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const remark = require('remark');
const zone = require('mdast-zone');
const frontMatter = require('remark-frontmatter');
const ejs = require('ejs');
const ngHelpers = require('../ngHelpers');
module.exports = {
"processDocs": processDocs
processDocs: processDocs
};
var docsFolderPath = path.resolve("docs");
var histFilePath = path.resolve(docsFolderPath, "versionIndex.md");
var initialVersion = "v2.0.0";
var templateFolder = path.resolve("tools", "doc", "templates");
const docsFolderPath = path.resolve('docs');
const histFilePath = path.resolve(docsFolderPath, 'versionIndex.md');
const initialVersion = 'v2.0.0';
const templateFolder = path.resolve('tools', 'doc', 'templates');
function processDocs(mdCache, aggData) {
initPhase(aggData);
@ -32,34 +22,29 @@ function processDocs(mdCache, aggData) {
aggPhase(aggData);
}
function initPhase(aggData) {
aggData.versions = { "v2.0.0":[] };
aggData.versions = { 'v2.0.0': [] };
}
function readPhase(mdCache, aggData) {
var pathnames = Object.keys(mdCache);
const pathNames = Object.keys(mdCache);
pathnames.forEach(pathname => {
pathNames.forEach((pathname) => {
getFileData(mdCache[pathname].mdInTree, pathname, aggData);
});
}
function getFileData(tree, pathname, aggData) {
var compName = pathname;
var angNameRegex = /([a-zA-Z0-9\-]+)\.((component)|(directive)|(model)|(pipe)|(service)|(widget)|(dialog))/;
const compName = pathname;
const angNameRegex = /([a-zA-Z0-9\-]+)\.((component)|(directive)|(model)|(pipe)|(service)|(widget)|(dialog))/;
if (!compName.match(angNameRegex))
return;
if (!compName.match(angNameRegex)) return;
if (compName.match(/boilerplate/))
return;
if (compName.match(/boilerplate/)) return;
if (tree && tree.children[0] && tree.children[0].type == "yaml") {
var metadata = yaml.load(tree.children[0].value);
var version = metadata["Added"];
if (tree && tree.children[0] && tree.children[0].type === 'yaml') {
const metadata = yaml.load(tree.children[0].value);
const version = metadata['Added'];
if (version) {
if (aggData.versions[version]) {
@ -76,40 +61,43 @@ function getFileData(tree, pathname, aggData) {
}
function aggPhase(aggData) {
var histFileText = fs.readFileSync(histFilePath, "utf8");
var histFileTree = remark().use(frontMatter, ["yaml"]).data("settings", {paddedTable: false, gfm: false}).parse(histFileText);
const histFileText = fs.readFileSync(histFilePath, 'utf8');
const histFileTree = remark()
.use(frontMatter, ['yaml'])
.data('settings', {
paddedTable: false,
gfm: false
})
.parse(histFileText);
var keys = Object.keys(aggData.versions);
const keys = Object.keys(aggData.versions);
keys.sort((a, b) => {
if (a > b)
return -1;
else if (b > a)
return 1;
else
return 0;
if (a > b) return -1;
else if (b > a) return 1;
else return 0;
});
var templateName = path.resolve(templateFolder, "versIndex.ejs");
var templateSource = fs.readFileSync(templateName, "utf8");
var template = ejs.compile(templateSource);
const templateName = path.resolve(templateFolder, 'versIndex.ejs');
const templateSource = fs.readFileSync(templateName, 'utf8');
const template = ejs.compile(templateSource);
for (var i = 0; i < keys.length; i++) {
var version = keys[i];
var versionItems = aggData.versions[version];
for (let i = 0; i < keys.length; i++) {
const version = keys[i];
const versionItems = aggData.versions[version];
versionItems.sort((a, b) => {
var aa = path.basename(a, ".md");
var bb = path.basename(b, ".md");
const aa = path.basename(a, '.md');
const bb = path.basename(b, '.md');
return aa.localeCompare(bb);
});
var versionTemplateData = {items: []};
const versionTemplateData = { items: [] };
for (var v = 0; v < versionItems.length; v++) {
var displayName = ngHelpers.ngNameToDisplayName(path.basename(versionItems[v], ".md"));
var pageLink = versionItems[v];// + ".md";
for (let v = 0; v < versionItems.length; v++) {
const displayName = ngHelpers.ngNameToDisplayName(path.basename(versionItems[v], '.md'));
let pageLink = versionItems[v]; // + ".md";
pageLink = pageLink.replace(/\\/g, '/');
pageLink = pageLink.substr(pageLink.indexOf("docs") + 5);
pageLink = pageLink.substr(pageLink.indexOf('docs') + 5);
versionTemplateData.items.push({
title: displayName,
@ -117,12 +105,18 @@ function aggPhase(aggData) {
});
}
var mdText = template(versionTemplateData);
mdText = mdText.replace(/^ +-/mg, "-");
let mdText = template(versionTemplateData);
mdText = mdText.replace(/^ +-/gm, '-');
var 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;
var versSectionName = version.replace(/\./g, "");;
const versSectionName = version.replace(/\./g, '');
zone(histFileTree, versSectionName, (startComment, oldSection, endComment) => {
newSection.unshift(startComment);
@ -131,5 +125,8 @@ function aggPhase(aggData) {
});
}
fs.writeFileSync(histFilePath, remark().use(frontMatter, {type: 'yaml', fence: '---'}).data("settings", {paddedTable: false, gfm: false}).stringify(histFileTree));
fs.writeFileSync(
histFilePath,
remark().use(frontMatter, { type: 'yaml', fence: '---' }).data('settings', { paddedTable: false, gfm: false }).stringify(histFileTree)
);
}

View File

@ -11,7 +11,6 @@
"lib": ["es2018", "dom"]
},
"files": [
"remarkGraphQl.ts",
"mqDefs.ts",
"tools/fileChecker.ts",
"tools/gqIndex.ts",
@ -19,7 +18,6 @@
"tools/sourceLinker.ts",
"tools/tsInfo.ts",
"tools/tutorialIndex.ts",
"tools/typeLinker.ts",
"reviewChecker.ts"
"tools/typeLinker.ts"
]
}

View File

@ -1,141 +1,82 @@
module.exports = {
makeRoot: function (children) {
return {
"type": "root",
"children": children
};
},
makeText: function (textVal) {
return {
"type": "text",
"value": textVal
type: 'text',
value: textVal
};
},
makeEmphasis: function (content) {
return {
"type": "emphasis",
"children": content
type: 'emphasis',
children: content
};
},
makeStrong: function (content) {
return {
"type": "strong",
"children": content
};
},
makeHeading: function (caption, depth) {
return {
"type": "heading",
"depth": depth,
"children": [caption]
type: 'heading',
depth: depth,
children: [caption]
};
},
makeLink: function (caption, url, title = null) {
return {
"type": "link",
"title": title,
"url": url,
"children": [ caption ]
type: 'link',
title: title,
url: url,
children: [caption]
};
},
makeListItem: function (itemValue) {
return {
"type": "listItem",
"loose": false,
"children": [ itemValue ]
type: 'listItem',
loose: false,
children: [itemValue]
};
},
makeListUnordered: function (itemsArray) {
return {
"type": "list",
"ordered": false,
"children": itemsArray,
"loose": false
type: 'list',
ordered: false,
children: itemsArray,
loose: false
};
},
makeParagraph: function (itemsArray) {
return {
"type": "paragraph",
"children": itemsArray
}
},
makeTable: function (colAlignArray, rowArray) {
return {
"type": "table",
"align": colAlignArray,
"children": rowArray
type: 'table',
align: colAlignArray,
children: rowArray
};
},
makeTableRow: function (cellArray) {
return {
"type": "tableRow",
"children": cellArray
type: 'tableRow',
children: cellArray
};
},
makeTableCell: function (content) {
return {
"type": "tableCell",
"children": content
type: 'tableCell',
children: content
};
},
makeInlineCode: function (codeText) {
return {
"type": "inlineCode",
"value": codeText
}
},
makeHTML: function (htmlText) {
return {
"type": "html",
"value": htmlText
};
},
makeBreak: function () {
return {
"type": "break"
}
},
makeImage: function (url, alt) {
return {
"type": "image",
"url": url,
"alt": alt
}
type: 'image',
url: url,
alt: alt
};
},
isHeading: function (node) {
return node.type === "heading";
return node.type === 'heading';
},
isListUnordered: function (node) {
return (node.type === "list") && !node.ordered;
return node.type === 'list' && !node.ordered;
},
isParagraph: function (node) {
return node.type === "paragraph";
return node.type === 'paragraph';
},
isText: function (node) {
return node.type === "text";
},
isLink: function (node) {
return node.type === "inlineCode";
return node.type === 'inlineCode';
}
}
};