Files
alfresco-ng2-components/tools/doc/tools/gqIndex.ts
Andy Stark 5c63b7c0f8 [ADF-4252] Added doc link fixing tool (#4461)
* [ADF-4252] Added basic fixer for link and image URLs

* [ADF-4252] Added full check to link fixing tool

* [ADF-4252] Manually replaced http Github doc URLs

* [ADF-4252] Fixed rel note doc links with tool
2019-03-19 22:17:30 +00:00

84 lines
2.3 KiB
TypeScript

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 = [
'content-services', 'core', 'extensions',
'insights', 'process-services', 'process-services-cloud'
];
let query = `
query libIndex($libName: String) {
documents(idFilter: $libName) {
title: metadata(key: "Title")
status: metadata(key: "Status")
id
classType: folder(depth: 2)
heading {
link {
url
}
}
paragraph {
plaintext
}
}
}
`;
export function processDocs(mdCache, aggData, _errorMessages) {
let 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);
let indexFilePath = path.resolve(aggData['rootFolder'], 'docs', 'README.md');
let indexFileText = fs.readFileSync(indexFilePath, 'utf8');
let indexMD = remark()
.use(frontMatter, ["yaml"])
.parse(indexFileText);
let schema = buildSchema(MQ.schema);
libNamesList.forEach(libName => {
graphql(schema, query, docset, null, {'libName': libName})
.then((response) => {
if (!response['data']) {
console.log(JSON.stringify(response));
} else {
//console.log(template(response['data']));
let newSection = remark().parse(template(response['data'])).children;
replaceZone(indexMD, libName, (start, _oldZone, end) => {
newSection.unshift(start);
newSection.push(end);
return newSection;
});
let outText = remark()
.use(frontMatter, {type: 'yaml', fence: '---'})
.data("settings", {paddedTable: false, gfm: false})
.stringify(indexMD);
fs.writeFileSync(indexFilePath, outText);
}
});
});
}