feat(project.json): use yaml template instead of json
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import path from 'path'
|
||||
import Matcher from './content_processor.js'
|
||||
import { read, exists } from './file.js'
|
||||
import { read as readFile, exists } from './file.js'
|
||||
import { read as readYAML } from './yaml.js'
|
||||
|
||||
export default class ProjectJson {
|
||||
#json
|
||||
@@ -9,6 +10,8 @@ export default class ProjectJson {
|
||||
#operatorSourceFolder
|
||||
#operatorShareFolder
|
||||
#assets
|
||||
#rootDir
|
||||
#template
|
||||
|
||||
constructor(config, operatorName, __dirname, operatorShareFolder, assets) {
|
||||
this.#config = config
|
||||
@@ -16,11 +19,13 @@ export default class ProjectJson {
|
||||
this.#operatorSourceFolder = path.join(__dirname, this.#config.folder.operator)
|
||||
this.#operatorShareFolder = operatorShareFolder
|
||||
this.#assets = assets
|
||||
this.#rootDir = __dirname
|
||||
this.#template = this.#processYAML(readYAML(path.join(this.#rootDir, 'config', '_project_json.yaml')))
|
||||
}
|
||||
|
||||
async load() {
|
||||
// load json from file
|
||||
this.#json = JSON.parse(await read(this.#getPath()))
|
||||
this.#json = JSON.parse(await readFile(this.#getPath()))
|
||||
this.#process()
|
||||
return this.#json
|
||||
}
|
||||
@@ -36,17 +41,13 @@ export default class ProjectJson {
|
||||
}
|
||||
|
||||
#process() {
|
||||
const matcher = new Matcher(this.#json.description, '${', '}', this.#config.operators[this.#operatorName])
|
||||
if (matcher.match() !== null) {
|
||||
this.#json.description = matcher.process()
|
||||
}
|
||||
// TODO: move the template generation to here
|
||||
this.#json = {
|
||||
...this.#json,
|
||||
description: this.#json.description,
|
||||
description: this.#template.description,
|
||||
title: this.#config.operators[this.#operatorName].title,
|
||||
general: {
|
||||
...this.#json.general,
|
||||
localization: this.#template.localization,
|
||||
properties: {
|
||||
...this.#json.general.properties,
|
||||
...this.#properties
|
||||
@@ -55,63 +56,16 @@ export default class ProjectJson {
|
||||
}
|
||||
}
|
||||
|
||||
get #properties() {
|
||||
const properties = [
|
||||
#processYAML(template) {
|
||||
const matcher = new Matcher(template.description, '${', '}', this.#config.operators[this.#operatorName])
|
||||
if (matcher.match() !== null) {
|
||||
template.description = matcher.process()
|
||||
}
|
||||
const replacePropertyPairs = [
|
||||
{
|
||||
key: "notice",
|
||||
value: {
|
||||
text: "ui_logo_notice",
|
||||
type: "textinput",
|
||||
"value": "Set FPS target in Settings"
|
||||
}
|
||||
}, {
|
||||
key: "logo",
|
||||
value: {
|
||||
text: "ui_operator_logo",
|
||||
type: "bool",
|
||||
value: true
|
||||
}
|
||||
}, {
|
||||
key: "logoimage",
|
||||
value: {
|
||||
text: "ui_logo_image",
|
||||
type: "file",
|
||||
value: "",
|
||||
condition: "logo.value == true",
|
||||
}
|
||||
}, {
|
||||
key: "logoratio",
|
||||
value: {
|
||||
text: "ui_logo_ratio",
|
||||
type: "slider",
|
||||
value: 61.8,
|
||||
condition: "logo.value == true",
|
||||
fraction: true,
|
||||
max: 100,
|
||||
min: 0,
|
||||
precision: 2,
|
||||
step: 0.1,
|
||||
}
|
||||
}, {
|
||||
key: "logoopacity",
|
||||
value: {
|
||||
text: "ui_logo_opacity",
|
||||
type: "slider",
|
||||
value: 30,
|
||||
condition: "logo.value == true",
|
||||
fraction: false,
|
||||
max: 100,
|
||||
min: 0,
|
||||
}
|
||||
}, {
|
||||
key: "defaultbackground",
|
||||
value: {
|
||||
text: "ui_default_background",
|
||||
type: "combo",
|
||||
value: this.#assets.backgrounds[0],
|
||||
fraction: false,
|
||||
max: 100,
|
||||
min: 0,
|
||||
options: this.#assets.backgrounds.map((b) => {
|
||||
return {
|
||||
"label": b,
|
||||
@@ -119,66 +73,44 @@ export default class ProjectJson {
|
||||
}
|
||||
})
|
||||
}
|
||||
}, {
|
||||
key: "background",
|
||||
value: {
|
||||
text: "ui_custom_background",
|
||||
type: "file",
|
||||
value: "",
|
||||
}
|
||||
}, {
|
||||
key: "position",
|
||||
value: {
|
||||
text: "ui_position",
|
||||
type: "bool",
|
||||
value: false,
|
||||
}
|
||||
}, {
|
||||
},
|
||||
{
|
||||
key: "paddingleft",
|
||||
value: {
|
||||
text: "ui_position_padding_left",
|
||||
type: "slider",
|
||||
value: this.#config.operators[this.#operatorName].viewport_left,
|
||||
condition: "position.value == true",
|
||||
fraction: false,
|
||||
max: 100,
|
||||
min: -100,
|
||||
}
|
||||
}, {
|
||||
value: this.#config.operators[this.#operatorName].viewport_left
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "paddingright",
|
||||
value: {
|
||||
text: "ui_position_padding_right",
|
||||
type: "slider",
|
||||
value: this.#config.operators[this.#operatorName].viewport_right,
|
||||
condition: "position.value == true",
|
||||
fraction: false,
|
||||
max: 100,
|
||||
min: -100,
|
||||
}
|
||||
}, {
|
||||
value: this.#config.operators[this.#operatorName].viewport_right
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "paddingtop",
|
||||
value: {
|
||||
text: "ui_position_padding_top",
|
||||
type: "slider",
|
||||
value: this.#config.operators[this.#operatorName].viewport_top,
|
||||
condition: "position.value == true",
|
||||
fraction: false,
|
||||
max: 100,
|
||||
min: -100,
|
||||
}
|
||||
}, {
|
||||
value: this.#config.operators[this.#operatorName].viewport_top
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "paddingbottom",
|
||||
value: {
|
||||
text: "ui_position_padding_bottom",
|
||||
type: "slider",
|
||||
value: this.#config.operators[this.#operatorName].viewport_bottom,
|
||||
condition: "position.value == true",
|
||||
fraction: false,
|
||||
max: 100,
|
||||
min: -100,
|
||||
}
|
||||
}
|
||||
value: this.#config.operators[this.#operatorName].viewport_bottom
|
||||
},
|
||||
},
|
||||
]
|
||||
replacePropertyPairs.forEach((pair) => {
|
||||
const property = template.properties.find((p) => p.key === pair.key)
|
||||
property.value = {
|
||||
...property.value,
|
||||
...pair.value
|
||||
}
|
||||
})
|
||||
return template
|
||||
}
|
||||
|
||||
get #properties() {
|
||||
const properties = this.#template.properties
|
||||
const output = {}
|
||||
for (let i = 0; i < properties.length; i++) {
|
||||
output[properties[i].key] = {
|
||||
|
||||
Reference in New Issue
Block a user