UNPKG

comb-cli

Version:

comb cli

24 lines (23 loc) 690 B
#!/usr/bin/env node const fs = require('fs'); const path = require('path'); const process = require('process'); const rootPath = process.cwd(); require('shelljs/global'); require('colors'); module.exports = function createJson (data, jsonPath) { if (!test('-f', jsonPath)) { echo('创建json文件'); touch('-r', jsonPath); } return new Promise ((resolve, reject) => { fs.open(jsonPath, "w", 0644, function(e, fd) { if(e) throw e; fs.write(fd,JSON.stringify(data, '', 4), 0, 'utf8', function(e){ if(e) throw e; fs.closeSync(fd); resolve(data); }) }); }); }