1
0
Fork 0
mirror of synced 2024-07-15 03:05:57 +12:00
budibase/packages/cli/src/utils.js

47 lines
947 B
JavaScript
Raw Normal View History

const chalk = require("chalk")
2021-02-27 02:30:24 +13:00
const fs = require("fs")
const axios = require("axios")
2021-02-27 02:33:31 +13:00
const path = require("path")
2021-02-27 02:30:24 +13:00
2021-02-27 02:33:31 +13:00
exports.downloadFile = async (url, filePath) => {
filePath = path.resolve(filePath)
const writer = fs.createWriteStream(filePath)
2021-02-27 02:30:24 +13:00
const response = await axios({
url,
method: "GET",
2021-02-27 06:09:20 +13:00
responseType: "stream",
2021-02-27 02:30:24 +13:00
})
response.data.pipe(writer)
return new Promise((resolve, reject) => {
writer.on("finish", resolve)
writer.on("error", reject)
})
}
exports.getHelpDescription = string => {
return chalk.cyan(string)
}
exports.getSubHelpDescription = string => {
return chalk.green(string)
}
exports.error = error => {
return chalk.red(`Error - ${error}`)
}
exports.success = success => {
return chalk.green(success)
}
exports.info = info => {
return chalk.cyan(info)
}
exports.logErrorToFile = (file, error) => {
fs.writeFileSync(path.resolve(`./${file}`), `Budiase Error\n${error}`)
}