forked from microsoft/FluidStorybook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
src-viewer-build.js
39 lines (32 loc) · 1.04 KB
/
src-viewer-build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const fs = require('fs'),
path = require('path');
let targetDirectory = __dirname + '/src';
let outputDirectory = __dirname + '/public';
function parseDirectory(directoryName, files) {
fs.readdirSync(directoryName).forEach((file) => {
var fullFileName = path.join(directoryName, file);
var stat = fs.lstatSync(fullFileName);
if (stat.isDirectory()) {
parseDirectory(fullFileName, files);
}
else {
let srcFileName = getSrcFileName(fullFileName);
files[srcFileName] = { raw: getFile(fullFileName) };
}
});
}
function getSrcFileName(fileName) {
return fileName.replace(targetDirectory + '/', '');
}
function getFile(fileName) {
return fs.readFileSync(fileName, { encoding: 'utf8' }).replace(/\r/g, '');
}
let files = {};
parseDirectory(targetDirectory, files);
// Generate file
fs.writeFileSync(outputDirectory + '/rawSources.json', JSON.stringify({
"files": {
...files
}
}));
console.log(outputDirectory + '/rawSources.json created!');