Skip to content

Commit

Permalink
chore: Modernize setup
Browse files Browse the repository at this point in the history
- Update dependencies
- Update tests' snapshots version
- Align setup with `template-javascript`
- Update package-lock version
- Add `CHANGELOG.md` - copy info from GitHub Release
- Fix ESLint reported issues
- Update `ci` and `publish` workflows with Node.js 18 and 19 and latest actions
- Align `publish` workflow with https://github.com/actions/starter-workflows/blob/10f6091ee89f01509479e792e3f982ea3d615fdb/ci/npm-publish.yml
- ESLint: Set `parserOptions.ecmaVersion: 'latest'` to support top-level `await`
- Add Russian README. Follow https://github.com/jonatasemidio/multilanguage-readme-pattern
- Add `--no-warnings` to the `bin` script to suppress "ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time" warning (caused by `webtorrent` code)

BREAKING CHANGE: Require node version 18 and higher
  • Loading branch information
nikolay-borzov committed Feb 22, 2023
1 parent f2ee600 commit cd64867
Show file tree
Hide file tree
Showing 23 changed files with 7,462 additions and 4,874 deletions.
39 changes: 32 additions & 7 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
module.exports = {
root: true,

ignorePatterns: [
'**/*.*',
'!**/*.js',
'!**/*.cjs',
'node_modules',
'/dist',
'/coverage',
'dist',
'coverage',
],

parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},

env: {
node: true,
},

extends: [
'eslint:recommended',
'plugin:jsdoc/recommended',
'plugin:unicorn/recommended',
'plugin:node/recommended',
'prettier-standard/prettier-file',
],
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
},

settings: {
jsdoc: {
mode: 'typescript',
},
},

// Keep rules grouped by plugin and sorted alphabetically
rules: {
'padding-line-between-statements': [
Expand Down Expand Up @@ -70,14 +76,33 @@ module.exports = {
'import/extensions': ['error', 'always', { ignorePackages: true }],
// Force using only named exports
'import/no-default-export': 'error',
// Sort imports
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'type',
],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: false,
},
},
],

/* eslint-plugin-prettier */

'prettier/prettier': 'warn',

/* eslint-plugin-node */

