-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0fcca3b
Showing
14 changed files
with
360 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = tab | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.yml] | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Publish npm package | ||
on: | ||
release: | ||
types: [created] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
- run: npm install --global npm | ||
- run: npm pkg delete scripts devDependencies | ||
- run: npm publish --provenance --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.* | ||
biome.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Changelog | ||
|
||
This project uses [semantic versioning](https://semver.org/). | ||
|
||
## [v1.0.0] (2023-11-01) | ||
|
||
- Initial release | ||
|
||
[v1.0.0]: https://github.com/valtlai/picodel/tree/v1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# ISC License | ||
|
||
Copyright © 2023 Valtteri Laitinen | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# picodel | ||
|
||
[![NPM](https://img.shields.io/npm/v/picodel.svg)](https://www.npmjs.com/package/picodel) | ||
|
||
Delete files and directories inside the current working directory | ||
|
||
- Zero dependencies | ||
- Only static paths, no glob patterns | ||
- ESM and async only | ||
|
||
## Install | ||
|
||
``` | ||
npm install --save-dev picodel | ||
``` | ||
|
||
## Usage | ||
|
||
### CLI | ||
|
||
Syntax: | ||
|
||
``` | ||
picodel [...paths] | ||
``` | ||
|
||
Example CLI prompt: | ||
|
||
``` | ||
npx picodel .cache public | ||
``` | ||
|
||
Example npm script: | ||
|
||
```json | ||
{ | ||
"scripts": { | ||
"clean": "picodel .cache public" | ||
} | ||
} | ||
``` | ||
|
||
### Module | ||
|
||
Syntax: | ||
|
||
```ts | ||
picodel(...string[]) | ||
``` | ||
|
||
Example: | ||
|
||
```ts | ||
import picodel from 'picodel'; | ||
|
||
await picodel('.cache', 'public'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"javascript": { | ||
"formatter": { | ||
"quoteStyle": "single" | ||
} | ||
}, | ||
"linter": { | ||
"rules": { | ||
"correctness": { | ||
"noUndeclaredVariables": "error", | ||
"noUnusedVariables": "error" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env node | ||
|
||
import picodel from './index.js'; | ||
|
||
const filePaths = process.argv.slice(2); | ||
await picodel(...filePaths); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* Delete specified files and directories | ||
* @param paths Must be inside CWD | ||
*/ | ||
export default function picodel(...paths: string[]): Promise<void>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import fsPromises from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
|
||
const osNormalize = (filePath) => { | ||
return filePath.replaceAll(path.posix.sep, path.sep); | ||
}; | ||
|
||
const isSubpathOf = (childPath, parentPath) => { | ||
const parentRelative = path.relative(parentPath, osNormalize(childPath)); | ||
return parentRelative && !parentRelative.startsWith(`..${path.sep}`); | ||
}; | ||
|
||
const cwd = process.cwd(); | ||
|
||
export default async function picodel(...filePaths) { | ||
for (const [index, filePath] of filePaths.entries()) { | ||
if (!isSubpathOf(filePath, cwd)) { | ||
throw new Error(`Path must be inside CWD: #${index + 1}: ${filePath}`); | ||
} | ||
} | ||
|
||
await Promise.all( | ||
filePaths.map((filePath) => | ||
fsPromises.rm(filePath, { recursive: true, force: true }), | ||
), | ||
); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "picodel", | ||
"version": "1.0.0", | ||
"description": "Delete files and directories inside the current working directory", | ||
"license": "ISC", | ||
"author": { | ||
"name": "Valtteri Laitinen", | ||
"email": "[email protected]", | ||
"url": "https://valtlai.fi/" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/valtlai/picodel.git" | ||
}, | ||
"type": "module", | ||
"bin": "./cli.js", | ||
"exports": { | ||
"types": "./index.d.ts", | ||
"default": "./index.js" | ||
}, | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"scripts": { | ||
"check": "biome check --apply ." | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "1.3.3" | ||
}, | ||
"keywords": [ | ||
"delete", | ||
"remove", | ||
"destroy", | ||
"unlink", | ||
"clean", | ||
"files", | ||
"folders", | ||
"directories", | ||
"del", | ||
"rm", | ||
"rmrf", | ||
"rmdir", | ||
"fs", | ||
"filesystem", | ||
"zero-dependency" | ||
] | ||
} |