apple2js/bin/index

61 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2019-03-03 06:46:37 +00:00
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const diskPath = path.resolve('json/disks');
const dir = fs.readdirSync(diskPath);
const index = [];
for (const fileName of dir.sort()) {
if (/\.json$/.test(fileName)) {
const json = fs.readFileSync(path.resolve(diskPath, fileName));
const data = JSON.parse(json);
if (data.private) {
continue;
}
if (!data.name || !data.category) {
continue;
}
2019-03-03 06:46:37 +00:00
const entry = {
filename: `json/disks/${fileName}`,
e: data['2e'],
name: data.name,
disk: data.disk,
category: data.category,
};
index.push(entry);
}
}
2022-08-20 15:33:09 +00:00
index.sort((x, y) => {
2020-04-24 03:57:59 +00:00
const xc = x.category.toLowerCase();
const yc = y.category.toLowerCase();
const xn = x.name.toLowerCase();
const yn = y.name.toLowerCase();
if (xc < yc) {
return -1;
} else if (xc > yc) {
return 1;
} else if (xn < yn) {
return -1;
} else if (xn > yn) {
return 1;
} else {
return 0;
}
});
2019-03-03 06:46:37 +00:00
fs.writeFileSync(
path.resolve(diskPath, 'index.js'),
`disk_index = ${JSON.stringify(index, null, 2)};`
);
2022-08-20 15:33:09 +00:00
fs.writeFileSync(
path.resolve(diskPath, 'index.json'),
JSON.stringify(index, null, 2)
);