-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathkatacodaAssetManager.ts
52 lines (45 loc) · 1.95 KB
/
katacodaAssetManager.ts
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
import { KatacodaAsset, AssetManagerData } from "./katacodaInterfaces";
import * as fs from 'fs';
import * as path from 'path';
export class KatacodaAssetManager {
private assetDirectory: string;
private assetData: AssetManagerData[] = [];
private katacodaAssets: KatacodaAsset[] = [];
constructor(assetDir: string) {
this.assetDirectory = assetDir;
}
registerFile(filepathSource: string, filepathTarget: string, katacodaDirectory: string, copyFile: boolean, copyIntoKatacodaEnvironment: boolean) {
this.assetData.push({
sourcePath: filepathSource,
targetPath: filepathTarget,
katacodaDirectory: katacodaDirectory,
copyFile: copyFile
});
if(copyIntoKatacodaEnvironment) {
this.katacodaAssets.push({
file: filepathTarget.replace(/\\/g, "/"),
target: katacodaDirectory.replace(/\\/g, "/")
})
}
}
registerDirectory(directorySource: string, filepathTarget: string, katacodaDirectory: string, copyFile: boolean, copyIntoKatacodaEnvironment: boolean) {
let dir = fs.readdirSync(directorySource);
dir.forEach(file => {
if(fs.lstatSync(path.join(directorySource, file)).isDirectory()) {
this.registerDirectory(path.join(directorySource, file), filepathTarget, katacodaDirectory, copyFile, copyIntoKatacodaEnvironment);
} else {
this.registerFile(path.join(directorySource, file), path.join(filepathTarget, file), katacodaDirectory, copyFile, copyIntoKatacodaEnvironment);
}
});
}
getKatacodaAssets() {
return this.katacodaAssets;
}
copyAssets() {
for(let i = 0; i < this.assetData.length; i++) {
if(this.assetData[i].copyFile) {
fs.copyFileSync(this.assetData[i].sourcePath, path.join(this.assetDirectory, this.assetData[i].targetPath));
}
}
}
}