Skip to content

Commit

Permalink
Merge branch 'main' into emmercm/20230803-renovate
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm committed Aug 4, 2023
2 parents 329900b + ed423c3 commit ac86c08
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

# !!! This check should be required by GitHub !!!
pages-status-check:
if: always()
if: github.event_name == 'pull_request'
needs:
- markdown-lint
- mkdocs-build
Expand All @@ -58,6 +58,9 @@ jobs:
contents: write
steps:
- uses: actions/checkout@v3
with:
# the `git-revision-date-localized` plugin needs full history to find page creation date
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: 3.x
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/version-bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
- id: create-pull-request
uses: peter-evans/create-pull-request@v5
with:
# GitHub won't run workflows off of events from the `github-actions` user
# But also, I want the PR to be created under my name for cosmetic reasons
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
author: ${{ steps.bump-and-commit.outputs.USER_NAME }} <${{ steps.bump-and-commit.outputs.USER_EMAIL }}>
branch: ${{ github.actor }}/${{ steps.bump-and-commit.outputs.PACKAGE_VERSION }}
Expand Down
1 change: 1 addition & 0 deletions docs/output/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ROMs-Sorted/
When using [DATs](../dats.md), you can make use of console & game information contained in them:

- `{datName}` the matching DAT's name, similar to how the `--dir-dat-name` option works
- `{datDescription}` the matching DAT's description, similar to how the `--dir-dat-description` option works
- `{datReleaseLanguage}` each of the ROM's language(s) (e.g. `EN`, `ES`, `JA`)
- `{datReleaseRegion}` each of the ROM's region(s) (e.g. `USA`, `EUR`, `JPN`, `WORLD`)

