diff --git a/.gitignore b/.gitignore index 70bbaec..bba2191 100644 --- a/.gitignore +++ b/.gitignore @@ -139,4 +139,8 @@ dist /playwright/.cache/ # test values -/test/project/.env \ No newline at end of file +/test/project/.env +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ diff --git a/package-lock.json b/package-lock.json index e2d38af..380d054 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "tinfoil-hat", "version": "1.1.5", + "hasInstallScript": true, "license": "ISC", "dependencies": { "basic-ftp": "^5.0.3", @@ -28,7 +29,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" } }, @@ -70,22 +72,18 @@ } }, "node_modules/@playwright/test": { - "version": "1.36.2", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.36.2.tgz", - "integrity": "sha512-2rVZeyPRjxfPH6J0oGJqE8YxiM1IBRyM8hyrXYK7eSiAqmbNhxwcLa7dZ7fy9Kj26V7FYia5fh9XJRq4Dqme+g==", + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.45.1.tgz", + "integrity": "sha512-Wo1bWTzQvGA7LyKGIZc8nFSTFf2TkthGIFBR+QVNilvwouGzFd4PYukZe3rvf5PSqjHi1+1NyKSDZKcQWETzaA==", "dev": true, "dependencies": { - "@types/node": "*", - "playwright-core": "1.36.2" + "playwright": "1.45.1" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=16" - }, - "optionalDependencies": { - "fsevents": "2.3.2" + "node": ">=18" } }, "node_modules/@sindresorhus/is": { @@ -116,10 +114,13 @@ "integrity": "sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==" }, "node_modules/@types/node": { - "version": "20.4.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.9.tgz", - "integrity": "sha512-8e2HYcg7ohnTUbHk8focoklEQYvemQmu9M/f43DZVx43kHn0tE3BY/6gSDxS7k0SprtS0NHvj+L80cGLnoOUcQ==", - "dev": true + "version": "20.14.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.10.tgz", + "integrity": "sha512-MdiXf+nDuMvY0gJKxyfZ7/6UFsETO7mGKF54MVD/ekJS6HdFtpZFBgrh6Pseu64XTb2MLyFPlbW6hj8HYRQNOQ==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } }, "node_modules/abbrev": { "version": "1.1.1", @@ -1360,16 +1361,34 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/playwright": { + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.45.1.tgz", + "integrity": "sha512-Hjrgae4kpSQBr98nhCj3IScxVeVUixqj+5oyif8TdIn2opTCPEzqAqNMeK42i3cWDCVu9MI+ZsGWw+gVR4ISBg==", + "dev": true, + "dependencies": { + "playwright-core": "1.45.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, "node_modules/playwright-core": { - "version": "1.36.2", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.36.2.tgz", - "integrity": "sha512-sQYZt31dwkqxOrP7xy2ggDfEzUxM1lodjhsQ3NMMv5uGTRDsLxU0e4xf4wwMkF2gplIxf17QMBCodSFgm6bFVQ==", + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.45.1.tgz", + "integrity": "sha512-LF4CUUtrUu2TCpDw4mcrAIuYrEjVDfT1cHbJMfwnE2+1b8PZcFzPNgvZCvq2JfQ4aTjRCCHw5EJ2tmr2NSzdPg==", "dev": true, "bin": { "playwright-core": "cli.js" }, "engines": { - "node": ">=16" + "node": ">=18" } }, "node_modules/proxy-addr": { @@ -1824,6 +1843,12 @@ "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", "dev": true }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -1887,14 +1912,12 @@ } }, "@playwright/test": { - "version": "1.36.2", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.36.2.tgz", - "integrity": "sha512-2rVZeyPRjxfPH6J0oGJqE8YxiM1IBRyM8hyrXYK7eSiAqmbNhxwcLa7dZ7fy9Kj26V7FYia5fh9XJRq4Dqme+g==", + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.45.1.tgz", + "integrity": "sha512-Wo1bWTzQvGA7LyKGIZc8nFSTFf2TkthGIFBR+QVNilvwouGzFd4PYukZe3rvf5PSqjHi1+1NyKSDZKcQWETzaA==", "dev": true, "requires": { - "@types/node": "*", - "fsevents": "2.3.2", - "playwright-core": "1.36.2" + "playwright": "1.45.1" } }, "@sindresorhus/is": { @@ -1916,10 +1939,13 @@ "integrity": "sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==" }, "@types/node": { - "version": "20.4.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.9.tgz", - "integrity": "sha512-8e2HYcg7ohnTUbHk8focoklEQYvemQmu9M/f43DZVx43kHn0tE3BY/6gSDxS7k0SprtS0NHvj+L80cGLnoOUcQ==", - "dev": true + "version": "20.14.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.10.tgz", + "integrity": "sha512-MdiXf+nDuMvY0gJKxyfZ7/6UFsETO7mGKF54MVD/ekJS6HdFtpZFBgrh6Pseu64XTb2MLyFPlbW6hj8HYRQNOQ==", + "dev": true, + "requires": { + "undici-types": "~5.26.4" + } }, "abbrev": { "version": "1.1.1", @@ -2837,10 +2863,20 @@ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==" }, + "playwright": { + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.45.1.tgz", + "integrity": "sha512-Hjrgae4kpSQBr98nhCj3IScxVeVUixqj+5oyif8TdIn2opTCPEzqAqNMeK42i3cWDCVu9MI+ZsGWw+gVR4ISBg==", + "dev": true, + "requires": { + "fsevents": "2.3.2", + "playwright-core": "1.45.1" + } + }, "playwright-core": { - "version": "1.36.2", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.36.2.tgz", - "integrity": "sha512-sQYZt31dwkqxOrP7xy2ggDfEzUxM1lodjhsQ3NMMv5uGTRDsLxU0e4xf4wwMkF2gplIxf17QMBCodSFgm6bFVQ==", + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.45.1.tgz", + "integrity": "sha512-LF4CUUtrUu2TCpDw4mcrAIuYrEjVDfT1cHbJMfwnE2+1b8PZcFzPNgvZCvq2JfQ4aTjRCCHw5EJ2tmr2NSzdPg==", "dev": true }, "proxy-addr": { @@ -3167,6 +3203,12 @@ "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", "dev": true }, + "undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/package.json b/package.json index bdae43f..76aeb51 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { @@ -49,4 +51,4 @@ "node": "16.20.2", "npm": "9.8.1" } -} +} \ No newline at end of file diff --git a/src/create-index-content.js b/src/create-index-content.js index 84a3d5c..1e1bea4 100644 --- a/src/create-index-content.js +++ b/src/create-index-content.js @@ -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"; @@ -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 diff --git a/src/helpers/helpers.js b/src/helpers/helpers.js index 6134028..6fac114 100644 --- a/src/helpers/helpers.js +++ b/src/helpers/helpers.js @@ -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; @@ -84,5 +70,4 @@ export { addRelativeStartPath, getJsonTemplateFile, fileDirName, - createIfNoExists, }; diff --git a/src/index.js b/src/index.js index 880f1a8..d470702 100644 --- a/src/index.js +++ b/src/index.js @@ -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(); @@ -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)); diff --git a/src/package.js b/src/package.js index 1cb437b..09c6bd8 100644 --- a/src/package.js +++ b/src/package.js @@ -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") diff --git a/src/staticIndexHTML.js b/src/staticIndexHTML.js new file mode 100644 index 0000000..7ba9586 --- /dev/null +++ b/src/staticIndexHTML.js @@ -0,0 +1,365 @@ +export default (locals, callback) => { + const template = ` + + + + + + listing directory / + + + + + +
+

~ /

+ +
+ +` + +callback(undefined, template) +} \ No newline at end of file