Skip to content

Commit

Permalink
fix: create tmp dir if not here
Browse files Browse the repository at this point in the history
  • Loading branch information
y-nk committed Nov 10, 2023
1 parent 9cce217 commit b653f5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion server/controllers/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion server/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
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)
console.info({ command, ...stds })
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() {
Expand Down

0 comments on commit b653f5a

Please sign in to comment.