import * as fs from 'fs'; import * as path from 'path'; const IS_DIR_DEFINED = process.argv.indexOf('--dir'); if (IS_DIR_DEFINED < 0) { console.error(new Error('--dir not specificed').message); process.exit(1); } const DIR = path.join(process.cwd(), process.argv[IS_DIR_DEFINED + 1]); const OUT_FILE = path.join(DIR, './index.d.ts'); fs.readdir(DIR, (error, result: string[]) => { if (error) { console.error(error); process.exit(1); } result = result.filter(file => !/index/.test(file)); console.log(`Files found:\n\t${result.join('\n\t')}`); fs.writeFileSync(OUT_FILE, template(result)); }); function template(files: string[]) { return files.map(file => `/// `).join('\n') }