forked from nolimits4web/swiper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.js
57 lines (53 loc) · 1.52 KB
/
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
49
50
51
52
53
54
55
56
57
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const buildJsCore = require('./build-js-core');
const buildJsBundle = require('./build-js-bundle');
const buildTypes = require('./build-types');
const buildStyles = require('./build-styles');
const buildReact = require('./build-react');
const buildVue = require('./build-vue');
const buildSvelte = require('./build-svelte');
console.log(chalk.cyan('Watching file changes ...'));
const watchFunction = async (fileName) => {
if (fileName.includes('.less') || fileName.includes('.css') || fileName.includes('.scss')) {
console.log('Building styles');
await buildStyles();
console.log('Building styles DONE');
return;
}
if (fileName.includes('.d.ts')) {
console.log('Building Types');
await buildTypes();
return;
}
if (fileName.includes('react')) {
console.log('Building React');
buildReact('build');
return;
}
if (fileName.includes('vue')) {
console.log('Building Vue');
buildVue('build');
return;
}
if (fileName.includes('svelte')) {
console.log('Building Svelte');
buildSvelte('build');
return;
}
if (fileName.includes('.js')) {
console.log('Building JS');
buildJsCore();
buildJsBundle();
return;
}
console.log('something wrong...');
};
let watchTimeout;
fs.watch(path.resolve(__dirname, '../src'), { recursive: true }, (eventType, fileName) => {
clearTimeout(watchTimeout);
watchTimeout = setTimeout(() => {
watchFunction(fileName);
}, 100);
});