removed jest because it was screwing things up

build-validation
David Tookey 5 years ago
parent 6a5d479dd8
commit 747aa51359

9077
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -9,9 +9,10 @@
"url": "git://github.com/username/repository.git" "url": "git://github.com/username/repository.git"
}, },
"scripts": { "scripts": {
"test": "jest", "test": "jest --verbose",
"clean": "gulp clean", "clean": "gulp clean",
"build": "gulp", "build": "gulp",
"ts-compile": "tsc --outDir build/util",
"start": "npm run build && electron ./build", "start": "npm run build && electron ./build",
"start-fast": "gulp runFast && electron ./build", "start-fast": "gulp runFast && electron ./build",
"dev": "npm run build && electron ./build --debug", "dev": "npm run build && electron ./build --debug",
@ -42,18 +43,15 @@
"bootstrap": "^4.5.3" "bootstrap": "^4.5.3"
}, },
"devDependencies": { "devDependencies": {
"@types/jquery": "^3.5.1",
"devtron": "^1.4.0", "devtron": "^1.4.0",
"electron": "^7.2.4", "electron": "^7.2.4",
"electron-settings": "^3.0.7", "electron-settings": "^3.0.7",
"electron-shortcut-normalizer": "^1.0.0", "electron-shortcut-normalizer": "^1.0.0",
"electron-packager": "^15.1.0", "electron-packager": "^15.1.0",
"@types/jquery": "^3.5.1",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-typescript": "^6.0.0-alpha.1", "gulp-typescript": "^6.0.0-alpha.1",
"gulp-exec": "^5.0.0", "gulp-exec": "^5.0.0",
"del": "^6.0.0", "del": "^6.0.0"
"jest": "^26.6.1",
"ts-jest": "^26.4.2",
"@types/jest": "^26.0.15"
} }
} }

