use mkdtemp

This commit is contained in:
Nebel 2023-12-05 00:20:59 +09:00
parent ce0fc9001e
commit 445110c552
Signed by: nebel
GPG key ID: 79807D08C6EF6460
4 changed files with 9 additions and 5 deletions

View file

@ -1,3 +1,6 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import util from "node:util"; import util from "node:util";
import { createBrowser } from "./browser"; import { createBrowser } from "./browser";
import { createDatabase } from "./database"; import { createDatabase } from "./database";
@ -174,7 +177,9 @@ const options = {
db, db,
browser, browser,
}); });
const dir = `${args.values["out-dir"]!}/${book.id}`; const dir = await fs.mkdtemp(
path.join(os.tmpdir(), `gadl-${book.id}-`),
);
await platform.download(dir, book); await platform.download(dir, book);
await library.archive(dir, book, { await library.archive(dir, book, {
outDir: args.values["out-dir"]!, outDir: args.values["out-dir"]!,

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "@fogtype/gadl", "name": "@fogtype/gadl",
"version": "1.3.1", "version": "1.4.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@fogtype/gadl", "name": "@fogtype/gadl",
"version": "1.3.1", "version": "1.4.0",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"dependencies": { "dependencies": {
"fflate": "^0.8.1", "fflate": "^0.8.1",

View file

@ -1,6 +1,6 @@
{ {
"name": "@fogtype/gadl", "name": "@fogtype/gadl",
"version": "1.3.1", "version": "1.4.0",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"type": "module", "type": "module",
"bin": "bin/run.js", "bin": "bin/run.js",

View file

@ -44,7 +44,6 @@ export function createPlatform(opts: {
...platform, ...platform,
async download(dir: string, book: Book): Promise<void> { async download(dir: string, book: Book): Promise<void> {
await fs.mkdir(path.dirname(dir), { recursive: true });
await fs.mkdir(dir); await fs.mkdir(dir);
const files: Array<() => Promise<Blob>> = await platform.getFiles(book); const files: Array<() => Promise<Blob>> = await platform.getFiles(book);