-
Notifications
You must be signed in to change notification settings - Fork 40
/
updateModules.js
67 lines (62 loc) · 2.88 KB
/
updateModules.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
58
59
60
61
62
63
64
65
66
67
const fs = require('fs');
const path = require('path');
const js_modules_path = './assets/ts/modules';
const css_modules_path = './assets/sass/modules';
const static_path = './static';
const modules = {
'jump.js/dist/jump.js': `${js_modules_path}/jump.js`,
'clipboard/dist/clipboard.js': `${js_modules_path}/clipboard.js`,
'vanilla-lazyload/dist/lazyload.js': `${js_modules_path}/lazyload.js`,
'medium-zoom/dist/medium-zoom.js': `${js_modules_path}/medium-zoom.js`,
'swup/dist/Swup.umd.js': `${js_modules_path}/swup.js`,
'@swup/fade-theme/dist/index.umd.js': `${js_modules_path}/swupFadeTheme.js`,
'@swup/ga-plugin/dist/index.umd.js': `${js_modules_path}/swupGaPlugin.js`,
'@swup/progress-plugin/dist/index.umd.js': `${js_modules_path}/swupProgressPlugin.js`,
'@swup/scripts-plugin/dist/index.umd.js': `${js_modules_path}/swupScriptsPlugin.js`,
'@swup/slide-theme/dist/index.umd.js': `${js_modules_path}/swupSlideTheme.js`,
'@swup/head-plugin/dist/index.umd.js': `${js_modules_path}/swupHeadPlugin.js`,
'swup-morph-plugin/dist/index.umd.js': `${js_modules_path}/swupMorphPlugin.js`,
'flexsearch/dist/flexsearch.bundle.js': `${js_modules_path}/flexsearch.js`,
'katex/dist/katex.js': `${js_modules_path}/katex.js`,
'pangu/dist/browser/pangu.js': `${js_modules_path}/pangu.js`,
'katex/dist/katex.css': `${css_modules_path}/katex.css`,
'katex/dist/fonts': `${static_path}/fonts`,
'katex/dist/contrib/auto-render.js': `${js_modules_path}/katex-render.js`,
'katex/dist/contrib/copy-tex.js': `${js_modules_path}/katex-copy.js`,
'normalize.css/normalize.css': `${css_modules_path}/normalize.css`,
'eva-icons/style/eva-icons.css': `${css_modules_path}/eva-icons.css`,
'eva-icons/style/fonts': `${static_path}/fonts`,
}
function copyFolderSync(from, to) {
try {
fs.mkdirSync(to);
} catch (error) {}
fs.readdirSync(from).forEach(element => {
if (fs.lstatSync(path.join(from, element)).isFile()) {
fs.copyFileSync(path.join(from, element), path.join(to, element));
} else {
copyFolderSync(path.join(from, element), path.join(to, element));
}
});
}
for (let index = 0; index < Object.keys(modules).length; index++) {
const key = Object.keys(modules)[index];
const key_path = `node_modules/${key}`;
const value = modules[key];
const value_path = value;
if (!fs.existsSync(key_path)) {
console.log(`${key_path} not found`);
continue;
}
const dir_path = path.join(value_path, '..');
if (!fs.existsSync(dir_path)) {
fs.mkdirSync(dir_path, { recursive: true });
}
if (fs.lstatSync(key_path).isDirectory() ) {
// copy dir
copyFolderSync(key_path, value_path);
} else {
// copy file
fs.copyFileSync(key_path, value_path);
}
}