Skip to content

Commit 0fcca3b

Browse files
committed
Initialize
0 parents  commit 0fcca3b

14 files changed

+360
-0
lines changed

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_style = tab
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[*.yml]
11+
indent_style = space

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.github/workflows/publish.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Publish npm package
2+
on:
3+
release:
4+
types: [created]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
permissions:
9+
contents: read
10+
id-token: write
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: '20.x'
16+
registry-url: 'https://registry.npmjs.org'
17+
- run: npm install --global npm
18+
- run: npm pkg delete scripts devDependencies
19+
- run: npm publish --provenance --access public
20+
env:
21+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.*
2+
biome.json

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
This project uses [semantic versioning](https://semver.org/).
4+
5+
## [v1.0.0] (2023-11-01)
6+
7+
- Initial release
8+
9+
[v1.0.0]: https://github.com/valtlai/picodel/tree/v1.0.0

LICENSE.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ISC License
2+
3+
Copyright © 2023 Valtteri Laitinen
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# picodel
2+
3+
[![NPM](https://img.shields.io/npm/v/picodel.svg)](https://www.npmjs.com/package/picodel)
4+
5+
Delete files and directories inside the current working directory
6+
7+
- Zero dependencies
8+
- Only static paths, no glob patterns
9+
- ESM and async only
10+
11+
## Install
12+
13+
```
14+
npm install --save-dev picodel
15+
```
16+
17+
## Usage
18+
19+
### CLI
20+
21+
Syntax:
22+
23+
```
24+
picodel [...paths]
25+
```
26+
27+
Example CLI prompt:
28+
29+
```
30+
npx picodel .cache public
31+
```
32+
33+
Example npm script:
34+
35+
```json
36+
{
37+
"scripts": {
38+
"clean": "picodel .cache public"
39+
}
40+
}
41+
```
42+
43+
### Module
44+
45+
Syntax:
46+
47+
```ts
48+
picodel(...string[])
49+
```
50+
51+
Example:
52+
53+
```ts
54+
import picodel from 'picodel';
55+
56+
await picodel('.cache', 'public');
57+
```

biome.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"javascript": {
3+
"formatter": {
4+
"quoteStyle": "single"
5+
}
6+
},
7+
"linter": {
8+
"rules": {
9+
"correctness": {
10+
"noUndeclaredVariables": "error",
11+
"noUnusedVariables": "error"
12+
}
13+
}
14+
}
15+
}

cli.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
3+
import picodel from './index.js';
4+
5+
const filePaths = process.argv.slice(2);
6+
await picodel(...filePaths);

index.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Delete specified files and directories
3+
* @param paths Must be inside CWD
4+
*/
5+
export default function picodel(...paths: string[]): Promise<void>;

index.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import fsPromises from 'node:fs/promises';
2+
import path from 'node:path';
3+
4+
const osNormalize = (filePath) => {
5+
return filePath.replaceAll(path.posix.sep, path.sep);
6+
};
7+
8+
const isSubpathOf = (childPath, parentPath) => {
9+
const parentRelative = path.relative(parentPath, osNormalize(childPath));
10+
return parentRelative && !parentRelative.startsWith(`..${path.sep}`);
11+
};
12+
13+
const cwd = process.cwd();
14+
15+
export default async function picodel(...filePaths) {
16+
for (const [index, filePath] of filePaths.entries()) {
17+
if (!isSubpathOf(filePath, cwd)) {
18+
throw new Error(`Path must be inside CWD: #${index + 1}: ${filePath}`);
19+
}
20+
}
21+
22+
await Promise.all(
23+
filePaths.map((filePath) =>
24+
fsPromises.rm(filePath, { recursive: true, force: true }),
25+
),
26+
);
27+
}

package-lock.json

+143
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "picodel",
3+
"version": "1.0.0",
4+
"description": "Delete files and directories inside the current working directory",
5+
"license": "ISC",
6+
"author": {
7+
"name": "Valtteri Laitinen",
8+
"email": "dev@valtlai.fi",
9+
"url": "https://valtlai.fi/"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/valtlai/picodel.git"
14+
},
15+
"type": "module",
16+
"bin": "./cli.js",
17+
"exports": {
18+
"types": "./index.d.ts",
19+
"default": "./index.js"
20+
},
21+
"engines": {
22+
"node": ">=18"
23+
},
24+
"scripts": {
25+
"check": "biome check --apply ."
26+
},
27+
"devDependencies": {
28+
"@biomejs/biome": "1.3.3"
29+
},
30+
"keywords": [
31+
"delete",
32+
"remove",
33+
"destroy",
34+
"unlink",
35+
"clean",
36+
"files",
37+
"folders",
38+
"directories",
39+
"del",
40+
"rm",
41+
"rmrf",
42+
"rmdir",
43+
"fs",
44+
"filesystem",
45+
"zero-dependency"
46+
]
47+
}

0 commit comments

Comments
 (0)