osr-mono/packages/osr-templates/discourse/variables.osr
2025-01-29 17:53:27 +01:00

63 lines
1.7 KiB
Plaintext

[% capture config %][% js %]
const globalVariables = readJSON('${OSR_ROOT}/osr-templates/discourse/base.json');
addGlobal({config:globalVariables})
addGlobal({config:globalVariables.variables})
register('config',globalVariables.variables)
register('variables',globalVariables.variables)
register('show',globalVariables.variables.show)
return globalVariables
[%endjs%][% endcapture -%]
[% capture product %][% js %]
const globalVariables = readJSON('${OSR_ROOT}/osr-templates/discourse/base.json')
let localVariables = readJSON('${PRODUCT_ROOT}/config.json')
delete localVariables['download']
delete localVariables['product_dimensions']
delete localVariables['edrawings']
localVariables['image']='${product_rel}/renderings/perspective.jpg'
let defaultsJSON = fs.findUp.sync('defaults.json', {
cwd:PRODUCT_ROOT,
stopAt:root
});
if(defaultsJSON){
defaultsJSON = readJSON(defaultsJSON);
localVariables = {
...defaultsJSON,
...localVariables
}
}
let allVariables = {
...globalVariables.variables,
...localVariables,
...scope
}
const _scope = scope
allVariables.product_rel = product;
writeJSON("./tmp.json",allVariables)
const allStr = read("./tmp.json")
let all = forward_slash(substitute(allStr,allVariables))
write("./tmp-a.json",forward_slash(all))
try{
allVariables = JSON.parse(all);
resolveConfig(allVariables);
addGlobal({product:allVariables});
register('product',allVariables)
return allVariables;
}catch(e){
debugger
}
[%endjs%][% endcapture -%]