forked from jgthms/bulma
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02-read-derived-variables.js
More file actions
40 lines (31 loc) · 1.15 KB
/
Copy path02-read-derived-variables.js
File metadata and controls
40 lines (31 loc) · 1.15 KB
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
module.exports = plugin;
const utils = require('./utils');
const fs = require('fs');
let initial_variables = JSON.parse(fs.readFileSync(utils.files.initial_variables));
let derived_variables = JSON.parse(fs.readFileSync(utils.files.derived_variables));
function plugin() {
return (files, metalsmith, done) => {
setImmediate(done);
Object.keys(files).forEach(file_path => {
const {file_name, lines} = utils.getLines(files, file_path);
let variables = {
by_name: {},
list: [],
file_path,
};
lines.forEach(line => {
const variable = utils.parseLine(line);
if (variable != false) {
const computed_data = utils.getComputedData(variable.name, variable.value, variable.type, initial_variables, derived_variables);
if (Object.keys(computed_data).length > 0) {
variable.computed_type = computed_data.computed_type;
variable.computed_value = computed_data.computed_value;
}
variables.by_name[variable.name] = variable;
variables.list.push(variable.name);
}
});
utils.writeFile(file_path, variables);
});
};
}