Skip to content

Commit

Permalink
feat: update watch script (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
moushicheng authored Aug 29, 2023
1 parent 52fadcd commit 795c8ae
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions scripts/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,41 @@ function getComponentName(path) {
return path.split(/[\\/]/)[1];
}

function getRoot(filePath) {
return filePath.split(/[\\/]/)[0];
}
function runReBuild(path) {
runTask(`npm run build`, path, 'watch', {
silent: false
});
}

chokidar
.watch('./components', {
ignored: /(dist)|(node_modules)/ // ignore dotfiles
.watch(['./components', './utils', './preset'], {
ignored: /(dist)|(node_modules)|(__test__)/ // ignore dotfiles
})
.on('ready', () => log('success', 'Initial scan complete. Ready for changes'))
.on('change', (path) => {
const component = getComponentName(path);
log('success', `${component} has been changed, rebuilding now.....`);
runTask(`npm run build`, `components/${component}`, 'watch', {
silent: false
});
.on('change', (filePath) => {
const root = getRoot(filePath);
switch (root) {
case 'components': {
const component = getComponentName(filePath);
log('success', `${component} has been changed, rebuilding now.....`);
runReBuild(`components/${component}`);
break;
}
case 'utils': {
log('success', `utlis has been changed, rebuilding now.....`);
runReBuild('utils');
break;
}
case 'preset': {
log('success', `preset has been changed, rebuilding now.....`);
runReBuild('preset');
break;
}
default: {
log('warning', `unexpected path ${filePath}`);
}
}
});

0 comments on commit 795c8ae

Please sign in to comment.