Skip to content

Commit

Permalink
feat: 🎸 add .toTree() to Volume
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 25, 2023
1 parent 1850dae commit 2d5c4cb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
37 changes: 37 additions & 0 deletions demo/volume/print-tree.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Run: npx ts-node demo/volume/print-tree.ts

import { memfs } from '../../src';

const { vol } = memfs({
'/Users/streamich/src/github/memfs/src': {
'package.json': '...',
'tsconfig.json': '...',
'index.ts': '...',
'util': {
'index.ts': '...',
'print': {
'index.ts': '...',
'printTree.ts': '...',
},
},
},
});

console.log(vol.toTree());

// Output:
// /
// └─ Users/
// └─ streamich/
// └─ src/
// └─ github/
// └─ memfs/
// └─ src/
// β”œβ”€ index.ts
// β”œβ”€ package.json
// β”œβ”€ tsconfig.json
// └─ util/
// β”œβ”€ index.ts
// └─ print/
// β”œβ”€ index.ts
// └─ printTree.ts
5 changes: 5 additions & 0 deletions src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as misc from './node/types/misc';
import * as opts from './node/types/options';
import { FsCallbackApi } from './node/types/FsCallbackApi';
import { FsPromises } from './node/FsPromises';
import {ToTreeOptions, toTreeSync} from './print';
import { ERRSTR, FLAGS, MODE } from './node/constants';
import {
getDefaultOpts,
Expand Down Expand Up @@ -605,6 +606,10 @@ export class Volume implements FsCallbackApi {
this.fromJSON(flattenJSON(json), cwd);
}

public toTree(opts?: ToTreeOptions): string {
return toTreeSync(this, opts);
}

reset() {
this.ino = 0;
this.inodes = {};
Expand Down

0 comments on commit 2d5c4cb

Please sign in to comment.