file-specific configs implemented

pull/3/head
David Tookey 5 years ago
parent 3c4db7d05e
commit 844a26e2a1

@ -0,0 +1,5 @@
{
"description": "Coming soon pdf",
"imagePath": "../resources/coming-soon.pdf",
"show": true
}

@ -1,3 +1,5 @@
let path = require('path')
let fs = require('fs');
const shell = require('electron').shell;
@ -107,7 +109,6 @@ export class DocumentDirectory {
getCards(): object {
return DocumentDirectory.walkCards(this.root);
}
private static walkCards(d: DirectoryNode): Map<String, object[]> {
@ -124,7 +125,17 @@ export class DocumentDirectory {
this.mergeMaps(cardsByCategory, subCards);
}
}
let sCards = dir.getDocuments()
let sCards = dir.getDocuments();
let category = dir.getCategory();
for (let sCard in sCards) {
let scrd = sCards[sCard];
let cards = cardsByCategory.get(category);
if (cards === undefined || cards === null) {
cards = [];
}
cards.push(scrd.toCard());
cardsByCategory.set(category, cards);
}
} else {
let category = (child.parent as DirectoryNode).getCategory();
let cards = cardsByCategory.get(category);
@ -148,7 +159,7 @@ export class DocumentDirectory {
sa = [];
}
let sb = b.get(key)
if (sb === undefined || sa === null) {
if (sb === undefined) {
sb = [];
}
sa.push(...sb);
@ -168,24 +179,50 @@ export class FileNode {
this.parent = parent;
}
static loadAltProps(path: String): object {
let props = {};
let jsonPath = path + ".json"
if (fs.existsSync(jsonPath)) {
let raw = fs.readFileSync(jsonPath);
props = JSON.parse(raw.toString());
}
return props
}
open() {
shell.openItem(this.filePath);
}
show() {
shell.showItemInFolder(this.filePath);
}
toCard(): object {
let altProps = FileNode.loadAltProps(this.filePath)
let cardObj = {
"title": this.getTitle(),
"description": "",
"imagePath": "",
"urlText": this.filePath,
"altText": ""
"altText": "",
"fileCard": true
}
let altKeys = Object.keys(altProps);
for (let kidx in altKeys) {
let key = altKeys[kidx];
cardObj[key] = altProps[key]
}
return cardObj
}
getTitle(): String {
let name = path.basename(this.filePath);
return name
let ext = path.extname(name);
let cName = name.replace(ext, "");
cName = cName.replace(/[\-._]/ig, " ")
return `${cName} (${ext.substr(1).toUpperCase()})`
}
isDescriptor() {

@ -2,12 +2,13 @@ import {DocumentDirectory, FileNode} from "../src/ts_source/fileutils";
const path = require('path');
const chai = require('chai');
const {performance} = require('perf_hooks');
describe('fileutils', () => {
it('DocumentDirectory Constructor fail-on-not-exist', testDocumentDirectoryFailNoExist)
it('DocumentDirectory Constructor fail-on-file', testDocumentDirectoryFailFile)
it('documentDirectoryConstructor - debug', testDocumentDirectoryConstructor);
it('pass by test', passBy);
});
function testDocumentDirectoryFailNoExist() {
@ -26,21 +27,10 @@ function testDocumentDirectoryFailFile() {
function testDocumentDirectoryConstructor() {
let directoryPath = path.join(__dirname, "../src/assets/resources");
let start = performance.now()
let documents = new DocumentDirectory(directoryPath);
documents.getCards()
}
function passBy(){
let a = ["a", "b"];
let b = ["c", "d"];
testCopy(a, b);
for(let c in a){
console.log(c);
}
}
let end = performance.now()
console.log(documents.getCards());
console.log(`Execution time: ${end-start}ms`)
function testCopy(a: String[], b: String[]){
a.push(...b);
}

Loading…
Cancel
Save