Skip to content

Commit

Permalink
feat: add metadata.json to overwrite story.json metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jersou committed Dec 27, 2023
1 parent 8e85d15 commit b03d60f
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.34.2
deno-version: v1.39.1

- name: Verify formatting
run: deno task fmt
Expand All @@ -43,7 +43,7 @@ jobs:
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.34.2
deno-version: v1.39.1

- name: check version
run: test $(./version.ts) = ${GITHUB_REF##*/}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/.idea/jpa-buddy.xml
/.idea/google-java-format.xml
/.idea/inspectionProfiles
/.idea/sonarlint/
5 changes: 4 additions & 1 deletion .idea/deno.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### v0.2.10 / 2023.12.27

- use deno 1.39.1
- add metadata.json to overwrite story.json metadata

### v0.2.9 / 2023.07.28

- feat: add images convertion #21
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,23 @@ Options:
- Option to skip the beginning of stories.
- Zip Pack aggregation

### Overwrite metadata

If the file `metadata.json` exists in the story folder, it will be used to
overwrite the `story.json` metadata.

All key/value are optional, ex:

```json
{
"title": "title - overwrite",
"description": "description - overwrite",
"format": "v1",
"version": 1,
"nightModeAvailable": false
}
```

## Development

Some dev command are listed in the deno.json file :
Expand Down
7 changes: 6 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions gen_pack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File, Folder } from "./serialize/types.ts";
import { File, Folder, Metadata } from "./serialize/types.ts";
import { fsToFolder } from "./serialize/fs.ts";
import { extractImagesFromAudio } from "./generate/extract_images_from_audio.ts";
import { genMissingItems } from "./generate/gen_missing_items.ts";
Expand Down Expand Up @@ -95,7 +95,9 @@ export async function generatePack(opt: ModOptions) {
}
if (!opt.skipZipGeneration) {
folder = await fsToFolder(opt.storyPath, true);
const pack = folderToPack(folder, !!opt.nightMode);

const metadata: Metadata = await getMetadata(opt);
const pack = folderToPack(folder, metadata);
const nightModeAudioItemName = getNightModeAudioItem(folder);
const serializedPack = await serializePack(pack, opt, {
autoNextStoryTransition: opt.autoNextStoryTransition,
Expand All @@ -115,3 +117,15 @@ export async function generatePack(opt: ModOptions) {
}
}
}

async function getMetadata(opt: ModOptions): Promise<Metadata> {
const metadataPath = `${opt.storyPath}/metadata.json`;
if (await exists(metadataPath)) {
const metadataJson = await Deno.readTextFile(metadataPath);
return JSON.parse(metadataJson);
} else {
return {
nightMode: !!opt.nightMode,
};
}
}
13 changes: 7 additions & 6 deletions serialize/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
File,
Folder,
Menu,
Metadata,
Pack,
Story,
StoryItem,
Expand All @@ -20,14 +21,14 @@ import {
isZipFile,
} from "../utils/utils.ts";

export function folderToPack(folder: Folder, nightMode = false): Pack {
export function folderToPack(folder: Folder, metadata?: Metadata): Pack {
const firstSubFolder = folder.files.find((f) => isFolder(f)) as Folder;
return {
title: folder!.name,
description: "",
format: "v1",
version: 1,
nightModeAvailable: nightMode,
title: metadata?.title ?? folder!.name,
description: metadata?.description ?? "",
format: metadata?.format ?? "v1",
version: metadata?.version ?? 1,
nightModeAvailable: !!(metadata?.nightMode),
entrypoint: {
class: "StageNode-Entrypoint",
name: "Cover node",
Expand Down
20 changes: 14 additions & 6 deletions serialize/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export type File = {

export type Pack = {
title: string;
description: "";
format: "v1";
version: 1;
description: string;
format: string;
version: number;
nightModeAvailable: boolean;
entrypoint: Entrypoint;
};
Expand Down Expand Up @@ -81,9 +81,9 @@ export type ActionNode = {

export type SerializedPack = {
title: string;
description: "";
format: "v1";
version: 1;
description: string;
format: string;
version: number;
nightModeAvailable: boolean;
actionNodes: ActionNode[];
stageNodes: StageNode[];
Expand All @@ -94,3 +94,11 @@ export type ZipMenu = {
class: "ZipMenu";
path: string;
};

export type Metadata = {
title?: string;
description?: string;
format?: string;
version?: number;
nightMode?: boolean;
};
2 changes: 1 addition & 1 deletion version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env -S deno run -A

export const version = "v0.2.9";
export const version = "v0.2.10";

if (import.meta.main) {
console.log(version);
Expand Down

0 comments on commit b03d60f

Please sign in to comment.