This repository was archived by the owner on Mar 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink_with_web_components_watch.js
49 lines (42 loc) · 1.73 KB
/
link_with_web_components_watch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* This file watches the original Unipept web components directory for changes and automatically applies these changes
* to the local copy of the Unipept web components (inside the node_modules folder).
*
* This script is only here for use during development of Unipept and should not be used in the production environment.
* The package Chokidar is required to run this file.
*/
const chokidar = require('chokidar');
const fs = require('fs');
const path = require('path');
const directory = './../unipept-web-components/dist'
const typesDirectory = './../unipept-web-components/types'
const errHandler = function(err) {
if (err) {
console.error(err);
}
}
console.log("Watching file system for changes...");
// Watch for changes to the web components directory.
function watchDirectory(dir) {
chokidar.watch(dir).on('all', (event, currentPath) => {
if (!currentPath.includes('/node_modules') && !currentPath.includes('/.git')) {
const filteredPath = currentPath.replace('../unipept-web-components', './node_modules/unipept-web-components');
const directory = path.dirname(filteredPath);
switch(event) {
case 'add':
fs.mkdirSync(directory, { recursive: true }, errHandler);
fs.copyFile(currentPath, filteredPath, errHandler);
break;
case 'change':
fs.copyFile(currentPath, filteredPath, errHandler);
break;
case 'unlink':
fs.unlink(filteredPath, errHandler);
break;
}
console.log(event, currentPath);
}
});
}
watchDirectory(directory);
watchDirectory(typesDirectory);