@@ -45,6 +45,7 @@ const watchPackage = async (name, outputDir) => {
4545 const destinationPath = getDestinationPath ( name , outputDir )
4646 const sourceRootPath = path . join ( rootPath , `core/${ name } /` )
4747 const dev = runCommand ( `yarn run dev` , { cwd : sourceRootPath } )
48+
4849 try {
4950 await runCommand ( `yarn run build` , { cwd : sourceRootPath } )
5051 } catch ( err ) {
@@ -65,8 +66,7 @@ const watchPackage = async (name, outputDir) => {
6566 cpx . watch ( `${ sourcePath } /lib/**/*` , getDestinationPath ( name , 'lib' ) )
6667 )
6768 } else {
68- const sync = cpx . watch ( `${ sourcePath } /**/*` , destinationPath )
69- fileWatchers . push ( sync )
69+ fileWatchers . push ( cpx . watch ( `${ sourcePath } /**/*` , destinationPath ) )
7070 }
7171
7272 const unsubscribers = fileWatchers . map ( fileWatcher => {
@@ -81,12 +81,15 @@ const watchPackage = async (name, outputDir) => {
8181 }
8282 return stop
8383 } )
84+
8485 const stop = ( ) => {
8586 dev . cancel ( )
8687 unsubscribers . forEach ( unsub => {
8788 unsub ( )
8889 } )
8990 }
91+
92+ console . log ( 'watching package: ' , name )
9093 return stop
9194}
9295
@@ -97,20 +100,21 @@ const main = async () => {
97100 for ( let stopWatching of watchStoppers ) {
98101 stopWatching ( )
99102 }
103+
100104 console . log ( `\nTerminated ${ watchStoppers . length } running processes\n` )
101105 process . exit ( 0 )
102106 } )
107+
103108 const build = runCommand ( `yarn packages:build` , { cwd : rootPath } )
109+
104110 watchStoppers . push ( ( ) => build . cancel ( ) )
111+
105112 await build
106- for ( let package of packages ) {
107- const stopWatchingPackage = await watchPackage (
108- package . name ,
109- package . outputDir
110- )
111- console . log ( 'watching package ' , package . name )
112- watchStoppers . push ( stopWatchingPackage )
113+
114+ for ( const package of packages ) {
115+ watchStoppers . push ( await watchPackage ( package . name , package . outputDir ) )
113116 }
117+
114118 const dev = runCommand ( `yarn docz dev` , { cwd : __dirname } )
115119 watchStoppers . push ( ( ) => dev . cancel ( ) )
116120}
0 commit comments