Skip to content

Commit

Permalink
v1.0.1 - export Tree type
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Jan 3, 2024
1 parent 1dad1e4 commit caad1ae
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
10 changes: 8 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# History

## v1.0.0 2015 October 25
## v1.0.1 2024 January 3

- Some feature
- Export `Tree` type
- Thank you to the sponsors: [Andrew Nesbitt](https://nesbitt.io), [Balsa](https://balsa.com), [Codecov](https://codecov.io), [Frontend Masters](https://FrontendMasters.com), [Poonacha Medappa](https://poonachamedappa.com), [Rob Morris](https://github.com/Rob-Morris), [Sentry](https://sentry.io), [Syntax](https://syntax.fm)

## v1.0.0 2024 January 3

- Initial working release
- Thank you to the sponsors: [Andrew Nesbitt](https://nesbitt.io), [Balsa](https://balsa.com), [Codecov](https://codecov.io), [Frontend Masters](https://FrontendMasters.com), [Poonacha Medappa](https://poonachamedappa.com), [Rob Morris](https://github.com/Rob-Morris), [Sentry](https://sentry.io), [Syntax](https://syntax.fm)
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Unless stated otherwise all works are:

- Copyright © [Benjamin Lupton](https://github.com/balupton)
- Copyright © [Benjamin Lupton](https://balupton.com)

and licensed under:

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ This package is published with the following editions:

#### Authors

- [Benjamin Lupton](https://github.com/balupton)
- [Benjamin Lupton](https://balupton.com) — Accelerating collaborative wisdom.

#### Maintainers

- [Benjamin Lupton](https://github.com/balupton)
- [Benjamin Lupton](https://balupton.com) — Accelerating collaborative wisdom.

#### Contributors

Expand Down Expand Up @@ -145,7 +145,7 @@ This package is published with the following editions:

Unless stated otherwise all works are:

- Copyright © [Benjamin Lupton](https://github.com/balupton)
- Copyright © [Benjamin Lupton](https://balupton.com)

and licensed under:

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bevry/fs-tree",
"version": "1.0.0",
"version": "1.0.1",
"license": "Artistic-2.0",
"description": "Read and write to the filesystem as a tree, useful for quick scaffolding and comparisons of filesystem directories",
"homepage": "https://github.com/bevry/fs-tree",
Expand Down Expand Up @@ -74,15 +74,15 @@
"npmPackageName": "@bevry/fs-tree"
}
},
"author": "Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)",
"author": "Benjamin Lupton <b@lupton.cc> (https://balupton.com) (https://github.com/balupton)",
"authors": [
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)"
"Benjamin Lupton <b@lupton.cc> (https://balupton.com) (https://github.com/balupton): Accelerating collaborative wisdom."
],
"maintainers": [
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)"
"Benjamin Lupton <b@lupton.cc> (https://balupton.com) (https://github.com/balupton): Accelerating collaborative wisdom."
],
"contributors": [
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)"
"Benjamin Lupton <b@lupton.cc> (https://balupton.com) (https://github.com/balupton)"
],
"sponsors": [
"Andrew Nesbitt (https://nesbitt.io) (https://github.com/andrew): Software engineer and researcher",
Expand Down
14 changes: 11 additions & 3 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ import write from '@bevry/fs-write'
import {
scanDirectory,
ResultEncoding,
Tree,
Tree as ScanTree,
Options,
toTree,
} from 'scandirectory'

/**
* A tree for reading and writing.
* @example if Encoding is `utf8` then `{ [basename: string]: string | Tree }`
* @example if Encoding is `binary` then `{ [basename: string]: Buffer | Tree }`
* @example if Encoding is `undefined` then `{ [basename: string]: true | Tree }`
*/
export type Tree<Encoding extends ResultEncoding = 'utf8'> = ScanTree<Encoding>

/** Read a directory to a tree */
export async function readTree<Encoding extends ResultEncoding = 'utf8'>(
directory: string,
Expand All @@ -27,7 +35,7 @@ export async function readTree<Encoding extends ResultEncoding = 'utf8'>(
/** Write a tree to a directory */
export async function writeTree<Encoding extends ResultEncoding = 'utf8'>(
directory: string,
tree: Tree<ResultEncoding>,
tree: Tree<Encoding>,
opts: WriteFileOptions = {
encoding: 'utf8' as Encoding,
}
Expand All @@ -36,7 +44,7 @@ export async function writeTree<Encoding extends ResultEncoding = 'utf8'>(
const value = tree[basename]
const path = join(directory, basename)
if (isPlainObject(value)) {
await writeTree(path, value as Tree<ResultEncoding>, opts)
await writeTree(path, value as Tree<Encoding>, opts)
} else {
await write(path, value === true ? '' : value, opts)
}
Expand Down

0 comments on commit caad1ae

Please sign in to comment.