Skip to content

Commit 6c82636

Browse files
committed
refactor: remove unnecessary comments and improve code clarity across multiple scripts
1 parent 3b0b54c commit 6c82636

8 files changed

Lines changed: 13 additions & 58 deletions

File tree

‎scripts/check-engine.mjs‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ function runScript(file, cwd) {
6565
return { code: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "", timedOut: r.error?.code === "ETIMEDOUT" };
6666
}
6767

68-
// ------------------------------------------------------------ 1. code blocks
69-
7068
function listMarkdown(dir, out = []) {
7169
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
7270
const full = path.join(dir, e.name);
@@ -121,8 +119,6 @@ for (const file of mdFiles) {
121119
});
122120
}
123121

124-
// --------------------------------------------------------------- 2. examples
125-
126122
const exDir = path.join(root, "src/examples");
127123
for (const name of fs.readdirSync(exDir).filter((n) => /^\d+_/.test(n)).sort()) {
128124
const full = path.join(exDir, name);
@@ -139,8 +135,6 @@ for (const name of fs.readdirSync(exDir).filter((n) => /^\d+_/.test(n)).sort())
139135
if (verbose) console.log(` ${r.code === 0 ? "ok " : "ERR"} src/examples/${name}`);
140136
}
141137

142-
// --------------------------------------------- 3 + 4. names and the web policy
143-
144138
const meta = JSON.parse(fs.readFileSync(path.join(root, "src/generated/engine-meta.json"), "utf8"));
145139
const known = new Set([...Object.values(meta.dlc).flatMap((d) => d.functions), ...meta.coreBuiltins]);
146140
// A prefix counts as "a library prefix" when at least two functions share it (math_, str_, list_ ...).
@@ -168,8 +162,6 @@ for (const name of Object.keys(policy.blockedDlcs ?? {})) {
168162
if (!(name in meta.dlc)) fail("src/engine/webPolicy.json", `blocks DLC "${name}", which the engine does not have (typo, or the library was removed)`);
169163
}
170164

171-
// ------------------------------------------------------- 5. metadata freshness
172-
173165
const engineDir = opt("--engine") ?? [path.join(root, "../cuffscript"), path.join(root, "../cuffscript-main"), path.dirname(cuffc)].find((d) => fs.existsSync(path.join(d, "engine")));
174166
let metaStatus = "not checked (no engine source found; pass --engine <dir>)";
175167
if (engineDir && fs.existsSync(path.join(engineDir, "engine"))) {
@@ -185,8 +177,6 @@ if (engineDir && fs.existsSync(path.join(engineDir, "engine"))) {
185177
}
186178
}
187179

188-
// -------------------------------------------------------------------- report
189-
190180
console.log(`cuffc: ${cuffc}`);
191181
console.log(`code blocks run: ${counts.run} (${counts.outputs} with output compared) skipped (fragment/skip): ${counts.skipped} examples run: ${counts.examples} library names checked: ${counts.names}`);
192182
console.log(`engine metadata: ${metaStatus}`);

‎scripts/lib/content.mjs‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function readJson(file, fallback) {
3737
throw new Error(`cannot read ${file}: ${err.message}`, { cause: err });
3838
}
3939
}
40+
4041
function listMarkdown(dir) {
4142
if (!fs.existsSync(dir)) throw new Error(`content directory not found: ${dir}`);
4243
return fs
@@ -91,8 +92,6 @@ export function buildVars(ctx, extra = {}) {
9192
};
9293
}
9394

94-
// ------------------------------------------------------ generated reference
95-
9695
function code(s) {
9796
return `<code>${escapeText(s)}</code>`;
9897
}
@@ -131,8 +130,6 @@ function makeInclude(ctx) {
131130
return (name) => (table[name] ? table[name]() : undefined);
132131
}
133132

