Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,20 @@ quickTemp.remove(this, 'tmpDestDir');

This will also assign `this.tmpDestDir = null`. If `this.tmpDestDir` is
already null or undefined, it will be a no-op.

### Building a temporary directory path

To generate a temporary directory path (but not create it) and assign its
path to `this.someThing`, call:

```js
quickTemp.buildTmpPath(this, 'someThing')
```

An optional third argument lets you override the class-name component of the
temporary directory name:

```js
quickTemp.buildTmpPath(this, 'tmpDestDir', 'TreeMerger');
quickTemp.buildTmpPath(this, 'tmpDestDir', this.constructor.name); // default
```
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ var mktemp = require('mktemp')
var rimraf = require('rimraf')
var underscoreString = require('underscore.string')

exports.buildTmpPath = buildTmpPath
function buildTmpPath(obj, prop, className) {
if (className == null) className = obj.constructor && obj.constructor.name

var tmpDirName = prettyTmpDirName(className, prop)
return obj[prop] = path.join(findBaseDir(), tmpDirName)
Copy link
Member

@joliss joliss Dec 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The obj[prop] = assignment wasn't in the function this was extracted from, so we're technically assigning twice when you call makeOrRemake now. I'm not sure if this actually breaks anything.

Other than that I'm fine with this PR. 👍

Out of curiosity, are we still using this for anything post Broccoli 1.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya, I think some other packages use it for the shear convenience value (i.e. ember-cli uses it in its test suite)

}

exports.makeOrRemake = makeOrRemake
function makeOrRemake(obj, prop, className) {
if (obj[prop] != null) {
Expand Down Expand Up @@ -40,9 +48,8 @@ function remove(obj, prop) {


function makeTmpDir(obj, prop, className) {
if (className == null) className = obj.constructor && obj.constructor.name
var tmpDirName = prettyTmpDirName(className, prop)
return mktemp.createDirSync(path.join(findBaseDir(), tmpDirName))
var tmpDirPath = buildTmpPath(obj, prop, className)
return mktemp.createDirSync(tmpDirPath)
}

function currentTmp() {
Expand Down