Skip to content

Commit

Permalink
watcher npm run dev
Browse files Browse the repository at this point in the history
  • Loading branch information
NotChristianGarcia committed Jul 8, 2024
1 parent 5a950ac commit c3760a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"homepage": "https://tapis-project.github.io/tapis-ui",
"scripts": {
"start": "vite --config ./vite/vite.local.config.mts",
"dev": "npm run watcher & npm run start",
"deploy": "vite --config ./vite/vite.config.mts",
"build": "tsc && vite build --config ./vite/vite.config.mts",
"watcher": "node ./scripts/watcher.js",
Expand Down
25 changes: 14 additions & 11 deletions scripts/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,39 @@ const libsToWatch = [
'lib/tapisui-common',
'lib/tapisui-extensions-core',
'lib/tapisui-api',
'lib/icicle-tapisui-extensions'
'lib/icicle-tapisui-extensions',
// Add other libraries you want watched and rebuilt here
];

libsToWatch.forEach(libPath => {
libsToWatch.forEach((libPath) => {
console.log(`Watching: ${libPath}`);
const watcher = chokidar.watch(`${libPath}/src`, { ignoreInitial: true });

watcher.on('all', (event, filePath) => {
if (filePath.endsWith('.css') || filePath.endsWith('.scss')) {
// Handle CSS and SCSS files separately
const destPath = filePath.replace('/src/', '/dist/');
fs.copyFile(filePath, destPath, err => {
fs.copyFile(filePath, destPath, (err) => {
if (err) {
console.error(`Error copying file ${filePath}: ${err}`);
return;
}
console.log(`Copying: ${filePath}`);
});
} else {
// rebuild is incremental due to the lib/libname/tsconfig.json > compilerOptions
// rebuild is incremental due to the lib/libname/tsconfig.json > compilerOptions
// > incremental: true, meaning only changed files are recompiled
console.log(`Rebuilding: ${libPath}`);
exec(`cd ${libPath} && npx tsc --build ./tsconfig.json`, (error, stdout, stderr) => {
if (error) {
console.error(`Error rebuilding ${libPath}: ${error}\n${stdout}`);
return;
exec(
`cd ${libPath} && npx tsc --build ./tsconfig.json`,
(error, stdout, stderr) => {
if (error) {
console.error(`Error rebuilding ${libPath}: ${error}\n${stdout}`);
return;
}
console.log(`Changed: ${filePath}`);
}
console.log(`Changed: ${filePath}`);
});
);
}
});
});
});

0 comments on commit c3760a5

Please sign in to comment.