-
Notifications
You must be signed in to change notification settings - Fork 0
/
appendChild.js
40 lines (31 loc) · 975 Bytes
/
appendChild.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
import fs from 'fs';
import chokidar from 'chokidar';
import {basename} from 'path';
export default function appendChild (tag){
return function(parent, child) {
console.log(`append ${tag} child`,{parent,child});
if(parent.type=='folder'){
if(!parent.path){
var path = parent.props.name;
fs.mkdirSync(`./wd/${path}`);
parent.path = path;
}
}
if(parent.type=='folder' && child.type=='file'){
var newLocation = `./wd/${parent.path}/${child.props.name}`;
fs.linkSync(child.realPath,newLocation);
try{
fs.unlinkSync(child.realPath);
} catch(e){
}
fs.linkSync(`./wd/${parent.path}/${child.props.name}`,child.realPath);
} else if (parent.type=='folder' && child.type=='folder'){
if(child.path){
fs.renameSync(`./wd/${child.path}`,`./wd/${parent.path}/${child.path}`);
} else {
fs.mkdirSync(`./wd/${parent.path}/${child.props.name}`);
}
child.path = `${parent.path}/${child.props.name}`;
}
}
}