README
文件夹转json
const fs = require('fs');
function dirtojson(dir) {
let stat = fs.statSync(dir);
if (stat.isFile()) {
return {
name: dir,
isfile: true,
content: fs.readFileSync(dir, 'utf8'),
ext: dir.slice(dir.lastIndexOf('.')),
}
} else {
return {
name: dir,
isfile: false,
content: fs.readdirSync(dir).map(item => {
return dirtojson(dir + '/' + item);
})
}
}
}
let data = JSON.stringify(dirtojson('2'));
fs.writeFileSync('index.json', data);