Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console reminder if new version released #1002

Merged
merged 3 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# Useful if you want to comment some options from NexT `_config.yml` by `next.yml` without editing default config.
override: false

# Console reminder if new version released.
reminder: true

# Allow to cache content generation. Introduced in NexT v6.0.0.
cache:
enable: true
Expand Down
41 changes: 40 additions & 1 deletion scripts/merge-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'use strict';

var merge = require('lodash/merge');
const merge = require('lodash/merge');

hexo.on('generateBefore', function() {
if (hexo.locals.get) {
Expand Down Expand Up @@ -47,3 +47,42 @@ hexo.on('generateBefore', function() {
require('./injects')(hexo);

});

hexo.on('generateAfter', function() {
if (!hexo.theme.config.reminder) return;
const https = require('https');
const path = require('path');
const env = require(path.normalize('../package.json'));
https.get('https://api.github.com/repos/theme-next/hexo-theme-next/releases/latest', {
headers: {
'User-Agent': 'Theme NexT Client'
}
}, res => {
var result = '';
res.on('data', data => {
result += data;
});
res.on('end', () => {
try {
var latest = JSON.parse(result).tag_name.replace('v', '').split('.');
var current = env.version.split('.');
var isOutdated = false;
for (var i = 0; i < Math.max(latest.length, current.length); i++) {
if (!current[i] || latest[i] > current[i]) {
isOutdated = true;
break;
}
}
if (isOutdated) {
hexo.log.warn(`Your theme NexT is outdated. Current version: v${current.join('.')}, latest version: v${latest.join('.')}`);
hexo.log.warn('Visit https://github.com/theme-next/hexo-theme-next/releases for more information.');
} else {
hexo.log.info('Congratulations! Your are using the latest version of theme NexT.');
}
} catch (e) {
hexo.log.error('Failed to detect version info. Error message:');
hexo.log.error(e);
}
});
});
});