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

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

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

@ -5,8 +5,6 @@ import {WebUtils} from "./webutils"
const shell = require('electron').shell;
const config = new Configurator();
const fu = new FileUtils();
export class CardModel {
imagePath: string;
@ -108,13 +106,13 @@ function fileNameToPrettyString(fileName: string): string {
}
function getImagePathFromDocumentName(name: string): string {
let ext = fu.getFileExtension(name);
let ext = FileUtils.getFileExtension(name);
let thumbnail = config.getFileExtensionToImageMap()[ext];
return fu.getPathToImage(thumbnail);
return FileUtils.getPathToImage(thumbnail);
}
function launchDocument(filename: string) {
let fullPath = fu.getPathToDocument(filename);
let fullPath = FileUtils.getPathToDocument(filename);
console.log(`Attempting to open file: ${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": {
"module": "commonjs",
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true
},
"exclude": [

Loading…
Cancel
Save