nw-skeleton

Class: FileManager

appWrapper. FileManager

A class for file operations

FileManager()

Creates FileManager instance

Properties

Name Type Description
watchedFiles array An array with absolute watched file paths
watched Object Object that stores references to unwatch methods for watched files

Extends

Methods

_doLog(debugMessage){undefined}

Parameters

Name Type Description
debugMessage Object Message object to be logged (returned by this.getMessageObject method)

Return

Does actual logging to console (and log file is file logging is enabled)

addBoundMethods(){undefined}

Return

Method that sets up this.boundMethods property by binding this objects functions to itself to be used as event listener handlers

addDesktopNotification(message, data, dontTranslate, options, callbacks){undefined}

Parameters

Name Type Description
message string Notification message
data array An array of data strings that are to be applied to notification
dontTranslate Boolean Flag to prevent automatic notification translation
options Object Desktop notification options (passed to HTML5 Notification object constructor)
callbacks Object Object with onshow, onClicked, onClosed and onerror notification handlers

Return

Displays desktop notification Notification message is being interpolated by replacing placeholders such as '{1}', '{2}' etc. by corresponding values from 'data' argument

addModalMessage(message, type, data, important, dontTranslate, force, passToDebug){undefined}

Parameters

Name Type Description
message string Message to be logged
type string Type of log message (debug, info, warning, error)
data array An array of data strings that are to be applied to logging message
important Boolean Flag to indicate message importance
dontTranslate Boolean Flag to prevent automatic message translation
force Boolean Flag to force message output even if configuration wouldn't allow it
passToDebug Boolean Flag to force passing same message to debug log

Return

Adds modal message to currently open modal dialog Message is being interpolated by replacing placeholders such as '{1}', '{2}' etc. by corresponding values from 'data' argument

addNotification(message, type, data, dontTranslate, options){undefined}

Parameters

Name Type Description
message string Notification message
type string Notification message type
data array An array of data strings that are to be applied to notification
dontTranslate Boolean Flag to prevent automatic notification translation
options Object Additional notification options

Return

Displays app notification Notification message is being interpolated by replacing placeholders such as '{1}', '{2}' etc. by corresponding values from 'data' argument

addUserMessage(message, type, data, important, dontTranslate, force, passToDebug){undefined}

Parameters

Name Type Description
message string Message to be logged
type string Type of log message (debug, info, warning, error)
data array An array of data strings that are to be applied to logging message
important Boolean Flag to indicate message importance
dontTranslate Boolean Flag to prevent automatic message translation
force Boolean Flag to force message output even if configuration wouldn't allow it
passToDebug Boolean Flag to force passing same message to debug log

Return

Logs user message if conditions are met Message is being interpolated by replacing placeholders such as '{1}', '{2}' etc. by corresponding values from 'data' argument

asyncMessage(data){mixed}

Parameters

Name Type Description
data Object Message data object

Return

Emits 'asyncMessage' global event, listened by main script

asyncMessageInfo(data, verboseOutput){Object}

Parameters

Name Type Description
data Object Message data.data object
verboseOutput Boolean Toggles verbose output

Return

Returns info on async messages that can be passed to mainScript

copyDirRecursive(sourceDir, destinationDir){Boolean}

Parameters

Name Type Description
sourceDir string Source directory
destinationDir string Destination directory

Return

Copies source directory (with subdirs and files) to destination directory

copyFile(sourceFile, destinationFile){Boolean}

Parameters

Name Type Description
sourceFile string Source file path
destinationFile string Destination file path

Return

Copies single file from source to destination

createDirFileRecursive(fileName, mode, options, data){Boolean}

Parameters

Name Type Description
fileName string Absolute path to file
mode Number Octal mode definition (i.e. 0o775)
options Object Options object for fs.writeFileSync
data string Data to write to file

Return

Creates directory (recursive) and writes file to it

createDirRecursive(directory, mode){Boolean}

Parameters

