UNPKG

594 BJavaScriptView Raw
1'use strict'
2
3const path = require('path')
4const fs = require('graceful-fs')
5const rimraf = require('rimraf')
6const log = require('./logger').create('temp-dir')
7
8const TEMP_DIR = require('os').tmpdir()
9
10module.exports = {
11 getPath (suffix) {
12 return path.normalize(TEMP_DIR + suffix)
13 },
14
15 create (path) {
16 log.debug(`Creating temp dir at ${path}`)
17
18 try {
19 fs.mkdirSync(path)
20 } catch (e) {
21 log.warn(`Failed to create a temp dir at ${path}`)
22 }
23
24 return path
25 },
26
27 remove (path, done) {
28 log.debug(`Cleaning temp dir ${path}`)
29 rimraf(path, done)
30 }
31}