@ -6,8 +6,6 @@ let fileExtensionToImage: object;
export class Configurator { export class Configurator {
fileutils: FileUtils = new FileUtils();
getFileExtensionToImageMap(): Object { getFileExtensionToImageMap(): Object {
if (!fileExtensionToImage) { if (!fileExtensionToImage) {
fileExtensionToImage = this.loadAppConfig("file-extensions.json"); fileExtensionToImage = this.loadAppConfig("file-extensions.json");
@ -16,14 +14,14 @@ export class Configurator {
}; };
loadAppConfig(fileName: string): object { loadAppConfig(fileName: string): object {
let filePath = this.fileutils.getPathToConfig(fileName); let filePath = FileUtils.getPathToConfig(fileName);
let fileBuffer = fs.readFileSync(filePath); let fileBuffer = fs.readFileSync(filePath);
let content = fileBuffer.toString('utf8') let content = fileBuffer.toString('utf8')
return JSON.parse(content) return JSON.parse(content)
} }
loadUserConfig(fileName: string): object { loadUserConfig(fileName: string): object {
let userConfigPath = this.fileutils.getPathToUserDir(fileName); let userConfigPath = FileUtils.getPathToUserDir(fileName);
if (!fs.existsSync(userConfigPath)) { if (!fs.existsSync(userConfigPath)) {
return {}; return {};
} else { } else {
@ -33,7 +31,7 @@ export class Configurator {
} }
saveUserConfig(fileName: string, obj: any) { saveUserConfig(fileName: string, obj: any) {
let userConfigPath = this.fileutils.getPathToUserDir(fileName); let userConfigPath = FileUtils.getPathToUserDir(fileName);
let content = JSON.stringify(obj); let content = JSON.stringify(obj);
fs.writeFile(userConfigPath, content, (err) => { fs.writeFile(userConfigPath, content, (err) => {
if (err) { if (err) {
@ -45,81 +43,104 @@ export class Configurator {
} }
export class FileUtils { export module FileUtils {
getPathToView(templateName: string): string { export function getPathToView(templateName: string): string {
return path.join(this.getPathToAssets(), "views", templateName + ".mustache") return path.join(this.getPathToAssets(), "views", templateName + ".mustache")
} }
getPathToImage(imageName: string): string { export function getPathToImage(imageName: string): string {
return path.join(this.getPathToAssets(), "images", imageName) return path.join(this.getPathToAssets(), "images", imageName)
} }
getPathToDocument(documentName: string): string { export function getPathToDocument(documentName: string): string {
return path.join(this.getPathToAssets(), "documents", documentName) return path.join(this.getPathToAssets(), "documents", documentName)
} }
getPathToConfig(documentName: string): string { export function getPathToConfig(documentName: string): string {
return path.join(this.getPathToAssets(), "conf", documentName) return path.join(this.getPathToAssets(), "conf", documentName)
} }
getPathToAssets(): string { export function getPathToAssets(): string {
return path.join(__dirname, "..", "assets"); return path.join(__dirname, "..", "assets");
} }
getFileExtension(fileName: string): string { export function getFileExtension(fileName: string): string {
return path.extname(fileName); return path.extname(fileName);
} }
getPathToUserDir(fileName: string): string { export function getPathToUserDir(fileName: string): string {
let dirPath = path.join(__dirname, "..", "user"); let dirPath = path.join(__dirname, "..", "user");
let filePath = path.join(dirPath, fileName); let filePath = path.join(dirPath, fileName);
this.touchDir(dirPath); this.touchDir(dirPath);
return filePath; return filePath;
} }
touchDir(dirPath: string) { export function touchDir(dirPath: string) {
if (!fs.existsSync(dirPath)) { if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath); fs.mkdirSync(dirPath);
} }
} }
} }
export class DocumentDirectory { export class DocumentDirectory {
constructor(filepath: string) { /**
if (fs.existsSync(filepath)) { * you *must* provide an absolute file path here
let stats = fs.lstatSync(filepath); */
if (stats.isDirectory()) { constructor(filePath: string) {
let contents = fs.readdirSync(filepath); this.root = new DirectoryNode(filePath);
for (let i = 0, l = contents.length; i < l; i++) {
console.log(contents[i]);
}
} else {
throw Error("attempted to scan non-directory");
}
} else {
throw Error("attempted to load document directory for non-existing directory");
}
} }
children: FileNode[]; root: DirectoryNode;
} }
export class FileNode { export class FileNode {
filePath: string;
constructor(filePath: string) {
this.filePath = filePath;
}
open() {
}
} }
export class DirectoryNode extends FileNode { export class DirectoryNode extends FileNode {
constructor() { children: FileNode[] = [];
super();
}
children: FileNode[]; constructor(filePath: string) {
super(filePath);
if (fs.existsSync(filePath)) {
let stats = fs.lstatSync(filePath);
if (stats.isDirectory()) {
let contents = fs.readdirSync(filePath);
for (let i = 0, l = contents.length; i < l; i++) {
let childPath = path.join(filePath, contents[i]);
let childStats = fs.lstatSync(childPath);
if (childStats.isDirectory()) {
this.children.push(new DirectoryNode(childPath));
} else {
this.children.push(new DocumentNode(childPath));
}
}
} else {
throw Error(`attempted to scan non-directory: ${filePath}`);
}
} else {
throw Error(`attempted to load document directory for non-existing directory: ${filePath}`);
}
}
} }
export class DocumentNode extends FileNode { export class DocumentNode extends FileNode {
constructor(filePath: string) {
super(filePath);
}
} }

@ -13,8 +13,7 @@ interface TemplateCallbackType {
const templateCache = {}; const templateCache = {};
export function cacheTemplates() { export function cacheTemplates() {
let fu = new FileUtils(); let basePath = path.join(FileUtils.getPathToAssets(), "views");
let basePath = path.join(fu.getPathToAssets(), "views");
fs.readdirSync(basePath) fs.readdirSync(basePath)
.forEach((file) => { .forEach((file) => {
templateCache[file] = fs.readFileSync(path.join(basePath.toString(), file)).toString(); templateCache[file] = fs.readFileSync(path.join(basePath.toString(), file)).toString();

@ -5,8 +5,6 @@ import {WebUtils} from "./webutils"
const shell = require('electron').shell; const shell = require('electron').shell;
const config = new Configurator(); const config = new Configurator();
const fu = new FileUtils();
export class CardModel { export class CardModel {
imagePath: string; imagePath: string;
@ -108,13 +106,13 @@ function fileNameToPrettyString(fileName: string): string {
} }
function getImagePathFromDocumentName(name: string): string { function getImagePathFromDocumentName(name: string): string {
let ext = fu.getFileExtension(name); let ext = FileUtils.getFileExtension(name);
let thumbnail = config.getFileExtensionToImageMap()[ext]; let thumbnail = config.getFileExtensionToImageMap()[ext];
return fu.getPathToImage(thumbnail); return FileUtils.getPathToImage(thumbnail);
} }
function launchDocument(filename: string) { function launchDocument(filename: string) {
let fullPath = fu.getPathToDocument(filename); let fullPath = FileUtils.getPathToDocument(filename);
console.log(`Attempting to open file: ${fullPath}`); console.log(`Attempting to open file: ${fullPath}`);
shell.openItem(fullPath); shell.openItem(fullPath);
} }

@ -0,0 +1,13 @@
import {DocumentDirectory} from "../src/ts_source/fileutils";
const path = require('path');
describe('fileutils', ()=>{
it('documentDirectoryConstructor', testDocumentDirectoryConstructor);
});
function testDocumentDirectoryConstructor(){
let directoryPath = path.join(__dirname, "../src/assets/documents");
let documents = new DocumentDirectory(directoryPath);
let firstChild = documents.root.children[0];
}

@ -1,8 +1,9 @@
{ {
"files": ["src/ts_source/*.ts"], "include": ["src/ts_source/*.ts"],
"compilerOptions": { "compilerOptions": {
"module": "commonjs",
"target": "es6", "target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true "sourceMap": true
}, },
"exclude": [ "exclude": [

Loading…
Cancel
Save