Name Type Description
directory string Absolute directory path
mode Number Octal mode definition (i.e. 0o775)

Return

Creates directory recursively

finalize(){Boolean}

Return

Finalizes current class instance, setting up any additional properties etc. Entire app structure, including frontend app is available here

getConfig(name, defaultValue){mixed}

Parameters

Name Type Description
name string String representing path to requested var (i.e. 'appConfig.appInfo.name')
defaultValue mixed Default value to be returned if configuration var is not found

Return

Returns configuration var value

getDebugMessageFileLine(message){string}

Parameters

Name Type Description
message obj Message object to be logged (returned by this.getMessageObject method)

Return

Returns string representing log line for appending to debug log file

getFirstFileFromDirs(fileName, dirs){string|null}

Parameters

Name Type Description
fileName string File name (basename)
dirs Array.<string> An array of absolute directory paths

Return

Scans given directories for file, returning path to first one found

getHelper(name){Object}

Parameters

Name Type Description
name string Name of the helper

Return

Returns instance of helper object based on passed parameter (or false if helper can't be found)

getMessageFileLine(message){string}

Parameters

Name Type Description
message obj Message object to be logged (returned by this.getMessageObject method)

Return

Gets JSON represenation of message object for saving into log file, removing unneccessary properties and adding necessary ones

getMessageObject(messageLevel, message, type, data, important, dontTranslate, force){Object}

Parameters

Name Type Description
messageLevel int Number representing current message level (0=debug, 1=info, 2=warning, 3=error)
message string Message to be logged
type string Type of log message (debug, info, warning, error)
data array An array of data strings that are to be applied to logging message
important Boolean Flag to indicate message importance
dontTranslate Boolean Flag to prevent automatic message translation
force Boolean Flag to force message output even if configuration wouldn't allow it

Return

Returns prepared message object based on passed arguments. Message is being interpolated by replacing placeholders such as '{1}', '{2}' etc. by corresponding values from 'data' argument

getMessageObjectRow(index, messageRowData){Object}

Parameters

Name Type Description
index mixed Key or array index
messageRowData Object Message row data for logging

Return

Gets single row for tabular message logging

getStateVar(varPath, defaultValue){mixed}

Parameters

Name Type Description
varPath string String representing path to requested var (i.e. 'appData.appMainData.cancelable')
defaultValue mixed Default value to be returned if appState var is not found

Return

Returns appState var value

getTableMessageData(message){Object}

Parameters

Name Type Description
message Object Tabular data

Return

Prepares table data for tabular message logging

getUserMessageFileLine(message){string}

Parameters

Name Type Description
message obj Message object to be logged (returned by this.getMessageObject method)

Return

Returns string representing log line for appending to user message log file

globalEmit(eventName, data){undefined}

Parameters

Name Type Description
eventName String Name of the event
data Object Event data object

Return

Emits event to globalEmitter (listened by both main script and app code)

initializeLogging(options){appWrapper.AppBaseClass}

Parameters

Name Type Description
options Object Options for logging initialization (currently only 'silent' property is used, determining whether warnings should be printed if no config found)

Return

Determines whether logging for this class is regulated through configuration, setting the logging by it (or warning if there are no configuration settings for this class)

loadFile(filePath, requireFile, notSilent){string|Object}

Parameters

Name Type Description
filePath string Absolute path to file
requireFile Boolean Flag to indicate whether to require() file or return its contents as string
notSilent Boolean Flag to force logging output

Return

Loads file from argument

loadFileFromDirs(fileName, dirs, requireFile, notSilent){string|Object|boolean}

Parameters

Name Type Description
fileName string File name (basename)
dirs Array.<string> An array of absolute directory paths to search
requireFile Boolean Flag to indicate whether to require() file or return its contents as string
notSilent Boolean Flag to force logging output

Return

Scans given dirs for file and returns first file found

loadFilesFromDir(directory, extensionMatch, requireFiles, notSilent){Object}

Parameters

Name Type Description
directory string Absolute path to directory
extensionMatch string Regex string for extension matching
requireFiles Boolean Flag to indicate whether to require() files or return their contents as strings
notSilent Boolean Flag to indicate whether to log outout

Return

Loads all files from given directory that match extension regex from argument

log(message, type, data, force){undefined}

Parameters

Name Type Description
message string Message to be logged
type string Type of log message (debug, info, warning, error, group, groupCollaped, groupend)
data array An array of data strings that are to be applied to logging message
force Boolean Flag to force logging output even if config does not allow it

Return

Logs debug message if conditions are met Message is being interpolated by replacing placeholders such as '{1}', '{2}' etc. by corresponding values from 'data' argument

message(data){undefined}

Parameters

Name Type Description
data Object Event data object

Return

Emits 'message' global event, listened by main script

messageInfo(data, verboseOutput){Object}

Parameters

Name Type Description
data Object Message data.data object
verboseOutput Boolean Toggles verbose output

Return

Returns info on messages that can be passed to mainScript

messageInfoOutput(messageData, verboseOutput){undefined}

Parameters

Name Type Description
messageData Object Message response data
verboseOutput Boolean Toggles verbose output

Return

Logs messages info to console

readDir(path){Array.<string>}

Parameters

Name Type Description
path string Absolute directory path

Return

Reads file list from dir and returns it, excluding '.' and '..'

readDirRecursive(dirPath, extensionRegex){Array.<string>}

Parameters

Name Type Description
dirPath string Absolute directory path
extensionRegex string Regex for extension matching

Return

Reads recursive file list from dir and returns it, excluding all '.' and '..' entries

readFileSync(file, options){string|null}

Parameters

Name Type Description
file string Absolute path to file
options Object Options object for fs.writeFileSync

Return

Reads file from disk

setAppError(title, text, debugText, data, doNotTranslate, messageType, omitIcon){undefined}

Parameters

Name Type Description
title String App error title
text String App error text
debugText String App error debug text (shown only if debug is enabled)
data Array.<String> An array with replacement data for error title, text and debugText
doNotTranslate Boolean Flag to prevent automatic traslation of title and text
messageType String | null Type of messages to show in app-error ('user', 'debug' or null)
omitIcon Boolean Flag to control app-error icon rendering

Return

Sets (turns on) application error, triggering rendering of app-error component

translate(text, currentLanguage, data){string}

Parameters

Name Type Description
text string Text to be translated
currentLanguage string Curent language code
data array An array of data strings that are to be applied to translated message

Return

Returns translated value for passed arguments Translation is being interpolated by replacing placeholders such as '{1}', '{2}' etc. by corresponding values from 'data' argument

unwatch(filePath, listener){undefined}

Parameters

Name Type Description
filePath string Absolute path to file
listener function Method to call when file changes

Return

Removes listener that is bound to be called when file changes on disk

unWatchFile(filePath, listener){undefined}

Parameters

Name Type Description
filePath string Absolute path to file
listener function Method to call when file changes

Return

Removes listener that is bound to be called when file changes on disk

watch(filePath, options, listener){undefined}

Parameters

Name Type Description
filePath string Absolute path to file
options Object Options object for fs.watchFile
listener function Method to call when file changes

Return

Add listener that gets called when file changes on disk

watchFile(filePath, options, listener){undefined}

Parameters

Name Type Description
filePath string Absolute path to file
options Object Options object for fs.watchFile
listener function Method to call when file changes

Return

Add listener that gets called when file changes on disk

writeFileSync(file, data, options){Boolean}

Parameters

Name Type Description
file string Absolute path to file
data string Data to write
options Object Options object for fs.writeFileSync

Return

Writes file to disk

zipFiles(archivePath, files){string|boolean}

Parameters

Name Type Description
archivePath string Absolute path to zip archive
files Array.<string> An array of file paths to compress

Return

Compresses files into zip archive