cordova-sync
Version:
Respond to file changes and build Cordova application
45 lines (39 loc) • 810 B
JavaScript
const fs = require('fs')
const fse = require('fs-extra')
const path = require('path')
const currentDir = process.cwd()
const createDirName = (...name) => path.resolve(currentDir, ...name)
function isDir (dir) {
return new Promise((res) => {
fs.stat(dir, (err, data) => {
if (data) res(true)
res(false)
})
})
}
function createDir (dir) {
return new Promise((res, rej) => {
fs.mkdir(dir, (err) => {
if (err) rej(err)
res(dir)
})
})
}
function copyDir (from, to) {
return fse.copy(from, to)
}
function write (filepath, contents) {
return new Promise((res, rej) => {
fs.writeFile(filepath, contents, 'utf-8', (err) => {
if (err) rej(err)
res(true)
})
})
}
module.exports = {
createDirName,
createDir,
copyDir,
isDir,
write
}