rpg-engine 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adventures/index.d.ts +1 -1
- package/dist/adventures/index.js +1 -1
- package/dist/adventures/source.d.ts +3 -0
- package/dist/adventures/source.js +11 -49
- package/dist/campaign/create-campaign.d.ts +1 -1
- package/dist/campaign/create-campaign.js +3 -2
- package/dist/campaign/find-campaign.d.ts +2 -0
- package/dist/campaign/find-campaign.js +2 -0
- package/dist/campaign/host-files.js +4 -1
- package/dist/campaign/index.d.ts +3 -2
- package/dist/campaign/index.js +3 -2
- package/dist/campaign/port.d.ts +6 -0
- package/dist/campaign/port.js +24 -0
- package/dist/campaign/settings.d.ts +17 -0
- package/dist/campaign/settings.js +26 -3
- package/dist/cli/cli.js +15 -0
- package/dist/commands/book.d.ts +16 -35
- package/dist/commands/book.js +86 -62
- package/dist/commands/config/config.js +16 -2
- package/dist/commands/config/dashboard.d.ts +6 -2
- package/dist/commands/config/dashboard.js +45 -8
- package/dist/commands/config/shown.js +4 -0
- package/dist/commands/config/words.d.ts +3 -1
- package/dist/commands/config/words.js +29 -2
- package/dist/commands/image.d.ts +5 -0
- package/dist/commands/image.js +6 -3
- package/dist/commands/mode.d.ts +1 -1
- package/dist/commands/package/data.d.ts +35 -0
- package/dist/commands/package/data.js +144 -0
- package/dist/commands/package/here.d.ts +7 -2
- package/dist/commands/package/here.js +23 -11
- package/dist/commands/package/install.js +14 -15
- package/dist/commands/package/language.d.ts +15 -0
- package/dist/commands/package/language.js +109 -0
- package/dist/commands/package/package.js +20 -10
- package/dist/commands/package/result.d.ts +19 -0
- package/dist/commands/package/theme.d.ts +13 -0
- package/dist/commands/package/theme.js +67 -0
- package/dist/commands/package/uninstall.d.ts +4 -1
- package/dist/commands/package/uninstall.js +29 -9
- package/dist/commands/scene/close.d.ts +1 -1
- package/dist/commands/scene/close.js +15 -8
- package/dist/commands/scene/scene.js +6 -1
- package/dist/commands/shared/books/adventures.d.ts +1 -4
- package/dist/commands/shared/books/adventures.js +3 -32
- package/dist/commands/shared/books/words.js +3 -2
- package/dist/commands/shared/campaign/book.d.ts +21 -8
- package/dist/commands/shared/campaign/book.js +65 -42
- package/dist/commands/shared/campaign/git.d.ts +25 -0
- package/dist/commands/shared/campaign/git.js +104 -0
- package/dist/commands/shared/campaign/saves.js +7 -3
- package/dist/commands/shared/campaign/world.js +2 -1
- package/dist/commands/shared/packages/catalog.d.ts +3 -3
- package/dist/commands/shared/packages/catalog.js +118 -43
- package/dist/commands/shared/packages/unpacked.d.ts +50 -0
- package/dist/commands/shared/packages/unpacked.js +146 -0
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +8 -4
- package/dist/core/archive.d.ts +13 -0
- package/dist/core/archive.js +76 -0
- package/dist/core/context.d.ts +4 -0
- package/dist/core/context.js +1 -0
- package/dist/core/store.d.ts +5 -1
- package/dist/core/store.js +15 -2
- package/dist/core/version.d.ts +2 -0
- package/dist/core/version.js +5 -0
- package/dist/dashboard/api.js +24 -1
- package/dist/dashboard/app.js +7 -2
- package/dist/dashboard/guide/ar.md +11 -9
- package/dist/dashboard/guide/cs.md +11 -9
- package/dist/dashboard/guide/da.md +12 -10
- package/dist/dashboard/guide/de.md +13 -11
- package/dist/dashboard/guide/el.md +11 -9
- package/dist/dashboard/guide/en.md +10 -8
- package/dist/dashboard/guide/es.md +11 -9
- package/dist/dashboard/guide/fi.md +11 -9
- package/dist/dashboard/guide/fr.md +11 -9
- package/dist/dashboard/guide/he.md +11 -9
- package/dist/dashboard/guide/hi.md +11 -9
- package/dist/dashboard/guide/hu.md +11 -9
- package/dist/dashboard/guide/is.md +11 -9
- package/dist/dashboard/guide/it.md +11 -9
- package/dist/dashboard/guide/ja.md +12 -10
- package/dist/dashboard/guide/ko.md +11 -9
- package/dist/dashboard/guide/nb.md +12 -10
- package/dist/dashboard/guide/nl.md +11 -9
- package/dist/dashboard/guide/pl.md +11 -9
- package/dist/dashboard/guide/pt.md +11 -9
- package/dist/dashboard/guide/ro.md +11 -9
- package/dist/dashboard/guide/ru.md +12 -10
- package/dist/dashboard/guide/sv.md +11 -9
- package/dist/dashboard/guide/tr.md +11 -9
- package/dist/dashboard/guide/uk.md +12 -10
- package/dist/dashboard/guide/zh.md +11 -9
- package/dist/dashboard/i18n/ar.json +58 -5
- package/dist/dashboard/i18n/cs.json +58 -5
- package/dist/dashboard/i18n/da.json +58 -5
- package/dist/dashboard/i18n/de.json +58 -5
- package/dist/dashboard/i18n/el.json +58 -5
- package/dist/dashboard/i18n/es.json +58 -5
- package/dist/dashboard/i18n/fi.json +58 -5
- package/dist/dashboard/i18n/fr.json +58 -5
- package/dist/dashboard/i18n/he.json +58 -5
- package/dist/dashboard/i18n/hi.json +58 -5
- package/dist/dashboard/i18n/hu.json +58 -5
- package/dist/dashboard/i18n/is.json +58 -5
- package/dist/dashboard/i18n/it.json +58 -5
- package/dist/dashboard/i18n/ja.json +58 -5
- package/dist/dashboard/i18n/ko.json +58 -5
- package/dist/dashboard/i18n/nb.json +58 -5
- package/dist/dashboard/i18n/nl.json +58 -5
- package/dist/dashboard/i18n/pl.json +58 -5
- package/dist/dashboard/i18n/pt.json +58 -5
- package/dist/dashboard/i18n/ro.json +58 -5
- package/dist/dashboard/i18n/ru.json +58 -5
- package/dist/dashboard/i18n/sv.json +58 -5
- package/dist/dashboard/i18n/tr.json +58 -5
- package/dist/dashboard/i18n/uk.json +58 -5
- package/dist/dashboard/i18n/zh.json +58 -5
- package/dist/dashboard/journal/book.js +3 -2
- package/dist/dashboard/journal/journal.js +8 -5
- package/dist/dashboard/kit.js +1 -1
- package/dist/dashboard/packages/catalog.js +31 -14
- package/dist/dashboard/packages/engine.js +46 -2
- package/dist/dashboard/packages/installed.js +13 -0
- package/dist/dashboard/packages/outcomes.js +21 -0
- package/dist/dashboard/packages/packages.js +41 -18
- package/dist/dashboard/packages/rows.js +3 -1
- package/dist/dashboard/parts/icons.js +3 -0
- package/dist/dashboard/parts/labels.js +7 -0
- package/dist/dashboard/parts/picture.js +89 -0
- package/dist/dashboard/parts/refusals.js +8 -1
- package/dist/dashboard/parts/widgets.js +2 -1
- package/dist/dashboard/play/scene.js +8 -5
- package/dist/dashboard/settings/settings.js +55 -18
- package/dist/dashboard/sheet/party.js +5 -2
- package/dist/dashboard/sheet/sheet.js +2 -1
- package/dist/dashboard/shell/notices.js +2 -2
- package/dist/dashboard/shell/system-style.js +132 -15
- package/dist/dashboard/shell/tooltip.js +224 -0
- package/dist/dashboard/style.css +497 -193
- package/dist/dashboard/world/lore.js +4 -3
- package/dist/dashboard/world/place-card.js +2 -1
- package/dist/git/git.d.ts +12 -0
- package/dist/git/git.js +175 -0
- package/dist/git/ignore.d.ts +2 -0
- package/dist/git/ignore.js +16 -0
- package/dist/git/index.d.ts +2 -0
- package/dist/git/index.js +2 -0
- package/dist/importer/index.d.ts +1 -1
- package/dist/importer/index.js +1 -1
- package/dist/languages/index.d.ts +1 -1
- package/dist/languages/index.js +1 -1
- package/dist/languages/pack.d.ts +4 -1
- package/dist/languages/pack.js +18 -6
- package/dist/packages/engine.d.ts +7 -0
- package/dist/packages/engine.js +32 -1
- package/dist/packages/index.d.ts +1 -1
- package/dist/packages/index.js +1 -1
- package/dist/server/bell-listener.d.ts +2 -1
- package/dist/server/bell-listener.js +10 -41
- package/dist/server/dashboard/engine.d.ts +18 -0
- package/dist/server/dashboard/engine.js +31 -0
- package/dist/server/dashboard/files.d.ts +11 -3
- package/dist/server/dashboard/files.js +66 -17
- package/dist/server/dashboard/index.d.ts +18 -2
- package/dist/server/dashboard/index.js +62 -23
- package/dist/server/dashboard/news.d.ts +3 -2
- package/dist/server/dashboard/news.js +19 -5
- package/dist/server/dashboard/pictures.d.ts +7 -0
- package/dist/server/dashboard/pictures.js +62 -0
- package/dist/server/dashboard/ports.d.ts +17 -2
- package/dist/server/dashboard/ports.js +60 -4
- package/dist/server/dashboard/writes.d.ts +5 -3
- package/dist/server/dashboard/writes.js +45 -14
- package/dist/server/mcp.d.ts +3 -2
- package/dist/server/mcp.js +55 -11
- package/dist/testing/index.js +1 -0
- package/dist/themes/css.d.ts +1 -1
- package/dist/themes/css.js +101 -2
- package/dist/themes/index.d.ts +2 -1
- package/dist/themes/index.js +4 -2
- package/dist/themes/installed.d.ts +14 -0
- package/dist/themes/installed.js +28 -0
- package/dist/themes/theme.d.ts +38 -0
- package/dist/themes/theme.js +192 -13
- package/instructions/core.md +4 -3
- package/instructions/dashboard-guide.md +2 -1
- package/instructions/mentor-hints.md +1 -1
- package/instructions/mentor-tutorial.md +1 -1
- package/instructions/party.md +1 -1
- package/instructions/play.md +2 -2
- package/package.json +1 -1
- package/systems/free/instructions/outcomes-told.md +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The saves of a campaign as commands use them (D-54, D-55): which files a save holds, a save made at the end of a scene or when asked, and given back.
|
|
2
2
|
import { join, relative, resolve, sep } from "node:path";
|
|
3
|
-
import { bookFolderName, campaignFileName, hostFileNames, readSettings, sessionsFolderName } from "../../../campaign/index.js";
|
|
3
|
+
import { bookFolderName, campaignFileName, hostFileNames, inboxFolderName, readSettings, sessionsFolderName } from "../../../campaign/index.js";
|
|
4
4
|
import { filesIn } from "../../../core/files.js";
|
|
5
5
|
import { appendLogEntry, logFileName, logLine, readLog } from "../../../core/log.js";
|
|
6
6
|
import { files, isInside } from "../../../core/store.js";
|
|
@@ -10,6 +10,7 @@ import { packFiles, readSaves, saveFileName, unpackFiles } from "../../../saves/
|
|
|
10
10
|
import { formatGameDate } from "../../../time/index.js";
|
|
11
11
|
import { playerCharacter } from "../characters/knowledge.js";
|
|
12
12
|
import { newDatedLogEntry, readPresent } from "../time/time.js";
|
|
13
|
+
import { commitCampaign } from "./git.js";
|
|
13
14
|
import { campaignWorld } from "./world.js";
|
|
14
15
|
/** The folder of the saves, at the top of the campaign. */
|
|
15
16
|
export const savesFolderName = ".saves";
|
|
@@ -73,7 +74,9 @@ export function makeSave(root, context, label, why) {
|
|
|
73
74
|
held[logFileName] = joinBytes(held[logFileName], new TextEncoder().encode(logLine(entry)));
|
|
74
75
|
files().writeBytes(join(root, savesFolderName, file), packFiles(held));
|
|
75
76
|
appendLogEntry(root, entry);
|
|
76
|
-
|
|
77
|
+
const save = readSaves([file])[0];
|
|
78
|
+
void commitCampaign(root, `rpg: ${saveText(save)}`);
|
|
79
|
+
return save;
|
|
77
80
|
}
|
|
78
81
|
/**
|
|
79
82
|
* Gives the campaign back as a save holds it (SAV-5): its game files as they were, but campaign.yaml, its settings, as it is now (D-360), those made since
|
|
@@ -128,6 +131,7 @@ export function loadSave(root, context, save) {
|
|
|
128
131
|
}));
|
|
129
132
|
files().remove(join(folder, loadingMarkName));
|
|
130
133
|
files().writeBytes(join(folder, newChatMarkName), new TextEncoder().encode(saveText(save)));
|
|
134
|
+
void commitCampaign(root, `rpg: loaded ${saveText(save)}`);
|
|
131
135
|
return { removed: later, copy };
|
|
132
136
|
}
|
|
133
137
|
/** The save the game went back to, until the player confirms a new chat: the chat that went on before remembers what is gone (D-361, D-362). */
|
|
@@ -274,7 +278,7 @@ function gameFiles(root) {
|
|
|
274
278
|
/** Whether a name at the top of a campaign is the game's: not the host's, in any case, as Windows reads them, and not starting with a dot. */
|
|
275
279
|
function isGameName(name) {
|
|
276
280
|
return !name.startsWith(".") && !hostNames.has(name.toLowerCase()) && name.toLowerCase() !== exportsFolderName && name.toLowerCase() !== sessionsFolderName
|
|
277
|
-
&& name.toLowerCase() !== bookFolderName;
|
|
281
|
+
&& name.toLowerCase() !== bookFolderName && name.toLowerCase() !== inboxFolderName;
|
|
278
282
|
}
|
|
279
283
|
function joinBytes(first, second) {
|
|
280
284
|
const joined = new Uint8Array((first?.length ?? 0) + second.length);
|
|
@@ -10,6 +10,7 @@ import { layerFolder, layersFolderName, loadWorld, playerCharacters, searchSyste
|
|
|
10
10
|
import { engineSettingValue, findCampaignSystem, findSystem, layeredSystemWords, readableSystems, rulesetSetting, systemContentFolders, systemWords, withSettings, } from "../../../systems/index.js";
|
|
11
11
|
import { homeSystemWords } from "../books/words.js";
|
|
12
12
|
import { campaignExtensions, extensionSources, layeredParts } from "../packages/extensions.js";
|
|
13
|
+
import { languageFolders } from "../packages/unpacked.js";
|
|
13
14
|
/** The world of the campaign in `root`, with the pages of its game system when campaign.yaml names one that is installed (SYS-1, SYS-3). */
|
|
14
15
|
export function campaignWorld(root, context) {
|
|
15
16
|
// The same world until one of its pages, campaign.yaml or the system's pages translated on this computer change, or a folder of the packages is read again
|
|
@@ -48,7 +49,7 @@ export function ownTranslationFolder(context, system, language) {
|
|
|
48
49
|
*/
|
|
49
50
|
export function systemWordsOf(root, system, language, context) {
|
|
50
51
|
// A language package's words come first, then the system's own, then those translated on the fly (D-485 (3)).
|
|
51
|
-
const pack = languagePackFor(context
|
|
52
|
+
const pack = languagePackFor(languageFolders(context), language);
|
|
52
53
|
const packed = pack === undefined ? undefined : packSystemFolder(pack, system.name);
|
|
53
54
|
const own = (packed === undefined ? undefined : systemWords(packed, language)) ?? layeredSystemWords(systemContentFolders(system), language) ?? homeSystemWords(context.home, system, language);
|
|
54
55
|
const added = campaignExtensions(root, context).extensions.reduce((fields, extension) => ({ ...fields, ...extensionFieldWords(extension, language) }), {});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Context } from "../../../core/context.ts";
|
|
2
2
|
/** The kinds of packages the catalog lists. */
|
|
3
|
-
export type CatalogKind = "system" | "adventure" | "extension" | "language";
|
|
3
|
+
export type CatalogKind = "system" | "adventure" | "extension" | "language" | "theme";
|
|
4
4
|
/** A package one may add, as the page lists it (D-486 (3)). */
|
|
5
5
|
export interface CatalogEntry {
|
|
6
6
|
kind: CatalogKind;
|
|
@@ -13,7 +13,7 @@ export interface CatalogEntry {
|
|
|
13
13
|
code: boolean;
|
|
14
14
|
/** What the player adds it by: an npm name or a GitHub link. */
|
|
15
15
|
source: string;
|
|
16
|
-
/** The version here, when it is installed. */
|
|
16
|
+
/** The version here, when it is installed; empty for a theme installed without one. */
|
|
17
17
|
installed?: string;
|
|
18
18
|
update: boolean;
|
|
19
19
|
/** Its latest version, when it needs a newer rpg-engine than this one, which version offers the newest it reads (D-515 (2)): with the first engine that reads it. */
|
|
@@ -23,7 +23,7 @@ export interface CatalogEntry {
|
|
|
23
23
|
};
|
|
24
24
|
/** The game system an extension is made for, as its package.json says (D-548). */
|
|
25
25
|
system?: string;
|
|
26
|
-
/** An adventure's levels, length and language, as its adventure.yaml says. */
|
|
26
|
+
/** An adventure's levels, length and language, as its adventure.yaml says; a language's code. */
|
|
27
27
|
levels?: string;
|
|
28
28
|
length?: string;
|
|
29
29
|
language?: string;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
// The catalog of the packages one may add (D-485, D-486): what npm has for this rpg-engine, extensions, game systems and languages, and the
|
|
2
|
-
// GitHub has by their topic, each with what the player needs to trust it and whether it is here already.
|
|
1
|
+
// The catalog of the packages one may add (D-485, D-486): what npm has for this rpg-engine, extensions, game systems and languages, and the packages of data
|
|
2
|
+
// alone GitHub has by their topic, adventures, themes and languages, each with what the player needs to trust it and whether it is here already.
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
+
import { parse } from "yaml";
|
|
4
5
|
import { readManifest } from "../../../adventures/index.js";
|
|
5
6
|
import { ourSystems, readsApi } from "../../../core/packages/declarations.js";
|
|
6
7
|
import { files } from "../../../core/store.js";
|
|
7
8
|
import { comparableText } from "../../../core/text.js";
|
|
8
|
-
import { isNewerVersion } from "../../../core/version.js";
|
|
9
|
+
import { isNewerVersion, newerEngineAsked } from "../../../core/version.js";
|
|
9
10
|
import { installedExtensions, readExtension, shortName } from "../../../extensions/index.js";
|
|
10
11
|
import { installedLanguages } from "../../../languages/index.js";
|
|
11
12
|
import { isVerified } from "../../../packages/index.js";
|
|
12
13
|
import { systemFolders } from "../../../systems/index.js";
|
|
13
14
|
import { installedAdventures } from "../books/adventures.js";
|
|
15
|
+
import { isDataLanguage, isSameSource, languageFolders, themesHere, unpackedSource } from "./unpacked.js";
|
|
14
16
|
// How long the setup waits for npm before it offers ours alone.
|
|
15
17
|
const systemsWait = 5000;
|
|
16
18
|
/** The game systems npm has that this computer has not, ours first, with ours from the engine's list beside them, npm answering in time or not (D-513 (1)). */
|
|
@@ -34,10 +36,14 @@ export async function installableSystems(context) {
|
|
|
34
36
|
const here = systemFolders(context.systemFolders).map((one) => comparableText(one.name));
|
|
35
37
|
return listed.filter((system) => !here.includes(installedName(system))).sort((first, second) => Number(second.verified) - Number(first.verified) || first.name.localeCompare(second.name));
|
|
36
38
|
}
|
|
37
|
-
/** The topic a GitHub repository carries to be found
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
/** The topic a GitHub repository carries to be found, by the kind of package of data alone it is (D-485 (4)), and the file at its top that says what it is. */
|
|
40
|
+
const githubTopics = [
|
|
41
|
+
{ kind: "adventure", topic: "rpg-engine-adventure", file: "adventure.yaml" },
|
|
42
|
+
{ kind: "theme", topic: "rpg-engine-theme", file: "theme.yaml" },
|
|
43
|
+
{ kind: "language", topic: "rpg-engine-language", file: "language.yaml" },
|
|
44
|
+
];
|
|
45
|
+
// How many repositories of each topic are read, each with the file at its top: GitHub answers a search without a login only so many times an hour.
|
|
46
|
+
const mostRepositories = 20;
|
|
41
47
|
const kinds = new Set(["system", "extension", "language"]);
|
|
42
48
|
/** What npm and GitHub offer now, ours first, then by title; each source asked once, side by side. */
|
|
43
49
|
export async function catalog(root, context) {
|
|
@@ -84,7 +90,7 @@ function installedVersion(context, found) {
|
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
if (found.kind === "language") {
|
|
87
|
-
return installedLanguages(context
|
|
93
|
+
return installedLanguages(languageFolders(context)).find((one) => one.package === found.name)?.version;
|
|
88
94
|
}
|
|
89
95
|
// A system npm installed, by its package's own version.
|
|
90
96
|
const folder = systemFolders(context.systemFolders).find((one) => packageIn(one.folder)?.name === found.name)?.folder;
|
|
@@ -98,47 +104,116 @@ function packageIn(folder) {
|
|
|
98
104
|
return undefined;
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* The adventures, themes and languages GitHub has by their topics, the three searches side by side, each repository read from the file at its top; one without
|
|
109
|
+
* one that reads is left out, and a search that fails leaves the others listed.
|
|
110
|
+
*/
|
|
102
111
|
async function githubEntries(root, context) {
|
|
103
|
-
if (context.download === undefined) {
|
|
104
|
-
return { entries: [], failed: "only the game's server and the command line reach GitHub" };
|
|
105
|
-
}
|
|
106
112
|
const download = context.download;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const found = JSON.parse(new TextDecoder().decode(await download(`https://api.github.com/search/repositories?q=topic:${adventureTopic}&sort=stars&per_page=${mostAdventures}`, 2 * 1024 * 1024, context.signal)));
|
|
110
|
-
repositories = found.items ?? [];
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
return { entries: [], failed: `GitHub could not be asked: ${error instanceof Error ? error.message : String(error)}` };
|
|
113
|
+
if (download === undefined) {
|
|
114
|
+
return { entries: [], failed: "only the game's server and the command line reach GitHub" };
|
|
114
115
|
}
|
|
115
|
-
const
|
|
116
|
-
|
|
116
|
+
const searched = await Promise.all(githubTopics.map(async (topic) => {
|
|
117
|
+
try {
|
|
118
|
+
const url = `https://api.github.com/search/repositories?q=topic:${topic.topic}&sort=stars&per_page=${mostRepositories}`;
|
|
119
|
+
const found = JSON.parse(new TextDecoder().decode(await download(url, 2 * 1024 * 1024, context.signal)));
|
|
120
|
+
return { topic, repositories: found.items ?? [] };
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
// The reason without the long address, so that three searches refused alike read as one.
|
|
124
|
+
const why = (error instanceof Error ? error.message : String(error)).replace(/^https:\/\/\S+ /, "").replace(/: check the address.*$/, "");
|
|
125
|
+
return { topic, repositories: [], failed: why };
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
128
|
+
const here = { adventures: installedAdventures(root), themes: themesHere(context), languages: installedLanguages(languageFolders(context)).filter((one) => isDataLanguage(context, one)) };
|
|
129
|
+
const read = await Promise.all(searched.flatMap(({ topic, repositories }) => repositories.map(async (repository) => {
|
|
117
130
|
try {
|
|
118
|
-
const
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
description: manifest.about,
|
|
126
|
-
author: manifest.author ?? repository.owner?.login,
|
|
127
|
-
version: manifest.version,
|
|
128
|
-
verified: false,
|
|
129
|
-
code: false,
|
|
130
|
-
source: repository.html_url,
|
|
131
|
-
...(installed === undefined ? {} : { installed }),
|
|
132
|
-
update: installed !== undefined && isNewerVersion(manifest.version, installed),
|
|
133
|
-
...(levels === undefined ? {} : { levels }),
|
|
134
|
-
...(manifest.length === undefined ? {} : { length: manifest.length }),
|
|
135
|
-
language: manifest.language,
|
|
136
|
-
...(repository.stargazers_count === undefined ? {} : { stars: repository.stargazers_count }),
|
|
137
|
-
};
|
|
131
|
+
const raw = `https://raw.githubusercontent.com/${repository.full_name}/${repository.default_branch}/${topic.file}`;
|
|
132
|
+
const text = new TextDecoder().decode(await download(raw, 64 * 1024, context.signal));
|
|
133
|
+
return topic.kind === "adventure"
|
|
134
|
+
? adventureEntry(repository, readManifest(text, repository.full_name), here)
|
|
135
|
+
: topic.kind === "theme"
|
|
136
|
+
? themeEntry(repository, text, here)
|
|
137
|
+
: languageEntry(repository, text, here);
|
|
138
138
|
}
|
|
139
139
|
catch {
|
|
140
140
|
return undefined;
|
|
141
141
|
}
|
|
142
|
-
}));
|
|
143
|
-
|
|
142
|
+
})));
|
|
143
|
+
const reasons = [...new Set(searched.flatMap((one) => (one.failed === undefined ? [] : [one.failed])))];
|
|
144
|
+
const failed = reasons.map((why) => `GitHub could not be asked for its ${searched.filter((one) => one.failed === why).map((one) => `${one.topic.kind}s`).join(" and ")}: ${why}`);
|
|
145
|
+
return { entries: read.filter((one) => one !== undefined), ...(failed.length === 0 ? {} : { failed: failed.join("; ") }) };
|
|
146
|
+
}
|
|
147
|
+
/** An adventure GitHub has, as its adventure.yaml says. */
|
|
148
|
+
function adventureEntry(repository, manifest, here) {
|
|
149
|
+
const installed = here.adventures.find((one) => comparableText(one.title) === comparableText(manifest.title))?.version;
|
|
150
|
+
const levels = manifest.levels === undefined ? undefined : manifest.levels.from === manifest.levels.to ? String(manifest.levels.from) : `${manifest.levels.from}-${manifest.levels.to}`;
|
|
151
|
+
const author = manifest.author ?? repository.owner?.login;
|
|
152
|
+
return {
|
|
153
|
+
...githubEntry("adventure", repository, manifest.title, manifest.version, installed),
|
|
154
|
+
description: manifest.about,
|
|
155
|
+
...(author === undefined ? {} : { author }),
|
|
156
|
+
...(levels === undefined ? {} : { levels }),
|
|
157
|
+
...(manifest.length === undefined ? {} : { length: manifest.length }),
|
|
158
|
+
language: manifest.language,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* A theme GitHub has, by the name, version and engine its theme.yaml gives; here only when it was installed from this repository. Its checks are made as it is
|
|
163
|
+
* installed.
|
|
164
|
+
*/
|
|
165
|
+
function themeEntry(repository, text, here) {
|
|
166
|
+
const read = parse(text);
|
|
167
|
+
if (typeof read?.name !== "string" || read.name.trim() === "") {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
const name = read.name;
|
|
171
|
+
const found = here.themes.find((one) => isSameSource(unpackedSource(one.folder), repository.html_url));
|
|
172
|
+
return readableEntry(githubEntry("theme", repository, name, versionOf(read.version), found === undefined ? undefined : (found.theme?.version ?? "")), read.engine);
|
|
173
|
+
}
|
|
174
|
+
/** A language GitHub has, by the code, name, version and engine its language.yaml gives: here only when it was installed from this repository, never npm's. */
|
|
175
|
+
function languageEntry(repository, text, here) {
|
|
176
|
+
const read = parse(text);
|
|
177
|
+
if (typeof read?.code !== "string" || typeof read.name !== "string") {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
const code = read.code;
|
|
181
|
+
const installed = here.languages.find((one) => isSameSource(unpackedSource(one.folder), repository.html_url))?.version;
|
|
182
|
+
return readableEntry({ ...githubEntry("language", repository, read.name, versionOf(read.version), installed), language: code }, read.engine);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* A theme or a language as this engine reads it, by the lowest rpg-engine its file asks (D-515 (2)): one that asks a newer engine is no update, and says the
|
|
186
|
+
* engine its version needs; not offered when it is not here, as npm's that no version of reads, since adding it would be refused.
|
|
187
|
+
*/
|
|
188
|
+
function readableEntry(entry, asked) {
|
|
189
|
+
const engine = newerEngineAsked(asked);
|
|
190
|
+
if (engine === undefined) {
|
|
191
|
+
return entry;
|
|
192
|
+
}
|
|
193
|
+
if (entry.installed === undefined) {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
const { version, ...rest } = entry;
|
|
197
|
+
const newer = version !== undefined && (entry.installed === "" || isNewerVersion(version, entry.installed));
|
|
198
|
+
return { ...rest, ...(entry.installed === "" ? {} : { version: entry.installed }), update: false, ...(newer ? { newer: { version, engine } } : {}) };
|
|
199
|
+
}
|
|
200
|
+
/** What every package GitHub has gives: never verified, never code, added by its link; its version here, and whether GitHub's is newer: only when both are known. */
|
|
201
|
+
function githubEntry(kind, repository, title, version, installed) {
|
|
202
|
+
return {
|
|
203
|
+
kind,
|
|
204
|
+
title,
|
|
205
|
+
...(typeof repository.description === "string" ? { description: repository.description } : {}),
|
|
206
|
+
...(repository.owner?.login === undefined ? {} : { author: repository.owner.login }),
|
|
207
|
+
...(version === undefined ? {} : { version }),
|
|
208
|
+
verified: false,
|
|
209
|
+
code: false,
|
|
210
|
+
source: repository.html_url,
|
|
211
|
+
...(installed === undefined ? {} : { installed }),
|
|
212
|
+
update: installed !== undefined && installed !== "" && version !== undefined && isNewerVersion(version, installed),
|
|
213
|
+
...(repository.stargazers_count === undefined ? {} : { stars: repository.stargazers_count }),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/** A version as a YAML file may write it, 1.0 a number; undefined when it gives none. */
|
|
217
|
+
function versionOf(value) {
|
|
218
|
+
return typeof value === "string" || typeof value === "number" ? String(value) : undefined;
|
|
144
219
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { PackageEntry } from "../../../core/archive.ts";
|
|
2
|
+
import type { Context } from "../../../core/context.ts";
|
|
3
|
+
import { type LanguagePack } from "../../../languages/index.ts";
|
|
4
|
+
import { type InstalledTheme } from "../../../themes/index.ts";
|
|
5
|
+
/** The most the files a theme or a language keeps may weigh, all together: faces and pictures, or phrases and a Guide. */
|
|
6
|
+
export declare const largestUnpacked: number;
|
|
7
|
+
/** The most the .zip of a theme or a language may unpack to, before what it keeps is chosen. */
|
|
8
|
+
export declare const largestDataZip: number;
|
|
9
|
+
/** The folder of the themes installed on their own; undefined where nothing installs them. */
|
|
10
|
+
export declare function themesFolder(context: Context): string | undefined;
|
|
11
|
+
/** The folder of the languages installed as data alone; undefined where nothing installs them. */
|
|
12
|
+
export declare function dataLanguagesFolder(context: Context): string | undefined;
|
|
13
|
+
/** The folders languages are read from: npm's packages first, then those of data alone. */
|
|
14
|
+
export declare function languageFolders(context: Context): string[];
|
|
15
|
+
/** The themes installed on this computer, those refused included with why. */
|
|
16
|
+
export declare function themesHere(context: Context): InstalledTheme[];
|
|
17
|
+
/** An installed theme by its id or its name; undefined when there is none. */
|
|
18
|
+
export declare function findTheme(context: Context, name: string): InstalledTheme | undefined;
|
|
19
|
+
/** A theme or a language of data alone, as a name finds it. */
|
|
20
|
+
export type Unpacked = {
|
|
21
|
+
kind: "theme";
|
|
22
|
+
theme: InstalledTheme;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "language";
|
|
25
|
+
pack: LanguagePack;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The theme or the language of data alone a name finds: theme:<id or name> and language:<code or name> name one kind alone; an npm name, @scope/name or
|
|
29
|
+
* npm:name, none. Without a prefix a theme first, then a language; undefined when none is here.
|
|
30
|
+
*/
|
|
31
|
+
export declare function findUnpacked(context: Context, name: string): Unpacked | undefined;
|
|
32
|
+
/** How a theme or a language of data alone is named to be told from an npm package of the same name: theme:<id>, language:<code>. */
|
|
33
|
+
export declare function unpackedName(found: Unpacked): string;
|
|
34
|
+
/** Where a theme or a language of data alone came from, as it was installed: a GitHub repository's link, another link, a .zip's or a folder's path. */
|
|
35
|
+
export declare function unpackedSource(folder: string): string | undefined;
|
|
36
|
+
/** Whether a link a catalog gives is where a package here came from: GitHub's links are the same in any case, with or without a slash at their end. */
|
|
37
|
+
export declare function isSameSource(recorded: string | undefined, link: string): boolean;
|
|
38
|
+
/** Whether a language package is one of data alone, unpacked by the engine rather than installed by npm. */
|
|
39
|
+
export declare function isDataLanguage(context: Context, pack: LanguagePack): boolean;
|
|
40
|
+
/** A language of data alone by its code, its name or its package's name; undefined when there is none. */
|
|
41
|
+
export declare function findDataLanguage(context: Context, name: string): LanguagePack | undefined;
|
|
42
|
+
/** The files of a package of data a theme or a language keeps, those `keep` takes; refused, with `code`, when they weigh more than `what` may, or come twice. */
|
|
43
|
+
export declare function keptFiles(label: string, entries: PackageEntry[], keep: (parts: string[]) => boolean, code: string, what: string): PackageEntry[];
|
|
44
|
+
/**
|
|
45
|
+
* Writes a package's files, with where it came from, into a folder of its own beside those installed, which no list reads, for it to be checked there; the
|
|
46
|
+
* folders an install left behind more than an hour ago go first.
|
|
47
|
+
*/
|
|
48
|
+
export declare function writeTrial(folder: string, context: Context, entries: PackageEntry[], source: string): string;
|
|
49
|
+
/** Puts a folder checked in place of the one there, each move in one step: the one before is set aside, then taken away once the new one is there. */
|
|
50
|
+
export declare function placeTrial(trial: string, target: string, context: Context): void;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Where the packages of data alone live on this computer, for every campaign: themes and languages unpacked by the engine, apart from npm's packages.
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { refuseTwice } from "../../../core/archive-paths.js";
|
|
4
|
+
import { Refusal } from "../../../core/refusal.js";
|
|
5
|
+
import { files, isInside } from "../../../core/store.js";
|
|
6
|
+
import { comparableText } from "../../../core/text.js";
|
|
7
|
+
import { installedLanguages } from "../../../languages/index.js";
|
|
8
|
+
import { installedThemes } from "../../../themes/index.js";
|
|
9
|
+
/** The most the files a theme or a language keeps may weigh, all together: faces and pictures, or phrases and a Guide. */
|
|
10
|
+
export const largestUnpacked = 20 * 1024 * 1024;
|
|
11
|
+
/** The most the .zip of a theme or a language may unpack to, before what it keeps is chosen. */
|
|
12
|
+
export const largestDataZip = 50 * 1024 * 1024;
|
|
13
|
+
// The file beside a theme's or a language's own where it came from: a dot, so that no package brings one of its own.
|
|
14
|
+
const sourceFileName = ".source";
|
|
15
|
+
// How long a folder being unpacked may lie before it is taken for one an install left behind.
|
|
16
|
+
const staleAfter = 60 * 60 * 1000;
|
|
17
|
+
/** The folder of the themes installed on their own; undefined where nothing installs them. */
|
|
18
|
+
export function themesFolder(context) {
|
|
19
|
+
return context.unpacked === undefined ? undefined : join(context.unpacked, "themes");
|
|
20
|
+
}
|
|
21
|
+
/** The folder of the languages installed as data alone; undefined where nothing installs them. */
|
|
22
|
+
export function dataLanguagesFolder(context) {
|
|
23
|
+
return context.unpacked === undefined ? undefined : join(context.unpacked, "languages");
|
|
24
|
+
}
|
|
25
|
+
/** The folders languages are read from: npm's packages first, then those of data alone. */
|
|
26
|
+
export function languageFolders(context) {
|
|
27
|
+
const data = dataLanguagesFolder(context);
|
|
28
|
+
return [...(context.extensionFolders ?? []), ...(data === undefined ? [] : [data])];
|
|
29
|
+
}
|
|
30
|
+
/** The themes installed on this computer, those refused included with why. */
|
|
31
|
+
export function themesHere(context) {
|
|
32
|
+
const folder = themesFolder(context);
|
|
33
|
+
return folder === undefined ? [] : installedThemes(folder);
|
|
34
|
+
}
|
|
35
|
+
/** An installed theme by its id or its name; undefined when there is none. */
|
|
36
|
+
export function findTheme(context, name) {
|
|
37
|
+
return themesHere(context).find((one) => one.id === name.trim() || (one.theme !== undefined && comparableText(one.theme.name) === comparableText(name)));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The theme or the language of data alone a name finds: theme:<id or name> and language:<code or name> name one kind alone; an npm name, @scope/name or
|
|
41
|
+
* npm:name, none. Without a prefix a theme first, then a language; undefined when none is here.
|
|
42
|
+
*/
|
|
43
|
+
export function findUnpacked(context, name) {
|
|
44
|
+
const prefixed = /^(theme|language):(.+)$/i.exec(name.trim());
|
|
45
|
+
const kind = prefixed?.[1].toLowerCase();
|
|
46
|
+
const asked = prefixed?.[2] ?? name;
|
|
47
|
+
if (prefixed === null && /^(@|npm:)/i.test(name.trim())) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const theme = kind === "language" ? undefined : findTheme(context, asked);
|
|
51
|
+
const pack = kind === "theme" || theme !== undefined ? undefined : findDataLanguage(context, asked);
|
|
52
|
+
return theme !== undefined ? { kind: "theme", theme } : pack !== undefined ? { kind: "language", pack } : undefined;
|
|
53
|
+
}
|
|
54
|
+
/** How a theme or a language of data alone is named to be told from an npm package of the same name: theme:<id>, language:<code>. */
|
|
55
|
+
export function unpackedName(found) {
|
|
56
|
+
return found.kind === "theme" ? `theme:${found.theme.id}` : `language:${found.pack.code}`;
|
|
57
|
+
}
|
|
58
|
+
/** Where a theme or a language of data alone came from, as it was installed: a GitHub repository's link, another link, a .zip's or a folder's path. */
|
|
59
|
+
export function unpackedSource(folder) {
|
|
60
|
+
return files().text(join(folder, sourceFileName))?.trim() || undefined;
|
|
61
|
+
}
|
|
62
|
+
/** Whether a link a catalog gives is where a package here came from: GitHub's links are the same in any case, with or without a slash at their end. */
|
|
63
|
+
export function isSameSource(recorded, link) {
|
|
64
|
+
const plain = (text) => text.trim().replace(/(\.git)?\/*$/i, "").toLowerCase();
|
|
65
|
+
return recorded !== undefined && plain(recorded) === plain(link);
|
|
66
|
+
}
|
|
67
|
+
/** Whether a language package is one of data alone, unpacked by the engine rather than installed by npm. */
|
|
68
|
+
export function isDataLanguage(context, pack) {
|
|
69
|
+
const folder = dataLanguagesFolder(context);
|
|
70
|
+
return folder !== undefined && isInside(folder, pack.folder);
|
|
71
|
+
}
|
|
72
|
+
/** A language of data alone by its code, its name or its package's name; undefined when there is none. */
|
|
73
|
+
export function findDataLanguage(context, name) {
|
|
74
|
+
const wanted = comparableText(name);
|
|
75
|
+
return installedLanguages(languageFolders(context)).find((pack) => isDataLanguage(context, pack) && [pack.code, pack.name, pack.package].some((one) => comparableText(one) === wanted));
|
|
76
|
+
}
|
|
77
|
+
/** The files of a package of data a theme or a language keeps, those `keep` takes; refused, with `code`, when they weigh more than `what` may, or come twice. */
|
|
78
|
+
export function keptFiles(label, entries, keep, code, what) {
|
|
79
|
+
const kept = entries.filter(([parts]) => keep(parts));
|
|
80
|
+
refuseTwice(label, kept.map(([parts]) => parts.join("/")));
|
|
81
|
+
const size = kept.reduce((total, [, bytes]) => total + bytes.length, 0);
|
|
82
|
+
if (size > largestUnpacked) {
|
|
83
|
+
const why = `its files weigh ${Math.ceil(size / 1024 / 1024)} MB, more than the ${largestUnpacked / 1024 / 1024} MB ${what} may`;
|
|
84
|
+
throw new Refusal(`${label} cannot be used: ${why}. Nothing changed.`, code, { name: label, why });
|
|
85
|
+
}
|
|
86
|
+
return kept;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Writes a package's files, with where it came from, into a folder of its own beside those installed, which no list reads, for it to be checked there; the
|
|
90
|
+
* folders an install left behind more than an hour ago go first.
|
|
91
|
+
*/
|
|
92
|
+
export function writeTrial(folder, context, entries, source) {
|
|
93
|
+
const now = context.now().getTime();
|
|
94
|
+
for (const entry of files().entries(folder)) {
|
|
95
|
+
const path = join(folder, entry.name);
|
|
96
|
+
if (entry.isFolder && /^\.(installing|replaced)-/.test(entry.name) && now - (files().modified(path) ?? now) > staleAfter) {
|
|
97
|
+
files().removeFolder(path);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const trial = join(folder, `.installing-${context.newId()}`);
|
|
101
|
+
for (const [parts, bytes] of entries) {
|
|
102
|
+
files().writeBytes(join(trial, ...parts), bytes);
|
|
103
|
+
}
|
|
104
|
+
files().write(join(trial, sourceFileName), `${source}\n`);
|
|
105
|
+
return trial;
|
|
106
|
+
}
|
|
107
|
+
/** Puts a folder checked in place of the one there, each move in one step: the one before is set aside, then taken away once the new one is there. */
|
|
108
|
+
export function placeTrial(trial, target, context) {
|
|
109
|
+
const aside = join(dirname(target), `.replaced-${context.newId()}`);
|
|
110
|
+
const before = files().modified(target) !== undefined;
|
|
111
|
+
if (before) {
|
|
112
|
+
moveFolder(target, aside);
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
moveFolder(trial, target);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
if (before) {
|
|
119
|
+
moveFolder(aside, target);
|
|
120
|
+
}
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
files().removeFolder(aside);
|
|
124
|
+
}
|
|
125
|
+
// How many times a folder is moved before giving up, a tenth of a second apart: an antivirus or an open window may hold it for a moment.
|
|
126
|
+
const moveTries = 10;
|
|
127
|
+
/** Moves a folder, trying again while something holds it; refused, with what to do, when it stays held. */
|
|
128
|
+
function moveFolder(from, to) {
|
|
129
|
+
for (let tried = 1;; tried++) {
|
|
130
|
+
try {
|
|
131
|
+
files().move(from, to);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
const code = error.code;
|
|
136
|
+
if ((code !== "EPERM" && code !== "EBUSY" && code !== "EACCES") || tried === moveTries) {
|
|
137
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
138
|
+
throw new Refusal(`${from} could not be moved: ${why}. Close what is using that folder, such as a window open on it, and install it again. Nothing changed.`, "folder-held", {
|
|
139
|
+
name: from,
|
|
140
|
+
why,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 100);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -31,6 +31,7 @@ export declare const status: import("../core/registry.ts").Command<z.ZodObject<{
|
|
|
31
31
|
companions: Member[];
|
|
32
32
|
orders: string[];
|
|
33
33
|
dashboard: string | undefined;
|
|
34
|
+
dashboardHeld: boolean;
|
|
34
35
|
offerDashboard: boolean;
|
|
35
36
|
pictures: string | undefined;
|
|
36
37
|
importing: string;
|
package/dist/commands/status.js
CHANGED
|
@@ -161,6 +161,8 @@ export const status = defineCommand({
|
|
|
161
161
|
// The player's standing orders to the companions, in play, for those who come later too (D-563).
|
|
162
162
|
orders: mode === "play" ? settings.orders ?? [] : [],
|
|
163
163
|
dashboard: context.dashboard,
|
|
164
|
+
// What the player does on a page another chat serves reaches that chat, not this one (D-577).
|
|
165
|
+
dashboardHeld: context.dashboardHeld === true,
|
|
164
166
|
// The chat's first status opens with the dashboard, for the master to offer it in their first answer (D-353).
|
|
165
167
|
offerDashboard: offerDashboard(context),
|
|
166
168
|
// Whether to ask for the places' pictures, or to have this one made (D-308).
|
|
@@ -211,9 +213,11 @@ export const status = defineCommand({
|
|
|
211
213
|
format(result) {
|
|
212
214
|
const companion = (member) => `${member.name}${member.with === undefined ? whereabouts(member) : `, with ${member.with}`}${memberCounters(member)}`;
|
|
213
215
|
const state = [
|
|
214
|
-
result.
|
|
215
|
-
? `
|
|
216
|
-
:
|
|
216
|
+
result.dashboardHeld
|
|
217
|
+
? `The dashboard at ${result.dashboard ?? ""} is served by another chat of this campaign that is still open: what the player does on it reaches that chat, not you. Ask the player to close that chat; this one takes the page over within seconds.`
|
|
218
|
+
: result.offerDashboard && result.dashboard !== undefined
|
|
219
|
+
? `Offer the player their dashboard's link in your first answer: ${result.dashboard}.`
|
|
220
|
+
: "",
|
|
217
221
|
result.campaign.join(" · "),
|
|
218
222
|
...result.meanings,
|
|
219
223
|
result.note,
|
|
@@ -234,7 +238,7 @@ export const status = defineCommand({
|
|
|
234
238
|
result.orders.length === 0
|
|
235
239
|
? ""
|
|
236
240
|
: `Standing orders, the player's to the companions (they follow them as their pages allow, and break one only in the open): ${quotedOrders(result.orders)}.`,
|
|
237
|
-
result.dashboard === undefined || result.offerDashboard ? "" : `Dashboard: ${result.dashboard}.`,
|
|
241
|
+
result.dashboard === undefined || result.offerDashboard || result.dashboardHeld ? "" : `Dashboard: ${result.dashboard}.`,
|
|
238
242
|
result.pictures ?? "",
|
|
239
243
|
result.importing,
|
|
240
244
|
result.translation ?? "",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** A file of a package: its path in parts, from the package's top, and its bytes. */
|
|
2
|
+
export type PackageEntry = [string[], Uint8Array];
|
|
3
|
+
/** The files a .zip holds, by their names as written, unpacking to at most `most` bytes; it throws, saying why, when it does not read. `what` names the package: an adventure. */
|
|
4
|
+
export declare function unzipFiles(bytes: Uint8Array, label: string, most: number, what: string): [string, Uint8Array][];
|
|
5
|
+
/** The files a .zip holds, by their names as written, with what each unpacks to, none of them unpacked: to tell what it is before reading it. */
|
|
6
|
+
export declare function zipListing(bytes: Uint8Array, label: string): [string, number][];
|
|
7
|
+
/**
|
|
8
|
+
* A package's files: each path checked, what a computer leaves beside them dropped, and the one folder at its top that holds them all taken away while none of
|
|
9
|
+
* `tops`, the files that tell what it is, lies at its top. `what` names it in a refusal: the adventure.
|
|
10
|
+
*/
|
|
11
|
+
export declare function packageEntries(label: string, entries: [string, Uint8Array][], what: string, tops: readonly string[]): PackageEntry[];
|
|
12
|
+
/** The file at a package's top named so, in any case; undefined when there is none. */
|
|
13
|
+
export declare function topFile(entries: PackageEntry[], name: string): PackageEntry | undefined;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// A package of data someone else made, read whole into memory (ADV-1): a .zip unpacked with its size capped and its names read as UTF-8, then each path
|
|
2
|
+
// checked, what a computer leaves beside files dropped, and the one folder GitHub zips a repository in taken away.
|
|
3
|
+
import { unzipSync } from "fflate";
|
|
4
|
+
import { archivePathParts } from "./archive-paths.js";
|
|
5
|
+
import { Refusal } from "./refusal.js";
|
|
6
|
+
// What a computer leaves beside files, which no one put in the package.
|
|
7
|
+
const litter = /^(\..*|__macosx|thumbs\.db|desktop\.ini)$/i;
|
|
8
|
+
/** The files a .zip holds, by their names as written, unpacking to at most `most` bytes; it throws, saying why, when it does not read. `what` names the package: an adventure. */
|
|
9
|
+
export function unzipFiles(bytes, label, most, what) {
|
|
10
|
+
let declared = 0;
|
|
11
|
+
let read;
|
|
12
|
+
try {
|
|
13
|
+
read = unzipSync(bytes, {
|
|
14
|
+
filter: (file) => {
|
|
15
|
+
declared += file.originalSize;
|
|
16
|
+
if (declared > most) {
|
|
17
|
+
throw new Error(`it unpacks to more than ${most / 1024 / 1024} MB, more than ${what} may`);
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new Refusal(`${label} is not a .zip that reads: ${error instanceof Error ? error.message : String(error)}. Nothing changed.`, "archive-unread", { name: label });
|
|
25
|
+
}
|
|
26
|
+
return Object.entries(read).filter(([name]) => !/[\\/]$/.test(name)).map(([name, data]) => [utf8Name(label, name), data]);
|
|
27
|
+
}
|
|
28
|
+
/** The files a .zip holds, by their names as written, with what each unpacks to, none of them unpacked: to tell what it is before reading it. */
|
|
29
|
+
export function zipListing(bytes, label) {
|
|
30
|
+
const listed = [];
|
|
31
|
+
try {
|
|
32
|
+
unzipSync(bytes, {
|
|
33
|
+
filter: (file) => {
|
|
34
|
+
listed.push([file.name, file.originalSize]);
|
|
35
|
+
return false;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new Refusal(`${label} is not a .zip that reads: ${error instanceof Error ? error.message : String(error)}. Nothing changed.`, "archive-unread", { name: label });
|
|
41
|
+
}
|
|
42
|
+
return listed.filter(([name]) => !/[\\/]$/.test(name)).map(([name, size]) => [utf8Name(label, name), size]);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A package's files: each path checked, what a computer leaves beside them dropped, and the one folder at its top that holds them all taken away while none of
|
|
46
|
+
* `tops`, the files that tell what it is, lies at its top. `what` names it in a refusal: the adventure.
|
|
47
|
+
*/
|
|
48
|
+
export function packageEntries(label, entries, what, tops) {
|
|
49
|
+
// What a computer leaves beside the files, as macOS's __MACOSX, goes before the folder at the top is looked for.
|
|
50
|
+
const checked = entries.map(([name, data]) => [archivePathParts(label, name, what), data]).filter(([parts]) => parts.length > 0 && !parts.some((part) => litter.test(part)));
|
|
51
|
+
const atTop = checked.some(([parts]) => parts.length === 1 && tops.includes(parts[0].toLowerCase()));
|
|
52
|
+
const folders = new Set(checked.map(([parts]) => parts[0]));
|
|
53
|
+
return !atTop && folders.size === 1 ? checked.map(([parts, data]) => [parts.slice(1), data]).filter(([parts]) => parts.length > 0) : checked;
|
|
54
|
+
}
|
|
55
|
+
/** The file at a package's top named so, in any case; undefined when there is none. */
|
|
56
|
+
export function topFile(entries, name) {
|
|
57
|
+
return entries.find(([parts]) => parts.length === 1 && parts[0].toLowerCase() === name);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A file's name in a .zip as it was written: one without the zip's UTF-8 mark reads byte by byte, so its UTF-8 is read again, as macOS writes it; one in an old
|
|
61
|
+
* code page, as Windows' own tar writes it, is refused with what to do.
|
|
62
|
+
*/
|
|
63
|
+
function utf8Name(label, name) {
|
|
64
|
+
if (/^[\u0000-ÿ]*$/.test(name) && /[\u0080-ÿ]/.test(name)) {
|
|
65
|
+
try {
|
|
66
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(name, (character) => character.charCodeAt(0))).normalize("NFC");
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Not UTF-8 byte by byte: a name the zip marked as UTF-8 already, or one in an old code page.
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (/[\u0080-\u009f]/.test(name)) {
|
|
73
|
+
throw new Refusal(`${label} names a file with accents not written in UTF-8 (${name}): make the zip again with 7-Zip, or Compress-Archive in PowerShell. Nothing changed.`, "archive-accents", { name: label });
|
|
74
|
+
}
|
|
75
|
+
return name.normalize("NFC");
|
|
76
|
+
}
|