Skip to content

Commit 3fd4d35

Browse files
authored
Merge pull request #9 from scpwiki/build
Replace build system with vite
2 parents fa42083 + c0c8bc4 commit 3fd4d35

8 files changed

Lines changed: 87 additions & 150 deletions

File tree

index.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>SCP Tag List Generator</title>
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<script type="module" src="/src/main.ts"></script>
11+
12+
<main>
13+
<p>
14+
This tool uses the
15+
<a href="https://wikidot.croquembouche.net/">wikidot.croquembouche.net</a> CORS Proxy.
16+
</p>
17+
<h2>1. Templates <span id="template-state"></span></h2>
18+
19+
<p>Paste the EJS template for the tag list hub page into here:</p>
20+
<textarea id="template-hub"></textarea>
21+
22+
<p>Then, paste the EJS template for the TOML data page into here:</p>
23+
<textarea id="template-data"></textarea>
24+
25+
<p>Or, fetch them via URL:</p>
26+
<form>
27+
<input id="template-hub-url"></input>
28+
<button type="button" id="template-hub-url-button">Fetch</button>
29+
30+
<input id="template-data-url"></input>
31+
<button type="button" id="template-data-url-button">Fetch</button>
32+
</form>
33+
34+
<h2>2. Tag definitions <span id="definitions-state"></span></h2>
35+
<p>
36+
Paste a tag definitions file in here. It will be removed instantly and
37+
will appear in the list below. Repeat for each tag file.
38+
</p>
39+
<textarea id="definitions"></textarea>
40+
<p>Or, fetch them via URL:</p>
41+
<form>
42+
<textarea id="definitions-urls"></textarea>
43+
<button type="button" id="definitions-urls-button">Fetch all</button>
44+
</form>
45+
46+
<p>Tag definition files received:</p>
47+
<ul id="tags-received"></ul>
48+
<p><span id="total-tags"></span> tags in total.</p>
49+
<div id="definitions-errors" class="errors"></div>
50+
51+
<h2>3. Outputs <span id="output-state"></span></h2>
52+
53+
<p>Copy and paste this into the tag list hub page:</p>
54+
<textarea id="output-hub" readonly></textarea>
55+
<p id="output-hub-errors" class="errors"></p>
56+
57+
<p>Then, copy and paste this into the TOML data page:</p>
58+
<textarea id="output-data" readonly></textarea>
59+
<p id="output-data-errors" class="errors"></p>
60+
</main>
61+
</body>
62+
</html>

package.json

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,26 @@
11
{
22
"name": "tag-list",
33
"version": "0.0.0",
4-
"main": "src/index.ts",
4+
"main": "src/main.ts",
55
"scripts": {
6-
"lint": "standardx src/**/*.ts",
7-
"fix": "standardx src/**/*.ts --fix",
8-
"start": "NODE_ENV=development webpack serve --config webpack.config.js --open --open-page webpack-dev-server/",
9-
"build": "NODE_ENV=production webpack --config webpack.config.js",
10-
"tests": "jest"
11-
},
12-
"jest": {
13-
"moduleFileExtensions": [
14-
"js",
15-
"ts"
16-
]
6+
"dev": "vite",
7+
"build": "vite build",
8+
"preview": "vite preview",
9+
"lint": "prettier --check . && eslint . && stylelint ./src/**/*.css",
10+
"lint:fix": "prettier --write . && eslint . --fix && stylelint ./src/**/*.css --fix",
11+
"format": "prettier --write .",
12+
"tests": "vitest run"
1713
},
1814
"browserslist": "last 5 years",
19-
"babel": {
20-
"presets": [
21-
"@babel/preset-env",
22-
"@babel/preset-typescript"
23-
],
24-
"plugins": [
25-
"@babel/plugin-transform-runtime"
26-
]
27-
},
2815
"devDependencies": {
29-
"@babel/core": "^7.12.10",
30-
"@babel/plugin-transform-runtime": "^7.12.10",
31-
"@babel/preset-env": "^7.12.11",
32-
"@babel/preset-typescript": "^7.12.7",
33-
"@types/ejs": "^3.0.5",
34-
"@types/jest": "^26.0.20",
35-
"@typescript-eslint/eslint-plugin": "^4.13.0",
36-
"@typescript-eslint/parser": "^4.13.0",
37-
"babel-loader": "^8.2.2",
38-
"clean-webpack-plugin": "^3.0.0",
39-
"css-loader": "^5.0.1",
40-
"ejs": "^3.1.5",
41-
"eslint": "^7.18.0",
42-
"html-loader": "^1.3.2",
43-
"html-webpack-plugin": "^4.5.1",
44-
"jest": "^26.6.3",
45-
"runtypes": "^5.0.1",
46-
"standardx": "^7.0.0",
47-
"style-loader": "^2.0.0",
48-
"toml": "^3.0.0",
49-
"typescript": "^4.1.3",
50-
"webpack": "^5.15.0",
51-
"webpack-cli": "^4.3.1",
52-
"webpack-dev-server": "^3.11.2"
16+
"@types/ejs": "^3.1.5",
17+
"ejs": "^6.0.1",
18+
"prettier": "^3.9.5",
19+
"prettier-plugin-organize-imports": "^4.3.0",
20+
"runtypes": "6.7.0",
21+
"toml": "^4.1.2",
22+
"typescript": "^6.0.2",
23+
"vite": "^8.1.4",
24+
"vitest": "^4.1.10"
5325
}
5426
}

