Skip to content

Commit

Permalink
Use eslint-plugin-node
Browse files Browse the repository at this point in the history
- Update dependencies
  • Loading branch information
nikolay-borzov committed Apr 18, 2020
1 parent 64ad88d commit 86f16e2
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 81 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
'prettier',
'plugin:prettier/recommended',
'prettier/standard',
'plugin:node/recommended',
'plugin:jsdoc/recommended'
],
'settings': {
Expand Down
148 changes: 74 additions & 74 deletions bin/torrent-clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,80 +19,80 @@ const argv = require('minimist')(process.argv.slice(2), {

if (argv.version) {
console.log(packageJson.version)
process.exit(0)
}

console.log(logColor.info.bold('dir:'.padEnd(10)), argv.dir)
console.log(logColor.info.bold('torrent:'.padEnd(10)), argv.torrent, os.EOL)

if (!argv.torrent) {
console.log(logColor.error(`${chalk.bold('torrent')} argument is required`))
process.exit(1)
}

const torrentId = argv.torrent
const directoryPath = path.resolve(argv.dir)

console.log(logColor.info('Parsing torrent file...'))

cleanTorrentDir({ torrentId, directoryPath, dryRun: true })
.then(async ({ extraFiles, deleteFiles }) => {
if (extraFiles.length === 0) {
console.log('No extra files found!')
return
}

console.log(`Found ${chalk.bold(extraFiles.length)} extra file(s).`)

const dirRoot = `${directoryPath}${path.sep}`

const filesChoices = extraFiles.map((filename) => ({
name: filename.replace(dirRoot, ''),
value: filename,
}))

const filesToDeleteMultiSelect = new FilesSelect({
name: 'selectFilesToDelete',
message: `Select file(s) to delete ('space' - toggle item selection, 'i' - invert selection)`,
choices: filesChoices,
limit: FILES_ON_SCREEN_LIMIT,
indicator: '■',
initial() {
// TODO: Remove after https://github.com/enquirer/enquirer/issues/201 is fixed
this.options.initial = filesChoices
return filesChoices
},
// Get values from selected names https://github.com/enquirer/enquirer/issues/121
result(names) {
return names.map((name) => this.find(name).value)
},
} else {
console.log(logColor.info.bold('dir:'.padEnd(10)), argv.dir)
console.log(logColor.info.bold('torrent:'.padEnd(10)), argv.torrent, os.EOL)

if (!argv.torrent) {
throw new Error(
logColor.error(`${chalk.bold('torrent')} argument is required`)
)
}

const torrentId = argv.torrent
const directoryPath = path.resolve(argv.dir)

console.log(logColor.info('Parsing torrent file...'))

cleanTorrentDir({ torrentId, directoryPath, dryRun: true })
.then(async ({ extraFiles, deleteFiles }) => {
if (extraFiles.length === 0) {
console.log('No extra files found!')
return
}

console.log(`Found ${chalk.bold(extraFiles.length)} extra file(s).`)

const dirRoot = `${directoryPath}${path.sep}`

const filesChoices = extraFiles.map((filename) => ({
name: filename.replace(dirRoot, ''),
value: filename,
}))

const filesToDeleteMultiSelect = new FilesSelect({
name: 'selectFilesToDelete',
message: `Select file(s) to delete ('space' - toggle item selection, 'i' - invert selection)`,
choices: filesChoices,
limit: FILES_ON_SCREEN_LIMIT,
indicator: '■',
initial() {
// TODO: Remove after https://github.com/enquirer/enquirer/issues/201 is fixed
this.options.initial = filesChoices
return filesChoices
},
// Get values from selected names https://github.com/enquirer/enquirer/issues/121
result(names) {
return names.map((name) => this.find(name).value)
},
})

const filesToDelete = await filesToDeleteMultiSelect.run()

if (filesToDelete.length === 0) {
return
}

const deleteConfirm = new Confirm({
name: 'delete',
message: 'Delete extra files?',
initial: true,
})

const deleteFilesAnswer = await deleteConfirm.run()

if (deleteFilesAnswer) {
console.log()
console.log(logColor.info('Deleting extra files...'))

await deleteFiles(filesToDelete)

console.log('Files deleted.')
}
})
.catch((error) => {
console.log(logColor.error(error.stack))

const filesToDelete = await filesToDeleteMultiSelect.run()

if (filesToDelete.length === 0) {
return
}

const deleteConfirm = new Confirm({
name: 'delete',
message: 'Delete extra files?',
initial: true,
process.exitCode = 1
})

const deleteFilesAnswer = await deleteConfirm.run()

if (deleteFilesAnswer) {
console.log()
console.log(logColor.info('Deleting extra files...'))

await deleteFiles(filesToDelete)

console.log('Files deleted.')
}
})
.catch((error) => {
console.log(logColor.error(error.stack))

process.exitCode = 1
})
}
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"husky": "^4.2.5",
"lint-staged": "^10.1.3",
"lint-staged": "^10.1.5",
"prettier": "^2.0.4"
}
}

0 comments on commit 86f16e2

Please sign in to comment.