forked from sulu/sulu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
styleguide.config.js
144 lines (125 loc) · 5 KB
/
styleguide.config.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* eslint-disable flowtype/require-valid-file-annotation */
/* eslint-disable import/no-nodejs-modules */
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const glob = require('glob');
const webpackConfig = require('./webpack.config.js');
const firstLetterIsUppercase = (string) => {
const first = string.charAt(0);
return first === first.toUpperCase();
};
const compareFolderName = (folderA, folderB) => {
folderA = path.basename(folderA).toUpperCase();
folderB = path.basename(folderB).toUpperCase();
if (folderA < folderB) {
return -1;
}
if (folderA > folderB) {
return 1;
}
return 0;
};
const javaScriptFileExists = (path, fileName) => {
return fs.existsSync(`${path}/${fileName}.js`);
};
module.exports = { // eslint-disable-line
title: 'Sulu Javascript Docs',
require: [
'./src/Sulu/Bundle/AdminBundle/Resources/js/containers/Application/global.scss',
'./src/Sulu/Bundle/AdminBundle/Resources/js/containers/Application/styleguidist.scss',
],
styles: {
Playground: {
preview: {
background: '#f5f5f5',
},
},
},
sections: [
{
name: 'Views',
sections: (function() {
const folders = glob.sync('./src/Sulu/Bundle/*/Resources/js/views/*');
return folders
.filter((folder) => path.basename(folder) !== 'index.js')
.filter((folder) => javaScriptFileExists(folder, path.basename(folder)))
.map((folder) => {
const component = path.basename(folder);
return {name: component, content: folder + '/README.md'};
});
})(),
},
{
name: 'Services',
sections: (function() {
const folders = glob.sync('./src/Sulu/Bundle/*/Resources/js/services/*');
return folders
.filter((folder) => path.basename(folder) !== 'index.js')
.filter((folder) => javaScriptFileExists(folder, path.basename(folder)))
.sort(compareFolderName)
.map((folder) => {
const component = path.basename(folder);
return {name: component, content: folder + '/README.md'};
});
})(),
},
{
name: 'Containers',
components() {
let folders = glob.sync('./src/Sulu/Bundle/*/Resources/js/containers/*');
// filter out containers
folders = folders
.filter((folder) => firstLetterIsUppercase(path.basename(folder)))
.filter((folder) => javaScriptFileExists(folder, path.basename(folder)))
.sort(compareFolderName);
return folders.map((folder) => {
const component = path.basename(folder);
return path.join(folder, component + '.js');
});
},
},
{
name: 'Higher-Order components',
sections: (function() {
let folders = glob.sync('./src/Sulu/Bundle/*/Resources/js/components/*');
folders = folders.filter((folder) => !firstLetterIsUppercase(path.basename(folder)));
return folders
.filter((folder) => path.basename(folder) !== 'index.js')
.sort(compareFolderName)
.map((folder) => {
const component = path.basename(folder);
return {name: component, content: folder + '/README.md'};
});
})(),
},
{
name: 'Components',
components() {
let folders = glob.sync('./src/Sulu/Bundle/*/Resources/js/components/*');
// filter out higher order components
folders = folders
.filter((folder) => firstLetterIsUppercase(path.basename(folder)))
.filter((folder) => javaScriptFileExists(folder, path.basename(folder)))
.sort(compareFolderName);
return folders.map((folder) => {
const component = path.basename(folder);
return path.join(folder, component + '.js');
});
},
},
],
webpackConfig: (env, argv) => {
const config = webpackConfig(env, argv);
config.plugins.push(
new webpack.DefinePlugin({
SULU_CONFIG: {},
})
);
// set alias for "fos-jsrouting" package to allow for building styleguide without composer dependencies
delete config.resolve.alias['fos-jsrouting'];
// eslint-disable-next-line no-undef
config.resolve.alias['fos-jsrouting/router'] = path.resolve(__dirname, 'tests/js/mocks/empty.js');
return config;
},
};