Add radar file walker
This commit is contained in:
@@ -14,8 +14,10 @@
|
|||||||
"async": "2.1.4",
|
"async": "2.1.4",
|
||||||
"babel-cli": "6.22.2",
|
"babel-cli": "6.22.2",
|
||||||
"babel-preset-latest": "6.22.0",
|
"babel-preset-latest": "6.22.0",
|
||||||
|
"babel-preset-stage-0": "6.22.0",
|
||||||
"front-matter": "2.1.1",
|
"front-matter": "2.1.1",
|
||||||
"fs-extra": "2.0.0",
|
"fs-extra": "2.0.0",
|
||||||
"marked": "0.3.6"
|
"marked": "0.3.6",
|
||||||
|
"walk": "2.3.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
radar/2016-02-02/languages-and-frameworks/react.md
Normal file
27
radar/2016-02-02/languages-and-frameworks/react.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
layout: post
|
||||||
|
title: "React"
|
||||||
|
ring: adopt
|
||||||
|
---
|
||||||
|
|
||||||
|
Hier steht eine Einleitung über *React* - super "cool"
|
||||||
|
|
||||||
|
Hier noch ein [link](http://www.google.de) zu google
|
||||||
|
|
||||||
|
<!--except-->
|
||||||
|
|
||||||
|
Hier steht der Rest!
|
||||||
|
|
||||||
|
History
|
||||||
|
-------
|
||||||
|
|
||||||
|
{% include
|
||||||
|
history-entry.html
|
||||||
|
ring="trial"
|
||||||
|
date="2017-12-10"
|
||||||
|
content="This is a history entry
|
||||||
|
|
||||||
|
- Foo
|
||||||
|
- Bar
|
||||||
|
"
|
||||||
|
%}
|
||||||
27
radar/2016-02-02/languages-and-frameworks/vue.md
Normal file
27
radar/2016-02-02/languages-and-frameworks/vue.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
layout: post
|
||||||
|
title: "React"
|
||||||
|
ring: adopt
|
||||||
|
---
|
||||||
|
|
||||||
|
Hier steht eine Einleitung über *React* - super "cool"
|
||||||
|
|
||||||
|
Hier noch ein [link](http://www.google.de) zu google
|
||||||
|
|
||||||
|
<!--except-->
|
||||||
|
|
||||||
|
Hier steht der Rest!
|
||||||
|
|
||||||
|
History
|
||||||
|
-------
|
||||||
|
|
||||||
|
{% include
|
||||||
|
history-entry.html
|
||||||
|
ring="trial"
|
||||||
|
date="2017-12-10"
|
||||||
|
content="This is a history entry
|
||||||
|
|
||||||
|
- Foo
|
||||||
|
- Bar
|
||||||
|
"
|
||||||
|
%}
|
||||||
8
radar/2016-02-02/methods-and-patterns/foo.md
Normal file
8
radar/2016-02-02/methods-and-patterns/foo.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
layout: post
|
||||||
|
title: "Foo"
|
||||||
|
ring: trial
|
||||||
|
new: true
|
||||||
|
---
|
||||||
|
|
||||||
|
Foo
|
||||||
17
radar/2016-02-02/tools/grunt.md
Normal file
17
radar/2016-02-02/tools/grunt.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
layout: post
|
||||||
|
title: "Grunt"
|
||||||
|
ring: hold
|
||||||
|
new: true
|
||||||
|
---
|
||||||
|
|
||||||
|
Hier steht was über *Grunt*
|
||||||
|
|
||||||
|
Hier noch ein [link](http://www.google.de) zu google
|
||||||
|
|
||||||
|
<!--except-->
|
||||||
|
|
||||||
|
Hier steht der Rest!
|
||||||
|
|
||||||
|
History
|
||||||
|
-------
|
||||||
@@ -9,27 +9,44 @@ import {
|
|||||||
srcPath,
|
srcPath,
|
||||||
distPath,
|
distPath,
|
||||||
} from './file';
|
} from './file';
|
||||||
|
import {
|
||||||
|
getTree,
|
||||||
|
createRadar,
|
||||||
|
} from './radar';
|
||||||
|
|
||||||
const fileName = srcPath('v1/tools/grunt.md');
|
|
||||||
|
|
||||||
console.log('<<< start creating files');
|
(async () => {
|
||||||
|
try {
|
||||||
waterfall([
|
const tree = await getTree();
|
||||||
(callback) => {
|
// console.log(JSON.stringify(tree, null, 2));
|
||||||
readFile(fileName, 'utf8', callback);
|
const radar = await createRadar(tree);
|
||||||
},
|
console.log(JSON.stringify(radar, null, 2));
|
||||||
(data, callback) => {
|
} catch(e) {
|
||||||
const item = frontmatter(data);
|
console.error('error:', e);
|
||||||
const html = marked(item.body);
|
|
||||||
|
|
||||||
outputFile(distPath('test3.html'), html, callback);
|
|
||||||
}
|
|
||||||
],
|
|
||||||
(err, results) => {
|
|
||||||
if (!err) {
|
|
||||||
console.log('done creating files >>>');
|
|
||||||
} else {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
})()
|
||||||
|
|
||||||
|
//
|
||||||
|
// const fileName = srcPath('v1/tools/grunt.md');
|
||||||
|
//
|
||||||
|
// console.log('<<< start creating files');
|
||||||
|
//
|
||||||
|
// waterfall([
|
||||||
|
// (callback) => {
|
||||||
|
// readFile(fileName, 'utf8', callback);
|
||||||
|
// },
|
||||||
|
// (data, callback) => {
|
||||||
|
// const item = frontmatter(data);
|
||||||
|
// const html = marked(item.body);
|
||||||
|
//
|
||||||
|
// outputFile(distPath('test3.html'), html, callback);
|
||||||
|
// }
|
||||||
|
// ],
|
||||||
|
// (err, results) => {
|
||||||
|
// if (!err) {
|
||||||
|
// console.log('done creating files >>>');
|
||||||
|
// } else {
|
||||||
|
// console.error(err);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|||||||
141
scripts/radar.js
Normal file
141
scripts/radar.js
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
import { walk } from 'walk';
|
||||||
|
import fs, { readFileSync } from 'fs-extra';
|
||||||
|
import path from 'path';
|
||||||
|
import frontmatter from 'front-matter';
|
||||||
|
import marked from 'marked';
|
||||||
|
import waterfall from 'async/waterfall';
|
||||||
|
import { srcPath } from './file';
|
||||||
|
|
||||||
|
export const getTree = () => (
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const walker = walk(srcPath(), { followLinks: false });
|
||||||
|
let radar = {};
|
||||||
|
|
||||||
|
walker.on("file", (root, fileStat, next) => {
|
||||||
|
if (isMarkdownFile(fileStat.name)) {
|
||||||
|
radar = addItemToRadar(radar, path.resolve(root, fileStat.name))
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
walker.on("errors", (root, nodeStatsArray, next) => {
|
||||||
|
nodeStatsArray.forEach(function (n) {
|
||||||
|
console.error("[ERROR] " + n.name)
|
||||||
|
console.error(n.error.message || (n.error.code + ": " + n.error.path));
|
||||||
|
});
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
walker.on("end", () => {
|
||||||
|
resolve(radar);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const isMarkdownFile = (name) => name.match(/\.md$/);
|
||||||
|
|
||||||
|
const addItemToRadar = (radar, pathName) => {
|
||||||
|
const item = createItemFromPath(pathName);
|
||||||
|
return {
|
||||||
|
...radar,
|
||||||
|
[item.version]: addItemToVersion(radar[item.version] || {}, item),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const addItemToVersion = (version, item) => {
|
||||||
|
return {
|
||||||
|
...version,
|
||||||
|
[item.quadrant]: addItemToQuadrant(version[item.quadrant] || {}, item),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const addItemToQuadrant = (quadrant, item) => {
|
||||||
|
return {
|
||||||
|
...quadrant,
|
||||||
|
[item.name]: item.path,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const createItemFromPath = (pathName) => {
|
||||||
|
const [version, quadrant, fileName] = pathName.split('/').slice(-3);
|
||||||
|
return {
|
||||||
|
version,
|
||||||
|
quadrant,
|
||||||
|
path: pathName,
|
||||||
|
name: fileName.substr(0, fileName.length - 3),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createRadar = async (tree) => {
|
||||||
|
const versionNames = Object.keys(tree).sort();
|
||||||
|
const radar = versionNames.reduce((radar, versionName) => {
|
||||||
|
return updateRadarWithVersion(radar, versionName, tree);
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
return readItemsDataFromFiles(radar);
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateRadarWithVersion = (radar, versionName, tree) => {
|
||||||
|
const version = tree[versionName];
|
||||||
|
const quadrantNames = Object.keys(version);
|
||||||
|
return quadrantNames.reduce((updatedRadar, quadrantName) => {
|
||||||
|
return {
|
||||||
|
...updatedRadar,
|
||||||
|
[quadrantName]: updateQuadrantWithVersion(updatedRadar[quadrantName] || {}, quadrantName, versionName, tree),
|
||||||
|
}
|
||||||
|
}, radar);
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateQuadrantWithVersion = (quadrant, quadrantName, versionName, tree) => {
|
||||||
|
const quadrantInNewVersion = tree[versionName][quadrantName];
|
||||||
|
const fileNames = Object.keys(quadrantInNewVersion);
|
||||||
|
return fileNames.reduce((updatedQuadrant, fileName) => {
|
||||||
|
return {
|
||||||
|
...updatedQuadrant,
|
||||||
|
[fileName]: updateItemWithVersion(updatedQuadrant[fileName], fileName, quadrantName, versionName, tree),
|
||||||
|
}
|
||||||
|
}, quadrant);
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateItemWithVersion = (file = { revision: 0, files: [] }, fileName, quadrantName, versionName, tree) => {
|
||||||
|
const fileInNewVersion = tree[versionName][quadrantName][fileName];
|
||||||
|
return {
|
||||||
|
files: file.files.concat([{
|
||||||
|
version: versionName,
|
||||||
|
file: fileInNewVersion,
|
||||||
|
}]),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const readItemsDataFromFiles = (radar) => {
|
||||||
|
return Object.entries(radar).reduce((newRadar, [quadrantName, quadrant]) => {
|
||||||
|
return {
|
||||||
|
...newRadar,
|
||||||
|
[quadrantName]: Object.entries(quadrant).reduce((newQuadrant, [itemName, item]) => {
|
||||||
|
return {
|
||||||
|
...newQuadrant,
|
||||||
|
[itemName]: {
|
||||||
|
revisions: item.files.length,
|
||||||
|
data: mergeDataFromFiles(item.files)
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, {}),
|
||||||
|
}
|
||||||
|
}, {});
|
||||||
|
};
|
||||||
|
|
||||||
|
const mergeDataFromFiles = (files) => {
|
||||||
|
const frontmatters = getFrontmatterForAllFiles(files);
|
||||||
|
console.log()
|
||||||
|
return frontmatters;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getFrontmatterForAllFiles = (files) => {
|
||||||
|
return files.map(({ file }) => {
|
||||||
|
return getFrontmatter(file);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
const getFrontmatter = (fileName) => {
|
||||||
|
return frontmatter(readFileSync(fileName, 'utf8'));
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user