diff --git a/server/controllers/export.ts b/server/controllers/export.ts index 1743728..aa66c17 100644 --- a/server/controllers/export.ts +++ b/server/controllers/export.ts @@ -4,7 +4,7 @@ import { join } from "path"; import pluginId from "../../pluginId.json"; -import { getProjectName, withExt } from "../utils"; +import { getProjectName, mkdirp, withExt } from "../utils"; import type { ControllerFactory } from "./types"; @@ -22,6 +22,7 @@ export const exportController: ControllerFactory = ({ strapi }) => ({ throw new Error("nothing enabled to export"); } + await mkdirp(ARCHIVE_DIR); const filePath = join(ARCHIVE_DIR, randomUUID()); const archiveName = strapi diff --git a/server/utils/index.ts b/server/utils/index.ts index ec48a97..de40e50 100644 --- a/server/utils/index.ts +++ b/server/utils/index.ts @@ -1,9 +1,10 @@ import { exec } from "child_process"; -import { readFileSync } from "fs"; +import { mkdir, readFileSync } from "fs"; import { join } from "path"; import { promisify } from "util"; const _execa = promisify(exec); +const _mkdir = promisify(mkdir); export async function execa(command: string) { const stds = await _execa(command) @@ -11,6 +12,15 @@ export async function execa(command: string) { return stds } +export async function mkdirp(path: string) { + let success = false + + return _mkdir(path, { recursive: true }) + .then(() => success = true) + .catch(() => success = false) + .finally(() => success) +} + let pckgJsn: string | undefined; export function getProjectName() {