2021-02-26 12:46:48 +01:00
|
|
|
const chalk = require("chalk")
|
2021-02-26 14:30:24 +01:00
|
|
|
const fs = require("fs")
|
|
|
|
const axios = require("axios")
|
2021-02-26 14:33:31 +01:00
|
|
|
const path = require("path")
|
2021-02-26 14:30:24 +01:00
|
|
|
|
2021-02-26 14:33:31 +01:00
|
|
|
exports.downloadFile = async (url, filePath) => {
|
|
|
|
filePath = path.resolve(filePath)
|
|
|
|
const writer = fs.createWriteStream(filePath)
|
2021-02-26 14:30:24 +01:00
|
|
|
|
|
|
|
const response = await axios({
|
|
|
|
url,
|
|
|
|
method: "GET",
|
|
|
|
responseType: "stream"
|
|
|
|
})
|
|
|
|
|
|
|
|
response.data.pipe(writer)
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
writer.on("finish", resolve)
|
|
|
|
writer.on("error", reject)
|
|
|
|
})
|
|
|
|
}
|
2021-02-26 12:46:48 +01:00
|
|
|
|
|
|
|
exports.getHelpDescription = string => {
|
|
|
|
return chalk.cyan(string)
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.getSubHelpDescription = string => {
|
|
|
|
return chalk.green(string)
|
|
|
|
}
|
|
|
|
|
2021-02-26 18:08:28 +01:00
|
|
|
exports.error = error => {
|
2021-02-26 12:46:48 +01:00
|
|
|
return chalk.red(`Error - ${error}`)
|
|
|
|
}
|
2021-02-26 14:48:11 +01:00
|
|
|
|
2021-02-26 18:08:28 +01:00
|
|
|
exports.success = success => {
|
2021-02-26 14:48:11 +01:00
|
|
|
return chalk.green(success)
|
|
|
|
}
|
2021-02-26 16:09:25 +01:00
|
|
|
|
2021-02-26 18:08:28 +01:00
|
|
|
exports.info = info => {
|
|
|
|
return chalk.cyan(info)
|
|
|
|
}
|
|
|
|
|
2021-02-26 16:09:25 +01:00
|
|
|
exports.logErrorToFile = (file, error) => {
|
|
|
|
fs.writeFileSync(path.resolve(`./${file}`), `Budiase Error\n${error}`)
|
|
|
|
}
|