mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
* ACS-5041 Changed json to js * ACS-5041 Corrected paths * ACS-5041 Changed json to js * ACS-5041 Updated eslintrc * ACS-5041 Small correction * ACS-5041 Small correction * ACS-5041 Updated license headers * ACS-5041 Updated license headers * ACS-5041 Replaced references to alfresco * ACS-5041 Added Hyland to known words * ACS-5041 Fixed coverage issue * ACS-5041 Fixed duplication issue * ACS-5041 Fixed duplications issue * ACS-5041 Fixed duplications issue * ACS-5041 Fixed duplications issue * ACS-5041 Fixed duplications issue * ACS-5041 Fixed duplications issue * ACS-5041 Fixed duplications issue * ACS-5041 Fixed duplications issue * ACS-5041 Fixed duplications issue * ACS-5041 Fixed test * ACS-5041 Fixed test * ACS-5041 Reverted one change * ACS-5041 Added missing license to files after rebase
147 lines
4.4 KiB
TypeScript
147 lines
4.4 KiB
TypeScript
/*!
|
|
* @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 * 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() {
|
|
const indexDocData = getIndexDocData();
|
|
|
|
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, '|');
|
|
|
|
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);
|
|
|
|
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));
|
|
}
|
|
|
|
function getIndexDocData() {
|
|
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'];
|
|
}
|
|
});
|
|
|
|
const result = {
|
|
tuts: []
|
|
};
|
|
|
|
indexArray.forEach(element => {
|
|
const tutData = { link: element['file'] };
|
|
|
|
const tutFile = path.resolve(tutFolder, element['file']);
|
|
const tutFileText = fs.readFileSync(tutFile, 'utf8');
|
|
const tutMD = remark().use(frontMatter, ['yaml']).parse(tutFileText);
|
|
|
|
const metadata = getDocMetadata(tutMD);
|
|
|
|
if (metadata['Level']) {
|
|
tutData['level'] = metadata['Level'];
|
|
} else {
|
|
tutData['level'] = '';
|
|
}
|
|
|
|
const briefDesc = getFirstParagraph(tutMD);
|
|
|
|
const briefDescText = remark()
|
|
.use(frontMatter, {type: 'yaml', fence: '---'})
|
|
.data('settings', {paddedTable: false, gfm: false})
|
|
.stringify(briefDesc);
|
|
|
|
tutData['briefDesc'] = briefDescText;
|
|
|
|
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;
|
|
|
|
result.tuts.push(tutData);
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
function getDocMetadata(tree) {
|
|
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++) {}
|
|
|
|
if (s < tree.children.length) {
|
|
return tree.children[s];
|
|
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function getFirstHeading(tree) {
|
|
let s = 0;
|
|
|
|
for (; (s < tree.children.length) && !unist.isHeading(tree.children[s]); s++) {}
|
|
|
|
if (s < tree.children.length) {
|
|
return tree.children[s];
|
|
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|