-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates.js
39 lines (31 loc) · 1 KB
/
templates.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const fs = require('fs');
const yaml = require('js-yaml');
// Function to load YAML files
function LoadYAMLFile(filePath) {
try {
const fileContents = fs.readFileSync(filePath, 'utf8');
return yaml.load(fileContents);
} catch (error) {
console.error(`Error loading YAML file ${filePath}:`, error);
return null;
}
}
function GetTemplates() {
const filePath = "templates/templates.yaml";
if (!fs.existsSync(filePath)) {
console.error('Error: templates.yaml file is missing.');
return [];
}
const config = LoadYAMLFile(filePath);
if (!config || !Array.isArray(config.files) || config.files.length === 0) {
console.error('Error: templates.yaml is empty or invalid.');
return [];
}
// Load each YAML file
const loadedFiles = config.files.map(file => {
const data = LoadYAMLFile(file.path);
return { name: file.name, data };
});
return loadedFiles;
}
module.exports = { GetTemplates };