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