diff --git a/gulpfile.js b/gulpfile.js index 679125c..bd9b8a3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -10,6 +10,7 @@ let tsSource = ts.createProject('tsconfig.json') function clean(cb) { del(['build/*']); + del(['out/*']); cb(); } @@ -45,6 +46,10 @@ function validateConfigSources(cb) { cb(); } +let deploy = () => { + +}; + function conf() { return src(['src/assets/**/*', '!src/assets/**/*.scss'], {base: 'src/assets'}) .pipe(dest('build/assets/')); @@ -112,7 +117,6 @@ let validationRules = { "description": stringLengthRule } } - } @@ -124,3 +128,4 @@ exports.tests = series(validateConfigSources, conf, style, scss, root, pkg, type exports.runFast = series(validateConfigSources, conf, style, scss, root, pkg) +exports.deploy = series(clean, validateConfigSources, conf, style, scss, root, pkg, typescript, dependencies, deploy); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 68fb319..d6b56cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -871,9 +871,9 @@ } }, "base64-js": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", - "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", "dev": true }, "bcrypt-pbkdf": { @@ -4879,9 +4879,9 @@ } }, "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", "dev": true }, "yargs": { @@ -5394,9 +5394,9 @@ } }, "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", "dev": true }, "yargs": { @@ -5864,14 +5864,14 @@ } }, "plist": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/plist/-/plist-3.0.1.tgz", - "integrity": "sha512-GpgvHHocGRyQm74b6FWEZZVRroHKE1I0/BTjAmySaohK+cUn+hZpbqXkc3KWgW3gQYkqcQej35FohcT0FRlkRQ==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/plist/-/plist-3.0.2.tgz", + "integrity": "sha512-MSrkwZBdQ6YapHy87/8hDU8MnIcyxBKjeF+McXnr5A9MtffPewTs7G3hlpodT5TacyfIyFTaJEhh3GGcmasTgQ==", "dev": true, "requires": { - "base64-js": "^1.2.3", + "base64-js": "^1.5.1", "xmlbuilder": "^9.0.7", - "xmldom": "0.1.x" + "xmldom": "^0.5.0" } }, "plugin-error": { @@ -6461,9 +6461,9 @@ } }, "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", "dev": true }, "yargs": { @@ -7690,9 +7690,9 @@ "dev": true }, "xmldom": { - "version": "0.1.31", - "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.31.tgz", - "integrity": "sha512-yS2uJflVQs6n+CyjHoaBmVSqIDevTAWrzMmjG1Gc7h1qQ7uVozNhEPJAwZXWyGQ/Gafo3fCwrcaokezLPupVyQ==", + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.5.0.tgz", + "integrity": "sha512-Foaj5FXVzgn7xFzsKeNIde9g6aFBxTPi37iwsno8QvApmtg7KYrr+OPyRHcJF7dud2a5nGRBXK3n0dL62Gf7PA==", "dev": true }, "xtend": { diff --git a/package.json b/package.json index 8e6f233..2db982e 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,10 @@ "start-fast": "gulp runFast && electron ./build --debug", "dev": "npm run build && electron ./build --debug", "package": "npm-run-all package:*", - "package:mac": "electron-packager ./build --overwrite --platform=darwin --arch=x64 --out=out --icon=assets/images/app.icns --osx-sign.identity='Developer ID Application: GitHub' --extend-info=assets/mac/info.plist", - "package:win32": "electron-packager ./build --overwrite --platform=win32 --arch=ia32 --out=out --icon=assets/images/app.ico", - "package:win64": "electron-packager ./build --overwrite --platform=win32 --arch=x64 --out=out --icon=assets/images/app.ico", - "package:linux": "electron-packager ./build --overwrite --platform=linux --arch=x64 --out=out", + "package:mac": "electron-packager ./build --overwrite --platform=darwin --arch=x64 --out=out --icon=src/assets/images/icon.ico --osx-sign.identity='Developer ID Application: GitHub' --extend-info=assets/mac/info.plist", + "package:win32": "electron-packager ./build --overwrite --platform=win32 --arch=ia32 --out=out --icon=src/assets/images/icon.ico", + "package:win64": "electron-packager ./build --overwrite --platform=win32 --arch=x64 --out=out --icon=src/assets/images/icon.ico", + "package:linux": "electron-packager ./build --overwrite --platform=linux --arch=x64 --out=out --icon=src/assets/images/icon.ico", "package:installer": "node ./script/installer.js", "release": "node ./script/release.js", "prepack": "check-for-leaks", diff --git a/src/assets/images/icon.ico b/src/assets/images/icon.ico new file mode 100644 index 0000000..2badb37 Binary files /dev/null and b/src/assets/images/icon.ico differ diff --git a/src/assets/images/icon.png b/src/assets/images/icon.png new file mode 100644 index 0000000..a1ba298 Binary files /dev/null and b/src/assets/images/icon.png differ diff --git a/src/index.js b/src/index.js index 9cd4d7d..e217e45 100644 --- a/src/index.js +++ b/src/index.js @@ -2,19 +2,54 @@ require('update-electron-app')({ logger: require('electron-log') }) +const updateCheckInterval = 1000 * 60 + const path = require('path') -const {app, BrowserWindow} = require('electron') +const {app, BrowserWindow, autoUpdater} = require('electron') + +const server = 'https://update.jdsconsulting.net' +const url = `${server}/update/${process.platform}/${app.getVersion()}` + +autoUpdater.setFeedURL({url}) + +autoUpdater.checkForUpdates(); +setInterval(() => { + console.log("Checking for update..."); + autoUpdater.checkForUpdates(); +}, updateCheckInterval) + +autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => { + console.log("Handling updates...") + const dialogOpts = { + type: 'info', + buttons: ['Restart', 'Later'], + title: 'Application Update', + message: process.platform === 'win32' ? releaseNotes : releaseName, + detail: 'A new version has been downloaded. Restart the application to apply the updates.' + } + + dialog.showMessageBox(dialogOpts).then((returnValue) => { + if (returnValue.response === 0) autoUpdater.quitAndInstall() + }) +}) + +autoUpdater.on('error', message => { + console.error('There was a problem updating the application') + console.error(message) +}) + + const debug = /--debug/.test(process.argv[2]) -if (process.mas) app.setName('JDSfaulkner Portal') +if (process.mas) app.setName('JDS Consulting Portal') let mainWindow = null -function initialize () { +function initialize() { makeSingleInstance() - function createWindow () { + function createWindow() { const windowOptions = { width: 1080, minWidth: 769, @@ -69,7 +104,7 @@ function initialize () { // // Returns true if the current version of the app should quit instead of // launching. -function makeSingleInstance () { +function makeSingleInstance() { if (process.mas) return app.requestSingleInstanceLock() diff --git a/src/ts_source/fileutils.ts b/src/ts_source/fileutils.ts index be7fafb..a7c3d86 100644 --- a/src/ts_source/fileutils.ts +++ b/src/ts_source/fileutils.ts @@ -1,5 +1,6 @@ let path = require('path') let fs = require('fs'); +let os = require('os'); const shell = require('electron').shell; let fileExtensionToImage: object; @@ -59,6 +60,7 @@ export module FileUtils { export function getPathToView(templateName: string): string { return path.join(getPathToAssets(), "views", templateName + ".mustache") } + export function getPathToPage(pageName: string): string { return path.join(getPathToAssets(), "pages", pageName) } @@ -95,6 +97,34 @@ export module FileUtils { fs.mkdirSync(dirPath); } } + + export function showFileInDir(resourcePath: string) { + let localFile = copyFileToUserDocuments(resourcePath); + shell.showItemInFolder(localFile); + } + + /** + * @param resourcePath pathlike of system resource + * @private + * @returns pathlike of local user resource + */ + function copyFileToUserDocuments(resourcePath: string): string { + let fileName = path.basename(resourcePath); + let userFilePath = getPathToUserDocumentDir(fileName); + if(!fs.existsSync(userFilePath)){ + fs.copyFileSync(resourcePath, userFilePath); + } + return userFilePath; + } + + function getPathToUserDocumentDir(fileName: string): string { + let homeDir = os.homedir(); + let parent = path.join(homeDir, "Documents", "Employee Resources"); + if(!fs.existsSync(parent)){ + fs.mkdirSync(parent); + } + return path.join(parent, fileName); + } } @@ -114,27 +144,24 @@ export class DocumentDirectory { private static walkCards(d: DirectoryNode): Map { let cardsByCategory = new Map(); - for (let i = 0, l = d.children.length; i < l; i++) { - let child = d.children[i]; + for (let child of d.children) { if (child instanceof DirectoryNode) { let dir = child as DirectoryNode; if (dir.containsDirectory()) { let childDirectories = dir.getDirectories(); - for (let j = 0, k = childDirectories.length; j < k; j++) { - let dir = childDirectories[j]; + for (let dir of childDirectories) { let subCards = DocumentDirectory.walkCards(dir); this.mergeMaps(cardsByCategory, subCards); } } let sCards = dir.getDocuments(); let category = dir.getCategory(); - for (let sCard in sCards) { - let scrd = sCards[sCard]; + for (let sCard of sCards) { let cards = cardsByCategory.get(category); if (cards === undefined || cards === null) { cards = []; } - cards.push(scrd.toCard()); + cards.push(sCard.toCard()); cardsByCategory.set(category, cards); } } else { @@ -153,8 +180,7 @@ export class DocumentDirectory { private static mergeMaps(a: Map, b: Map) { let keys = Object.keys(b); - for (let z in keys) { - let key = keys[z]; + for (let key of keys) { let sa = a.get(key) if (sa === undefined || sa === null) { sa = []; @@ -192,8 +218,7 @@ export class FileNode { private static getImagePathFromDocumentName(name: string): string { let ext = FileUtils.getFileExtension(name); - let thumbnail = Configurator.getFileExtensionToImageMap()[ext]; - return thumbnail; + return Configurator.getFileExtensionToImageMap()[ext]; } open() { @@ -213,12 +238,12 @@ export class FileNode { "imagePath": imageName, "urlText": this.filePath, "altText": "", - "fileCard": true + "fileCard": true, + "open": this.open } let altKeys = Object.keys(altProps); - for (let kidx in altKeys) { - let key = altKeys[kidx]; + for (let key of altKeys) { cardObj[key] = altProps[key] } @@ -251,9 +276,9 @@ export class DirectoryNode extends FileNode { let stats = fs.lstatSync(filePath); if (stats.isDirectory()) { let contents = fs.readdirSync(filePath); - for (let i = 0, l = contents.length; i < l; i++) { - if (path.extname(contents[i]) === ".json") continue; - let childPath = path.join(filePath, contents[i]); + for (let fileName of contents) { + if (path.extname(fileName) === ".json") continue; + let childPath = path.join(filePath, fileName); let childStats = fs.lstatSync(childPath); if (childStats.isDirectory()) { this.children.push(new DirectoryNode(childPath, this)); @@ -282,8 +307,7 @@ export class DirectoryNode extends FileNode { } containsDirectory(): Boolean { - for (let i = 0, l = this.children.length; i < l; i++) { - let child = this.children[i]; + for (let child of this.children) { if (child instanceof DirectoryNode) return true; } return false diff --git a/src/ts_source/search.ts b/src/ts_source/search.ts index e19d676..d651f05 100644 --- a/src/ts_source/search.ts +++ b/src/ts_source/search.ts @@ -14,7 +14,7 @@ function register() { search(term); } - }else{ + } else { let term = searchBar.val().toString(); if (!term || 0 === term.length) { reset() @@ -23,7 +23,7 @@ function register() { }); - searchButton.on("click", ()=>{ + searchButton.on("click", () => { let term = searchBar.val().toString(); if (!term || 0 === term.length) { reset() @@ -33,7 +33,7 @@ function register() { }) } -function reset(){ +function reset() { buildUiFromConfig("resources-landing-page.json"); } @@ -47,7 +47,7 @@ function search(term: string) { expandAllContainers(); } -function copyMissingKeys(webCards: object, fileCards: Map){ +function copyMissingKeys(webCards: object, fileCards: Map) { let elementConfig = Configurator.loadAppConfig("resources-landing-page.json"); let containerKeys = Object.keys(elementConfig); for (let containerKey of containerKeys) { @@ -127,8 +127,14 @@ function addToFileMap(map: Map, categoryKey: string, card) { function cardContainsTerm(term: string, card: object): boolean { let titleContains = card["title"].toLowerCase().includes(term.toLowerCase()); let descriptionContains = card["description"].toLowerCase().includes(term.toLowerCase()); + + let keywordContains = false; + if (card["keywords"]) { + keywordContains = card["keywords"].toLowerCase().includes(term.toLowerCase()); + } + //todo: add keywords - return titleContains || descriptionContains; + return titleContains || descriptionContains || keywordContains; } function highlightCardTerm(term: string, card: object): object { @@ -143,9 +149,9 @@ function escapeRegExp(term: string): string { return term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string } -function expandAllContainers(){ +function expandAllContainers() { let containers = $('[id$="collapser"]') - for(let container of containers){ + for (let container of containers) { container.click() } diff --git a/src/ts_source/viewFactory.ts b/src/ts_source/viewFactory.ts index f89ef73..4860c48 100644 --- a/src/ts_source/viewFactory.ts +++ b/src/ts_source/viewFactory.ts @@ -37,15 +37,19 @@ export function buildFileCard(elem: JQuery, obj, append: boolean = elem.html(content) } - if (model["show"] !== undefined) { - $(`#${id}`).on("click", () => { - shell.showItemInFolder(model.resourcePath) - }); - } else { - $(`#${id}`).on("click", () => { - shell.openItem(model.resourcePath) - }); - } + $(`#${id}`).on("click", () => { + FileUtils.showFileInDir(model.resourcePath); + }); + + // if (model["show"] !== undefined) { + // $(`#${id}`).on("click", () => { + // shell.showItemInFolder(model.resourcePath) + // }); + // } else { + // $(`#${id}`).on("click", () => { + // shell.openItem(model.resourcePath) + // }); + // } }); }