-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: start to implement prescanner with the one in the scanner #50
- Loading branch information
Showing
18 changed files
with
172 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
export interface Action { | ||
isScan(): boolean; | ||
type(): ActionType; | ||
} | ||
|
||
export enum ActionType { | ||
PRESCANNER = "PRESCANNER", | ||
PUBLISHER = "PUBLISHER", | ||
SCANNER = "SCANNER", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { File } from "../../../common/domain/valueobject/File.ts"; | ||
import { type Action, ActionType } from "./Action.ts"; | ||
|
||
export class PreScannerAction implements Action { | ||
constructor(public readonly configuration: File) {} | ||
|
||
type(): ActionType { | ||
return ActionType.PRESCANNER; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { type Action, ActionType } from "./Action.ts"; | ||
|
||
export class ScannerAction implements Action { | ||
type(): ActionType { | ||
return ActionType.SCANNER; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { main } from "./main"; | ||
|
||
Deno.exit((await main(Deno.args)) ? 0 : 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { Configuration } from "./configuration/domain/aggregate/Configuration.ts"; | ||
import { VideoGamePlatform } from "./scanner/domain/valueobject/VideoGamePlatform.ts"; | ||
import { scanDirectory } from "./utils/scan-directory.ts"; | ||
|
||
export const preScan = (configuration: Configuration): boolean => { | ||
let filesCount = 0; | ||
let errorsCount = 0; | ||
|
||
for (const scan of configuration.scans) { | ||
const directory: string = scan.directory.path.value; | ||
console.log(`Pre-scanning ${directory}...`); | ||
|
||
const platIndex: number = scan.pattern.groups.indexOf("platform"); | ||
if (platIndex === -1) { | ||
console.error( | ||
` - The pattern "${scan.pattern.regex.source}" does not have a "platform" group.`, | ||
); | ||
errorsCount++; | ||
continue; | ||
} | ||
|
||
scanDirectory(directory, scan.pattern.regex, (filepath) => { | ||
const regexResult: RegExpExecArray = scan.pattern.regex.exec( | ||
filepath, | ||
) as RegExpExecArray; | ||
|
||
const group3: string = regexResult[3]; | ||
try { | ||
new VideoGamePlatform(group3); | ||
filesCount++; | ||
} catch (_) { | ||
console.error(` - "${filepath}" has an invalid platform: ${group3}`); | ||
errorsCount++; | ||
} | ||
}); | ||
} | ||
|
||
console.log("Pre-scan completed!"); | ||
console.log(`Found ${filesCount} files.`); | ||
console.log(`Had ${errorsCount} errors.`); | ||
|
||
return errorsCount > 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.