mirror of
https://github.com/strapi/strapi.git
synced 2025-08-10 09:47:46 +00:00
29 lines
715 B
TypeScript
29 lines
715 B
TypeScript
![]() |
import { randomUUID } from 'crypto';
|
||
|
import { mkdir, rm } from 'fs/promises';
|
||
|
import path from 'path';
|
||
|
|
||
|
/**
|
||
|
* Remove all the tmp folder and everything in it.
|
||
|
* Great for when it all goes wrong.
|
||
|
*/
|
||
|
const cleanupWorkspaces = async () => {
|
||
|
const workspacePath = path.resolve(__dirname, `__tmp__`);
|
||
|
|
||
|
return rm(workspacePath, { recursive: true, force: true });
|
||
|
};
|
||
|
|
||
|
const createWorkspace = async () => {
|
||
|
const key = randomUUID();
|
||
|
|
||
|
const workspacePath = path.resolve(__dirname, '__tmp__', key);
|
||
|
|
||
|
await mkdir(workspacePath, { recursive: true });
|
||
|
|
||
|
return {
|
||
|
path: workspacePath,
|
||
|
remove: () => rm(workspacePath, { recursive: true, force: true }),
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export { cleanupWorkspaces, createWorkspace };
|