From 58b4fb4afad76842aa35dd968ee753795190f5df Mon Sep 17 00:00:00 2001
From: Nutthapat Pongtanyavichai <59821765+Leomotors@users.noreply.github.com>
Date: Mon, 22 Aug 2022 23:59:40 +0700
Subject: [PATCH] refactor: migrate sveltekit
---
.eslintrc.cjs | 5 ++-
.gitattributes | 2 +-
.github/workflows/codeql-analysis.yml | 59 +++++++++++++-------------
.github/workflows/test.yml | 31 --------------
.prettierignore | 3 --
.prettierrc | 8 ----
.prettierrc.cjs | 14 +++++++
CHANGELOG.md | 4 ++
package.json | 7 +---
playwright.config.js | 9 ----
pnpm-lock.yaml | 60 +++------------------------
postcss.config.cjs | 2 +-
src/routes/api/get/+server.ts | 25 ++++-------
src/routes/api/getall/+server.ts | 15 +++----
src/routes/api/insight/+server.ts | 13 ++----
src/routes/debug/+page.svelte | 42 ++-----------------
src/routes/debug/+page.ts | 11 ++---
src/routes/result/+page.ts | 1 -
svelte.config.js | 9 ++++
tests/index.spec.js | 6 ---
tsconfig.json | 18 +-------
vite.config.ts | 10 -----
22 files changed, 96 insertions(+), 258 deletions(-)
delete mode 100644 .github/workflows/test.yml
delete mode 100644 .prettierignore
delete mode 100644 .prettierrc
create mode 100644 .prettierrc.cjs
delete mode 100644 playwright.config.js
delete mode 100644 src/routes/result/+page.ts
delete mode 100644 tests/index.spec.js
diff --git a/.eslintrc.cjs b/.eslintrc.cjs
index de47224..bf8cd08 100644
--- a/.eslintrc.cjs
+++ b/.eslintrc.cjs
@@ -11,7 +11,10 @@ const config = {
],
plugins: ["svelte3", "@typescript-eslint", "simple-import-sort"],
overrides: [
- { files: ["*.svelte"], processor: "svelte3/svelte3" },
+ {
+ files: ["*.svelte"],
+ processor: "svelte3/svelte3",
+ },
{
files: ["*.cjs"],
rules: {
diff --git a/.gitattributes b/.gitattributes
index bceb2f8..82d0730 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1 @@
-src/app.d.ts linguist-vendored=false
+*.d.ts linguist-vendored=false
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index 7babe33..7113db6 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -13,10 +13,10 @@ name: "CodeQL"
on:
push:
- branches: [ main ]
+ branches: [main]
pull_request:
# The branches below must be a subset of the branches above
- branches: [ main ]
+ branches: [main]
jobs:
analyze:
@@ -30,41 +30,40 @@ jobs:
strategy:
fail-fast: false
matrix:
- language: [ 'javascript' ]
+ language: ["javascript"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps:
- - name: Checkout repository
- uses: actions/checkout@v3
+ - name: Checkout repository
+ uses: actions/checkout@v3
- # Initializes the CodeQL tools for scanning.
- - name: Initialize CodeQL
- uses: github/codeql-action/init@v2
- with:
- languages: ${{ matrix.language }}
- # If you wish to specify custom queries, you can do so here or in a config file.
- # By default, queries listed here will override any specified in a config file.
- # Prefix the list here with "+" to use these queries and those in the config file.
-
- # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
- # queries: security-extended,security-and-quality
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v2
+ with:
+ languages: ${{ matrix.language }}
+ # If you wish to specify custom queries, you can do so here or in a config file.
+ # By default, queries listed here will override any specified in a config file.
+ # Prefix the list here with "+" to use these queries and those in the config file.
-
- # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
- # If this step fails, then you should remove it and run the build manually (see below)
- - name: Autobuild
- uses: github/codeql-action/autobuild@v2
+ # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
+ # queries: security-extended,security-and-quality
- # âšī¸ Command-line programs to run using the OS shell.
- # đ See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
+ # If this step fails, then you should remove it and run the build manually (see below)
+ - name: Autobuild
+ uses: github/codeql-action/autobuild@v2
- # If the Autobuild fails above, remove it and uncomment the following three lines.
- # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
+ # âšī¸ Command-line programs to run using the OS shell.
+ # đ See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- # - run: |
- # echo "Run, Build Application using script"
- # ./location_of_script_within_repo/buildscript.sh
+ # If the Autobuild fails above, remove it and uncomment the following three lines.
+ # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
- - name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@v2
+ # - run: |
+ # echo "Run, Build Application using script"
+ # ./location_of_script_within_repo/buildscript.sh
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v2
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
deleted file mode 100644
index 649c05c..0000000
--- a/.github/workflows/test.yml
+++ /dev/null
@@ -1,31 +0,0 @@
-name: Tests
-
-on:
- push:
-
-jobs:
- main:
- name: Tests
- runs-on: ubuntu-latest
-
- steps:
- - name: actions/checkout
- uses: actions/checkout@v2
- - name: Setup Node
- uses: actions/setup-node@v3
- with:
- node-version: 16
- - name: Yarn Cache
- uses: c-hive/gha-yarn-cache@v2
- - name: Install Dependencies (Yarn)
- run: yarn install
- - name: Build Test
- run: yarn build
- - name: ESLint & Prettier Check
- run: yarn lint
- - name: CRLF Phobia Test
- run: npx crlf-phobia *
- - name: Install Browsers
- run: npx playwright install
- - name: Playwright Test
- run: yarn test
diff --git a/.prettierignore b/.prettierignore
deleted file mode 100644
index 57cd8d6..0000000
--- a/.prettierignore
+++ /dev/null
@@ -1,3 +0,0 @@
-*.yml
-*.md
-*.g.*
diff --git a/.prettierrc b/.prettierrc
deleted file mode 100644
index fc52234..0000000
--- a/.prettierrc
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "bracketSpacing": true,
- "tabWidth": 2,
- "useTabs": false,
- "singleQuote": false,
- "semi": true,
- "trailingComma": "es5"
-}
\ No newline at end of file
diff --git a/.prettierrc.cjs b/.prettierrc.cjs
new file mode 100644
index 0000000..2d961a8
--- /dev/null
+++ b/.prettierrc.cjs
@@ -0,0 +1,14 @@
+// @ts-check
+
+/** @type {import("prettier").Config} */
+const config = {
+ bracketSpacing: true,
+ tabWidth: 2,
+ useTabs: false,
+ singleQuote: false,
+ semi: true,
+ trailingComma: "es5",
+ plugins: [require("prettier-plugin-tailwindcss")],
+};
+
+module.exports = config;
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 460f36d..1c2c34b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
All change except updating data will be noted here
+## [1.5.160] - 2022-08-22
+
+- Bump Dependencies, no new feature
+
## [1.4.156] - 2022-06-02
- Statistics is now implemented!
diff --git a/package.json b/package.json
index 5c8a4be..a9a12f3 100644
--- a/package.json
+++ b/package.json
@@ -14,11 +14,10 @@
"homepage": "https://github.com/Leomotors/anime-captcha",
"scripts": {
"pre-build": "pnpm lm-config && node prebuild.js",
- "dev": "pnpm lm-inc && pnpm pre-build && vite dev -p 6912",
+ "dev": "pnpm lm-inc && pnpm pre-build && vite dev --port 6912",
"build": "pnpm pre-build && vite build",
"package": "svelte-kit package",
"preview": "vite preview",
- "test": "playwright test",
"check": "svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check \"*.config.{cjs,js,ts}\" \"{src,tests}/**/*.{ts,svelte,html}\" && eslint src && eslint *.{cjs,js}",
@@ -26,7 +25,6 @@
},
"devDependencies": {
"@leomotors/scripts": "^3.1.0",
- "@playwright/test": "^1.25.0",
"@sveltejs/adapter-vercel": "1.0.0-next.67",
"@sveltejs/kit": "1.0.0-next.428",
"@types/eslint": "^8.4.6",
@@ -40,17 +38,14 @@
"eslint-plugin-svelte3": "^4.0.0",
"globby": "^13.1.2",
"postcss": "^8.4.16",
- "postcss-load-config": "^4.0.1",
"prettier": "^2.7.1",
"prettier-plugin-svelte": "^2.7.0",
"prettier-plugin-tailwindcss": "^0.1.13",
- "rimraf": "^3.0.2",
"sass": "^1.54.5",
"svelte": "^3.49.0",
"svelte-check": "^2.8.1",
"svelte-preprocess": "^4.10.7",
"tailwindcss": "^3.1.8",
- "tslib": "^2.4.0",
"typescript": "^4.7.4",
"vite": "^3.0.9",
"vite-plugin-pwa": "^0.12.3"
diff --git a/playwright.config.js b/playwright.config.js
deleted file mode 100644
index 519a359..0000000
--- a/playwright.config.js
+++ /dev/null
@@ -1,9 +0,0 @@
-// @ts-check
-
-/** @type {import("@playwright/test").PlaywrightTestConfig} */
-export default {
- webServer: {
- command: "pnpm build && pnpm preview --port 6915",
- port: 6915,
- },
-};
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 022719d..6ba50e6 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2,7 +2,6 @@ lockfileVersion: 5.4
specifiers:
'@leomotors/scripts': ^3.1.0
- '@playwright/test': ^1.25.0
'@sveltejs/adapter-vercel': 1.0.0-next.67
'@sveltejs/kit': 1.0.0-next.428
'@types/eslint': ^8.4.6
@@ -16,24 +15,20 @@ specifiers:
eslint-plugin-svelte3: ^4.0.0
globby: ^13.1.2
postcss: ^8.4.16
- postcss-load-config: ^4.0.1
prettier: ^2.7.1
prettier-plugin-svelte: ^2.7.0
prettier-plugin-tailwindcss: ^0.1.13
- rimraf: ^3.0.2
sass: ^1.54.5
svelte: ^3.49.0
svelte-check: ^2.8.1
svelte-preprocess: ^4.10.7
tailwindcss: ^3.1.8
- tslib: ^2.4.0
typescript: ^4.7.4
vite: ^3.0.9
vite-plugin-pwa: ^0.12.3
devDependencies:
'@leomotors/scripts': 3.1.0
- '@playwright/test': 1.25.0
'@sveltejs/adapter-vercel': 1.0.0-next.67
'@sveltejs/kit': 1.0.0-next.428_svelte@3.49.0+vite@3.0.9
'@types/eslint': 8.4.6
@@ -47,17 +42,14 @@ devDependencies:
eslint-plugin-svelte3: 4.0.0_laaqauvsmoyypsiqkozwyi2fn4
globby: 13.1.2
postcss: 8.4.16
- postcss-load-config: 4.0.1_postcss@8.4.16
prettier: 2.7.1
prettier-plugin-svelte: 2.7.0_o3ioganyptcsrh6x4hnxvjkpqi
prettier-plugin-tailwindcss: 0.1.13_prettier@2.7.1
- rimraf: 3.0.2
sass: 1.54.5
svelte: 3.49.0
- svelte-check: 2.8.1_fm7cob7o2okoefsfy52decmzc4
- svelte-preprocess: 4.10.7_6rmvyrdnlelyjuylmqwbrp6lkq
+ svelte-check: 2.8.1_f4ocuume5qq4kteljx4yno44ge
+ svelte-preprocess: 4.10.7_vg6ducirvwwyf55jrdrmsrrkvq
tailwindcss: 3.1.8_postcss@8.4.16
- tslib: 2.4.0
typescript: 4.7.4
vite: 3.0.9_sass@1.54.5
vite-plugin-pwa: 0.12.3_vite@3.0.9
@@ -1357,15 +1349,6 @@ packages:
fastq: 1.13.0
dev: true
- /@playwright/test/1.25.0:
- resolution: {integrity: sha512-j4EZhTTQI3dBeWblE21EV//swwmBtOpIrLdOIJIRv4uqsLdHgBg1z+JtTg+AeC5o2bAXIE26kDNW5A0TimG8Bg==}
- engines: {node: '>=14'}
- hasBin: true
- dependencies:
- '@types/node': 18.7.9
- playwright-core: 1.25.0
- dev: true
-
/@polka/url/1.0.0-next.21:
resolution: {integrity: sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==}
dev: true
@@ -3531,12 +3514,6 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
- /playwright-core/1.25.0:
- resolution: {integrity: sha512-kZ3Jwaf3wlu0GgU0nB8UMQ+mXFTqBIFz9h1svTlNduNKjnbPXFxw7mJanLVjqxHJRn62uBfmgBj93YHidk2N5Q==}
- engines: {node: '>=14'}
- hasBin: true
- dev: true
-
/postcss-import/14.1.0_postcss@8.4.16:
resolution: {integrity: sha512-flwI+Vgm4SElObFVPpTIT7SU7R3qk2L7PyduMcokiaVKuWv9d/U+Gm/QAd8NDLuykTWTkcrjOeD2Pp1rMeBTGw==}
engines: {node: '>=10.0.0'}
@@ -3576,23 +3553,6 @@ packages:
yaml: 1.10.2
dev: true
- /postcss-load-config/4.0.1_postcss@8.4.16:
- resolution: {integrity: sha512-vEJIc8RdiBRu3oRAI0ymerOn+7rPuMvRXslTvZUKZonDHFIczxztIyJ1urxM1x9JXEikvpWWTUUqal5j/8QgvA==}
- engines: {node: '>= 14'}
- peerDependencies:
- postcss: '>=8.0.9'
- ts-node: '>=9.0.0'
- peerDependenciesMeta:
- postcss:
- optional: true
- ts-node:
- optional: true
- dependencies:
- lilconfig: 2.0.6
- postcss: 8.4.16
- yaml: 2.1.1
- dev: true
-
/postcss-nested/5.0.6_postcss@8.4.16:
resolution: {integrity: sha512-rKqm2Fk0KbA8Vt3AdGN0FB9OBOMDVajMG6ZCf/GoHgdxUJ4sBFp0A/uMIRm+MJUdo33YXEtjqIz8u7DAp8B7DA==}
engines: {node: '>=12.0'}
@@ -4097,7 +4057,7 @@ packages:
engines: {node: '>= 0.4'}
dev: true
- /svelte-check/2.8.1_fm7cob7o2okoefsfy52decmzc4:
+ /svelte-check/2.8.1_f4ocuume5qq4kteljx4yno44ge:
resolution: {integrity: sha512-cibyY1sgt3ONIDnQbSgV2X9AJFhwEslRHNo95lijrYfPzVEvTvbmL2ohsUyqB5L7j1GhLXtQbjCJ4lZZ/fwbeQ==}
hasBin: true
peerDependencies:
@@ -4110,7 +4070,7 @@ packages:
picocolors: 1.0.0
sade: 1.8.1
svelte: 3.49.0
- svelte-preprocess: 4.10.7_6rmvyrdnlelyjuylmqwbrp6lkq
+ svelte-preprocess: 4.10.7_vg6ducirvwwyf55jrdrmsrrkvq
typescript: 4.7.4
transitivePeerDependencies:
- '@babel/core'
@@ -4134,7 +4094,7 @@ packages:
svelte: 3.49.0
dev: true
- /svelte-preprocess/4.10.7_6rmvyrdnlelyjuylmqwbrp6lkq:
+ /svelte-preprocess/4.10.7_vg6ducirvwwyf55jrdrmsrrkvq:
resolution: {integrity: sha512-sNPBnqYD6FnmdBrUmBCaqS00RyCsCpj2BG58A1JBswNF7b0OKviwxqVrOL/CKyJrLSClrSeqQv5BXNg2RUbPOw==}
engines: {node: '>= 9.11.2'}
requiresBuild: true
@@ -4180,7 +4140,6 @@ packages:
detect-indent: 6.1.0
magic-string: 0.25.9
postcss: 8.4.16
- postcss-load-config: 4.0.1_postcss@8.4.16
sass: 1.54.5
sorcery: 0.10.0
strip-indent: 3.0.0
@@ -4306,10 +4265,6 @@ packages:
resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==}
dev: true
- /tslib/2.4.0:
- resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==}
- dev: true
-
/tsutils/3.21.0_typescript@4.7.4:
resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
engines: {node: '>= 6'}
@@ -4688,11 +4643,6 @@ packages:
engines: {node: '>= 6'}
dev: true
- /yaml/2.1.1:
- resolution: {integrity: sha512-o96x3OPo8GjWeSLF+wOAbrPfhFOGY0W00GNaxCDv+9hkcDJEnev1yh8S7pgHF0ik6zc8sQLuL8hjHjJULZp8bw==}
- engines: {node: '>= 14'}
- dev: true
-
/yocto-queue/0.1.0:
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
engines: {node: '>=10'}
diff --git a/postcss.config.cjs b/postcss.config.cjs
index 2a08de7..a61ee3e 100644
--- a/postcss.config.cjs
+++ b/postcss.config.cjs
@@ -2,5 +2,5 @@ const tailwindcss = require("tailwindcss");
const autoprefixer = require("autoprefixer");
module.exports = {
- plugins: [tailwindcss(), autoprefixer],
+ plugins: [tailwindcss(), autoprefixer()],
};
diff --git a/src/routes/api/get/+server.ts b/src/routes/api/get/+server.ts
index b060e6b..05f94b2 100644
--- a/src/routes/api/get/+server.ts
+++ b/src/routes/api/get/+server.ts
@@ -1,8 +1,9 @@
-import type { RequestHandler } from "@sveltejs/kit";
-import type { JSONObject } from "@sveltejs/kit/types/private";
+import { error, json } from "@sveltejs/kit";
import { getQuestions, getRandomQuestions } from "$data/getter";
+import type { RequestHandler } from "./$types";
+
export const GET: RequestHandler = ({ params }) => {
const category = params.category;
@@ -10,29 +11,17 @@ export const GET: RequestHandler = ({ params }) => {
const questions = getQuestions(category);
if (questions) {
- throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292701)");
- // Suggestion (check for correctness before using):
- // return new Response(questions as unknown as JSONObject);
- return {
- status: 200,
- body: questions as unknown as JSONObject,
- };
+ return json(questions);
} else {
- return new Response("Invalid Category", { status: 400 });
+ return error(400, "Invalid Category");
}
} else {
const questions = getRandomQuestions();
if (questions) {
- throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292701)");
- // Suggestion (check for correctness before using):
- // return new Response(questions as unknown as JSONObject);
- return {
- status: 200,
- body: questions as unknown as JSONObject,
- };
+ return json(questions);
} else {
- return new Response("Internal Server Error", { status: 500 });
+ return error(500, "Internal Server Error");
}
}
};
diff --git a/src/routes/api/getall/+server.ts b/src/routes/api/getall/+server.ts
index a61e481..92f2d36 100644
--- a/src/routes/api/getall/+server.ts
+++ b/src/routes/api/getall/+server.ts
@@ -1,12 +1,9 @@
-import type { RequestHandler } from "@sveltejs/kit";
-import type { JSONObject } from "@sveltejs/kit/types/private";
+import { json } from "@sveltejs/kit";
import { getAll } from "$data/getter";
-throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292701)");
-// Suggestion (check for correctness before using):
-// // return new Response(getAll() as unknown as JSONObject);
-export const GET: RequestHandler = () => ({
- status: 200,
- body: getAll() as unknown as JSONObject,
-});
+import type { RequestHandler } from "./$types";
+
+export const GET: RequestHandler = () => {
+ return json(getAll());
+};
diff --git a/src/routes/api/insight/+server.ts b/src/routes/api/insight/+server.ts
index faf1b26..630d00c 100644
--- a/src/routes/api/insight/+server.ts
+++ b/src/routes/api/insight/+server.ts
@@ -1,14 +1,9 @@
-import { json as json$1 } from '@sveltejs/kit';
-import type { RequestHandler } from "@sveltejs/kit";
+import { json } from "@sveltejs/kit";
import Insight from "$data/insight.g.json";
+import type { RequestHandler } from "./$types";
+
export const GET: RequestHandler = () => {
- throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292701)");
- // Suggestion (check for correctness before using):
- // return json$1(Insight);
- return {
- status: 200,
- body: Insight,
- };
+ return json(Insight);
};
diff --git a/src/routes/debug/+page.svelte b/src/routes/debug/+page.svelte
index 9d14028..f6599fc 100644
--- a/src/routes/debug/+page.svelte
+++ b/src/routes/debug/+page.svelte
@@ -1,44 +1,10 @@
-
-