Skip to content

Commit

Permalink
Initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
valtlai committed Nov 1, 2023
0 parents commit 0fcca3b
Show file tree
Hide file tree
Showing 14 changed files with 360 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
21 changes: 21 additions & 0 deletions .github/workflows/publish.yml
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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.*
biome.json
9 changes: 9 additions & 0 deletions CHANGELOG.md
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
15 changes: 15 additions & 0 deletions LICENSE.md
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.
57 changes: 57 additions & 0 deletions README.md
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');
```
15 changes: 15 additions & 0 deletions biome.json
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"
}
}
}
}
6 changes: 6 additions & 0 deletions cli.js
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);
5 changes: 5 additions & 0 deletions index.d.ts
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>;
27 changes: 27 additions & 0 deletions index.js
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 }),
),
);
}
143 changes: 143 additions & 0 deletions package-lock.json

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

47 changes: 47 additions & 0 deletions package.json
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"
]
}

0 comments on commit 0fcca3b

Please sign in to comment.