directory-lister-cli
Version:
A simple Node.js CLI tool to generate a directory structure map.
22 lines (19 loc) • 741 B
JavaScript
// scripts/add-shebang.js
const fs = require('fs');
const path = require('path');
const targetFile = path.resolve(__dirname, '../dist/index.js');
const shebang = '#!/usr/bin/env node\n';
try {
let content = fs.readFileSync(targetFile, 'utf8');
// 既にShebangがある場合は重複しないようにチェック
if (!content.startsWith(shebang)) {
content = shebang + content;
fs.writeFileSync(targetFile, content, 'utf8');
console.log(`✅ Shebang added to ${targetFile}`);
} else {
console.log(`ℹ️ Shebang already exists in ${targetFile}. Skipping.`);
}
} catch (error) {
console.error(`🔴 Error adding Shebang to ${targetFile}:`, error);
process.exit(1); // エラー時はプロセスを終了
}