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