temp-dir-cp

1.0.1 • Public • Published

temp-dir-cp

NPM version Build Status XO code style

⚡️ Copy folder to a unique temp location

Install

yarn add temp-dir-cp
# same as npm install --save

Usage

Assume that in the current directory, there is a directory called fixtures:

$ tree
.
├── fixtures
│   └── file.txt
└── index.js

Call temp-dir-cp with "fixtures"

// index.js
const tempDirCp = require('temp-dir-cp');

tempDirCp('fixtures');
//=> '/var/folders/6r/cyh35ykj4h77jnn0lz0xqx580000gn/T/87166550876/fixtures'

tempDirCp('fixtures');
//=> '/var/folders/6r/cyh35ykj4h77jnn0lz0xqx580000gn/T/75704852254/fixtures'

Both of these newly created directory's have the contents of the fixtures directory. Each can be mutated separately without affecting one another or the source.

$ tree /var/folders/6r/cyh35ykj4h77jnn0lz0xqx580000gn/T/87166550876
└── fixtures
    └── file.txt

$ tree /var/folders/6r/cyh35ykj4h77jnn0lz0xqx580000gn/T/75704852254
└── fixtures
    └── file.txt

For any tests which modify the file-system, you can't cd into your fixtures and then run the tests. That would modify your fixtures and therefore break future tests. Use tempDirCp instead and you will have a fresh copy of your files in a unique directory every time. The unique directory is temporary too, so it gets removed on computer startup!

API

tempDirCp(sourceDir)

Arguments

Name Description Type Default
sourceDir Directory that should be copied string None

Returns

Type: string

License

MIT © Dawson Botsford

Readme

Keywords

none

Package Sidebar

Install

npm i temp-dir-cp

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • dawsonbotsford