Skip to content

Commit

Permalink
refactor: remove the need to create fake shop.tfl and shop.json files…
Browse files Browse the repository at this point in the history
… in the /games root folder, avoiding change users file layout
  • Loading branch information
vinicioslc committed Jul 8, 2024
1 parent 3f67652 commit 1ffb114
Show file tree
Hide file tree
Showing 8 changed files with 454 additions and 62 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,8 @@ dist
/playwright/.cache/

# test values
/test/project/.env
/test/project/.env
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
104 changes: 73 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"test": "npx playwright test",
"test:ui": "npx playwright test --ui",
"d:publish:no:cache": "docker build --pull --no-cache --tag vinicioslc/tinfoil-hat:latest . && docker push vinicioslc/tinfoil-hat",
"d:publish": "docker build . && docker tag tinfoil-hat:latest vinicioslc/tinfoil-hat && docker push vinicioslc/tinfoil-hat"
"d:publish": "docker build . && docker tag tinfoil-hat:latest vinicioslc/tinfoil-hat && docker push vinicioslc/tinfoil-hat",
"preinstall": "npx playwright install"
},
"author": "vinicioslc",
"license": "ISC",
Expand All @@ -34,7 +35,8 @@
"urlencode": "^1.1.0"
},
"devDependencies": {
"@playwright/test": "^1.32.3",
"@playwright/test": "^1.45.1",
"@types/node": "^20.14.10",
"nodemon": "^2.0.20"
},
"repository": {
Expand All @@ -49,4 +51,4 @@
"node": "16.20.2",
"npm": "9.8.1"
}
}
}
8 changes: 1 addition & 7 deletions src/create-index-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { romsDirPath, welcomeMessage } from "./helpers/envs.js";
import {
addFileInfoToPath,
addRelativeStartPath,
addUrlEncodedFileInfo as encodeFilePath,
getJsonTemplateFile,
createIfNoExists,
addUrlEncodedFileInfo as encodeURL,
} from "./helpers/helpers.js";

Expand All @@ -17,11 +15,7 @@ const validExtensions = ["nsp", "nsz", "xci", "zip"].map(
);

export default async () => {
// create files info to be showned by the file index package
try {
await createIfNoExists(path.join(romsDirPath, "shop.json"));
await createIfNoExists(path.join(romsDirPath, "shop.tfl"));
} catch (error) {}

const jsonTemplate = getJsonTemplateFile();
let files = await FastGlob(validExtensions, {
cwd: romsDirPath, // use path to resolve games
Expand Down
15 changes: 0 additions & 15 deletions src/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@ import urlencode from "urlencode";
import url from "url";

import { romsDirPath, jsonTemplatePath } from "./envs.js";
import debug from "../debug.js";

// File Exist returns true
// dont use exists which is no more!
const createIfNoExists = async (fileNamePath) => {
try {
// try to read file
await readFile(fileNamePath);
} catch (error) {
// create empty file, because it wasn't found
debug.file("created index file: %o", fileNamePath);
await writeFile(fileNamePath, "");
}
};

const addRelativeStartPath = (path) => {
path.url = "../" + path.url;
Expand Down Expand Up @@ -84,5 +70,4 @@ export {
addRelativeStartPath,
getJsonTemplateFile,
fileDirName,
createIfNoExists,
};
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { romsDirPath, appPort, unauthorizedMessage } from "./helpers/envs.js";
import { afterStartFunction } from "./afterStartFunction.js";
import { getUsersFromEnv } from "./authUsersParser.js";
import SaveSyncManager from "./modules/ftp-client.js";
import staticIndexHTML from "./staticIndexHTML.js";


const saveSyncManager = new SaveSyncManager();
const expressApp = express();
Expand All @@ -31,10 +33,9 @@ expressApp.use(
// will ignore . starting files like .hidden, .env ....
hidden: false,
// should ignore games folders only showing index files
// to avoid bug with not listing when have many games
filter: (filename, index, files) => {
return filename.includes("shop");
},
// to avoid bug not listing on tinfoilapp when have too many games +50 itens aprox.
template: staticIndexHTML

})
);
const server = expressApp.listen(appPort, afterStartFunction(appPort));
Expand Down
1 change: 0 additions & 1 deletion src/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import JSON5 from "json5";
import path from "path";
import { fileDirName } from "./helpers/helpers.js";

path;
const content = JSON5.parse(
fs.readFileSync(
path.join(fileDirName(import.meta).__dirname, "../package.json")
Expand Down
Loading

0 comments on commit 1ffb114

Please sign in to comment.