Skip to content

Commit ca98c1c

Browse files
committed
🔨 unicode合成文字を除外
1 parent 138dc84 commit ca98c1c

14 files changed

+360
-73
lines changed

dev/build.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { execSync } = require("node:child_process");
1010

1111
const generateIndex = require("./build/generateIndex.js");
1212
const createEntryEndpoint = require("./build/createEntryEndpoint.js");
13+
const checkIllegalStrings = require("./build/checkIllegalStrings.js");
1314
const CL = require("./libs/ColorLogger.js");
1415

1516
const script_name = "JavaLibraryScript";
@@ -133,9 +134,9 @@ function fixDtsOutputFlexible(filePath) {
133134

134135
(async () => {
135136
const debug = true;
137+
const start = performance.now();
136138
try {
137-
const start = performance.now();
138-
console.log(`🎉 ${CL.brightYellow("ビルド開始")}`);
139+
console.log(`🎉 ${CL.brightYellow("ビルド開始")}`);
139140
//
140141
console.log(`┣🔁 ${CL.brightWhite("index.js自動生成開始...")}`);
141142
generateIndex(entryDir);
@@ -175,11 +176,21 @@ function fixDtsOutputFlexible(filePath) {
175176
showFileSize(typesPath);
176177
}
177178

179+
console.log(`┃🔍 ${CL.brightWhite("問題性の高い文字列の検査を開始...")}`);
180+
const illegalFound = checkIllegalStrings(baseDir);
181+
if (illegalFound) {
182+
console.log(`┃┗❌ ${CL.brightWhite("検査完了")} ${CL.red("(違法文字列発見)")}`);
183+
} else {
184+
console.log(`┃┗✅ ${CL.brightWhite("検査完了")}`);
185+
}
186+
178187
const end = performance.now() - start;
179-
console.log(`┣🕒 ${CL.brightWhite("ビルド時間")}: ${CL.brightGreen(end.toFixed(2))} ms`);
180-
console.log(`┗🎉 ${CL.brightYellow("ビルド完了")}`);
188+
console.log(`┣🕒 ${CL.brightWhite("ビルド時間")}: ${CL.brightGreen(end.toFixed(2))} ms`);
189+
console.log(`┗🎉 ${CL.brightYellow("ビルド完了")}`);
181190
} catch (e) {
182-
console.error("┗❌ ビルド失敗:", e);
191+
const end = performance.now() - start;
192+
console.log(`┣🕒 ${CL.brightWhite("ビルド時間")}: ${CL.brightGreen(end.toFixed(2))} ms`);
193+
console.error(`┗❌ ${CL.brightRed("ビルド失敗")}:`, e);
183194
process.exit(1);
184195
}
185196
})();

dev/build/checkIllegalStrings.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const fs = require("node:fs");
2+
const path = require("node:path");
3+
4+
const CL = require("../libs/ColorLogger.js");
5+
6+
/**
7+
* 検査対象の設定
8+
*/
9+
const config = {
10+
includeExtensions: [".js", ".ts", ".json", ".md", "bat", ".txt", ".html", ".css"], // 検査対象ファイルの拡張子
11+
excludeFiles: ["checkIllegalStrings.js", "package-lock.json", "LICENSE"], // 除外するファイル
12+
excludeDirs: ["node_modules", ".git", "dist"], // 除外するフォルダ
13+
illegalPatterns: [/[\u3099\u309A]/], // 違法文字列(正規表現)
14+
};
15+
16+
/**
17+
* ファイルを検査する
18+
*/
19+
function checkFile(filePath, baseDir) {
20+
const content = fs.readFileSync(filePath, "utf-8");
21+
const lines = content.split(/\r?\n/);
22+
23+
let found = false;
24+
25+
lines.forEach((line, idx) => {
26+
for (const pattern of config.illegalPatterns) {
27+
const match = line.match(pattern);
28+
if (match) {
29+
if (!found) {
30+
console.log(`┃┣🚨 ${CL.brightRed("違法文字列を検出")}: ${path.relative(baseDir, filePath)}`);
31+
found = true;
32+
}
33+
const highlight = line.replace(pattern, (m) => `${CL.RESET}${CL.red(m)}${CL.STYLE.dim}`); // ハイライト
34+
console.log(`┃┃ [${idx + 1}行目] ${CL.STYLE.dim}${highlight}${CL.RESET}`);
35+
console.log(`┃┃ → マッチ: ${CL.brightCyan(match[0])}`);
36+
console.log(`┃┃ → パターン: ${CL.brightMagenta(pattern)}`);
37+
}
38+
}
39+
});
40+
return found;
41+
}
42+
43+
/**
44+
* ディレクトリを再帰的に探索
45+
*/
46+
function checkIllegalStrings(dirPath, baseDir = dirPath) {
47+
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
48+
49+
let found = false;
50+
51+
for (const entry of entries) {
52+
const fullPath = path.join(dirPath, entry.name);
53+
54+
// 除外処理
55+
if (entry.isDirectory()) {
56+
if (config.excludeDirs.includes(entry.name)) continue;
57+
found = checkIllegalStrings(fullPath, baseDir) || found;
58+
} else {
59+
if (config.excludeFiles.includes(entry.name)) continue;
60+
const ext = path.extname(entry.name).toLowerCase();
61+
if (!config.includeExtensions.includes(ext)) continue;
62+
found = checkFile(fullPath, baseDir) || found;
63+
}
64+
}
65+
return found;
66+
}
67+
68+
module.exports = checkIllegalStrings;

dev/libs/ColorLogger.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class ColorLogger {
3434

3535
static STYLE = {
3636
bold: "\x1b[1m",
37+
dim: "\x1b[2m",
38+
italic: "\x1b[3m",
3739
underline: "\x1b[4m",
3840
reverse: "\x1b[7m",
3941
};
@@ -90,6 +92,12 @@ class ColorLogger {
9092
static bold(text) {
9193
return this.color(text, this.STYLE.bold);
9294
}
95+
static dim(text) {
96+
return this.color(text, this.STYLE.dim);
97+
}
98+
static italic(text) {
99+
return this.color(text, this.STYLE.italic);
100+
}
93101
static underline(text) {
94102
return this.color(text, this.STYLE.underline);
95103
}

dist/JavaLibraryScript.js

Lines changed: 103 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)