src/index.html

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/index.ts renamed to src/main.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import html from "./index.html"
21
import "./root.css"
32

4-
import { render } from "ejs"
3+
import ejs from 'ejs';
54
import {
65
parseConfig, TagCategory, TomlParseError, ConfigParseError
76
} from "./parser"
@@ -40,19 +39,13 @@ function reportError (
4039
* Gets a parameter from the URL query, returning a default if no value is
4140
* found.
4241
*
43-
* This function only works if the <script> tag that references the bundle
44-
* contains the URL query parameters in the URL that points to the bundle, and
45-
* it must also have id 'script'.
46-
*
4742
* @param paramName - The name of the parameter.
4843
* @param defaultValue - The value to return if the parameter in the URL query
4944
* is not present.
5045
*/
5146
function getQueryParam(paramName: string, defaultValue: string): string {
5247
try {
53-
const script = <HTMLScriptElement | null>document.getElementById("script")
54-
if (!script) throw new Error("Script with #script not found")
55-
const params = new URL(script.src).searchParams
48+
const params = new URL(window.location.href).searchParams
5649
return params.get(paramName) ?? defaultValue
5750
} catch(error) {
5851
console.error(error)
@@ -78,8 +71,6 @@ let templates = { hub: "", data: "" }
7871
// Track the tag category definitions
7972
const definitions: { [category: string]: TagCategory } = {}
8073

81-
document.body.innerHTML = html;
82-
8374
const templateHubBox = el<HTMLTextAreaElement>("template-hub")
8475
const templateHubUrlBox = el<HTMLInputElement>("template-hub-url")
8576
const templateHubUrlButton = el<HTMLButtonElement>("template-hub-url-button")
@@ -200,7 +191,7 @@ function makeOutput(template: string, outputBox: HTMLTextAreaElement, errors: HT
200191

201192
let output
202193
try {
203-
output = render(template, {
194+
output = ejs.render(template, {
204195
getCategory: (name: string) => {
205196
if (!name.endsWith("/")) {
206197
throw new Error(

src/parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ const TagCategorySectionConfigRuntype = ArrayRT(
7070
name: String,
7171
description: String
7272
}),
73-
// Tags in the section
74-
TagDefinitionsRuntype
73+
// Relationship properties applied to the section
74+
TagRelationshipsRuntype
7575
)
7676
)
7777

@@ -207,7 +207,7 @@ export function parseConfig (config: string): TagCategory {
207207
}
208208

209209
// Remaining properties are tags
210-
return { ...section, tags: sectionConfig }
210+
return { ...section, tags: TagDefinitionsRuntype.check(sectionConfig) }
211211
})
212212
delete categoryConfig.section
213213
} else {

tests/documentation.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, it } from "vitest"
12
import { makeRelationshipsStringsForTag } from "../src/documentation"
23
import { getTargets } from "../src/documentation"
34
import { TagCategory } from "../src/parser"

tests/parser.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, it } from "vitest"
12
import { parseConfig, TomlParseError, ConfigParseError } from "../src/parser"
23

34
describe("config parser", () => {

webpack.config.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)