Skip to content

Commit 35b45f8

Browse files
committed
feat: minify json option
1 parent 42d62be commit 35b45f8

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

execute/src/commands/migrateCollection/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import task from "tasuku";
55
import mongoose from "mongoose";
66
import { GalleryModel } from "@riffyh/database";
77

8-
export const migrateCollection = async (config: Config, pathToCollectionJson: string) =>
8+
export const migrateCollection = async (
9+
config: Config,
10+
pathToCollectionJson: string,
11+
minify: boolean = false,
12+
) =>
913
task("migrate collection", async ({ setTitle, setError }) => {
1014
const fileContent = await fs.readFile(pathToCollectionJson, "utf-8");
1115
const oldCollection = JSON.parse(fileContent) as OldCollection[];
@@ -77,7 +81,10 @@ export const migrateCollection = async (config: Config, pathToCollectionJson: st
7781

7882
// write output.json of collection
7983
setTitle("writing output.json...");
80-
await fs.writeFile("./output.json", JSON.stringify(collection, null, 2));
84+
await fs.writeFile(
85+
"./output.json",
86+
minify ? JSON.stringify(collection) : JSON.stringify(collection, null, 2),
87+
);
8188

8289
if (hasMongoUrl) {
8390
await mongoose.disconnect();

execute/src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ yargs(hideBin(process.argv))
2727
.command(
2828
"collection <json-file>",
2929
"migrate legacy collection json file to database",
30-
{},
30+
(y) =>
31+
y.option("minify", {
32+
type: "boolean",
33+
description: "Write output.json as minified JSON",
34+
default: false,
35+
}),
3136
(argv) => {
32-
migrateCollection(config, path.resolve(argv["json-file"] as string));
37+
migrateCollection(
38+
config,
39+
path.resolve(argv["json-file"] as string),
40+
argv.minify as boolean,
41+
);
3342
},
3443
)
3544
.command("db <directory>", "migrate legacy hentai json files to database", {}, (argv) => {

0 commit comments

Comments
 (0)