Skip to content

Commit

Permalink
fix: dynamic pack version require for the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyxguo committed Aug 4, 2023
1 parent 7edf774 commit 9021007
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
const chalk = require('chalk');
const appRoot = require('app-root-path');
const pack = require(appRoot + '/node_modules/hexo-theme-aurora/package.json');
const { throwError, throwInfo } = require('./lib/helpers/utils');
const pluginPack = require('./package.json');
require('./lib/filters')(hexo);
require('./lib/generators')(hexo);
require('./lib/injector')(hexo);

var pack;

try {
pack = require(appRoot + '/node_modules/hexo-theme-aurora/package.json');
} catch (error) {
throwInfo(
'Aurora Plugin',
`Aurora Plugin fail to get current Aurora Theme version from package location, trying to get from themes folder instead...`
);
try {
pack = require(appRoot + '/themes/hexo-theme-aurora/package.json');
} catch (error) {
throwError(
'Aurora Plugin Error',
`Aurora Plugin fail to get current Aurora Theme version, please make sure you have the theme installed.`
);
return;
}
}

hexo.on('generateAfter', function () {
console.log(
chalk.green('INFO ') +
chalk.yellow('API data generated by') +
chalk.cyan.bold(' Aurora v' + pack.version)
chalk.green('INFO ') +
chalk.yellow('API data generated with ') +
chalk.cyan.bold('hexo-plugin-aurora') +
chalk.magenta(' v' + pluginPack.version)
);
});

hexo.on('exit', function () {
console.log(
chalk.green('INFO ') +
chalk.magenta('Thanks for using') +
chalk.cyan.bold(' Aurora Plugin v' + pack.version)
);
console.log(
chalk.green('INFO ') +
chalk.magenta('Check out the repo at:') +
chalk.cyan.underline(' https://github.com/auroral-ui/hexo-theme-aurora')
chalk.green('INFO ') +
'Thanks for using: ' +
chalk.cyan.bold('hexo-plugin-aurora') +
chalk.magenta(' v' + pluginPack.version) +
' & ' +
chalk.cyan.bold('hexo-theme-aurora') +
chalk.magenta(' v' + pack.version)
);
console.log(chalk.green('INFO ') + 'Crafted by ' + chalk.cyan.bold('bennyxguo <三钻>'));
});

0 comments on commit 9021007

Please sign in to comment.