-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupgrade.js
41 lines (37 loc) · 1.84 KB
/
upgrade.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict'
const utils = require('./utils')
const chalk = require('chalk')
const fs = require('fs')
const rimraf = require('rimraf')
module.exports = (args, configFile) => Promise.resolve()
.then(() => upgradeDownloadDirectory(args, configFile))
.then(() => upgradeSelectedShows(args))
const upgradeDownloadDirectory = (args, configFile) => Promise.resolve().then(() => {
if (utils.canRead(utils.cachePath(args.cache, 'download')) && !args.stopAskDeleteCacheDownload) {
console.error('%s: %s', chalk.bold.red('WARNING'), chalk.red('downloads cache format has changed, you should delete the old one to avoid wasting space'))
return utils.dirStats(utils.cachePath(args.cache, 'download'))
.then(stats => utils.ask.list(
'Would you like to remove it now (' + stats.count + ' files, ' + stats.hsize + ')?', [
{ name: 'Yes, remove it now', value: 'yes' },
{ name: 'No, remove it later', value: 'no' },
{ name: 'No, and don\'t ask me again, I\'ll handle it myself', value: 'never' }
], 'yes'))
.then(answer => {
if (answer === 'never') {
// Persist this choice in config file
fs.writeFileSync(configFile, Buffer.concat([fs.readFileSync(configFile), new Buffer('\n; Do not ask again about deleting cache/download folder\nstopAskDeleteCacheDownload = 1\n')]))
} else if (answer === 'yes') {
// Do delete
rimraf.sync(utils.cachePath(args.cache, 'download'))
}
})
}
})
const upgradeSelectedShows = args => Promise.resolve().then(() => {
const oldPath = utils.cachePath(args.cache, 'selected-shows.json')
if (utils.canRead(oldPath)) {
console.error('%s: %s', chalk.bold.yellow('WARNING'), chalk.yellow('path to the history of your selected shows (browse mode) has been updated'))
const newPath = utils.dotPath('selected-shows.json')
fs.renameSync(oldPath, newPath)
}
})