Skip to content

Commit

Permalink
fix(archive): correctly determine file type or return "Other"
Browse files Browse the repository at this point in the history
  • Loading branch information
damienbutt committed Feb 1, 2024
1 parent 0976139 commit 66e68df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
12 changes: 7 additions & 5 deletions lib/APW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,18 @@ export class APW {
return [...new Set<string>(fileReferences)];
}

public static getFileType(file: string): FileType | null {
if (!(path.extname(file) in AmxExtensions)) {
return null;
public static getFileType(file: string): FileType {
const extension = path.extname(file);

if (!(extension in Object.values<string>(AmxExtensions))) {
return FileType.Other;
}

const fileType = Object.keys(AmxExtensions).find(
(key) => AmxExtensions[key as FileType] === path.extname(file),
(key) => AmxExtensions[key as FileType] === extension,
);

return fileType as FileType;
return (fileType as FileType) || FileType.Other;
}

public static fileIsReadable(file: string): boolean {
Expand Down
15 changes: 1 addition & 14 deletions lib/ArchiveBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,22 +276,9 @@ export class ArchiveBuilder {
}

for (const reference of locatedExtraFileReferences) {
const fileType = APW.getFileType(reference);

if (!fileType) {
verbose &&
console.log(
chalk.red(
`Could not determine file type for ${reference}`,
),
);

continue;
}

const file: File = {
id: "",
type: fileType,
type: APW.getFileType(reference),
path: reference,
exists: true,
isExtra: true,
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import figlet from "figlet";
import StringBuilder from "string-builder";
import { Command, Option } from "commander";
import { Command } from "commander";
import { getAppVersion } from "../lib/utils/index.js";
import { archive, build, cfg } from "./commands/index.js";

Expand Down

0 comments on commit 66e68df

Please sign in to comment.