clean.js 779 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. const Promise = require('bluebird');
  3. const fs = require('hexo-fs');
  4. function cleanConsole(args) {
  5. return Promise.all([
  6. deleteDatabase(this),
  7. deletePublicDir(this),
  8. this.execFilter('after_clean', null, {context: this})
  9. ]);
  10. }
  11. function deleteDatabase(ctx) {
  12. const dbPath = ctx.database.options.path;
  13. return fs.exists(dbPath).then(exist => {
  14. if (!exist) return;
  15. return fs.unlink(dbPath).then(() => {
  16. ctx.log.info('Deleted database.');
  17. });
  18. });
  19. }
  20. function deletePublicDir(ctx) {
  21. const publicDir = ctx.public_dir;
  22. return fs.exists(publicDir).then(exist => {
  23. if (!exist) return;
  24. return fs.rmdir(publicDir).then(() => {
  25. ctx.log.info('Deleted public folder.');
  26. });
  27. });
  28. }
  29. module.exports = cleanConsole;