copy-libs.js 980 字节
Newer Older
1 2
if (!Array.prototype.flat) {
	Object.defineProperty(Array.prototype, 'flat', {
C
codecalm 已提交
3
		value: function (depth = 1) {
4
			return this.reduce(function (flat, toFlatten) {
C
codecalm 已提交
5
				return flat.concat((Array.isArray(toFlatten) && (depth > 1)) ? toFlatten.flat(depth - 1) : toFlatten);
6 7 8 9 10 11
			}, []);
		}
	});
}


C
codecalm 已提交
12
const all_libs = require('../pages/_data/libs'),
C
codecalm 已提交
13 14
	path = require('path'),
	{ exec } = require('child_process');
C
codecalm 已提交
15

C
codecalm 已提交
16 17 18
let files = [];

Object.keys(all_libs.js).forEach(function (lib) {
C
codecalm 已提交
19
	files.push(Array.isArray(all_libs.js[lib]) ? all_libs.js[lib] : [all_libs.js[lib]]);
C
codecalm 已提交
20 21 22
});

Object.keys(all_libs.css).forEach(function (lib) {
C
codecalm 已提交
23
	files.push(Array.isArray(all_libs.css[lib]) ? all_libs.css[lib] : [all_libs.css[lib]]);
C
codecalm 已提交
24 25 26 27 28
});

files = files.flat();

files.forEach(function (file) {
C
codecalm 已提交
29 30 31
	if(! file.match(/^https?/)) {
		let dirname = path.dirname(file).replace('@', '');
		let cmd = `mkdir -p "dist/libs/${dirname}" && cp -r node_modules/${file} dist/libs/${file.replace('@', '')}`;
C
codecalm 已提交
32

C
codecalm 已提交
33 34
		exec(cmd)
	}
C
codecalm 已提交
35
});