Skip to content

Commit c0faa54

Browse files
committed
🚧 作業前バックアップ
1 parent ca98c1c commit c0faa54

28 files changed

+1489
-1279
lines changed

api-extractor.json

Lines changed: 422 additions & 0 deletions
Large diffs are not rendered by default.

dev/build.js

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const exorcist = require("exorcist");
33
const rollup = require("rollup");
44
const dts = require("rollup-plugin-dts").default;
55
const commonjs = require("@rollup/plugin-commonjs");
6+
const { Extractor, ExtractorConfig } = require("@microsoft/api-extractor");
67
const fs = require("node:fs");
78
const path = require("node:path");
89
const { minify } = require("terser");
@@ -123,23 +124,62 @@ async function buildRollup() {
123124
});
124125
}
125126

126-
function fixDtsOutputFlexible(filePath) {
127+
function runApiExtractor() {
128+
const extractorConfigPath = path.resolve(baseDir, "api-extractor.json");
129+
const extractorConfig = ExtractorConfig.loadFileAndPrepare(extractorConfigPath);
130+
131+
const { succeeded, errors, warnings } = Extractor.invoke(extractorConfig, {
132+
localBuild: true,
133+
showVerboseMessages: true,
134+
});
135+
136+
if (succeeded) {
137+
console.log("✨ API Extractor completed successfully!");
138+
} else {
139+
throw new Error("💥API Extractor failed.");
140+
}
141+
}
142+
143+
function fixDtsOutputFlexible(filePath, log = false) {
127144
let code = fs.readFileSync(filePath, "utf8");
128145

129-
const reg = new RegExp(`export\s{\s${script_name}\sas\sdefault\s};`);
130-
code = code.replace(reg, `export default ${script_name};`);
146+
const regList = [
147+
// 修正をここに追加
148+
[
149+
`declare\\s+namespace\\s+(__(?:[a-z]+_)+[A-Za-z]+_js)\\s+{\\s+export\\s+{[\\s\\S]*?\\s+};\\s+}\\s+`,
150+
(a, b) => {
151+
if (log) console.log(`┃┃ namespace ${b} : ${CL.cyan("削除")}`);
152+
return "";
153+
},
154+
],
155+
[
156+
`(\\s+)(__(?:[a-z]+_)+([A-Za-z]+)_js)`,
157+
(a, b, c, d) => {
158+
if (log) console.log(`┃┃ ${c} -> ${d} : ${CL.cyan("統合")}`);
159+
return `${b}${d}`;
160+
},
161+
],
162+
];
163+
164+
for (const [reg, rep] of regList) {
165+
const re = new RegExp(reg, "gm");
166+
code = code.replace(re, rep);
167+
}
131168

132169
fs.writeFileSync(filePath, code);
133170
}
134171

135172
(async () => {
136173
const debug = true;
174+
// 動作確認用 ログ表示
175+
const logView = true;
176+
//
137177
const start = performance.now();
138178
try {
139179
console.log(`🎉 ${CL.brightYellow("ビルド開始")}`);
140180
//
141181
console.log(`┣🔁 ${CL.brightWhite("index.js自動生成開始...")}`);
142-
generateIndex(entryDir);
182+
generateIndex(entryDir, logView);
143183
console.log(`┃┗🌱 ${CL.brightWhite("自動生成完了")}`);
144184
//
145185
console.log(`┃🗑️ ${CL.brightWhite("distフォルダリセット")}`);
@@ -166,13 +206,14 @@ function fixDtsOutputFlexible(filePath) {
166206
console.log(`┃⛳ ${CL.brightWhite("rollup用entrypoint作成")}`);
167207
createEntryEndpoint(entryTypesPath);
168208
console.log("┃📦 .d.ts を rollup中...");
169-
await buildRollup();
209+
//await buildRollup();
210+
runApiExtractor();
170211
console.log(`┃┗✅ ${CL.brightWhite("rollup完了")}: ${getRelativePath(typesPath)}`);
171212
console.log(`┃🗑️ ${CL.brightWhite("types仮フォルダcleanup")}`);
172-
prepareDir(typesTmpDir);
173-
console.log(`┃🌵 ${CL.brightWhite("export問題を解決")}`);
174-
fixDtsOutputFlexible(typesPath);
175-
console.log(`┃┗✅ ${CL.brightWhite("export default 生成完了")}: ${getRelativePath(typesPath)}`);
213+
//prepareDir(typesTmpDir);
214+
console.log(`┃🌵 ${CL.brightWhite("予測候補問題を解決")}`);
215+
fixDtsOutputFlexible(typesPath, logView);
216+
console.log(`┃┗✅ ${CL.brightWhite("予測候補問題 修正完了")}: ${getRelativePath(typesPath)}`);
176217
showFileSize(typesPath);
177218
}
178219

dev/build/generateIndex.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function isPlainObjectExport(modulePath) {
2323
* index.jsを生成する
2424
* @param {string} dir
2525
*/
26-
function generateIndex(dir, baseDir = dir) {
26+
function generateIndex(dir, log = false, baseDir = dir) {
2727
const entries = fs.readdirSync(dir, { withFileTypes: true });
2828

2929
// jsファイルだけ、かつindex.jsは除外
@@ -34,7 +34,7 @@ function generateIndex(dir, baseDir = dir) {
3434

3535
// 先にサブディレクトリも再帰処理(深い階層から順に)
3636
for (const subDir of subDirs) {
37-
generateIndex(path.join(dir, subDir.name), baseDir);
37+
generateIndex(path.join(dir, subDir.name), log, baseDir);
3838
}
3939

4040
// export文を作成
@@ -66,7 +66,7 @@ function generateIndex(dir, baseDir = dir) {
6666
// index.jsを書き込み
6767
fs.writeFileSync(path.join(dir, "index.js"), content, "utf8");
6868

69-
console.log(`┃┣📜 Generated index.js in ${CL.brightBlue(path.relative(path.dirname(baseDir), dir))}`);
69+
if (log) console.log(`┃┣📜 Generated index.js in ${CL.brightBlue(path.relative(path.dirname(baseDir), dir))}`);
7070
}
7171

7272
module.exports = generateIndex;

0 commit comments

Comments
 (0)