// Disabled until https://github.com/mysticatea/eslint-plugin-node/issues/275 is fixed
// FIXME: Disabled until https://github.com/avajs/ava/discussions/2866 is resolved
'node/no-missing-import': 'off',
},
overrides: [
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jobs:
test:
strategy:
matrix:
node: [12, 14]
node: [18, 19]
os: [windows-latest, ubuntu-latest, macos-latest]

name: Test with ava (Node.js v${{ matrix.node }} on ${{ matrix.os }})

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
Expand All @@ -34,12 +34,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- run: npm ci
- uses: paambaati/codeclimate-action@v2.7.5
- uses: paambaati/codeclimate-action@v3.2.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
Expand All @@ -51,9 +51,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- run: npm ci
- run: npm run lint
15 changes: 8 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
cache: 'npm'
- run: npm ci
- run: npm test

publish-npm:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no-install lint-staged
8 changes: 0 additions & 8 deletions .lintstagedrc.cjs

This file was deleted.

3 changes: 0 additions & 3 deletions .ncurc.json

This file was deleted.

147 changes: 147 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

<!--
### Added
### Changed
### Deprecated
### Removed
### Fixed
### Security
### BREAKING CHANGES
-->

## [v3.0.0](https://github.com/nikolay-borzov/torrent-clean/compare/v2.0.0...v3.0.0) - 2023-02-22

### Added

- CHANGELOG.md according to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Russian README. Follow https://github.com/jonatasemidio/multilanguage-readme-pattern
- `--no-warnings` to the `bin` script to suppress "ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time" warning (caused by [`webtorrent` code](https://github.com/webtorrent/webtorrent/blob/ffacc37a9b5993e41ff003c6a2bb2bef734576ac/index.js#L21))

### Changed

- Update dependencies
- Update GitHub Actions' workflows

### Fixed

- Exception when `--version` (`-v`) argument is set

### BREAKING CHANGES

- Require node version 18 and higher

## [v2.0.0](https://github.com/nikolay-borzov/torrent-clean/compare/v1.7.2...v2.0.0) - 2021-04-20

### Changed

- `deleteFiles` callback is always set. It does nothing when `dryRun` is falsy
- When creating config file set `.yaml` extension

### BREAKING CHANGES

- Switch to ECMAScript modules
- Require node version 12 and higher
- Rename main function to `cleanTorrentDirectory`
- Rename `dirPath` parameter to `directoryPath`

## [v1.7.2](https://github.com/nikolay-borzov/torrent-clean/compare/v1.7.1...v1.7.2) - 2020-10-03

### Fixed

- Ignore filename path case when comparing files in torrent with files on the file system

## [v1.7.1](https://github.com/nikolay-borzov/torrent-clean/compare/v1.7.0...v1.7.1) - 2020-04-24

### Fixed

- Fix infinite loop when a config file is at the root

## [v1.7.0](https://github.com/nikolay-borzov/torrent-clean/compare/v1.6.0...v1.7.0) - 2020-04-20

### Added

- Make package scoped. Use `@nikolay-borzov/torrent-clean` instead of `torrent-clean`
- Implement remembering last torrent ID for the specified directory. Setting `rememberLastTorrent: true` in config file makes `torrent-clean` save last torrent ID value to `lastTorrent` property inside config file. `lastTorrent` value is used when `--torrent` argument is not set.

### Changed

- Make `--torrent` and `torrentId` optional. Throw error when `torrentId` cannot be received from `lastTorrent` property
- Return "Parsed TORRENT_NAME" CLI output

## [v1.6.0](https://github.com/nikolay-borzov/torrent-clean/compare/v1.5.0...v1.6.0) - 2020-04-12

### Added

- Add Node API. Add `dryRun` options to postpone deleting files
- Set `tc` as alias for `torrent-clean`
- Add tests

### Changed

- Replace `recursive-readdir` with `readdirp`

## [v1.5.0](https://github.com/nikolay-borzov/torrent-clean/compare/v1.4.2...v1.5.0) - 2020-03-29

### Added

- Display file number near filename

## [v1.4.2](https://github.com/nikolay-borzov/torrent-clean/compare/v1.4.1...v1.4.2) - 2020-03-14

### Changed

- Update dependencies

## [v1.4.1](https://github.com/nikolay-borzov/torrent-clean/compare/v1.4.0...v1.4.1) - 2019-10-04

### Fixed

- Fix config loader for the case when `ignore` isn't set

## [v1.4.0](https://github.com/nikolay-borzov/torrent-clean/compare/v1.3.0...v1.4.0) - 2019-09-16

### Added

- Allow specifying ignore globs via config files
- Load and merge config files up to root directory using [`cosmiconfig`](https://github.com/cosmiconfig/cosmiconfig)
- Add `--version` (`-v`) CLI argument

### Changed

- Limit extra files display count to 20. You can scroll down using arrows
- Change file select indicator to ``

## [v1.3.0](https://github.com/nikolay-borzov/torrent-clean/compare/v1.2.0...v1.3.0) - 2019-09-01

### Added

- Allow selecting files to delete

## [v1.2.0](https://github.com/nikolay-borzov/torrent-clean/compare/v1.1.0...v1.2.0) - 2019-01-09

### Added

- Add magnet URI and info hash support

## [v1.1.0](https://github.com/nikolay-borzov/torrent-clean/compare/v.1.0.0...v1.1.0) -

### Added

- Delete empty directories
- Limit filenames list output length to 20. Can be disabled by `--verbose` parameter
- Add colors using `chalk`
- Implement errors catching

## v1.0.0 - 2019-01-07

### Added

- Basic implementation for deleting files not listed in the torrent
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# torrent-clean

[![en](https://img.shields.io/badge/lang-en-%233c3b6e)](./README.md)
[![ru](https://img.shields.io/badge/lang-ru-%23d52b1e)](./README.ru.md)

[![NPM version][npm-image]][npm-url]
![][ci-image]
[![Inline docs][docs-image]][docs-url]
[![Known Vulnerabilities][vulnerabilities-image]][vulnerabilities-url]
[![Maintainability][maintability-image]][maintability-url]
[![Style Guide][style-guide-image]][style-guide-url]
[![Test Coverage][test-coverage-image]][test-coverage-url]

[npm-image]: https://img.shields.io/npm/v/@nikolay-borzov/torrent-clean.svg
[npm-url]: https://npmjs.org/package/@nikolay-borzov/torrent-clean
Expand All @@ -18,13 +22,19 @@
[maintability-url]: https://codeclimate.com/github/nikolay-borzov/torrent-clean/maintainability
[style-guide-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[style-guide-url]: https://standardjs.com
[test-coverage-image]: https://api.codeclimate.com/v1/badges/093465c943260646aa40/test_coverage
[test-coverage-url]: https://codeclimate.com/github/nikolay-borzov/torrent-clean/test_coverage

CLI utility deletes files not listed in the selected torrent. Useful when torrent is updated and some files have been removed.

## Prerequisites

- Node.js 18 or later

## Install

```
npm i -g @nikolay-borzov\torrent-clean
npm i -g @nikolay-borzov/torrent-clean
```

## Usage
Expand Down Expand Up @@ -56,7 +66,7 @@ gets files' paths from `nature-pack.torrent` and compares them with files from `

Parameter are:

- `ignore: string[]` - an array of globs (picomatch) or filenames that will be excluded from the list of extra files.
- `ignore: string[]` - an array of globs ([picomatch](https://github.com/micromatch/picomatch#globbing-features) is used) or filenames that will be excluded from the list of extra files.
- `rememberLastTorrent: boolean` - Enable remembering last specified torrent ID for specified directory to `lastTorrent` config parameter. Only string values are saved. `lastTorrent` is used when `--torrent` argument is not set.

## API
Expand All @@ -81,7 +91,7 @@ Parameter are:
import { cleanTorrentDirectory } from 'torrent-clean'

const { extraFiles } = await cleanTorrentDirectory({
torrentId: 'C:/Downloads/torrents/nature wallpapers.torrent',
torrentId: 'C:/torrents/nature wallpapers.torrent',
directoryPath: 'C:/Downloads/wallpapers/nature',
})

Expand Down Expand Up @@ -112,7 +122,7 @@ await deleteFiles(extraFiles)

- [webtorrent](https://github.com/webtorrent/webtorrent)
- [minimist](https://github.com/substack/minimist)
- [cosmiconfig](https://github.com/davidtheclark/cosmiconfig)
- [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig)
- [enquirer](https://github.com/enquirer/enquirer)
- [readdirp](https://github.com/paulmillr/readdirp)
- [picomatch](https://github.com/micromatch/picomatch)
Expand Down
Loading

0 comments on commit cd64867

Please sign in to comment.