Created
March 2, 2019 15:16
-
-
Save lqqyt2423/e858dc8ecc6dbdf0fbe5f120ecd970d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
'use strict'; | |
// 合并文件内容 | |
const fs = require('fs'); | |
const path = require('path'); | |
const { log } = console; | |
const cwd = process.cwd(); | |
function eachDir (dir) { | |
const files = fs.readdirSync(dir, { withFileTypes: true }); | |
files.forEach(f => { | |
const name = f.name; | |
const fullname = path.join(dir, name); | |
if (f.isDirectory()) { | |
eachDir(fullname); | |
return; | |
} | |
if (f.isFile() && /\.(c|h|md)$/.test(name)) { | |
const tmpname = fullname.replace(cwd, ''); | |
const content = fs.readFileSync(fullname, 'utf8'); | |
log('`' + tmpname + '`'); | |
log(); | |
if (/\.(c|h)$/.test(name)) { | |
log('``` c'); | |
log(content); | |
log('```'); | |
} | |
else { | |
log(content); | |
} | |
log(); | |
log('----------'); | |
log(); | |
} | |
}); | |
} | |
eachDir(cwd); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment