bulma/docs/_scripts/plugins/03-read-other-variables.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-06-16 17:26:55 +00:00
module.exports = plugin;
const utils = require('./utils');
2018-06-16 18:01:35 +00:00
const fs = require('fs');
let initial_variables = JSON.parse(fs.readFileSync(utils.files.initial_variables));
2018-06-16 18:58:58 +00:00
let derived_variables = JSON.parse(fs.readFileSync(utils.files.derived_variables));
2018-06-16 17:26:55 +00:00
function plugin() {
return (files, metalsmith, done) => {
setImmediate(done);
Object.keys(files).forEach(file_path => {
2018-06-19 12:33:54 +00:00
// if (file_path.startsWith('utilities')) {
// return;
// }
2018-06-16 18:58:58 +00:00
2018-06-16 19:47:52 +00:00
const {file_name, lines} = utils.getLines(files, file_path);
2018-06-16 18:58:58 +00:00
let variables = {
by_name: {},
list: [],
2018-06-16 19:47:52 +00:00
file_path,
2018-06-16 18:58:58 +00:00
};
2018-06-16 17:26:55 +00:00
lines.forEach(line => {
const variable = utils.parseLine(line);
if (variable != false) {
2018-06-17 00:05:48 +00:00
const computed_data = utils.getComputedData(variable.name, variable.value, variable.type, initial_variables, derived_variables);
2018-06-16 19:47:52 +00:00
if (Object.keys(computed_data).length > 0) {
variable.computed_type = computed_data.computed_type;
variable.computed_value = computed_data.computed_value;
}
2018-06-16 17:26:55 +00:00
variables.by_name[variable.name] = variable;
2018-06-16 18:01:35 +00:00
variables.list.push(variable.name);
2018-06-16 17:26:55 +00:00
}
});
2018-06-16 18:01:35 +00:00
2018-06-19 12:33:54 +00:00
if (variables.list.length > 0) {
utils.writeFile(file_path, variables);
}
2018-06-16 18:58:58 +00:00
});
2018-06-16 17:26:55 +00:00
};
}