mirror of https://github.com/Trivernis/whooshy.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
const yaml = require('js-yaml'),
|
|
fsx = require('fs-extra');
|
|
|
|
|
|
/**
|
|
* Parses the `queries.yaml` file in the path. queries.yaml-format:
|
|
* exports: {List} - query keys to export
|
|
*
|
|
* queryKey:
|
|
* file: {String} name of sql-file if the sql is stored in a file.
|
|
* sql: {String} pure sql if it is not stored in a file. Will be replaced by file contents if a file was given.
|
|
* @param path {String} - the path where the queries.yaml file is stored
|
|
*/
|
|
function parseSqlYaml(path) {
|
|
let queries = yaml.safeLoad(fsx.readFileSync(`${path}/queries.yaml`));
|
|
|
|
for (let query of queries.exports)
|
|
if (queries[query].file)
|
|
queries[query].sql = fsx.readFileSync(`${path}/${queries[query].file}`, 'utf-8');
|
|
|
|
return queries;
|
|
}
|
|
|
|
/**
|
|
* Reads the default-config.yaml and config.yaml in the path directory.
|
|
* @param path {String} - the directory of the settings files.
|
|
*/
|
|
function readSettings(path) {
|
|
let settings = yaml.safeLoad(fsx.readFileSync(`${path}/default-config.yaml`));
|
|
|
|
if (fsx.existsSync('config.yaml'))
|
|
Object.assign(settings, yaml.safeLoad(fsx.readFileSync(`${path}/config.yaml`)));
|
|
return settings;
|
|
}
|
|
|
|
Object.assign(exports, {
|
|
parseSqlYaml: parseSqlYaml,
|
|
readSettings: readSettings
|
|
});
|