Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ node_js:
env:
- TESTFILE=tests/fixtures_valid.js
- TESTFILE=tests/http_status.js
- TESTFILE=tests/manufacturers_index_correct.js
- TESTFILE=tests/register_correct.js
script:
- node "$TESTFILE"
cache:
Expand Down
25 changes: 0 additions & 25 deletions fixtures/index_manufacturers.json

This file was deleted.

26 changes: 0 additions & 26 deletions fixtures/index_types.json

This file was deleted.

70 changes: 70 additions & 0 deletions fixtures/register.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"filesystem": {
"cameo/outdoor-par-tri-12": {
"name": "Outdoor PAR Tri 12",
"manufacturerName": "cameo"
},
"cameo/thunder-wash-100-rgb": {
"name": "Thunder Wash 100 RGB",
"manufacturerName": "cameo"
},
"cameo/thunder-wash-100-w": {
"name": "Thunder Wash 100 W",
"manufacturerName": "cameo"
},
"cameo/thunder-wash-600-rgb": {
"name": "Thunder Wash 600 RGB",
"manufacturerName": "cameo"
},
"cameo/thunder-wash-600-w": {
"name": "Thunder Wash 600 W",
"manufacturerName": "cameo"
},
"gruft/ventilator": {
"name": "Ventilator",
"manufacturerName": "Gruft"
},
"lightmaxx/platinum-mini-tri-par": {
"name": "Platinum Mini TRI-PAR",
"manufacturerName": "lightmaXX"
},
"lightmaxx/vega-zoom-wash": {
"name": "Vega Zoom Wash",
"manufacturerName": "lightmaXX"
}
},
"manufacturers": {
"cameo": [
"outdoor-par-tri-12",
"thunder-wash-100-rgb",
"thunder-wash-100-w",
"thunder-wash-600-rgb",
"thunder-wash-600-w"
],
"gruft": [
"ventilator"
],
"lightmaxx": [
"platinum-mini-tri-par",
"vega-zoom-wash"
]
},
"types": {
"Color Changer": [
"cameo/outdoor-par-tri-12",
"lightmaxx/platinum-mini-tri-par"
],
"Strobe": [
"cameo/thunder-wash-100-rgb",
"cameo/thunder-wash-100-w",
"cameo/thunder-wash-600-rgb",
"cameo/thunder-wash-600-w"
],
"Fan": [
"gruft/ventilator"
],
"Moving Head": [
"lightmaxx/vega-zoom-wash"
]
}
}
64 changes: 64 additions & 0 deletions generate-register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/node

const fs = require('fs');
const path = require('path');

let register = {
filesystem: {},
manufacturers: {},
types: {}
};

const fixturePath = path.join(__dirname, 'fixtures');

try {
const manufacturers = JSON.parse(fs.readFileSync(path.join(fixturePath, 'manufacturers.json')));

// add all fixture.json files to the register
for (const man of fs.readdirSync(fixturePath).sort()) {
manDir = path.join(fixturePath, man);

// only directories
if (fs.statSync(manDir).isDirectory()) {
register.manufacturers[man] = [];

for (const filename of fs.readdirSync(manDir).sort()) {
const ext = path.extname(filename);
if (ext == '.json') {
const fix = path.basename(filename, ext);

// add to manufacturer register
register.manufacturers[man].push(fix);

// add to filesystem and type register
const fixData = JSON.parse(fs.readFileSync(path.join(fixturePath, man, filename), 'utf8'));

register.filesystem[man + '/' + fix] = {
name: fixData.name,
manufacturerName: manufacturers[man].name
};

if (!(fixData.type in register.types)) {
register.types[fixData.type] = [];
}
register.types[fixData.type].push(man + '/' + fix);
}
}
}
}
}
catch (readError) {
console.error('Read error. ', readError);
process.exit(1);
}

const filename = path.join(fixturePath, (process.argv.length == 3 ? process.argv[2] : 'register.json'));

fs.writeFile(filename, JSON.stringify(register, null, 2), 'utf8', error => {
if (error) {
console.error('Could not write register file.', error);
process.exit(1);
}
console.log(`Register file ${filename} successfully written.`);
process.exit(0);
});
27 changes: 9 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ app.engine('js', (filePath, options, callback) => {

let opts = {
manufacturers: manufacturers,
manufacturersIndex: manufacturersIndex,
typesIndex: typesIndex,
manufacturersIndex: register.manufacturers,
typesIndex: register.types,
messages: getMessages()
};
Object.assign(opts, options);
Expand All @@ -37,8 +37,7 @@ let messages = [];

// the interesting data
let manufacturers = null;
let manufacturersIndex = null;
let typesIndex = null;
let register = null;

// read in the JSON files to fill those data structures
fs.readFile(path.join(__dirname, 'fixtures', 'manufacturers.json'), 'utf8', (error, data) => {
Expand All @@ -49,21 +48,13 @@ fs.readFile(path.join(__dirname, 'fixtures', 'manufacturers.json'), 'utf8', (err

manufacturers = JSON.parse(data);
});
fs.readFile(path.join(__dirname, 'fixtures', 'index_manufacturers.json'), 'utf8', (error, data) => {
fs.readFile(path.join(__dirname, 'fixtures', 'register.json'), 'utf8', (error, data) => {
if (error) {
addFileReadError('There was an error reading in the manufacturer index data.', error);
addFileReadError('There was an error reading in the register.', error);
return;
}

manufacturersIndex = JSON.parse(data);
});
fs.readFile(path.join(__dirname, 'fixtures', 'index_types.json'), 'utf8', (error, data) => {
if (error) {
addFileReadError('There was an error reading in the category index data.', error);
return;
}

typesIndex = JSON.parse(data);
register = JSON.parse(data);
});


Expand Down Expand Up @@ -113,7 +104,7 @@ app.use((request, response, next) => {
return;
}
else {
if (segments.length == 2 && segments[0] in manufacturers && manufacturersIndex[segments[0]].indexOf(segments[1]) != -1) {
if (segments.length == 2 && segments[0] in manufacturers && register.manufacturers[segments[0]].indexOf(segments[1]) != -1) {
renderSingleFixture(response, segments[0], segments[1]);
return;
}
Expand All @@ -128,7 +119,7 @@ app.use((request, response, next) => {
function renderSingleManufacturer(response, man) {
let fixtures = [];

for (let fix of manufacturersIndex[man]) {
for (let fix of register.manufacturers[man]) {
const fixData = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures', man, fix + '.json'), 'utf-8'));

fixtures.push({
Expand Down Expand Up @@ -161,7 +152,7 @@ function getMessages() {
return messages;
}

if (manufacturers == null || manufacturersIndex == null || typesIndex == null) {
if (manufacturers == null || register == null) {
return [{
type: 'info',
text: 'We are still reading the data. Please reload the page in a few moments.'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"express": "4.14.1"
},
"devDependencies": {
"diff": "^3.2.0",
"colors": "^1.1.2",
"valid-url": "1.0.9"
},
Expand Down
6 changes: 3 additions & 3 deletions tests/http_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ const statusCodes = {
]
}
// add manufacturers and fixtures
const manufacturersIndex = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'index_manufacturers.json'), 'utf8'));
for (const man in manufacturersIndex) {
const register = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'register.json'), 'utf8'));
for (const man in register.manufacturers) {
statusCodes['200'].push(man);

for (const fixture of manufacturersIndex[man]) {
for (const fixture of register.manufacturers[man]) {
statusCodes['200'].push(path.join(man, fixture));
}
}
Expand Down
Loading