|
|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
let path = require('path')
|
|
|
|
|
|
|
|
|
|
let fs = require('fs');
|
|
|
|
|
|
|
|
|
|
let shell = require('electron').shell;
|
|
|
|
|
let fileExtensionToImage: object;
|
|
|
|
|
|
|
|
|
|
export class Configurator {
|
|
|
|
|
@ -88,7 +88,7 @@ export class DocumentDirectory {
|
|
|
|
|
* you *must* provide an absolute file path here
|
|
|
|
|
*/
|
|
|
|
|
constructor(filePath: string) {
|
|
|
|
|
this.root = new DirectoryNode(filePath);
|
|
|
|
|
this.root = new DirectoryNode(filePath, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
root: DirectoryNode;
|
|
|
|
|
@ -97,21 +97,23 @@ export class DocumentDirectory {
|
|
|
|
|
|
|
|
|
|
export class FileNode {
|
|
|
|
|
filePath: string;
|
|
|
|
|
parent: FileNode;
|
|
|
|
|
|
|
|
|
|
constructor(filePath: string) {
|
|
|
|
|
constructor(filePath: string, parent: FileNode) {
|
|
|
|
|
this.filePath = filePath;
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
open() {
|
|
|
|
|
|
|
|
|
|
shell.open(this.filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DirectoryNode extends FileNode {
|
|
|
|
|
children: FileNode[] = [];
|
|
|
|
|
|
|
|
|
|
constructor(filePath: string) {
|
|
|
|
|
super(filePath);
|
|
|
|
|
constructor(filePath: string, parent: FileNode) {
|
|
|
|
|
super(filePath, parent);
|
|
|
|
|
if (fs.existsSync(filePath)) {
|
|
|
|
|
let stats = fs.lstatSync(filePath);
|
|
|
|
|
if (stats.isDirectory()) {
|
|
|
|
|
@ -120,27 +122,37 @@ export class DirectoryNode extends FileNode {
|
|
|
|
|
let childPath = path.join(filePath, contents[i]);
|
|
|
|
|
let childStats = fs.lstatSync(childPath);
|
|
|
|
|
if (childStats.isDirectory()) {
|
|
|
|
|
this.children.push(new DirectoryNode(childPath));
|
|
|
|
|
this.children.push(new DirectoryNode(childPath, this));
|
|
|
|
|
} else {
|
|
|
|
|
this.children.push(new DocumentNode(childPath));
|
|
|
|
|
this.children.push(new DocumentNode(childPath, this));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw Error(`attempted to scan non-directory: ${filePath}`);
|
|
|
|
|
throw new DirectoryIsActuallyFileError(filePath);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw Error(`attempted to load document directory for non-existing directory: ${filePath}`);
|
|
|
|
|
throw new DirectoryDoesNotExistError(filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DocumentNode extends FileNode {
|
|
|
|
|
constructor(filePath: string, parent: FileNode) {
|
|
|
|
|
super(filePath, parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(filePath: string) {
|
|
|
|
|
super(filePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DirectoryIsActuallyFileError extends Error {
|
|
|
|
|
constructor(filePath: string) {
|
|
|
|
|
super(`attempted to scan non-directory: ${filePath}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DirectoryDoesNotExistError extends Error {
|
|
|
|
|
constructor(filePath: string) {
|
|
|
|
|
super(`attempted to load document directory for non-existing directory: ${filePath}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|