forked from Kode/khamake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExporter.js
48 lines (38 loc) · 1.03 KB
/
Exporter.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
"use strict";
const Files = require('./Files.js');
const Paths = require('./Paths.js');
const fs = require('fs');
class Exporter {
constructor() {
}
writeFile(file) {
this.out = fs.openSync(file.toString(), 'w');
}
closeFile() {
fs.closeSync(this.out);
}
p(line, indent) {
if (line === undefined) line = '';
if (indent === undefined) indent = 0;
let tabs = '';
for (let i = 0; i < indent; ++i) tabs += '\t';
let data = new Buffer(tabs + line + '\n');
fs.writeSync(this.out, data, 0, data.length, null);
}
copyFile(from, to) {
Files.copy(from, to, true);
}
copyDirectory(from, to) {
this.createDirectory(to);
let files = Files.newDirectoryStream(from);
for (let f in files) {
let file = Paths.get(from, files[f]);
if (Files.isDirectory(file)) this.copyDirectory(file, to.resolve(file));
else this.copyFile(file, to.resolve(files[f]));
}
}
createDirectory(dir) {
if (!Files.exists(dir)) Files.createDirectories(dir);
}
}
module.exports = Exporter;