Dependency Update Command

This commit is contained in:
Dragon Fire
2020-12-15 20:45:56 -05:00
parent 7ca89963a6
commit 0685459edb
3 changed files with 73 additions and 2 deletions
+3 -1
View File
@@ -259,7 +259,7 @@ in the appropriate channel's topic to use it.
## Commands
Total: 570
Total: 571
### Utility:
@@ -284,6 +284,7 @@ Total: 570
* **eval:** Executes JavaScript code. (Owner-Only)
* **command-leaderboard-export:** Exports a command leaderboard JSON file. (Owner-Only)
* **command-leaderboard-import:** Imports a command leaderboard JSON file. (Owner-Only)
* **dependency-update:** Checks for dependency updates. (Owner-Only)
* **exec:** Executes a command-line application. (Owner-Only)
* **generate-commands:** Generates the commands list for Xiao's README. (Owner-Only)
* **generate-credit:** Generates the credit list for Xiao's README. (Owner-Only)
@@ -1468,6 +1469,7 @@ here.
- [NotAWeebDev](https://github.com/NotAWeebDev/)
* triggered ([Image](https://github.com/NotAWeebDev/Misaki/blob/2e44f9efb467028dcbae5a2c9f836d2e99860b85/assets/images/plate_triggered.png))
- [npm](https://www.npmjs.com/)
* dependency-update (API)
* npm (API)
- [Numbers API](http://numbersapi.com/)
* number-fact (Trivia API)
+68
View File
@@ -0,0 +1,68 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
const semver = require('semver');
const { stripIndents } = require('common-tags');
const { dependencies, devDependencies } = require('../../package');
module.exports = class DependencyUpdateCommand extends Command {
constructor(client) {
super(client, {
name: 'dependency-update',
aliases: ['dep-update', 'dependencies-update', 'npm-update'],
group: 'util',
memberName: 'dependency-update',
description: 'Checks for dependency updates.',
details: 'Only the bot owner(s) may use this command.',
ownerOnly: true,
guarded: true,
credit: [
{
name: 'npm',
url: 'https://www.npmjs.com/',
reason: 'API'
}
]
});
}
async run(msg) {
const needUpdate = [];
for (const [dep, ver] of Object.entries(dependencies)) {
const latest = this.fetchVersion(dep);
const clean = semver.clean(ver);
if (latest === clean) continue;
needUpdate.push({
name: dep,
oldVer: clean,
newVer: latest,
breaking: !semver.satisfies(clean, latest)
});
}
for (const [dep, ver] of Object.entries(devDependencies)) {
const latest = this.fetchVersion(dep);
const clean = semver.clean(ver);
if (latest === clean) continue;
needUpdate.push({
name: dep,
oldVer: clean,
newVer: latest,
breaking: !semver.satisfies(clean, latest)
});
}
if (!needUpdate.length) return msg.say('All packages are up to date.');
const updatesList = needUpdate.map(pkg => {
const breaking = pkg.breaking ? ' ⚠️' : '';
return `${pkg.name} (${pkg.oldVer} -> ${pkg.newVer})${breaking}`;
});
return msg.say(stripIndents`
__**Package Updates Available:**__
${updatesList.join('\n')}
`);
}
async fetchVersion(dependency) {
const { body } = await request.get(`https://registry.npmjs.com/${dependency}`);
if (body.time.unpublished) return null;
return body.versions[body['dist-tags'].latest];
}
};
+2 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "124.0.0",
"version": "124.1.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
@@ -59,6 +59,7 @@
"pokersolver": "^2.1.4",
"random-js": "^2.1.0",
"rss-parser": "^3.10.0",
"semver": "^7.3.4",
"sherlockjs": "^1.4.0",
"stackblur-canvas": "^2.4.0",
"tesseract.js": "^2.1.4",