diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..cbd8b087 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +tools/pc-audit/Invoke-PcAudit.ps1 text working-tree-encoding=UTF-8-BOM diff --git a/scripts/run-pc-audit.js b/scripts/run-pc-audit.js new file mode 100644 index 00000000..c2b66e9d --- /dev/null +++ b/scripts/run-pc-audit.js @@ -0,0 +1,46 @@ +#!/usr/bin/env node +import { readFileSync, writeFileSync } from 'fs'; +import { spawnSync } from 'child_process'; +import { dirname, join } from 'path'; +import { fileURLToPath } from 'url'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const rootDir = join(__dirname, '..'); +const psScript = join(rootDir, 'tools', 'pc-audit', 'Invoke-PcAudit.ps1'); + +function ensureUtf8Bom(filePath) { + let data; + try { + data = readFileSync(filePath); + } catch { + console.error('[pc-audit] Invoke-PcAudit.ps1 が見つかりません:', filePath); + process.exit(1); + } + const hasBom = data.length >= 3 && data[0] === 0xef && data[1] === 0xbb && data[2] === 0xbf; + if (hasBom) return false; + writeFileSync(filePath, Buffer.concat([Buffer.from([0xef, 0xbb, 0xbf]), data])); + return true; +} + +function run() { + const shareSafe = process.argv.includes('--share-safe'); + const bomAdded = ensureUtf8Bom(psScript); + if (bomAdded) { + console.log('[pc-audit] Invoke-PcAudit.ps1 に UTF-8 BOM を自動付与しました。'); + } + + const args = ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', psScript]; + if (shareSafe) args.push('-ShareSafe'); + + const result = spawnSync('powershell', args, { + cwd: rootDir, + stdio: 'inherit', + }); + + if (result.error) { + console.error('[pc-audit] PowerShell 起動失敗:', result.error.message); + } + process.exit(result.status ?? 1); +} + +run();