Expand Down
3 changes: 2 additions & 1 deletion src/console/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export default class Logger {
const logoSplit = logo.split('\n');
const midLine = Math.min(Math.ceil(logoSplit.length / 2), logoSplit.length - 1);
const maxLineLen = logoSplit.reduce((max, line) => Math.max(max, line.length), 0);
logoSplit[midLine - 1] = `${logoSplit[midLine - 1].padEnd(maxLineLen, ' ')} ROM collection manager`;
logoSplit[midLine - 2] = `${logoSplit[midLine - 1].padEnd(maxLineLen, ' ')} ROM collection manager`;
logoSplit[midLine - 1] = `${logoSplit[midLine - 1].padEnd(maxLineLen, ' ')} ${Constants.HOMEPAGE}`;
logoSplit[midLine + 1] = `${logoSplit[midLine + 1].padEnd(maxLineLen, ' ')} v${Constants.COMMAND_VERSION}`;

this.print(LogLevel.ALWAYS, `${logoSplit.join('\n')}\n\n`);
Expand Down
7 changes: 7 additions & 0 deletions src/modules/argumentsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ export default class ArgumentsParser {
type: 'boolean',
implies: 'dat',
})
.option('dir-dat-description', {
group: groupRomOutput,
description: 'Use the DAT description as the output subdirectory',
type: 'boolean',
implies: 'dat',
})
.option('dir-letter', {
group: groupRomOutput,
description: 'Append the first letter of the ROM name as an output subdirectory',
Expand Down Expand Up @@ -526,6 +532,7 @@ Advanced usage:
Tokens that are replaced when generating the output (--output) path of a ROM:
{datName} The name of the DAT that contains the ROM (e.g. "Nintendo - Game Boy")
{datDescription} The description of the DAT that contains the ROM
{datReleaseRegion} The region of the ROM release (e.g. "USA"), each ROM can have multiple
{datReleaseLanguage} The language of the ROM release (e.g. "En"), each ROM can have multiple
{gameType} The type of the game (e.g. "Retail", "Demo", "Prototype")
Expand Down
4 changes: 4 additions & 0 deletions src/types/logiqx/dat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ export default class DAT {
.trim();
}

getDescription(): string | undefined {
return this.getHeader().getDescription();
}

getRomNamesContainDirectories(): boolean {
return this.getHeader().getRomNamesContainDirectories()
|| this.isBiosDat();
Expand Down
21 changes: 20 additions & 1 deletion src/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface OptionsProps {
readonly output?: string,
readonly dirMirror?: boolean,
readonly dirDatName?: boolean,
readonly dirDatDescription?: boolean,
readonly dirLetter?: boolean,
readonly dirLetterLimit?: number,
readonly overwrite?: boolean,
Expand Down Expand Up @@ -132,6 +133,8 @@ export default class Options implements OptionsProps {

readonly dirDatName: boolean;

readonly dirDatDescription: boolean;

readonly dirLetter: boolean;

readonly dirLetterLimit: number;
Expand Down Expand Up @@ -256,6 +259,7 @@ export default class Options implements OptionsProps {
this.output = options?.output ?? '';
this.dirMirror = options?.dirMirror ?? false;
this.dirDatName = options?.dirDatName ?? false;
this.dirDatDescription = options?.dirDatDescription ?? false;
this.dirLetter = options?.dirLetter ?? false;
this.dirLetterLimit = options?.dirLetterLimit ?? 0;
this.overwrite = options?.overwrite ?? false;
Expand Down Expand Up @@ -681,6 +685,9 @@ export default class Options implements OptionsProps {
if (this.getDirDatName() && dat.getNameShort()) {
output = path.join(output, dat.getNameShort());
}
if (this.getDirDatDescription() && dat.getDescription()) {
output = path.join(output, dat.getDescription() as string);
}

const dirLetter = this.getDirLetterParsed(romFilenameSanitized, romBasenames);
if (dirLetter) {
Expand Down Expand Up @@ -725,7 +732,15 @@ export default class Options implements OptionsProps {
}

private static replaceDatTokens(input: string, dat: DAT): string {
return input.replace('{datName}', dat.getName().replace(/[\\/]/g, '_'));
let output = input;
output = output.replace('{datName}', dat.getName().replace(/[\\/]/g, '_'));

const description = dat.getDescription();
if (description) {
output = output.replace('{datDescription}', description.replace(/[\\/]/g, '_'));
}

return output;
}

private static replaceGameTokens(input: string, game?: Game): string {
Expand Down Expand Up @@ -852,6 +867,10 @@ export default class Options implements OptionsProps {
return this.dirDatName;
}

getDirDatDescription(): boolean {
return this.dirDatDescription;
}

getDirLetter(): boolean {
return this.dirLetter;
}
Expand Down
12 changes: 11 additions & 1 deletion test/modules/argumentsParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ describe('options', () => {
expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dir-mirror', 'true', '--dir-mirror', 'false']).getDirMirror()).toEqual(false);
});

it('should parse "dir-datname"', () => {
it('should parse "dir-dat-name"', () => {
expect(() => argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dir-dat-name'])).toThrow(/dependent|implication/i);
expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dat', os.devNull, '-D']).getDirDatName()).toEqual(true);
expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dat', os.devNull, '--dir-dat-name']).getDirDatName()).toEqual(true);
Expand All @@ -259,6 +259,16 @@ describe('options', () => {
expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dat', os.devNull, '--dir-dat-name', 'true', '--dir-dat-name', 'false']).getDirDatName()).toEqual(false);
});

it('should parse "dir-dat-description"', () => {
expect(() => argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dir-dat-description'])).toThrow(/dependent|implication/i);
expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dat', os.devNull, '--dir-dat-description']).getDirDatDescription()).toEqual(true);
expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dat', os.devNull, '--dir-dat-description', 'true']).getDirDatDescription()).toEqual(true);
expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dat', os.devNull, '--dir-dat-description', 'false']).getDirDatDescription()).toEqual(false);
expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dat', os.devNull, '--dir-dat-description', '--dir-dat-description']).getDirDatDescription()).toEqual(true);
expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dat', os.devNull, '--dir-dat-description', 'false', '--dir-dat-description', 'true']).getDirDatDescription()).toEqual(true);
expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dat', os.devNull, '--dir-dat-description', 'true', '--dir-dat-description', 'false']).getDirDatDescription()).toEqual(false);
});

it('should parse "dir-letter"', () => {
expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dir-letter']).getDirLetter()).toEqual(true);
expect(argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dir-letter', 'true']).getDirLetter()).toEqual(true);
Expand Down
15 changes: 12 additions & 3 deletions test/types/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('getOutputDirRoot', () => {
['games/{mister}/', 'games'],
['Roms/{onion}/', 'Roms'],
['{datName}', '.'],
['{datDescription}', '.'],
])('should find the root dir: %s', (output, expectedPath) => {
expect(new Options({ commands: ['copy'], output }).getOutputDirRoot()).toEqual(expectedPath);
});
Expand Down Expand Up @@ -46,10 +47,11 @@ describe('getOutputFileParsed', () => {
describe('token replacement', () => {
test.each([
['foo/{datName}/bar', path.join('foo', 'DAT _ Name', 'bar', 'game.rom')],
['foo/{datDescription}/bar', path.join('foo', 'DAT _ Description', 'bar', 'game.rom')],
['root/{datReleaseRegion}', path.join('root', 'USA', 'game.rom')],
['root/{datReleaseLanguage}', path.join('root', 'En', 'game.rom')],
])('should replace {dat*}: %s', (output, expectedPath) => {
const dat = new DAT(new Header({ name: 'DAT / Name' }), []);
const dat = new DAT(new Header({ name: 'DAT / Name', description: 'DAT \\ Description' }), []);
const release = new Release('Game Name', 'USA', 'En');
expect(new Options({ commands: ['copy'], output }).getOutputFileParsed(dat, dummyInputRomPath, dummyGame, release, 'game.rom')).toEqual(expectedPath);
});
Expand Down Expand Up @@ -182,12 +184,19 @@ describe('getOutputFileParsed', () => {
});

it('should respect "--dir-dat-name"', () => {
const dat = new DAT(new Header({ name: 'system' }), []);
const dat = new DAT(new Header({ name: 'name', description: 'description' }), []);
expect(new Options({ commands: ['copy'], output: os.devNull, dirDatName: true }).getOutputFileParsed(dummyDat, dummyInputRomPath, dummyGame, dummyRelease, dummyRomFilename)).toEqual(os.devNull);
expect(new Options({ commands: ['copy'], output: os.devNull, dirDatName: true }).getOutputFileParsed(dat, dummyInputRomPath, dummyGame, dummyRelease, dummyRomFilename)).toEqual(path.join(os.devNull, 'system'));
expect(new Options({ commands: ['copy'], output: os.devNull, dirDatName: true }).getOutputFileParsed(dat, dummyInputRomPath, dummyGame, dummyRelease, dummyRomFilename)).toEqual(path.join(os.devNull, 'name'));
expect(new Options({ commands: ['copy'], output: os.devNull, dirDatName: false }).getOutputFileParsed(dat, dummyInputRomPath, dummyGame, dummyRelease, dummyRomFilename)).toEqual(os.devNull);
});

it('should respect "--dir-dat-description"', () => {
const dat = new DAT(new Header({ name: 'name', description: 'description' }), []);
expect(new Options({ commands: ['copy'], output: os.devNull, dirDatDescription: true }).getOutputFileParsed(dummyDat, dummyInputRomPath, dummyGame, dummyRelease, dummyRomFilename)).toEqual(os.devNull);
expect(new Options({ commands: ['copy'], output: os.devNull, dirDatDescription: true }).getOutputFileParsed(dat, dummyInputRomPath, dummyGame, dummyRelease, dummyRomFilename)).toEqual(path.join(os.devNull, 'description'));
expect(new Options({ commands: ['copy'], output: os.devNull, dirDatDescription: false }).getOutputFileParsed(dat, dummyInputRomPath, dummyGame, dummyRelease, dummyRomFilename)).toEqual(os.devNull);
});

it('should respect "--dir-letter"', () => {
expect(new Options({ commands: ['copy'], output: os.devNull, dirLetter: true }).getOutputFileParsed(dummyDat, dummyInputRomPath, dummyGame, dummyRelease, dummyRomFilename)).toEqual(os.devNull);
expect(new Options({ commands: ['copy'], output: os.devNull, dirLetter: true }).getOutputFileParsed(dummyDat, dummyInputRomPath, dummyGame, dummyRelease, 'file.rom')).toEqual(path.join(os.devNull, 'F', 'file.rom'));
Expand Down

0 comments on commit ac86c08

Please sign in to comment.