UNPKG

@atomist/automation-client

Version:
28 lines 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs-extra"); const tmp = require("tmp-promise"); /** * Uses tmp-promise (built on tmp) to create clean temporary directories * to work with git projects from remotes */ exports.TmpDirectoryManager = { directoryFor(owner, repo, branch, opts) { return tmp.dir({ keep: opts.keep }) // the lack of typings here causes lack of typechecking in this function .then(fromTmp => (Object.assign({}, fromTmp, { type: "empty-directory", release: () => cleanup(fromTmp.path, opts.keep), invalidate: () => Promise.resolve(), transient: true, provenance: "created with tmp, keep = " + opts.keep }))); }, }; /* * If !keep, attempts to delete directory. Swallows errors * because it is not that important. */ function cleanup(path, keep) { if (keep) { return Promise.resolve(); } else { return fs.remove(path) .then(() => Promise.resolve(), err => Promise.resolve()); } } //# sourceMappingURL=tmpDirectoryManager.js.map