https://github.com/npm/fs-vacuum
Remove empty branches in a directory tree.
https://github.com/npm/fs-vacuum
npm-cli
Last synced: 9 months ago
JSON representation
Remove empty branches in a directory tree.
- Host: GitHub
- URL: https://github.com/npm/fs-vacuum
- Owner: npm
- License: isc
- Archived: true
- Created: 2014-06-25T06:57:30.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2023-02-07T04:56:18.000Z (over 3 years ago)
- Last Synced: 2024-10-01T16:06:48.765Z (over 1 year ago)
- Topics: npm-cli
- Language: JavaScript
- Homepage: https://npmjs.org/package/fs-vacuum
- Size: 60.5 KB
- Stars: 8
- Watchers: 22
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fs-vacuum
Remove the empty branches of a directory tree, optionally up to (but not
including) a specified base directory. Optionally nukes the leaf directory.
## Usage
```javascript
var logger = require("npmlog");
var vacuum = require("fs-vacuum");
var options = {
base : "/path/to/my/tree/root",
purge : true,
log : logger.silly.bind(logger, "myCleanup")
};
/* Assuming there are no other files or directories in "out", "to", or "my",
* the final path will just be "/path/to/my/tree/root".
*/
vacuum("/path/to/my/tree/root/out/to/my/files", options, function (error) {
if (error) console.error("Unable to cleanly vacuum:", error.message);
});
```
# vacuum(directory, options, callback)
* `directory` {String} Leaf node to remove. **Must be a directory, symlink, or file.**
* `options` {Object}
* `base` {String} No directories at or above this level of the filesystem will be removed.
* `purge` {Boolean} If set, nuke the whole leaf directory, including its contents.
* `log` {Function} A logging function that takes `npmlog`-compatible argument lists.
* `callback` {Function} Function to call once vacuuming is complete.
* `error` {Error} What went wrong along the way, if anything.