2019-03-21 04:50:44 +09:00
|
|
|
import * as tmp from 'tmp';
|
|
|
|
|
2022-05-25 16:50:22 +09:00
|
|
|
export function createTemp(): Promise<[string, () => void]> {
|
|
|
|
return new Promise<[string, () => void]>((res, rej) => {
|
2019-03-21 04:50:44 +09:00
|
|
|
tmp.file((e, path, fd, cleanup) => {
|
|
|
|
if (e) return rej(e);
|
2022-12-30 12:00:50 +09:00
|
|
|
res([path, process.env.NODE_ENV === 'production' ? cleanup : () => {}]);
|
2019-03-21 04:50:44 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-05-25 16:50:22 +09:00
|
|
|
|
|
|
|
export function createTempDir(): Promise<[string, () => void]> {
|
|
|
|
return new Promise<[string, () => void]>((res, rej) => {
|
2022-06-14 23:00:10 +09:00
|
|
|
tmp.dir(
|
|
|
|
{
|
|
|
|
unsafeCleanup: true,
|
|
|
|
},
|
|
|
|
(e, path, cleanup) => {
|
|
|
|
if (e) return rej(e);
|
2022-12-30 12:00:50 +09:00
|
|
|
res([path, process.env.NODE_ENV === 'production' ? cleanup : () => {}]);
|
2022-12-03 19:42:05 +09:00
|
|
|
},
|
2022-06-14 23:00:10 +09:00
|
|
|
);
|
2022-05-25 16:50:22 +09:00
|
|
|
});
|
|
|
|
}
|