134-
// -------------------------------------------------------------------- guide
135-
136133
export function buildGuide(ctx) {
137134
const dir = path.join(ctx.root, "content/guide");
138135
const files = listMarkdown(dir);
@@ -196,8 +193,6 @@ function renderMarkdownInline(text, { file, vars }) {
196193
return r.html.replace(/^<p>([\s\S]*)<\/p>$/, "$1");
197194
}
198195

199-
// --------------------------------------------------------------------- home
200-
201196
function docsGridHtml(guide) {
202197
const items = guide.groups
203198
.filter((g) => g.showOnHome)
@@ -237,17 +232,17 @@ export function buildHome(ctx, guide) {
237232
if (type === "hero") {
238233
cards.push(
239234
`<section class="home-card home-card-hero">\n` +
240-
`<a class="home-logo-link" href="/">\n<img class="home-logo" src="/favicon.svg" alt="CuffScript 로고" />\n</a>\n` +
241-
`<h1>${renderInline(title)}</h1>\n` +
242-
(data.slogan ? `<p class="home-slogan">${renderInline(String(data.slogan))}</p>\n` : "") +
243-
`${rendered}\n</section>`,
235+
`<a class="home-logo-link" href="/">\n<img class="home-logo" src="/favicon.svg" alt="CuffScript 로고" />\n</a>\n` +
236+
`<h1>${renderInline(title)}</h1>\n` +
237+
(data.slogan ? `<p class="home-slogan">${renderInline(String(data.slogan))}</p>\n` : "") +
238+
`${rendered}\n</section>`,
244239
);
245240
} else if (type === "news") {
246241
cards.push(
247242
`<section class="home-card" id="${id}">\n<h2>${renderInline(title)}</h2>\n${rendered}\n` +
248-
`<ul class="home-news-list" id="news-list"></ul>\n` +
249-
`<p class="home-news-state" id="news-state">불러오는 중…</p>\n` +
250-
`<p class="home-news-more">\n<a href="${changelogUrl}" target="_blank" rel="noreferrer">전체 변경 이력 보기 →</a>\n</p>\n</section>`,
243+
`<ul class="home-news-list" id="news-list"></ul>\n` +
244+
`<p class="home-news-state" id="news-state">불러오는 중…</p>\n` +
245+
`<p class="home-news-more">\n<a href="${changelogUrl}" target="_blank" rel="noreferrer">전체 변경 이력 보기 →</a>\n</p>\n</section>`,
251246
);
252247
} else if (type === "docs") {
253248
cards.push(`<section class="home-card" id="${id}">\n<h2>${renderInline(title)}</h2>\n${rendered}\n${docs.html}\n</section>`);
@@ -260,8 +255,6 @@ export function buildHome(ctx, guide) {
260255
return { tocHtml: `<div class="home-toc-group">\n<h2>이 페이지</h2>\n${toc.join("\n")}\n</div>`, cardsHtml: cards.join("\n") };
261256
}
262257

263-
// --------------------------------------------------------------- html shells
264-
265258
const PLACEHOLDERS = {
266259
"<!--@guide:toc-->": (b) => b.guide.tocHtml,
267260
"<!--@guide:article-->": (b) => b.guide.articleHtml,

‎scripts/lib/engine-meta.mjs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ export function extractEngineMeta(engineDir) {
123123
const pkgPath = path.join(engineDir, "npm", "package.json");
124124
const engineVersion = fs.existsSync(pkgPath) ? JSON.parse(readText(pkgPath)).version : "unknown";
125125

126-
// ---- keywords / types / literals (lexer keyword map)
127126
const kw = src.find(/keywordMap\s*\(\s*\)\s*\{/, "keywordMap()");
128127
const kwBody = braceBody(kw.text, kw.match.index);
129128
const entries = [...kwBody.matchAll(/\{\s*"([^"]+)"\s*,\s*TokenType::([A-Z_]+)\s*\}/g)].map((m) => [m[1], m[2]]);
@@ -141,7 +140,6 @@ export function extractEngineMeta(engineDir) {
141140
const dlc = {};
142141
for (const name of dlcNames) dlc[name] = { functions: functionNames(src.registerBody(name)) };
143142

144-
// ---- always-available functions (no `use` needed)
145143
const core = src.find(/void\s+registerBuiltins\s*\([^)]*\)\s*\{/, "registerBuiltins()");
146144
const coreBody = braceBody(core.text, core.match.index);
147145
const coreBuiltins = functionNames(coreBody);
@@ -150,7 +148,6 @@ export function extractEngineMeta(engineDir) {
150148
if (dlc[lib]) coreBuiltins.push(...dlc[lib].functions);
151149
}
152150

153-
// ---- error codes
154151
const ec = src.find(/enum\s+class\s+ErrorCode\s*\{/, "enum class ErrorCode");
155152
const ecBody = braceBody(ec.text, ec.match.index);
156153
const errorCodes = [...ecBody.matchAll(/\b([A-Z]\w*)\s*=\s*(\d{4})\b/g)].map((m) => ({ code: `E${m[2]}`, name: m[1] }));
@@ -168,8 +165,6 @@ export function extractEngineMeta(engineDir) {
168165
};
169166
}
170167

171-
// ------------------------------------------------------ verify against cuffc
172-
173168
function runCuffc(cuffc, script) {
174169
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "cuff-probe-"));
175170
try {
@@ -212,8 +207,6 @@ export function verifyAgainstBinary(meta, cuffc) {
212207
return problems;
213208
}
214209

215-
// ------------------------------------------------------------------- diffing
216-
217210
export function describeDiff(oldMeta, newMeta) {
218211
const lines = [];
219212
const delta = (label, a, b) => {

‎scripts/lib/markdown.mjs‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// - block includes {{ns:name}} and inline variables {{a.b}}
1212
// - raw HTML blocks (a line starting with a tag) and a small inline-tag whitelist
1313
// Code is ALWAYS escaped, so things like "<year:[num]4>" in a snippet can never be
14-
// mistaken for HTML (a bug the hand-written guide used to have).
14+
// mistaken for HTML.
1515

1616
const TEXT_ESC = { "&": "&amp;", "<": "&lt;", ">": "&gt;" };
1717

@@ -30,8 +30,6 @@ export class ContentError extends Error {
3030
}
3131
}
3232

33-
// ---------------------------------------------------------------- front matter
34-
3533
function parseScalar(raw) {
3634
const v = raw.trim();
3735
if (v === "true") return true;
@@ -66,8 +64,6 @@ export function parseFrontmatter(source, file) {
6664
return { data, body: lines.slice(end + 1).join("\n"), bodyLine: end + 2 };
6765
}
6866

69-
// ------------------------------------------------------------------ variables
70-
7167
/** Replaces {{a.b}} (dot form) outside code, keeping line numbers intact. */
7268
export function substituteVars(text, vars, file, firstLine = 1) {
7369
const lines = text.split("\n");
@@ -89,8 +85,6 @@ export function substituteVars(text, vars, file, firstLine = 1) {
8985
const marker = fm[1] ?? "";
9086
if (!fence) {
9187
fence = marker;
92-
// Opt-in: a fence whose info string has the `vars` flag gets variables
93-
// substituted inside it (e.g. the clone URL in the install instructions).
9488
fenceSubstitutes = /(^|\s)vars(\s|$)/.test(fm[2] ?? "");
9589
} else if (marker[0] === fence[0] && marker.length >= fence.length && line.trim() === marker) {
9690
fence = null;
@@ -144,8 +138,6 @@ function findBacktickClose(s, from, n) {
144138
return -1;
145139
}
146140

147-
// -------------------------------------------------------------------- inline
148-
149141
const INLINE_TAGS = new Set(["a", "br", "kbd", "sub", "sup", "span", "abbr", "small", "mark", "em", "strong", "code"]);
150142

151143
function stripInlineMarkup(src) {
@@ -329,8 +321,6 @@ export function renderInline(src) {
329321
return out;
330322
}
331323

332-
// --------------------------------------------------------------------- blocks
333-
334324
const FENCE_RE = /^ {0,3}(`{3,}|~{3,})\s*(.*)$/;
335325
const HEADING_RE = /^(#{1,6})\s+(.*?)\s*$/;
336326
const ATTR_TAIL_RE = /\s+\{((?:[#.][\w-]+|[\w-]+="[^"]*")(?:\s+(?:[#.][\w-]+|[\w-]+="[^"]*"))*)\}\s*$/;
@@ -715,8 +705,6 @@ class Renderer {
715705
}
716706
}
717707

718-
// --------------------------------------------------------------------- public
719-
720708
/**
721709
* Renders Markdown to HTML.
722710
* options: {

‎scripts/render-content.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Prints a fully rendered page (shell + generated content) without starting Vite.
33
// node scripts/render-content.mjs guide -> stdout
44
// node scripts/render-content.mjs home --out dir -> dir/home.html
5-
// Handy for diffing generated HTML in a PR and for quick sanity checks.
65
import fs from "node:fs";
76
import path from "node:path";
87
import { fileURLToPath } from "node:url";

‎scripts/test/check-engine.test.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function brokenCopy(mutate) {
2222
return dir;
2323
}
2424
function check(dir) {
25-
// no --engine: metadata freshness is covered separately below
2625
const r = spawnSync(process.execPath, [path.join(root, "scripts/check-engine.mjs"), "--root", dir, "--cuffc", cuffc, "--engine", "/nonexistent"], { encoding: "utf8" });
2726
return { code: r.status, text: `${r.stdout}\n${r.stderr}` };
2827
}

‎src/newsFeed.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// Renders the "최신 소식" card on the home page by fetching the real
2-
// CHANGELOG.md straight from GitHub at runtime, so this section can never
3-
// drift out of sync with the engine the way the rest of the site once did.
2+
// CHANGELOG.md straight from GitHub at runtime.
43
//
54
// raw.githubusercontent.com serves with permissive CORS (Access-Control-
65
// Allow-Origin: *) and sits behind a CDN, so a plain client-side fetch is
76
// fine here — no API token, and none of api.github.com's low rate limits.
8-
//
9-
// Which repository / branch / how many entries comes from siteConfig.json.
107
import siteConfig from "./siteConfig.json";
118
import { parseChangelog, type ChangelogEntry } from "./changelog";
129

@@ -16,7 +13,7 @@ const CHANGELOG_BLOB_URL = `https://github.com/${siteConfig.repo}/blob/${siteCon
1613

1714
const PARSE_OPTIONS = { maxEntries: siteConfig.newsCount, summaryMaxLen: 200 };
1815
const CACHE_KEY = `cuffscript-site:changelog-feed:v1:${siteConfig.newsCount}`;
19-
const CACHE_TTL_MS = 10 * 60 * 1000; // 10 minutes — avoid refetching on every page view
16+
const CACHE_TTL_MS = 10 * 60 * 1000; // avoid refetching on every page view
2017

2118
function entriesHtml(entries: ChangelogEntry[]): string {
2219
return entries

‎src/styles/base.css‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,8 @@ pre {
549549
}
550550

551551
/* ---- home page ----
552-
A plain, information-dense layout: a light gray backdrop (reusing
553-
--bg-elevated) with stacked white "card" sections, plus a slim sticky
554-
sidebar — closer to a language reference site (e.g. lua.org) than a
555-
marketing landing page. Overriding --radius/--radius-sm/--shadow here
556-
makes every reused component (.btn, .ref-table, <pre>, ...) flatter
557-
within just this page, without touching the guide or IDE. */
552+
--radius/--radius-sm/--shadow are overridden on .home-main so the reused
553+
components (.btn, .ref-table, pre) look flatter here only, not in the guide or IDE. */
558554

559555
.home-main {
560556
flex: 1;

0 commit comments

Comments
 (0)