1 | const fs = require('fs-extra');
|
2 | const path = require('path');
|
3 |
|
4 | const getDemoEntries = function ({ demo: dir, typescript }) {
|
5 |
|
6 | if (fs.existsSync(dir)) {
|
7 |
|
8 | const extName = typescript ? '.ts' : '.js';
|
9 |
|
10 | const filesInDemo = fs.readdirSync(dir);
|
11 | const demoEntryList = filesInDemo.map(file => {
|
12 | if (path.extname(file) === extName) {
|
13 | const baseName = path.basename(file, extName);
|
14 | const htmlFileName = path.basename(file, extName) + '.html';
|
15 | if (filesInDemo.indexOf(htmlFileName) !== -1) {
|
16 | return baseName;
|
17 | }
|
18 | }
|
19 | return null;
|
20 | }).filter(Boolean);
|
21 |
|
22 | return demoEntryList;
|
23 |
|
24 | } else {
|
25 |
|
26 | return null;
|
27 | }
|
28 | }
|
29 |
|
30 | module.exports = getDemoEntries; |
\ | No newline at end of file |