feat: first pass, good enough

This commit is contained in:
Josh Sherman 2023-03-20 22:29:32 -05:00
parent 593e16a0e7
commit 0a2525ec97
No known key found for this signature in database
GPG key ID: 55B058A80530EF22
5 changed files with 3799 additions and 2 deletions

16
.eslintrc.js Normal file
View file

@ -0,0 +1,16 @@
module.exports = {
env: {
es2021: true,
node: true,
},
extends: 'airbnb-base',
overrides: [
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
'no-console': 'off',
},
};

View file

@ -1,2 +1,17 @@
# gmenu2x-aliasfile-generator # GMenu2X aliasfile generator
Generates a gmenu2x aliasfile from a directory of files
Generates a GMenu2X aliasfile from a directory of files
## Usage
Generate to standard out:
```shell
npm start -- --directory /path/to/roms
```
Pipe it to an aliasfile:
```shell
npm start -- -d /path/to/roms > /path/to/aliasfile
```

3702
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

29
package.json Normal file
View file

@ -0,0 +1,29 @@
{
"name": "gmenu2x-aliasfile-generator",
"version": "1.0.0",
"description": "Generates a gmenu2x aliasfile from a directory of files",
"main": "src/index.mjs",
"module": true,
"scripts": {
"start": "node src/index.mjs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/joshtronic/gmenu2x-aliasfile-generator.git"
},
"author": "Josh Sherman <hello@joshtronic.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/joshtronic/gmenu2x-aliasfile-generator/issues"
},
"homepage": "https://github.com/joshtronic/gmenu2x-aliasfile-generator#readme",
"devDependencies": {
"eslint": "^8.36.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.27.5"
},
"dependencies": {
"commander": "^10.0.0",
"mkdirp": "^2.1.5"
}
}

35
src/index.mjs Normal file
View file

@ -0,0 +1,35 @@
import { promises as fs } from 'fs';
import { program } from 'commander';
program
.requiredOption('-d, --directory <path>', 'directory to read')
.parse();
const { directory } = program.opts();
const files = await fs.readdir(directory);
files.forEach((file) => {
let alias = file.slice(0, file.lastIndexOf('.'));
// Awesome gist that inspired most of the following:
// https://gist.github.com/ramiabraham/ff41ba74f2b7104ecece
alias = alias
// Removes primary ROM codes
.replace(/\[(a|p|b|f|T-|T+|t|h|o|J|!)\]/gi, '')
.replace(/\((-|M\d+|U|E|UE)\)/gi, '')
// TODO: Stripe checksums - (###)
// Removes country codes
.replace(/\((1|4|A|J|B|K|C|NL|E|PD|F|S|F|FC|SW|FN|U|G|UK|GR|Unk|HK|I|H|Unl)\)/gi, '')
// Removes Nintendo Game Boy specific codes
.replace(/\[(C|S|BF)\]/gi, '')
// Removes Super Nintendo Entertainment System specific codes
.replace(/\((BS|ST|NP)\)/gi, '')
// Removes Sega Genesis specific codes
.replace(/\((1|4|5|8)\)/gi, '')
.replace(/\[ (\(B\) Brazil|\[c\] Checksum|\[x\] Bad Checksum|\[R-\] Countries) \]/gi, '')
// Removes Nintendo Entertainment System specific codes
.replace(/\[(PC10|VS)\]/gi, '');
console.log(`${file}=${alias}`);
});