@@ -11,7 +11,19 @@ const devWebpack = require('./webpack.dev.conf');
11
11
12
12
const configPath = path . join ( __dirname , './config.js' ) ;
13
13
14
- let { devComponent } = require ( './config' ) ;
14
+ /**
15
+ * a-bc-d --> aBcD
16
+ * @param {string } s
17
+ */
18
+ const camelize = s => s . replace ( / - ( \w ) / g, ( $ , $1 ) => $1 . toUpperCase ( ) ) ;
19
+
20
+ /**
21
+ * radio-group --> radio
22
+ * @param {string } s
23
+ */
24
+ const getUpper = s => s . replace ( / ( - [ a - z ] * ) / g, '' ) ;
25
+
26
+ let { componentName } = require ( './config' ) . dev ;
15
27
16
28
const componentsInPrototype = [ 'Modal' , 'message' , 'notification' ] ;
17
29
@@ -116,6 +128,7 @@ const generateInstall = components =>
116
128
const renderTemplate = name => {
117
129
const components = {
118
130
Tooltip : 'tooltip' , // for DemoBox
131
+ Icon : 'icon' , // Basic
119
132
} ;
120
133
121
134
const demoPaths = fs
@@ -128,16 +141,20 @@ const renderTemplate = name => {
128
141
const demo = fs . readFileSync ( path . join ( __dirname , demoPath ) ) . toString ( ) ;
129
142
130
143
const componentsInDemo = demo . match ( / a - ( \w + ( - \w + ) * ) / g) || [ ] ;
131
- componentsInDemo . forEach ( n => {
132
- const componentName = n . replace ( / - ( \w ) / g, ( $ , $1 ) => $1 . toUpperCase ( ) ) . replace ( / ^ a / , '' ) ;
133
-
134
- if ( componentsInPrototype . includes ( componentName ) ) {
135
- return ;
136
- }
144
+ componentsInDemo . forEach ( name => {
145
+ const dirName = name . replace ( / ^ a - / , '' ) ;
146
+ const componentName = camelize ( name ) . replace ( / ^ a / , '' ) ;
147
+ const upperComponentDir = getUpper ( dirName ) ;
148
+ const upperComponentName = upperComponentDir . replace ( / ^ [ a - z ] / , $ => $ . toUpperCase ( ) ) ;
137
149
138
- const componentPath = path . join ( __dirname , `../components/${ n . replace ( / ^ a - / , '' ) } ` ) ;
150
+ const componentPath = path . join ( __dirname , `../components/${ dirName } ` ) ;
139
151
if ( fs . existsSync ( componentPath ) ) {
140
- components [ componentName ] = n . replace ( / ^ a - / , '' ) ;
152
+ if ( componentsInPrototype . includes ( componentName ) ) {
153
+ return ;
154
+ }
155
+ components [ componentName ] = dirName ;
156
+ } else if ( fs . existsSync ( path . join ( __dirname , `../components/${ upperComponentDir } ` ) ) ) {
157
+ components [ upperComponentName ] = upperComponentDir ;
141
158
}
142
159
} ) ;
143
160
} ) ;
@@ -173,24 +190,19 @@ if (!fsExistsSync(path.join(__dirname, '../components/test/index.vue'))) {
173
190
let demoWatcher ;
174
191
175
192
chokidar . watch ( configPath , { ignoreInitial : true } ) . on ( 'change' , async ( ) => {
176
- devComponent = importFresh ( configPath ) . devComponent ;
193
+ ( { componentName } = importFresh ( configPath ) . dev ) ;
177
194
178
195
demoWatcher && ( await demoWatcher . close ( ) ) ;
179
196
180
- demoWatcher = chokidar . watch ( path . join ( __dirname , `../components/${ devComponent } /demo` ) ) ;
197
+ demoWatcher = chokidar . watch ( path . join ( __dirname , `../components/${ componentName } /demo` ) ) ;
181
198
demoWatcher . on ( 'change' , ( ) => {
182
- renderTemplate ( devComponent ) ;
199
+ renderTemplate ( componentName ) ;
183
200
} ) ;
184
201
185
- renderTemplate ( devComponent ) ;
186
- } ) ;
187
-
188
- testWatcher = chokidar . watch ( path . join ( __dirname , `../components/test` ) ) ;
189
- testWatcher . on ( 'change' , ( ) => {
190
- renderTemplate ( devComponent ) ;
202
+ renderTemplate ( componentName ) ;
191
203
} ) ;
192
204
193
- renderTemplate ( devComponent ) ;
205
+ renderTemplate ( componentName ) ;
194
206
195
207
const compiler = webpack ( devWebpack ) ;
196
208
0 commit comments