mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2463] Update doc tools to work with subfolders (#3056)
* [ADF-2463] Updated main doc tool and index tool to handle subfolders * [ADF-2463] Updated version index tool for subfolders
This commit is contained in:
committed by
Eugenio Romano
parent
16a8fa8cd8
commit
4ee7cc0870
@@ -23,9 +23,9 @@ function initPhase(aggData) {
|
||||
}
|
||||
|
||||
|
||||
function readPhase(srcFolder, filenames, aggData) {
|
||||
function readPhase(filenames, aggData) {
|
||||
for (var i = 0; i < filenames.length; i++) {
|
||||
var pathname = path.resolve(srcFolder, filenames[i]);
|
||||
var pathname = filenames[i];//path.resolve(srcFolder, filenames[i]);
|
||||
|
||||
var src = fs.readFileSync(pathname);
|
||||
var tree = remark().use(frontMatter, ["yaml"]).parse(src);
|
||||
@@ -46,9 +46,9 @@ function aggPhase(aggData) {
|
||||
}
|
||||
|
||||
|
||||
function updatePhase(srcFolder, destFolder, filenames, aggData) {
|
||||
function updatePhase(filenames, aggData) {
|
||||
for (var i = 0; i < filenames.length; i++) {
|
||||
var pathname = path.resolve(srcFolder, filenames[i]);
|
||||
var pathname = filenames[i]; // path.resolve(srcFolder, filenames[i]);
|
||||
|
||||
var src = fs.readFileSync(pathname);
|
||||
var tree = remark().use(frontMatter, ["yaml"]).parse(src)
|
||||
@@ -60,8 +60,9 @@ function updatePhase(srcFolder, destFolder, filenames, aggData) {
|
||||
});
|
||||
|
||||
if (modified)
|
||||
fs.writeFileSync(path.resolve(destFolder, filenames[i]), remark().use(frontMatter, {type: 'yaml', fence: '---'}).data("settings", {paddedTable: false}).stringify(tree));
|
||||
//console.log(JSON.stringify(tree));
|
||||
fs.writeFileSync(filenames[i], remark().use(frontMatter, {type: 'yaml', fence: '---'}).data("settings", {paddedTable: false}).stringify(tree));
|
||||
|
||||
//console.log(JSON.stringify(tree));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,8 +92,24 @@ function loadToolConfig(configFilePath) {
|
||||
}
|
||||
|
||||
|
||||
function getAllDocFilePaths(docFolder, files) {
|
||||
var items = fs.readdirSync(docFolder);
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var itemPath = path.resolve(docFolder, items[i]);
|
||||
var itemInfo = fs.statSync(itemPath);
|
||||
|
||||
if (itemInfo.isFile()){
|
||||
files.push(itemPath);
|
||||
} else if (itemInfo.isDirectory()) {
|
||||
getAllDocFilePaths(itemPath, files);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
program
|
||||
.usage("[options] <source> [dest]")
|
||||
.usage("[options] <source>")
|
||||
.parse(process.argv);
|
||||
|
||||
if (program.args.length === 0) {
|
||||
@@ -104,6 +121,7 @@ if (program.args.length === 0) {
|
||||
var sourcePath = path.resolve(program.args[0]);
|
||||
var sourceInfo = fs.statSync(sourcePath);
|
||||
|
||||
/*
|
||||
var destPath;
|
||||
var destInfo;
|
||||
|
||||
@@ -119,19 +137,21 @@ if (sourceInfo.isDirectory() && !destInfo.isDirectory()) {
|
||||
console.log("Error: The <dest> argument must be a directory");
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
var toolModules = loadToolModules();
|
||||
var toolList = loadToolConfig(path.resolve(__dirname, configFileName));
|
||||
|
||||
|
||||
var files;
|
||||
var files = [];
|
||||
|
||||
if (sourceInfo.isDirectory()) {
|
||||
files = fs.readdirSync(sourcePath);
|
||||
getAllDocFilePaths(sourcePath, files);
|
||||
} else if (sourceInfo.isFile()) {
|
||||
files = [ path.basename(sourcePath) ];
|
||||
sourcePath = path.dirname(sourcePath);
|
||||
destPath = path.dirname(destPath);
|
||||
files = [ sourcePath ];
|
||||
//files = [ path.basename(sourcePath) ];
|
||||
//sourcePath = path.dirname(sourcePath);
|
||||
//destPath = path.dirname(destPath);
|
||||
}
|
||||
|
||||
files = files.filter(filename =>
|
||||
@@ -145,13 +165,13 @@ console.log("Initialising...");
|
||||
initPhase(aggData);
|
||||
|
||||
console.log("Analysing Markdown files...");
|
||||
readPhase(sourcePath, files, aggData);
|
||||
readPhase(files, aggData);
|
||||
|
||||
console.log("Computing aggregate data...");
|
||||
aggPhase(aggData);
|
||||
|
||||
console.log("Updating Markdown files...");
|
||||
updatePhase(sourcePath, destPath, files, aggData);
|
||||
updatePhase(files, aggData);
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user