UNPKG

719 BJavaScriptView Raw
1const fs = require('fs');
2const path = require('path');
3const yaml = require('js-yaml');
4const ejs = require('ejs');
5
6module.exports = function (config, callback) {
7 const url = path.resolve(process.cwd(), config);
8
9 try {
10 // Read the YAML config
11 var rawConfig = yaml.safeLoad(fs.readFileSync(url, 'utf8'));
12
13 // Interpolate any env variables in content paths
14 var processedConfig = ejs.render(JSON.stringify(rawConfig), { ENV: process.env }, { cache: false });
15
16 // Restore stringified object to a plain javascript object
17 return JSON.parse(processedConfig);
18 } catch (e) {
19 throw new Error('Cannot parse configuration file. Please make sure your Swanky configuration file exists.');
20 }
21};
\No newline at end of file