forked from javascript-tutorial/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncResources.js
More file actions
executable file
·40 lines (29 loc) · 837 Bytes
/
syncResources.js
File metadata and controls
executable file
·40 lines (29 loc) · 837 Bytes
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
const fs = require('fs');
const fse = require('fs-extra');
const gp = require('gulp-load-plugins')();
const glob = require('glob');
module.exports = function(resources) {
return function(callback) {
for (var src in resources) {
var dst = resources[src];
var files = glob.sync(src + '/**');
for (var i = 0; i < files.length; i++) {
var srcPath = files[i];
var dstPath = srcPath.replace(src, dst);
var srcStat = fs.statSync(srcPath);
if (srcStat.isDirectory()) {
fse.ensureDirSync(dstPath);
continue;
}
var dstMtime = 0;
try {
dstMtime = fs.statSync(dstPath).mtime;
} catch(e) {}
if (srcStat.mtime > dstMtime) {
fse.copySync(srcPath, dstPath);
}
}
}
callback();
};
};