Skip to content

Commit ca3e886

Browse files
authored
Fixture redirects (#484)
* move M-Carré to IVL Carré * allow fixture redirects including schema, tests and UI * add redirect from minuit-une/m-carre to minuit-une/ivl-carre * improve code readability, reduce complexity in fixture test (cherrypicked from #425)
1 parent 5ceb9a7 commit ca3e886

File tree

18 files changed

+772
-613
lines changed

18 files changed

+772
-613
lines changed

cli/make-register.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,27 @@ try {
3636
}
3737

3838
for (const filename of fs.readdirSync(manDir).sort()) {
39-
const ext = path.extname(filename);
40-
if (ext === `.json`) {
41-
const fixKey = path.basename(filename, ext);
42-
const fixData = JSON.parse(fs.readFileSync(path.join(fixturePath, manKey, filename), `utf8`));
39+
if (path.extname(filename) !== `.json`) {
40+
continue;
41+
}
42+
43+
const fixKey = path.basename(filename, `.json`);
44+
const fixData = JSON.parse(fs.readFileSync(path.join(fixturePath, manKey, filename), `utf8`));
45+
let isRedirect = false;
46+
let redirectToData = null;
47+
48+
if (fixData.$schema.endsWith(`/fixture-redirect.json`)) {
49+
isRedirect = true;
50+
redirectToData = JSON.parse(fs.readFileSync(path.join(fixturePath, `${fixData.redirectTo}.json`), `utf8`));
4351

52+
// add to filesystem register
53+
register.filesystem[`${manKey}/${fixKey}`] = {
54+
name: fixData.name,
55+
redirectTo: fixData.redirectTo,
56+
reason: fixData.reason
57+
};
58+
}
59+
else {
4460
let lastAction = `modified`;
4561
if (fixData.meta.lastModifyDate === fixData.meta.createDate) {
4662
lastAction = `created`;
@@ -55,30 +71,34 @@ try {
5571
lastModifyDate: fixData.meta.lastModifyDate,
5672
lastAction: lastAction
5773
};
74+
}
5875

76+
if (!isRedirect || fixData.reason === `SameAsDifferentBrand`) {
5977
// add to manufacturer register
6078
register.manufacturers[manKey].push(fixKey);
6179

6280
// add to category register
63-
for (const cat of fixData.categories) {
81+
for (const cat of fixData.categories || redirectToData.categories) {
6482
if (!(cat in categories)) {
6583
categories[cat] = [];
6684
}
6785
categories[cat].push(`${manKey}/${fixKey}`);
6886
}
87+
}
6988

70-
// add to contributor register
89+
// add to contributor register
90+
if (!isRedirect) {
7191
for (const contributor of fixData.meta.authors) {
7292
if (!(contributor in contributors)) {
7393
contributors[contributor] = [];
7494
}
7595
contributors[contributor].push(`${manKey}/${fixKey}`);
7696
}
97+
}
7798

78-
// add to rdm register
79-
if (`rdm` in fixData) {
80-
rdm[manufacturers[manKey].rdmId].models[fixData.rdm.modelId] = fixKey;
81-
}
99+
// add to rdm register
100+
if (`rdm` in fixData) {
101+
rdm[manufacturers[manKey].rdmId].models[fixData.rdm.modelId] = fixKey;
82102
}
83103
}
84104
}
@@ -112,7 +132,9 @@ const lastActionRankMapping = {
112132
};
113133

114134
// add fixture list sorted by lastModifyDate
115-
register.lastUpdated = Object.keys(register.filesystem).sort((a, b) => {
135+
register.lastUpdated = Object.keys(register.filesystem).filter(
136+
fixtureKey => `lastModifyDate` in register.filesystem[fixtureKey]
137+
).sort((a, b) => {
116138
const fixA = register.filesystem[a];
117139
const fixB = register.filesystem[b];
118140
const dateDelta = new Date(fixB.lastModifyDate) - new Date(fixA.lastModifyDate);

docs/fixture-format.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This document gives a high-level overview of the concepts used in the JSON forma
1919
- [Matrix structure](#matrix-structure)
2020
- [Template channels](#template-channels)
2121
- [RDM (Remote Device Management) data](#rdm-remote-device-management-data)
22+
- [Fixture redirects](#fixture-redirects)
2223

2324

2425
## Schema
@@ -214,9 +215,15 @@ Then, either use the resolved channel keys directly in a mode's channel list, or
214215
- For the above [matrix structure](#matrix-structure) example, this results in `["Inner ring", "Middle ring", "Outer ring"]`.
215216

216217

217-
218218
### RDM (Remote Device Management) data
219219

220220
We link to [Open Lighting's RDM database](http://rdm.openlighting.org) if possible. Thus, we need to specify the RDM manufacturer ID per manufacturer and the RDM model ID per fixture. Additionally, each mode is mapped to the respective RDM personality via the `rdmPersonalityIndex` property. To ensure compatibility, we also track, for which RDM fixture software (firmware) version the mode indices are specified.
221221

222222
If RDM manufacturer and model ID are known, we open the respective fixture page when going to `/rdm` (handled in [`main.js`](../main.js) and `views/pages/rdm-*.js`).
223+
224+
225+
## Fixture redirects
226+
227+
Fixtures may be renamed by their manufacturers. If we would just update the fixture definition, links to its old fixture page would now lead to a *404 Not found* error. Instead, we add a fixture redirect JSON file (see [its schema](../schemas/fixture-redirect.json)) with the old manufacturer / fixture key, pointing to the updated fixture definition. See [Minuit Une M-Carré](../fixtures/minuit-une/m-carre.json) (and its [fixture page on OFL](https://open-fixture-library.org/minuit-une/m-carre)) as an example.
228+
229+
Another use case for redirects are fixtures that are sold under different brands, but which are technically the same. We add them to the library only once and let redirects with other names point to it.

0 commit comments

Comments
 (0)