Skip to content

Commit

Permalink
switch to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
binarykitchen committed Sep 14, 2024
1 parent 6e25c9e commit 2059906
Show file tree
Hide file tree
Showing 32 changed files with 8,585 additions and 15,122 deletions.
32 changes: 32 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// @ts-check

const PROJECTS = ["./tsconfig.json"];

module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2022,
project: PROJECTS,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
],
plugins: ["@typescript-eslint", "import"],
env: {
es2022: true,
node: true,
},
settings: {
"import/resolver": {
typescript: true,
node: true,
},
},
rules: {
// Turns on errors for missing imports which is great
"import/no-unresolved": "error",
},
};
27 changes: 0 additions & 27 deletions .eslintrc.json

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Test Runner for find-remove

on:
push:
branches:
- master

pull_request:
branches:
- master

jobs:
build-test-lint-check:
name: Build, Test, Prettier, Lint and Check
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Node.js via nvm
shell: bash --login {0}
run: |
nvm install --no-progress
echo "$(dirname $(nvm which node))" >> $GITHUB_PATH
- name: Install npm dependencies
run: npm ci

- name: Build assets
run: npm run build

- name: Run tests
uses: coactions/setup-xvfb@v1
with:
run: npm run test

- name: Run prettier
run: npm run prettier

- name: Run linter
run: npm run lint
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
node_modules
npm-debug.log
yarn-error.log
.vscode
.DS_Store
.vscode
*.code-workspace
package-lock.json
*.code-workspace
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.8.0
16 changes: 0 additions & 16 deletions .prettierrc

This file was deleted.

7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/extenstions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"editor.tabSize": 2,
"files.trimTrailingWhitespace": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"prettier.configPath": "./prettier.config.cjs",
"cSpell.words": [
"blahblah",
"fmerge",
"hehehe",
"microbundle",
"nodeunit",
"randomstring",
"someth"
]
}
22 changes: 0 additions & 22 deletions LICENSE

This file was deleted.

57 changes: 28 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# find-remove

[![Build Status](https://travis-ci.org/binarykitchen/find-remove.png?branch=master)](https://travis-ci.org/binarykitchen/find-remove)
finally in typescript (since v5)

recursively finds files by filter options from a start directory onwards and deletes only those which meet conditions you can define. useful if you want to clean up a directory in your node.js app.

Expand All @@ -14,16 +14,16 @@ to install find-remove, use [npm](http://github.com/isaacs/npm):

then in your node.js app, get reference to the function like that:

```javascript
const findRemoveSync = require('find-remove')
```ts
import findRemoveSync from "find-remove";
```

## quick examples

### 1. delete all _.bak or _.log files within the /temp/ directory

```javascript
const result = findRemoveSync('/temp', { extensions: ['.bak', '.log'] })
```ts
const result = findRemoveSync("/temp", { extensions: [".bak", ".log"] });
```

the return value `result` is a json object with successfully deleted files. if you output `result` to the console, you will get something like this:
Expand All @@ -37,48 +37,48 @@ the return value `result` is a json object with successfully deleted files. if y

### 2. delete all files called 'dump.log' within the /temp/ directory and within its subfolders

```javascript
var result = findRemoveSync('/temp', { files: 'dump.log' })
```ts
const result = findRemoveSync("/temp", { files: "dump.log" });
```

### 3. same as above, but also deletes any subfolders

```javascript
var result = findRemoveSync('/temp', { files: 'dump.log', dir: '*' })
```ts
const result = findRemoveSync("/temp", { files: "dump.log", dir: "*" });
```

### 4. delete all \*.bak files but not file 'haumiblau.bak'

```javascript
var result = findRemoveSync('/temp', { extensions: ['.bak'], ignore: 'haumiblau.bak' })
```ts
const result = findRemoveSync("/temp", { extensions: [".bak"], ignore: "haumiblau.bak" });
```

### 5. delete recursively any subdirectory called 'CVS' within /dist/

```javascript
var result = findRemoveSync('/dist', { dir: 'CVS' })
```ts
const result = findRemoveSync("/dist", { dir: "CVS" });
```

### 6. delete all jpg files older than one hour with limit of 100 files deletion per operation

```javascript
var result = findRemoveSync('/tmp', {
```ts
const result = findRemoveSync("/tmp", {
age: { seconds: 3600 },
extensions: '.jpg',
limit: 100
})
extensions: ".jpg",
limit: 100,
});
```

### 7. delete all files with prefix 'filenamestartswith'

```javascript
var result = findRemoveSync('/tmp', { prefix: 'filenamestartswith' })
const result = findRemoveSync("/tmp", { prefix: "filenamestartswith" });
```

### 8. apply filter options only for two levels inside the /temp directory for all tmp files

```javascript
var result = findRemoveSync('/tmp', { maxLevel: 2, extensions: '.tmp' })
```ts
const result = findRemoveSync("/tmp", { maxLevel: 2, extensions: ".tmp" });
```

this deletes any `.tmp` files up to two levels, for example: `/tmp/level1/level2/a.tmp`
Expand All @@ -89,22 +89,22 @@ why the heck do we have this `maxLevel` option? because of performance. if you c

### 9. delete everything recursively (hey, who needs that when you can use nodejs' fs.unlink?)

```javascript
var result = findRemoveSync(rootDirectory, { dir: '*', files: '*.*' })
```ts
const result = findRemoveSync(rootDirectory, { dir: "*", files: "*.*" });
```

### 10. delete all files that match a regular expression

```javascript
var result = findRemoveSync(rootDirectory, { files: 'example[1-3]', regex: true })
```ts
const result = findRemoveSync(rootDirectory, { files: "example[1-3]", regex: true });
```

this deletes files `example1.txt`, `example2.txt`, and `example3.txt`, but not `example8.txt`.

### 11. delete all directories that match a regular expression

```javascript
var result = findRemoveSync(rootDirectory, { dir: '^assets_', regex: true })
```ts
const result = findRemoveSync(rootDirectory, { dir: "^assets_", regex: true });
```

this deletes all directories that start with `assets_`.
Expand All @@ -121,7 +121,7 @@ findRemoveSync takes any start directory and searches files from there for remov
- options - currently those properties are supported:
- `files` - can be a string or an array of files you want to delete within `dir`.
- `dir` - can be a string or an array of directories you want to delete within `dir`.
- `extensions` - this too, can be a string or an array of file extentions you want to delete within `dir`.
- `extensions` - this too, can be a string or an array of file extensions you want to delete within `dir`.
- `ignore` - useful to exclude some files. again, can be a string or an array of file names you do NOT want to delete within `dir`
- `age.seconds` - can be any float number. findRemoveSync then compares it with the file stats and deletes those with modification times older than `age.seconds`
- `limit` - can be any integer number. Will limit the number of <b>files</b> to be deleted at single operation to be `limit`
Expand All @@ -140,7 +140,6 @@ JSON of files/directories that were deleted. For limit option - will only return

## todo

- needs a rewrite
- add more filtering options (e.g. combinations)
- have an asynchronous solution
- use streams instead
Expand Down
4 changes: 0 additions & 4 deletions babel.config.json

This file was deleted.

2 changes: 1 addition & 1 deletion dist/find-remove.js

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

Loading

0 comments on commit 2059906

Please sign in to comment.