@@ -2,6 +2,8 @@ const path = require('path')
22const util = require ( 'util' )
33const copy = require ( 'copy' )
44const fs = require ( 'fs' )
5+ const minimist = require ( 'minimist' )
6+ const c = require ( 'picocolors' )
57const exec = util . promisify ( require ( 'child_process' ) . exec )
68
79const libTsConfig = path . resolve ( __dirname , '../tsconfig.lib.json' )
@@ -60,12 +62,17 @@ async function copyStatic() {
6062}
6163
6264async function build ( ) {
63- await exec ( `rm -rf ${ libDir } /*` ) // 确保每次gen lib都是最新的
64- await compileTs ( libDir , libTsConfig )
65- await copyStatic ( )
66- modifyMpxScriptRef ( )
67-
68- // console.log('Done: compile component lib dir')
65+ try {
66+ console . log ( c . blue ( 'start building' ) )
67+ await exec ( `rm -rf ${ libDir } /*` ) // 确保每次gen lib都是最新的
68+ await compileTs ( libDir , libTsConfig )
69+ await copyStatic ( )
70+ modifyMpxScriptRef ( )
71+ } catch ( error ) {
72+ console . log ( c . redBright ( 'build fail' ) )
73+ throw Error ( error )
74+ }
75+ console . log ( c . greenBright ( 'Done: compile component lib dir!' ) )
6976}
7077
7178function modifyMpxScriptRef ( ) {
@@ -97,4 +104,16 @@ function modifyMpxScriptRef() {
97104 } )
98105}
99106
100- build ( )
107+ const argv = minimist ( process . argv . slice ( 2 ) )
108+ function runBuild ( ) {
109+ const { w : watch } = argv
110+ if ( watch ) {
111+ console . log ( c . blue ( 'watching file....' ) )
112+ const watchDir = path . resolve ( __dirname , '../src' )
113+ fs . watch ( watchDir , { recursive : true } , ( eventType , filename ) => {
114+ build ( )
115+ } )
116+ }
117+ build ( )
118+ }
119+ runBuild ( )
0 commit comments