-
Notifications
You must be signed in to change notification settings - Fork 375
/
generate-demos.js
59 lines (51 loc) · 1.71 KB
/
generate-demos.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
import fs from 'fs';
import path from 'path';
import {
generateThemeFilesRegistry,
generateDataHelpersRegistry,
} from './scripts/helper-files-parser.js';
import { getCurrentProductName } from './scripts/utils.js';
import {
loadDemosToGenerate, generateDemos, removePendingFiles,
} from './scripts/demos-generator.js';
import { generateDemoRegistry } from './scripts/registry-generator.js';
const THEMES_FOLDER = './src/theme-sources';
const DEMOS_REGISTRY_FILE = './src/demo-registry.js';
const reactCommonPath = '../dx-react-common/src';
const productDemosFile = productName => `${reactCommonPath}/${productName}-demo-registry.js`;
const productDemoDataFile = productName => `${reactCommonPath}/${productName}-demo-data-registry.js`;
const productThemeComponentsFile = productName => (
`${reactCommonPath}/${productName}-theme-components-registry.js`
);
const loadThemeNames = () => {
const themeNames = [];
fs.readdirSync(THEMES_FOLDER).forEach((themeName) => {
if (themeName.startsWith('.')) return;
if (fs.lstatSync(path.join(THEMES_FOLDER, themeName)).isDirectory()) {
themeNames.push(themeName);
}
});
return themeNames;
};
// {
// "file": ["path/dep1", "path/dep2"]
// }
// {
// "path/file": "file contents",
// }
generateThemeFilesRegistry(productThemeComponentsFile(getCurrentProductName()));
generateDataHelpersRegistry(productDemoDataFile(getCurrentProductName()));
const themeNames = loadThemeNames();
const demos = loadDemosToGenerate(themeNames);
generateDemos(demos);
generateDemoRegistry(
demos,
DEMOS_REGISTRY_FILE,
fileName => `require('.${fileName}').default`,
);
generateDemoRegistry(
demos,
productDemosFile(getCurrentProductName()),
() => '',
);
removePendingFiles();