forked from phereford/tui.calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demoConfigGenerator.js
72 lines (56 loc) · 1.92 KB
/
demoConfigGenerator.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const fs = require('fs');
const exec = require('child_process').exec;
console.log('\n * [START] Create a demo.json file for the storybook example on the TOAST UI brand site.\n');
exec(`find ./examples -name '*.html'`, (error, stdout, stderr) => {
const htmlFileList = stdout.split('\n');
console.log('- Total number of examples : ', htmlFileList.length);
const files = [];
const fileNameReg = /example[\w-]+.html/g;
htmlFileList.sort();
htmlFileList.forEach(filePath => {
let fileName = filePath.match(fileNameReg);
if (fileName) {
fileName = fileName[0];
const file = generateFileData(fileName);
files.push(file);
}
});
console.log('- Example Titles : ')
console.log(files.map((file, idx) => ` => ${file.title}`).join('\n'));
const demoConfig = {
files,
staticDir: ['css', 'fonts', 'images', 'js']
}
/*
console.log('stderr : %s', stderr);
*/
fs.writeFile('examples/demo.json', JSON.stringify(demoConfig), 'utf8', err => {
console.log('\n * [COMPLETED] Check the "examples/demo.json" file.\n');
});
if (error !== null) {
console.log('error: %s', error);
}
})
function getTitle(fileName) {
const titleReg = /(?![\.html])[^example0-9][\w-]+/g;
let title = fileName.match(titleReg)[0];
title = title.substr(1);
title = title.replace('-n-', '-&-'); // n을 & 치환
const titleWordArr = title.split('-');
title = titleWordArr
.map(word => (word.charAt(0).toUpperCase() + word.slice(1)))
.join(' ');
return title === 'Basic' ? 'Calendar App' : title;
}
function generateFileData(filename) {
const depJsFile = filename.indexOf('example00') > -1 ? 'js/app.js' : 'js/default.css';
const jsFilePaths = ['js/data/calendars.js', 'js/data/schedules.js', depJsFile];
const cssFilePaths = ['css/default.css', 'css/icons.css'];
const title = getTitle(filename);
return {
filename,
title,
jsFilePaths,
cssFilePaths
}
}