@@ -11,7 +11,19 @@ const devWebpack = require('./webpack.dev.conf');
1111
1212const configPath = path . join ( __dirname , './config.js' ) ;
1313
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 ;
1527
1628const componentsInPrototype = [ 'Modal' , 'message' , 'notification' ] ;
1729
@@ -116,6 +128,7 @@ const generateInstall = components =>
116128const renderTemplate = name => {
117129 const components = {
118130 Tooltip : 'tooltip' , // for DemoBox
131+ Icon : 'icon' , // Basic
119132 } ;
120133
121134 const demoPaths = fs
@@ -128,16 +141,20 @@ const renderTemplate = name => {
128141 const demo = fs . readFileSync ( path . join ( __dirname , demoPath ) ) . toString ( ) ;
129142
130143 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 ( ) ) ;
137149
138- const componentPath = path . join ( __dirname , `../components/${ n . replace ( / ^ a - / , '' ) } ` ) ;
150+ const componentPath = path . join ( __dirname , `../components/${ dirName } ` ) ;
139151 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 ;
141158 }
142159 } ) ;
143160 } ) ;
@@ -173,24 +190,19 @@ if (!fsExistsSync(path.join(__dirname, '../components/test/index.vue'))) {
173190let demoWatcher ;
174191
175192chokidar . watch ( configPath , { ignoreInitial : true } ) . on ( 'change' , async ( ) => {
176- devComponent = importFresh ( configPath ) . devComponent ;
193+ ( { componentName } = importFresh ( configPath ) . dev ) ;
177194
178195 demoWatcher && ( await demoWatcher . close ( ) ) ;
179196
180- demoWatcher = chokidar . watch ( path . join ( __dirname , `../components/${ devComponent } /demo` ) ) ;
197+ demoWatcher = chokidar . watch ( path . join ( __dirname , `../components/${ componentName } /demo` ) ) ;
181198 demoWatcher . on ( 'change' , ( ) => {
182- renderTemplate ( devComponent ) ;
199+ renderTemplate ( componentName ) ;
183200 } ) ;
184201
185- renderTemplate ( devComponent ) ;
186- } ) ;
187-
188- testWatcher = chokidar . watch ( path . join ( __dirname , `../components/test` ) ) ;
189- testWatcher . on ( 'change' , ( ) => {
190- renderTemplate ( devComponent ) ;
202+ renderTemplate ( componentName ) ;
191203} ) ;
192204
193- renderTemplate ( devComponent ) ;
205+ renderTemplate ( componentName ) ;
194206
195207const compiler = webpack ( devWebpack ) ;
196208
0 commit comments