Skip to content
Snippets Groups Projects
Commit 6d480329 authored by Eduard Nunes's avatar Eduard Nunes
Browse files

Adding method to get array of yml filenames

parent 1774b9de
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,16 @@ common.stringElseRandomKey = (variable) ->
if variable instanceof Array
variable[Math.floor(Math.random() * variable.length)]
getYAMLFiles = (filepath) ->
listFile = fs.readdirSync filepath
dataFiles = []
if listFile.length > 0
dataFiles = listFile.map (filename) ->
return yaml.safeLoad fs.readFileSync filepath+'/'+filename, 'utf8'
else
console.error('The directory: '+ filepath + ' is empty.')
return dataFiles
common.regexEscape = (string) ->
#http://stackoverflow.com/a/6969486
string.replace /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"
......@@ -30,7 +40,12 @@ common.getConfigFilePath = () ->
common.loadConfigfile = (filepath) ->
try
console.log("Loading corpus: " + filepath)
return yaml.safeLoad fs.readFileSync filepath, 'utf8'
if fs.lstatSync(filepath).isFile()
return yaml.safeLoad fs.readFileSync filepath, 'utf8'
else if fs.lstatSync(filepath).isDirectory()
# Return array with ymls files data
yamlFiles = getYAMLFiles(filepath)
console.log(yamlFiles)
catch err
console.error "An error occurred while trying to load bot's config."
console.error err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment