-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
52 lines (42 loc) · 1.18 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
import {load} from 'js-toml';
import { glob } from 'glob'
import path from 'path';
import fs from 'node:fs'
import {createCONFIG, createHTML} from './convert.js';
const tomlFilePath = "./definitions/**/*.toml";
// read toml files
glob.sync( tomlFilePath ).forEach( function( file ) {
//console.log(file);
// get filename
const filename = getFilename(file);
console.log(filename);
try {
const data = fs.readFileSync(file, 'utf8');
//console.log(data);
//
// input of toml converted to JSON
//
const tomlAsJson = load(data);
//console.log(tomlAsJson);
//
// create config file from toml file
//
createCONFIG(tomlAsJson, filename);
//
// create HTML file from toml file
//
createHTML(tomlAsJson, filename);
} catch (err) {
console.error(err);
}
});
/**
* Retrieves the filename (name without suffix .toml)
* @param {string} filepath
* @returns filename as string
*/
function getFilename(filepath) {
const extension = ".toml";
const filename = path.basename(filepath, extension);
return filename;
}