Skip to content

Commit

Permalink
feat: 🎸 add sumlink printing support
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 25, 2023
1 parent 09c9770 commit 1850dae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/print/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,33 @@ test('can stop recursion at specified depth', () => {
└─ dir2/ (...)"
`);
});

test('can print symlinks', () => {
const { fs } = memfs({
'/a/b/c/file.txt': '...',
'/a/b/main.rb': '...',
});
fs.symlinkSync('/a/b/c/file.txt', '/goto');
expect(toTreeSync(fs)).toMatchInlineSnapshot(`
"/
β”œβ”€ a/
β”‚ └─ b/
β”‚ β”œβ”€ c/
β”‚ β”‚ └─ file.txt
β”‚ └─ main.rb
└─ goto β†’ /a/b/c/file.txt"
`);
});

test('can print starting from subfolder', () => {
const { fs } = memfs({
'/a/b/c/file.txt': '...',
'/a/b/main.rb': '...',
});
expect(toTreeSync(fs, { dir: '/a/b' })).toMatchInlineSnapshot(`
"b/
β”œβ”€ c/
β”‚ └─ file.txt
└─ main.rb"
`);
});
2 changes: 2 additions & 0 deletions src/print/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const toTreeSync = (fs: FsSynchronousApi, opts: ToTreeOptions = {}) => {
const isDir = entry.isDirectory();
if (isDir) {
return toTreeSync(fs, {dir: dir + entry.name, depth: depth - 1, tab});
} else if (entry.isSymbolicLink()) {
return '' + entry.name + ' β†’ ' + fs.readlinkSync(dir + entry.name);
} else {
return '' + entry.name;
}
Expand Down

0 comments on commit 1850dae

Please sign in to comment.