@@ -11,6 +11,7 @@ const FROME = resolve('dist')
1111const INDEXFILE = resolve ( 'index.html' )
1212const CONFIGXML = resolve ( 'config.xml' )
1313const TO = resolve ( 'widget' )
14+ const OtherFiles = [ 'res' ]
1415
1516
1617function insertVendor ( ) {
@@ -40,6 +41,9 @@ function copyFile() {
4041 let { source, dir } = getSource ( )
4142 dir . forEach ( e => fs . mkdirSync ( `${ TO } ${ e } ` ) )
4243 source . forEach ( e => fs . copyFileSync ( e . path , `${ TO } ${ e . name } ` ) )
44+ OtherFiles . forEach ( e => {
45+ copyOtherFiles ( e , 'widget' )
46+ } )
4347 fs . copyFileSync ( CONFIGXML , `${ TO } /config.xml` )
4448 fs . renameSync ( `${ TO } /dist` , `${ TO } /html` )
4549 fs . writeFileSync ( `${ TO } /index.html` , fs . readFileSync ( INDEXFILE ) . toString ( ) . replace ( / u r l : [ \S \s ] * \/ [ \W \w ] * \. h t m l / , ( match ) => `${ match . replace ( / h t t p : \/ \/ [ \W \w ] * : \d + \/ / , 'html/' ) } ` ) )
@@ -64,8 +68,8 @@ function generate() {
6468 if ( ! fs . existsSync ( FROME ) ) {
6569 child_process . exec ( `npm run build` , ( error , stdout ) => {
6670 if ( error ) {
67- console . error ( `exec error: ${ error } ` ) ;
68- return ;
71+ console . error ( `exec error: ${ error } ` )
72+ return
6973 }
7074 console . log ( stdout )
7175 copyFile ( )
@@ -74,4 +78,17 @@ function generate() {
7478 copyFile ( )
7579 }
7680}
81+ function copyOtherFiles ( from , to ) {
82+ let source = [ ]
83+ let dir = [ ]
84+ glob . sync ( `${ resolve ( from ) } /**` ) . forEach ( ( pathname ) => {
85+ if ( fs . statSync ( pathname ) . isFile ( ) ) {
86+ source . push ( { path : pathname , name : pathname . replace ( new RegExp ( `[\\S\\s]*\/${ from } ` , 'g' ) , `/${ from } ` ) } )
87+ } else {
88+ dir . push ( pathname . replace ( new RegExp ( `[\\S\\s]*\/${ from } ` , 'g' ) , `/${ from } ` ) )
89+ }
90+ } )
91+ dir . forEach ( e => fs . mkdirSync ( `${ resolve ( to ) } ${ e } ` ) )
92+ source . forEach ( e => fs . copyFileSync ( e . path , `${ resolve ( to ) } ${ e . name } ` ) )
93+ }
7794generate ( )
0 commit comments