@acdh-oeaw/content-lib 0.0.2 → 0.1.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/index.d.ts CHANGED
@@ -15,44 +15,76 @@ interface CollectionItem {
15
15
  timestamp: number;
16
16
  }
17
17
  interface TransformContext {
18
- createImportDeclaration: (path: string) => ImportDeclaration;
19
- createJavaScriptImport: (content: string) => JavaScriptImport;
20
- createJsonImport: (content: string) => JsonImport;
18
+ collections: Array<Collection>;
19
+ createImportDeclaration: <T>(path: string) => ImportDeclaration<T>;
20
+ createJavaScriptImport: <T>(content: string) => JavaScriptImport<T>;
21
+ createJsonImport: <T>(content: string) => JsonImport<T>;
21
22
  }
22
- interface CollectionConfig<TCollectionItemContent = any, TCollectionDocument = any> {
23
- name: string;
23
+ interface CollectionConfig<TCollectionName extends string = string, TCollectionItemContent = any, TCollectionDocument = any> {
24
+ name: TCollectionName;
24
25
  directory: string;
25
26
  include: NonEmptyReadonlyArray<GlobString>;
26
27
  exclude?: ReadonlyArray<GlobString>;
27
28
  read: (item: CollectionItem) => MaybePromise<TCollectionItemContent>;
28
29
  transform: (content: TCollectionItemContent, item: CollectionItem, context: TransformContext) => MaybePromise<TCollectionDocument>;
29
30
  }
30
- declare function createCollection<TCollectionItemContent, TCollectionDocument>(config: CollectionConfig<TCollectionItemContent, TCollectionDocument>): CollectionConfig<TCollectionItemContent, TCollectionDocument>;
31
+ declare function createCollection<TCollectionName extends string, TCollectionItemContent, TCollectionDocument>(config: CollectionConfig<TCollectionName, TCollectionItemContent, TCollectionDocument>): CollectionConfig<TCollectionName, TCollectionItemContent, TCollectionDocument>;
31
32
  interface ContentConfig {
32
33
  collections: Array<CollectionConfig>;
33
34
  }
34
35
  declare function createConfig<T extends ContentConfig>(config: T): T;
35
- declare class ImportDeclaration {
36
+ declare class ImportDeclaration<T> {
37
+ private __brand;
38
+ value: T;
36
39
  path: string;
37
40
  constructor(path: string);
38
41
  }
39
- declare class JavaScriptImport {
42
+ declare class JavaScriptImport<T> {
43
+ private __brand;
44
+ value: T;
40
45
  content: string;
41
46
  constructor(content: string);
42
47
  }
43
- declare class JsonImport {
48
+ declare class JsonImport<T> {
49
+ private __brand;
50
+ value: T;
44
51
  content: string;
45
52
  constructor(content: string);
46
53
  }
54
+ type GetCollection<TConfig extends ContentConfig, TName extends string> = Extract<TConfig["collections"][number], {
55
+ name: TName;
56
+ }>;
57
+ type Simplify<T> = { [K in keyof T]: T[K] } & {};
58
+ type Replace<T> = { [K in keyof T]: T[K] extends JavaScriptImport<infer U> ? U : T[K] extends JsonImport<infer U> ? U : T[K] extends ImportDeclaration<infer U> ? U : T[K] extends object ? Simplify<Replace<T[K]>> : T[K] };
59
+ type CollectionEntry<TCollection extends Collection> = Simplify<{
60
+ item: {
61
+ id: string;
62
+ };
63
+ content: Simplify<Awaited<ReturnType<TCollection["read"]>>>;
64
+ document: Simplify<Replace<Awaited<ReturnType<TCollection["transform"]>>>>;
65
+ }>;
66
+ interface Collection extends CollectionConfig {
67
+ absoluteDirectoryPath: string;
68
+ data: Map<CollectionItem["id"], {
69
+ item: CollectionItem;
70
+ content: any;
71
+ document: any;
72
+ }>;
73
+ outputDirectoryPath: string;
74
+ }
47
75
  interface BuildStats {
48
76
  collections: number;
49
77
  documents: number;
50
78
  }
79
+ interface ContentProcessorConfig {
80
+ /** Path to config file, relative to `process.cwd()`, which provides a named export `config`. */
81
+ configFilePath: string;
82
+ }
51
83
  interface ContentProcessor {
52
84
  build: () => Promise<BuildStats>;
53
85
  watch: () => Promise<Set<watcher.AsyncSubscription>>;
54
86
  }
55
- declare function createContentProcessor(config: ContentConfig): Promise<ContentProcessor>;
87
+ declare function createContentProcessor(contentProcessorConfig: ContentProcessorConfig): Promise<ContentProcessor>;
56
88
  //#endregion
57
- export { CollectionConfig, ContentConfig, ContentProcessor, createCollection, createConfig, createContentProcessor };
89
+ export { CollectionConfig, CollectionEntry, ContentConfig, ContentProcessor, ContentProcessorConfig, GetCollection, createCollection, createConfig, createContentProcessor };
58
90
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -2,10 +2,12 @@ import * as crypto from "node:crypto";
2
2
  import * as fs from "node:fs/promises";
3
3
  import { availableParallelism } from "node:os";
4
4
  import * as path from "node:path";
5
+ import { pathToFileURL } from "node:url";
5
6
  import { debuglog } from "node:util";
6
- import { addTrailingSlash, log } from "@acdh-oeaw/lib";
7
+ import { addTrailingSlash, capitalize, log } from "@acdh-oeaw/lib";
7
8
  import * as watcher from "@parcel/watcher";
8
9
  import plimit from "p-limit";
10
+ import pluralize from "pluralize";
9
11
 
10
12
  //#region src/index.ts
11
13
  const debug = debuglog("content-lib");
@@ -24,6 +26,8 @@ function createConfig(config) {
24
26
  return config;
25
27
  }
26
28
  var ImportDeclaration = class {
29
+ __brand;
30
+ value;
27
31
  path;
28
32
  constructor(path$1) {
29
33
  this.path = path$1;
@@ -33,6 +37,8 @@ function createImportDeclaration(path$1) {
33
37
  return new ImportDeclaration(path$1);
34
38
  }
35
39
  var JavaScriptImport = class {
40
+ __brand;
41
+ value;
36
42
  content;
37
43
  constructor(content) {
38
44
  this.content = content;
@@ -42,6 +48,8 @@ function createJavaScriptImport(content) {
42
48
  return new JavaScriptImport(content);
43
49
  }
44
50
  var JsonImport = class {
51
+ __brand;
52
+ value;
45
53
  content;
46
54
  constructor(content) {
47
55
  this.content = content;
@@ -52,7 +60,7 @@ function createJsonImport(content) {
52
60
  }
53
61
  const prefix = "__i__";
54
62
  const re = new RegExp(`"(${prefix}\\d+)"`, "g");
55
- function serialize(value) {
63
+ function serialize(value, contentProcessorConfigFilePath, collectionName) {
56
64
  debug("Serializing...\n");
57
65
  const imports = [];
58
66
  function addImport(filePath, type = "js") {
@@ -94,30 +102,46 @@ function serialize(value) {
94
102
  result += imports.join("\n");
95
103
  result += "\n\n";
96
104
  }
97
- result += `const items = new Map(${json});\n\nexport default items;`;
98
- return [result, files];
105
+ result += [`const items = new Map(${json});`, "export default items;"].join("\n\n");
106
+ files.set("index.js", result);
107
+ const typeName = capitalize(pluralize.singular(collectionName));
108
+ files.set("index.d.ts", [
109
+ `import type { GetCollection, CollectionEntry } from "@acdh-oeaw/content-lib";`,
110
+ "",
111
+ `import type { config } from "${contentProcessorConfigFilePath}";`,
112
+ "",
113
+ `type Collection = GetCollection<typeof config, "${collectionName}">;`,
114
+ `type ${typeName} = CollectionEntry<Collection>;`,
115
+ "",
116
+ `declare const items: Map<string, ${typeName}>;`,
117
+ `export { type ${typeName}, items as default };`
118
+ ].join("\n"));
119
+ return files;
99
120
  }
100
- async function createContentProcessor(config) {
121
+ async function createContentProcessor(contentProcessorConfig) {
101
122
  debug("Creating content processor...\n");
123
+ debug("Reading config file...");
124
+ const contentProcessorConfigUrl = pathToFileURL(path.resolve(contentProcessorConfig.configFilePath));
125
+ contentProcessorConfigUrl.searchParams.set("cache-key", String(Date.now()));
126
+ const contentProcessorConfigFilePath = String(contentProcessorConfigUrl);
127
+ const { config } = await import(contentProcessorConfigFilePath);
128
+ debug(`Done reading config file "${contentProcessorConfigFilePath}".`);
102
129
  const concurrency = availableParallelism();
103
130
  const limit = plimit(concurrency);
104
131
  debug(`Concurrency: ${String(concurrency)}.\n`);
105
132
  const outputDirectoryBasePath = path.join(process.cwd(), ".content", "generated");
106
- debug("Clearing output directory...\n");
107
- await fs.rm(outputDirectoryBasePath, {
108
- force: true,
109
- recursive: true
110
- });
111
133
  const collections = [];
112
134
  const context = {
135
+ collections,
113
136
  createImportDeclaration,
114
137
  createJavaScriptImport,
115
138
  createJsonImport
116
139
  };
117
140
  for (const collection of config.collections) {
118
141
  const absoluteDirectoryPath = addTrailingSlash(path.resolve(collection.directory));
142
+ /** Ensure directory exists, which is expected by `@parcel/watcher`. */
143
+ await fs.mkdir(absoluteDirectoryPath, { recursive: true });
119
144
  const outputDirectoryPath = path.join(outputDirectoryBasePath, collection.name.toLowerCase().replaceAll(/[^a-z0-9_-]/g, "-"));
120
- await fs.mkdir(outputDirectoryPath, { recursive: true });
121
145
  collections.push({
122
146
  ...collection,
123
147
  absoluteDirectoryPath,
@@ -159,10 +183,16 @@ async function createContentProcessor(config) {
159
183
  debug("Aborted writing collections.");
160
184
  return;
161
185
  }
186
+ debug("Clearing output directory...\n");
187
+ await fs.rm(outputDirectoryBasePath, {
188
+ force: true,
189
+ recursive: true
190
+ });
162
191
  for (const collection of collections) {
163
192
  debug(`Writing collection "${collection.name}".`);
164
- const [serialized, files] = serialize(collection.data);
165
- files.set("index.js", serialized);
193
+ debug(`Creating output directory for "${collection.name}".`);
194
+ await fs.mkdir(collection.outputDirectoryPath, { recursive: true });
195
+ const files = serialize(collection.data, path.relative(collection.outputDirectoryPath, contentProcessorConfig.configFilePath), collection.name);
166
196
  await limit.map(Array.from(files), async ([filePath, fileContent]) => {
167
197
  const outputFilePath = path.join(collection.outputDirectoryPath, filePath);
168
198
  await fs.writeFile(outputFilePath, fileContent, { encoding: "utf-8" });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["path","imports: Array<string>","value","collections: Array<Collection>","context: TransformContext","item: CollectionItem","timer: ReturnType<typeof setTimeout> | null","controller: AbortController | null","events","error"],"sources":["../src/index.ts"],"sourcesContent":["import * as crypto from \"node:crypto\";\nimport * as fs from \"node:fs/promises\";\nimport { availableParallelism } from \"node:os\";\nimport * as path from \"node:path\";\nimport { debuglog } from \"node:util\";\n\nimport { addTrailingSlash, log } from \"@acdh-oeaw/lib\";\nimport * as watcher from \"@parcel/watcher\";\nimport plimit from \"p-limit\";\n\n//\n\nconst debug = debuglog(\"content-lib\");\n\n//\n\nfunction createContentHash(value: string): string {\n\treturn crypto.createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nfunction createIdFromFilePath(filePath: string): string {\n\tconst parsed = path.parse(filePath);\n\n\tif (parsed.name.toLowerCase() === \"index\") {\n\t\treturn path.basename(parsed.dir);\n\t}\n\n\treturn parsed.name;\n}\n\n//\n\ntype MaybePromise<T> = T | Promise<T>;\n\ntype NonEmptyReadonlyArray<T> = readonly [T, ...Array<T>];\n\ntype GlobString = string;\n\ninterface CollectionItem {\n\t/** Unique identifier. */\n\tid: string;\n\t/** File path relative to colleciton directory. */\n\tfilePath: string;\n\t/** File path relative to current working directory. */\n\tabsoluteFilePath: string;\n\t/** File modification timestamp. */\n\ttimestamp: number;\n}\n\ninterface TransformContext {\n\tcreateImportDeclaration: (path: string) => ImportDeclaration;\n\tcreateJavaScriptImport: (content: string) => JavaScriptImport;\n\tcreateJsonImport: (content: string) => JsonImport;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface CollectionConfig<TCollectionItemContent = any, TCollectionDocument = any> {\n\tname: string;\n\tdirectory: string;\n\tinclude: NonEmptyReadonlyArray<GlobString>;\n\texclude?: ReadonlyArray<GlobString>;\n\tread: (item: CollectionItem) => MaybePromise<TCollectionItemContent>;\n\ttransform: (\n\t\tcontent: TCollectionItemContent,\n\t\titem: CollectionItem,\n\t\tcontext: TransformContext,\n\t) => MaybePromise<TCollectionDocument>;\n}\n\nexport function createCollection<TCollectionItemContent, TCollectionDocument>(\n\tconfig: CollectionConfig<TCollectionItemContent, TCollectionDocument>,\n): CollectionConfig<TCollectionItemContent, TCollectionDocument> {\n\treturn config;\n}\n\nexport interface ContentConfig {\n\tcollections: Array<CollectionConfig>;\n}\n\nexport function createConfig<T extends ContentConfig>(config: T): T {\n\treturn config;\n}\n\n//\n\n// function createItemCacheKey(item: CollectionItem): string {\n// \treturn String(item.timestamp);\n// }\n\n//\n\nclass ImportDeclaration {\n\tpath: string;\n\n\tconstructor(path: string) {\n\t\tthis.path = path;\n\t}\n}\n\nfunction createImportDeclaration(path: string): ImportDeclaration {\n\treturn new ImportDeclaration(path);\n}\n\nclass JavaScriptImport {\n\tcontent: string;\n\n\tconstructor(content: string) {\n\t\tthis.content = content;\n\t}\n}\n\nfunction createJavaScriptImport(content: string): JavaScriptImport {\n\treturn new JavaScriptImport(content);\n}\n\nclass JsonImport {\n\tcontent: string;\n\n\tconstructor(content: string) {\n\t\tthis.content = content;\n\t}\n}\n\nfunction createJsonImport(content: string): JsonImport {\n\treturn new JsonImport(content);\n}\n\n//\n\nconst prefix = \"__i__\";\nconst re = new RegExp(`\"(${prefix}\\\\d+)\"`, \"g\");\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction serialize(value: Map<string, any>): [string, Map<string, string>] {\n\tdebug(\"Serializing...\\n\");\n\n\tconst imports: Array<string> = [];\n\n\tfunction addImport(filePath: string, type: \"js\" | \"json\" = \"js\"): string {\n\t\tconst identifier = [prefix, imports.length].join(\"\");\n\t\timports.push(\n\t\t\t`import ${identifier} from \"${filePath}\"${type !== \"js\" ? ` with { type: \"${type}\" }` : \"\"};`,\n\t\t);\n\n\t\treturn identifier;\n\t}\n\n\tconst files = new Map<string, string>();\n\n\tfunction addFiles(filePath: string, content: string): void {\n\t\tfiles.set(filePath, content);\n\t}\n\n\tconst json = JSON.stringify(\n\t\tArray.from(value),\n\t\t// TODO: Should we support (multiple) named imports?\n\t\t(_key, value) => {\n\t\t\tif (value instanceof ImportDeclaration) {\n\t\t\t\tconst filePath = value.path;\n\n\t\t\t\tdebug(`Adding import declaration for \"${filePath}\".`);\n\t\t\t\tconst identifier = addImport(filePath);\n\n\t\t\t\treturn identifier;\n\t\t\t}\n\n\t\t\tif (value instanceof JavaScriptImport) {\n\t\t\t\tconst hash = createContentHash(value.content);\n\t\t\t\tconst filePath = `./${hash}.js`;\n\n\t\t\t\tdebug(`Adding javascript import for \"${filePath}\".`);\n\t\t\t\tconst identifier = addImport(filePath);\n\t\t\t\taddFiles(filePath, `// @ts-nocheck\\n${value.content}`);\n\n\t\t\t\treturn identifier;\n\t\t\t}\n\n\t\t\tif (value instanceof JsonImport) {\n\t\t\t\tconst hash = createContentHash(value.content);\n\t\t\t\tconst filePath = `./${hash}.json`;\n\n\t\t\t\tdebug(`Adding json import for \"${filePath}\".`);\n\t\t\t\tconst identifier = addImport(filePath, \"json\");\n\t\t\t\taddFiles(filePath, value.content);\n\n\t\t\t\treturn identifier;\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\treturn value;\n\t\t},\n\t\t2,\n\t)\n\t\t/** Remove quotes from import identifiers. */\n\t\t.replaceAll(re, \"$1\");\n\n\tlet result = \"\";\n\n\tif (imports.length > 0) {\n\t\tresult += imports.join(\"\\n\");\n\t\tresult += \"\\n\\n\";\n\t}\n\n\tresult += `const items = new Map(${json});\\n\\nexport default items;`;\n\n\treturn [result, files];\n}\n\n//\n\ninterface Collection extends CollectionConfig {\n\tabsoluteDirectoryPath: string;\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Map<CollectionItem[\"id\"], { item: CollectionItem; content: any; document: any }>; // TODO: revisit\n\toutputDirectoryPath: string;\n}\n\ninterface BuildStats {\n\tcollections: number;\n\tdocuments: number;\n}\n\nexport interface ContentProcessor {\n\tbuild: () => Promise<BuildStats>;\n\twatch: () => Promise<Set<watcher.AsyncSubscription>>;\n}\n\nexport async function createContentProcessor(config: ContentConfig): Promise<ContentProcessor> {\n\tdebug(\"Creating content processor...\\n\");\n\n\tconst concurrency = availableParallelism();\n\tconst limit = plimit(concurrency);\n\tdebug(`Concurrency: ${String(concurrency)}.\\n`);\n\n\tconst outputDirectoryBasePath = path.join(process.cwd(), \".content\", \"generated\");\n\n\tdebug(\"Clearing output directory...\\n\");\n\tawait fs.rm(outputDirectoryBasePath, { force: true, recursive: true });\n\n\tconst collections: Array<Collection> = [];\n\n\tconst context: TransformContext = {\n\t\tcreateImportDeclaration,\n\t\tcreateJavaScriptImport,\n\t\tcreateJsonImport,\n\t};\n\n\tfor (const collection of config.collections) {\n\t\tconst absoluteDirectoryPath = addTrailingSlash(path.resolve(collection.directory));\n\n\t\tconst outputDirectoryPath = path.join(\n\t\t\toutputDirectoryBasePath,\n\t\t\tcollection.name.toLowerCase().replaceAll(/[^a-z0-9_-]/g, \"-\"),\n\t\t);\n\t\tawait fs.mkdir(outputDirectoryPath, { recursive: true });\n\n\t\tcollections.push({\n\t\t\t...collection,\n\t\t\tabsoluteDirectoryPath,\n\t\t\tdata: new Map(),\n\t\t\toutputDirectoryPath,\n\t\t});\n\t}\n\n\tasync function generate(signal?: AbortSignal): Promise<void> {\n\t\tdebug(\"Generating...\\n\");\n\n\t\tfor (const collection of collections) {\n\t\t\tdebug(`Reading collection \"${collection.name}\"...`);\n\n\t\t\tawait limit.map(Array.from(collection.data), async ([id, { item }]) => {\n\t\t\t\tif (signal?.aborted === true) {\n\t\t\t\t\tdebug(\"Aborted reading collections.\");\n\t\t\t\t\tlimit.clearQueue();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// FIXME: race condition: what if file has been deleted in the meantime\n\t\t\t\t// TODO: skip item when `read()` returns `null`?\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst content = await collection.read(item);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tcollection.data.get(id)!.content = content;\n\n\t\t\t\tdebug(`- Read item \"${id}\".`);\n\t\t\t});\n\n\t\t\tdebug(\n\t\t\t\t`Done reading ${String(collection.data.size)} item(s) in collection \"${collection.name}\".\\n`,\n\t\t\t);\n\t\t}\n\n\t\tfor (const collection of collections) {\n\t\t\tdebug(`Transforming collection \"${collection.name}\"...`);\n\n\t\t\tawait limit.map(Array.from(collection.data), async ([id, { content, item }]) => {\n\t\t\t\tif (signal?.aborted === true) {\n\t\t\t\t\tdebug(\"Aborted transforming collections.\");\n\t\t\t\t\tlimit.clearQueue();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst document = await collection.transform(content, item, context);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tcollection.data.get(id)!.document = document;\n\n\t\t\t\tdebug(`- Transformed item \"${id}\".`);\n\t\t\t});\n\n\t\t\tdebug(\n\t\t\t\t`Done transforming ${String(collection.data.size)} item(s) in collection \"${collection.name}\".\\n`,\n\t\t\t);\n\t\t}\n\n\t\tif (signal?.aborted === true) {\n\t\t\tdebug(\"Aborted writing collections.\");\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const collection of collections) {\n\t\t\tdebug(`Writing collection \"${collection.name}\".`);\n\n\t\t\t// TODO: Consider combining serializing and writing to disk in one function.\n\t\t\tconst [serialized, files] = serialize(collection.data);\n\t\t\tfiles.set(\"index.js\", serialized);\n\n\t\t\tawait limit.map(Array.from(files), async ([filePath, fileContent]) => {\n\t\t\t\tconst outputFilePath = path.join(collection.outputDirectoryPath, filePath);\n\t\t\t\tawait fs.writeFile(outputFilePath, fileContent, { encoding: \"utf-8\" });\n\t\t\t});\n\t\t}\n\t}\n\n\tasync function build(): Promise<BuildStats> {\n\t\tdebug(\"Building...\\n\");\n\n\t\tfor (const collection of collections) {\n\t\t\tdebug(`Building collection \"${collection.name}\"...`);\n\n\t\t\t// eslint-disable-next-line n/no-unsupported-features/node-builtins\n\t\t\tfor await (const filePath of fs.glob(collection.include, {\n\t\t\t\tcwd: collection.directory,\n\t\t\t\texclude: collection.exclude,\n\t\t\t})) {\n\t\t\t\tconst absoluteFilePath = path.join(collection.directory, filePath);\n\t\t\t\tconst id = createIdFromFilePath(filePath);\n\n\t\t\t\tconst stats = await fs.stat(absoluteFilePath).catch((error: unknown) => {\n\t\t\t\t\tif (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t\t\tif (stats == null) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst { mtimeMs: timestamp } = stats;\n\n\t\t\t\tconst item: CollectionItem = { id, filePath, absoluteFilePath, timestamp };\n\n\t\t\t\tcollection.data.set(id, { item, content: null, document: null });\n\n\t\t\t\tdebug(`- Added item \"${id}\" (path: \"${filePath}\").`);\n\t\t\t}\n\n\t\t\tdebug(\n\t\t\t\t`Done adding ${String(collection.data.size)} item(s) to collection \"${collection.name}\".\\n`,\n\t\t\t);\n\t\t}\n\n\t\tawait generate();\n\n\t\treturn {\n\t\t\tcollections: collections.length,\n\t\t\tdocuments: collections.reduce((acc, collection) => {\n\t\t\t\treturn acc + collection.data.size;\n\t\t\t}, 0),\n\t\t};\n\t}\n\n\tasync function watch(): Promise<Set<watcher.AsyncSubscription>> {\n\t\tdebug(\"Watching...\\n\");\n\n\t\tconst subscriptions = new Set<watcher.AsyncSubscription>();\n\n\t\tconst debounceDelayMs = 150;\n\t\tlet timer: ReturnType<typeof setTimeout> | null = null;\n\t\tlet controller: AbortController | null = null;\n\t\tlet batch = new Map<watcher.Event[\"path\"], watcher.Event & { relativeFilePath: string }>();\n\n\t\tfor (const collection of collections) {\n\t\t\tdebug(`Watching collection \"${collection.name}\"...`);\n\n\t\t\t/**\n\t\t\t * Ideally, we could just add `include` as a negative ignore pattern.\n\t\t\t *\n\t\t\t * This is currently not supported by `@parcel/watcher`. Simple patterns like \"!*.md\" do seem\n\t\t\t * to work, but others like \"!*\\/index.md\" do not.\n\t\t\t *\n\t\t\t * Therefore we need to filter out matching events in the javascript main thread\n\t\t\t * (see `path.matchesGlob` below).\n\t\t\t *\n\t\t\t * @see https://github.com/parcel-bundler/watcher/issues/166\n\t\t\t */\n\t\t\t// const ignore = [\n\t\t\t// \t...collection.include.map((glob) => {\n\t\t\t// \t\treturn `!${glob}`;\n\t\t\t// \t}),\n\t\t\t// \t...(collection.exclude ?? []),\n\t\t\t// ];\n\t\t\tconst ignore = (collection.exclude ?? []) as Array<string>;\n\n\t\t\tconst subscription = await watcher.subscribe(\n\t\t\t\tcollection.directory,\n\t\t\t\t(error, events) => {\n\t\t\t\t\tif (error != null) {\n\t\t\t\t\t\tlog.error(error);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tdebug(`- ${String(events.length)} events in collection \"${collection.name}\".`);\n\n\t\t\t\t\tfor (const event of events) {\n\t\t\t\t\t\t// const relativeFilePath = path.relative(collection.directory, event.path);\n\t\t\t\t\t\tconst relativeFilePath = event.path.slice(collection.absoluteDirectoryPath.length);\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tcollection.include.some((pattern) => {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line n/no-unsupported-features/node-builtins\n\t\t\t\t\t\t\t\treturn path.matchesGlob(relativeFilePath, pattern);\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t(event as watcher.Event & { relativeFilePath: string }).relativeFilePath =\n\t\t\t\t\t\t\t\trelativeFilePath;\n\t\t\t\t\t\t\tbatch.set(event.path, event as watcher.Event & { relativeFilePath: string });\n\n\t\t\t\t\t\t\tdebug(`- Added \"${event.type}\" event for \"${relativeFilePath}\" to queue.`);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdebug(`- Discarded \"${event.type}\" event for \"${relativeFilePath}\".`);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (timer != null) {\n\t\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\t}\n\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\t\t\t\ttimer = setTimeout(async () => {\n\t\t\t\t\t\tif (controller != null) {\n\t\t\t\t\t\t\tcontroller.abort();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcontroller = new AbortController();\n\n\t\t\t\t\t\tconst events = batch;\n\t\t\t\t\t\tbatch = new Map();\n\t\t\t\t\t\ttimer = null;\n\n\t\t\t\t\t\tlet isCollectionChanged = false;\n\n\t\t\t\t\t\tfor (const event of events.values()) {\n\t\t\t\t\t\t\tconst filePath = event.relativeFilePath;\n\t\t\t\t\t\t\tconst id = createIdFromFilePath(filePath);\n\n\t\t\t\t\t\t\tdebug(`Processing \"${event.type}\" event for \"${id}\".`);\n\n\t\t\t\t\t\t\tswitch (event.type) {\n\t\t\t\t\t\t\t\tcase \"create\":\n\t\t\t\t\t\t\t\tcase \"update\": {\n\t\t\t\t\t\t\t\t\tisCollectionChanged ||= event.type === \"create\" || collection.data.has(id);\n\n\t\t\t\t\t\t\t\t\tconst absoluteFilePath = path.join(collection.directory, filePath);\n\n\t\t\t\t\t\t\t\t\tconst stats = await fs.stat(absoluteFilePath).catch((error: unknown) => {\n\t\t\t\t\t\t\t\t\t\tif (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n\t\t\t\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\tif (stats == null) {\n\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst { mtimeMs: timestamp } = stats;\n\n\t\t\t\t\t\t\t\t\tconst item: CollectionItem = { id, filePath, absoluteFilePath, timestamp };\n\n\t\t\t\t\t\t\t\t\tcollection.data.set(id, { item, content: null, document: null });\n\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tcase \"delete\": {\n\t\t\t\t\t\t\t\t\tisCollectionChanged ||= collection.data.has(id);\n\n\t\t\t\t\t\t\t\t\tcollection.data.delete(id);\n\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (isCollectionChanged) {\n\t\t\t\t\t\t\tawait generate(controller.signal);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, debounceDelayMs);\n\t\t\t\t},\n\t\t\t\t{ ignore },\n\t\t\t);\n\n\t\t\tsubscriptions.add(subscription);\n\t\t}\n\n\t\tasync function unsubscribe() {\n\t\t\tdebug(\"Cleaning up...\");\n\n\t\t\tif (timer != null) {\n\t\t\t\tclearTimeout(timer);\n\t\t\t}\n\t\t\ttimer = null;\n\n\t\t\tif (controller != null) {\n\t\t\t\tcontroller.abort();\n\t\t\t}\n\t\t\tcontroller = null;\n\n\t\t\tfor (const subscription of subscriptions) {\n\t\t\t\tawait subscription.unsubscribe();\n\t\t\t}\n\t\t\tsubscriptions.clear();\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\tprocess.once(\"SIGINT\", unsubscribe);\n\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\tprocess.once(\"SIGTERM\", unsubscribe);\n\n\t\treturn subscriptions;\n\t}\n\n\treturn {\n\t\tbuild,\n\t\twatch,\n\t};\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,QAAQ,SAAS;AAIvB,SAAS,kBAAkB,OAAuB;AACjD,QAAO,OAAO,WAAW,UAAU,OAAO,OAAO,OAAO;AACxD;AAED,SAAS,qBAAqB,UAA0B;CACvD,MAAM,SAAS,KAAK,MAAM;AAE1B,KAAI,OAAO,KAAK,kBAAkB,QACjC,QAAO,KAAK,SAAS,OAAO;AAG7B,QAAO,OAAO;AACd;AAyCD,SAAgB,iBACf,QACgE;AAChE,QAAO;AACP;AAMD,SAAgB,aAAsC,QAAc;AACnE,QAAO;AACP;AAUD,IAAM,oBAAN,MAAwB;CACvB;CAEA,YAAY,QAAc;AACzB,OAAK,OAAOA;CACZ;AACD;AAED,SAAS,wBAAwB,QAAiC;AACjE,QAAO,IAAI,kBAAkBA;AAC7B;AAED,IAAM,mBAAN,MAAuB;CACtB;CAEA,YAAY,SAAiB;AAC5B,OAAK,UAAU;CACf;AACD;AAED,SAAS,uBAAuB,SAAmC;AAClE,QAAO,IAAI,iBAAiB;AAC5B;AAED,IAAM,aAAN,MAAiB;CAChB;CAEA,YAAY,SAAiB;AAC5B,OAAK,UAAU;CACf;AACD;AAED,SAAS,iBAAiB,SAA6B;AACtD,Q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AQ,MAAM,MAAd;OACC,KAAK;OACL,KAAK,UAAU;AACd,gCAAwB,MAAM,SAAS,YAAY,WAAW,KAAK,IAAI;QAEvE,MAAM,mBAAmB,KAAK,KAAK,WAAW,WAAW;QAEzD,MAAM,QAAQ,MAAM,GAAG,KAAK,kBAAkB,OAAO,YAAmB;AACvE,aAAIC,mBAAiB,SAAS,UAAUA,WAASA,QAAM,SAAS,SAC/D,QAAO;AAER,eAAMA;QACN;AACD,YAAI,SAAS,KACZ;QAED,MAAM,EAAE,SAAS,WAAW,GAAG;QAE/B,MAAMJ,OAAuB;SAAE;SAAI;SAAU;SAAkB;SAAW;AAE1E,mBAAW,KAAK,IAAI,IAAI;SAAE;SAAM,SAAS;SAAM,UAAU;SAAM;AAE/D;OACA;OAED,KAAK;AACJ,gCAAwB,WAAW,KAAK,IAAI;AAE5C,mBAAW,KAAK,OAAO;AAEvB;MAED;KACD;AAED,SAAI,oBACH,OAAM,SAAS,WAAW;IAE3B,GAAE;GACH,GACD,EAAE,QAAQ;AAGX,iBAAc,IAAI;EAClB;EAED,eAAe,cAAc;AAC5B,SAAM;AAEN,OAAI,SAAS,KACZ,cAAa;AAEd,WAAQ;AAER,OAAI,cAAc,KACjB,YAAW;AAEZ,gBAAa;AAEb,QAAK,MAAM,gBAAgB,cAC1B,OAAM,aAAa;AAEpB,iBAAc;EACd;AAGD,UAAQ,KAAK,UAAU;AAEvB,UAAQ,KAAK,WAAW;AAExB,SAAO;CACP;AAED,QAAO;EACN;EACA;EACA;AACD"}
1
+ {"version":3,"file":"index.js","names":["path","imports: Array<string>","value","collections: Array<Collection>","context: TransformContext","item: CollectionItem","timer: ReturnType<typeof setTimeout> | null","controller: AbortController | null","events","error"],"sources":["../src/index.ts"],"sourcesContent":["import * as crypto from \"node:crypto\";\nimport * as fs from \"node:fs/promises\";\nimport { availableParallelism } from \"node:os\";\nimport * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { debuglog } from \"node:util\";\n\nimport { addTrailingSlash, capitalize, log } from \"@acdh-oeaw/lib\";\nimport * as watcher from \"@parcel/watcher\";\nimport plimit from \"p-limit\";\nimport pluralize from \"pluralize\";\n\n//\n\nconst debug = debuglog(\"content-lib\");\n\n//\n\nfunction createContentHash(value: string): string {\n\treturn crypto.createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nfunction createIdFromFilePath(filePath: string): string {\n\tconst parsed = path.parse(filePath);\n\n\tif (parsed.name.toLowerCase() === \"index\") {\n\t\treturn path.basename(parsed.dir);\n\t}\n\n\treturn parsed.name;\n}\n\n//\n\ntype MaybePromise<T> = T | Promise<T>;\n\ntype NonEmptyReadonlyArray<T> = readonly [T, ...Array<T>];\n\ntype GlobString = string;\n\ninterface CollectionItem {\n\t/** Unique identifier. */\n\tid: string;\n\t/** File path relative to colleciton directory. */\n\tfilePath: string;\n\t/** File path relative to current working directory. */\n\tabsoluteFilePath: string;\n\t/** File modification timestamp. */\n\ttimestamp: number;\n}\n\ninterface TransformContext {\n\tcollections: Array<Collection>;\n\tcreateImportDeclaration: <T>(path: string) => ImportDeclaration<T>;\n\tcreateJavaScriptImport: <T>(content: string) => JavaScriptImport<T>;\n\tcreateJsonImport: <T>(content: string) => JsonImport<T>;\n}\n\nexport interface CollectionConfig<\n\tTCollectionName extends string = string,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTCollectionItemContent = any,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTCollectionDocument = any,\n> {\n\tname: TCollectionName;\n\tdirectory: string;\n\tinclude: NonEmptyReadonlyArray<GlobString>;\n\texclude?: ReadonlyArray<GlobString>;\n\tread: (item: CollectionItem) => MaybePromise<TCollectionItemContent>;\n\ttransform: (\n\t\tcontent: TCollectionItemContent,\n\t\titem: CollectionItem,\n\t\tcontext: TransformContext,\n\t) => MaybePromise<TCollectionDocument>;\n}\n\nexport function createCollection<\n\tTCollectionName extends string,\n\tTCollectionItemContent,\n\tTCollectionDocument,\n>(\n\tconfig: CollectionConfig<TCollectionName, TCollectionItemContent, TCollectionDocument>,\n): CollectionConfig<TCollectionName, TCollectionItemContent, TCollectionDocument> {\n\treturn config;\n}\n\nexport interface ContentConfig {\n\tcollections: Array<CollectionConfig>;\n}\n\nexport function createConfig<T extends ContentConfig>(config: T): T {\n\treturn config;\n}\n\n//\n\n// function createItemCacheKey(item: CollectionItem): string {\n// \treturn String(item.timestamp);\n// }\n\n//\n\nclass ImportDeclaration<T> {\n\tprivate __brand!: never;\n\tvalue!: T;\n\tpath: string;\n\n\tconstructor(path: string) {\n\t\tthis.path = path;\n\t}\n}\n\nfunction createImportDeclaration<T>(path: string): ImportDeclaration<T> {\n\treturn new ImportDeclaration<T>(path);\n}\n\nclass JavaScriptImport<T> {\n\tprivate __brand!: never;\n\tvalue!: T;\n\tcontent: string;\n\n\tconstructor(content: string) {\n\t\tthis.content = content;\n\t}\n}\n\nfunction createJavaScriptImport<T>(content: string): JavaScriptImport<T> {\n\treturn new JavaScriptImport<T>(content);\n}\n\nclass JsonImport<T> {\n\tprivate __brand!: never;\n\tvalue!: T;\n\tcontent: string;\n\n\tconstructor(content: string) {\n\t\tthis.content = content;\n\t}\n}\n\nfunction createJsonImport<T>(content: string): JsonImport<T> {\n\treturn new JsonImport<T>(content);\n}\n\n//\n\nexport type GetCollection<TConfig extends ContentConfig, TName extends string> = Extract<\n\tTConfig[\"collections\"][number],\n\t{ name: TName }\n>;\n\ntype Simplify<T> = { [K in keyof T]: T[K] } & {};\n\ntype Replace<T> = {\n\t[K in keyof T]: T[K] extends JavaScriptImport<infer U>\n\t\t? U\n\t\t: T[K] extends JsonImport<infer U>\n\t\t\t? U\n\t\t\t: T[K] extends ImportDeclaration<infer U>\n\t\t\t\t? U\n\t\t\t\t: T[K] extends object\n\t\t\t\t\t? Simplify<Replace<T[K]>>\n\t\t\t\t\t: T[K];\n};\n\nexport type CollectionEntry<TCollection extends Collection> = Simplify<{\n\titem: { id: string };\n\tcontent: Simplify<Awaited<ReturnType<TCollection[\"read\"]>>>;\n\tdocument: Simplify<Replace<Awaited<ReturnType<TCollection[\"transform\"]>>>>;\n}>;\n\n//\n\nconst prefix = \"__i__\";\nconst re = new RegExp(`\"(${prefix}\\\\d+)\"`, \"g\");\n\nfunction serialize(\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tvalue: Map<string, any>,\n\tcontentProcessorConfigFilePath: string,\n\tcollectionName: string,\n): Map<string, string> {\n\tdebug(\"Serializing...\\n\");\n\n\tconst imports: Array<string> = [];\n\n\tfunction addImport(filePath: string, type: \"js\" | \"json\" = \"js\"): string {\n\t\tconst identifier = [prefix, imports.length].join(\"\");\n\t\timports.push(\n\t\t\t`import ${identifier} from \"${filePath}\"${type !== \"js\" ? ` with { type: \"${type}\" }` : \"\"};`,\n\t\t);\n\n\t\treturn identifier;\n\t}\n\n\tconst files = new Map<string, string>();\n\n\tfunction addFiles(filePath: string, content: string): void {\n\t\tfiles.set(filePath, content);\n\t}\n\n\tconst json = JSON.stringify(\n\t\tArray.from(value),\n\t\t// TODO: Should we support (multiple) named imports?\n\t\t(_key, value) => {\n\t\t\tif (value instanceof ImportDeclaration) {\n\t\t\t\tconst filePath = value.path;\n\n\t\t\t\tdebug(`Adding import declaration for \"${filePath}\".`);\n\t\t\t\tconst identifier = addImport(filePath);\n\n\t\t\t\treturn identifier;\n\t\t\t}\n\n\t\t\tif (value instanceof JavaScriptImport) {\n\t\t\t\tconst hash = createContentHash(value.content);\n\t\t\t\tconst filePath = `./${hash}.js`;\n\n\t\t\t\tdebug(`Adding javascript import for \"${filePath}\".`);\n\t\t\t\tconst identifier = addImport(filePath);\n\t\t\t\taddFiles(filePath, `// @ts-nocheck\\n${value.content}`);\n\n\t\t\t\treturn identifier;\n\t\t\t}\n\n\t\t\tif (value instanceof JsonImport) {\n\t\t\t\tconst hash = createContentHash(value.content);\n\t\t\t\tconst filePath = `./${hash}.json`;\n\n\t\t\t\tdebug(`Adding json import for \"${filePath}\".`);\n\t\t\t\tconst identifier = addImport(filePath, \"json\");\n\t\t\t\taddFiles(filePath, value.content);\n\n\t\t\t\treturn identifier;\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\treturn value;\n\t\t},\n\t\t2,\n\t)\n\t\t/** Remove quotes from import identifiers. */\n\t\t.replaceAll(re, \"$1\");\n\n\tlet result = \"\";\n\n\tif (imports.length > 0) {\n\t\tresult += imports.join(\"\\n\");\n\t\tresult += \"\\n\\n\";\n\t}\n\n\tresult += [`const items = new Map(${json});`, \"export default items;\"].join(\"\\n\\n\");\n\n\tfiles.set(\"index.js\", result);\n\n\t// eslint-disable-next-line import-x/no-named-as-default-member\n\tconst typeName = capitalize(pluralize.singular(collectionName));\n\n\tfiles.set(\n\t\t\"index.d.ts\",\n\t\t[\n\t\t\t`import type { GetCollection, CollectionEntry } from \"@acdh-oeaw/content-lib\";`,\n\t\t\t\"\",\n\t\t\t`import type { config } from \"${contentProcessorConfigFilePath}\";`,\n\t\t\t\"\",\n\t\t\t`type Collection = GetCollection<typeof config, \"${collectionName}\">;`,\n\t\t\t`type ${typeName} = CollectionEntry<Collection>;`,\n\t\t\t\"\",\n\t\t\t`declare const items: Map<string, ${typeName}>;`,\n\t\t\t`export { type ${typeName}, items as default };`,\n\t\t].join(\"\\n\"),\n\t);\n\n\treturn files;\n}\n\n//\n\ninterface Collection extends CollectionConfig {\n\tabsoluteDirectoryPath: string;\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Map<CollectionItem[\"id\"], { item: CollectionItem; content: any; document: any }>; // TODO: revisit\n\toutputDirectoryPath: string;\n}\n\ninterface BuildStats {\n\tcollections: number;\n\tdocuments: number;\n}\n\nexport interface ContentProcessorConfig {\n\t/** Path to config file, relative to `process.cwd()`, which provides a named export `config`. */\n\tconfigFilePath: string;\n}\n\nexport interface ContentProcessor {\n\tbuild: () => Promise<BuildStats>;\n\twatch: () => Promise<Set<watcher.AsyncSubscription>>;\n}\n\nexport async function createContentProcessor(\n\tcontentProcessorConfig: ContentProcessorConfig,\n): Promise<ContentProcessor> {\n\tdebug(\"Creating content processor...\\n\");\n\n\tdebug(\"Reading config file...\");\n\tconst contentProcessorConfigUrl = pathToFileURL(\n\t\tpath.resolve(contentProcessorConfig.configFilePath),\n\t);\n\tcontentProcessorConfigUrl.searchParams.set(\"cache-key\", String(Date.now()));\n\tconst contentProcessorConfigFilePath = String(contentProcessorConfigUrl);\n\tconst { config } = (await import(contentProcessorConfigFilePath)) as { config: ContentConfig }; // TODO: validate\n\tdebug(`Done reading config file \"${contentProcessorConfigFilePath}\".`);\n\n\tconst concurrency = availableParallelism();\n\tconst limit = plimit(concurrency);\n\tdebug(`Concurrency: ${String(concurrency)}.\\n`);\n\n\tconst outputDirectoryBasePath = path.join(process.cwd(), \".content\", \"generated\");\n\n\tconst collections: Array<Collection> = [];\n\n\tconst context: TransformContext = {\n\t\tcollections,\n\t\tcreateImportDeclaration,\n\t\tcreateJavaScriptImport,\n\t\tcreateJsonImport,\n\t};\n\n\tfor (const collection of config.collections) {\n\t\tconst absoluteDirectoryPath = addTrailingSlash(path.resolve(collection.directory));\n\n\t\t/** Ensure directory exists, which is expected by `@parcel/watcher`. */\n\t\tawait fs.mkdir(absoluteDirectoryPath, { recursive: true });\n\n\t\tconst outputDirectoryPath = path.join(\n\t\t\toutputDirectoryBasePath,\n\t\t\tcollection.name.toLowerCase().replaceAll(/[^a-z0-9_-]/g, \"-\"),\n\t\t);\n\n\t\tcollections.push({\n\t\t\t...collection,\n\t\t\tabsoluteDirectoryPath,\n\t\t\tdata: new Map(),\n\t\t\toutputDirectoryPath,\n\t\t});\n\t}\n\n\tasync function generate(signal?: AbortSignal): Promise<void> {\n\t\tdebug(\"Generating...\\n\");\n\n\t\tfor (const collection of collections) {\n\t\t\tdebug(`Reading collection \"${collection.name}\"...`);\n\n\t\t\tawait limit.map(Array.from(collection.data), async ([id, { item }]) => {\n\t\t\t\tif (signal?.aborted === true) {\n\t\t\t\t\tdebug(\"Aborted reading collections.\");\n\t\t\t\t\tlimit.clearQueue();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// FIXME: race condition: what if file has been deleted in the meantime\n\t\t\t\t// TODO: skip item when `read()` returns `null`?\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst content = await collection.read(item);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tcollection.data.get(id)!.content = content;\n\n\t\t\t\tdebug(`- Read item \"${id}\".`);\n\t\t\t});\n\n\t\t\tdebug(\n\t\t\t\t`Done reading ${String(collection.data.size)} item(s) in collection \"${collection.name}\".\\n`,\n\t\t\t);\n\t\t}\n\n\t\tfor (const collection of collections) {\n\t\t\tdebug(`Transforming collection \"${collection.name}\"...`);\n\n\t\t\tawait limit.map(Array.from(collection.data), async ([id, { content, item }]) => {\n\t\t\t\tif (signal?.aborted === true) {\n\t\t\t\t\tdebug(\"Aborted transforming collections.\");\n\t\t\t\t\tlimit.clearQueue();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst document = await collection.transform(content, item, context);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tcollection.data.get(id)!.document = document;\n\n\t\t\t\tdebug(`- Transformed item \"${id}\".`);\n\t\t\t});\n\n\t\t\tdebug(\n\t\t\t\t`Done transforming ${String(collection.data.size)} item(s) in collection \"${collection.name}\".\\n`,\n\t\t\t);\n\t\t}\n\n\t\tif (signal?.aborted === true) {\n\t\t\tdebug(\"Aborted writing collections.\");\n\t\t\treturn;\n\t\t}\n\n\t\tdebug(\"Clearing output directory...\\n\");\n\t\tawait fs.rm(outputDirectoryBasePath, { force: true, recursive: true });\n\n\t\tfor (const collection of collections) {\n\t\t\tdebug(`Writing collection \"${collection.name}\".`);\n\n\t\t\tdebug(`Creating output directory for \"${collection.name}\".`);\n\t\t\tawait fs.mkdir(collection.outputDirectoryPath, { recursive: true });\n\n\t\t\tconst files = serialize(\n\t\t\t\tcollection.data,\n\t\t\t\tpath.relative(collection.outputDirectoryPath, contentProcessorConfig.configFilePath),\n\t\t\t\tcollection.name,\n\t\t\t);\n\n\t\t\tawait limit.map(Array.from(files), async ([filePath, fileContent]) => {\n\t\t\t\tconst outputFilePath = path.join(collection.outputDirectoryPath, filePath);\n\t\t\t\tawait fs.writeFile(outputFilePath, fileContent, { encoding: \"utf-8\" });\n\t\t\t});\n\t\t}\n\t}\n\n\tasync function build(): Promise<BuildStats> {\n\t\tdebug(\"Building...\\n\");\n\n\t\tfor (const collection of collections) {\n\t\t\tdebug(`Building collection \"${collection.name}\"...`);\n\n\t\t\t// eslint-disable-next-line n/no-unsupported-features/node-builtins\n\t\t\tfor await (const filePath of fs.glob(collection.include, {\n\t\t\t\tcwd: collection.directory,\n\t\t\t\texclude: collection.exclude,\n\t\t\t})) {\n\t\t\t\tconst absoluteFilePath = path.join(collection.directory, filePath);\n\t\t\t\tconst id = createIdFromFilePath(filePath);\n\n\t\t\t\tconst stats = await fs.stat(absoluteFilePath).catch((error: unknown) => {\n\t\t\t\t\tif (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t\t\tif (stats == null) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst { mtimeMs: timestamp } = stats;\n\n\t\t\t\tconst item: CollectionItem = { id, filePath, absoluteFilePath, timestamp };\n\n\t\t\t\tcollection.data.set(id, { item, content: null, document: null });\n\n\t\t\t\tdebug(`- Added item \"${id}\" (path: \"${filePath}\").`);\n\t\t\t}\n\n\t\t\tdebug(\n\t\t\t\t`Done adding ${String(collection.data.size)} item(s) to collection \"${collection.name}\".\\n`,\n\t\t\t);\n\t\t}\n\n\t\tawait generate();\n\n\t\treturn {\n\t\t\tcollections: collections.length,\n\t\t\tdocuments: collections.reduce((acc, collection) => {\n\t\t\t\treturn acc + collection.data.size;\n\t\t\t}, 0),\n\t\t};\n\t}\n\n\tasync function watch(): Promise<Set<watcher.AsyncSubscription>> {\n\t\tdebug(\"Watching...\\n\");\n\n\t\tconst subscriptions = new Set<watcher.AsyncSubscription>();\n\n\t\tconst debounceDelayMs = 150;\n\t\tlet timer: ReturnType<typeof setTimeout> | null = null;\n\t\tlet controller: AbortController | null = null;\n\t\tlet batch = new Map<watcher.Event[\"path\"], watcher.Event & { relativeFilePath: string }>();\n\n\t\tfor (const collection of collections) {\n\t\t\tdebug(`Watching collection \"${collection.name}\"...`);\n\n\t\t\t/**\n\t\t\t * Ideally, we could just add `include` as a negative ignore pattern.\n\t\t\t *\n\t\t\t * This is currently not supported by `@parcel/watcher`. Simple patterns like \"!*.md\" do seem\n\t\t\t * to work, but others like \"!*\\/index.md\" do not.\n\t\t\t *\n\t\t\t * Therefore we need to filter out matching events in the javascript main thread\n\t\t\t * (see `path.matchesGlob` below).\n\t\t\t *\n\t\t\t * @see https://github.com/parcel-bundler/watcher/issues/166\n\t\t\t */\n\t\t\t// const ignore = [\n\t\t\t// \t...collection.include.map((glob) => {\n\t\t\t// \t\treturn `!${glob}`;\n\t\t\t// \t}),\n\t\t\t// \t...(collection.exclude ?? []),\n\t\t\t// ];\n\t\t\tconst ignore = (collection.exclude ?? []) as Array<string>;\n\n\t\t\tconst subscription = await watcher.subscribe(\n\t\t\t\tcollection.directory,\n\t\t\t\t(error, events) => {\n\t\t\t\t\tif (error != null) {\n\t\t\t\t\t\tlog.error(error);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tdebug(`- ${String(events.length)} events in collection \"${collection.name}\".`);\n\n\t\t\t\t\tfor (const event of events) {\n\t\t\t\t\t\t// const relativeFilePath = path.relative(collection.directory, event.path);\n\t\t\t\t\t\tconst relativeFilePath = event.path.slice(collection.absoluteDirectoryPath.length);\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tcollection.include.some((pattern) => {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line n/no-unsupported-features/node-builtins\n\t\t\t\t\t\t\t\treturn path.matchesGlob(relativeFilePath, pattern);\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t(event as watcher.Event & { relativeFilePath: string }).relativeFilePath =\n\t\t\t\t\t\t\t\trelativeFilePath;\n\t\t\t\t\t\t\tbatch.set(event.path, event as watcher.Event & { relativeFilePath: string });\n\n\t\t\t\t\t\t\tdebug(`- Added \"${event.type}\" event for \"${relativeFilePath}\" to queue.`);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdebug(`- Discarded \"${event.type}\" event for \"${relativeFilePath}\".`);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (timer != null) {\n\t\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\t}\n\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\t\t\t\ttimer = setTimeout(async () => {\n\t\t\t\t\t\tif (controller != null) {\n\t\t\t\t\t\t\tcontroller.abort();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcontroller = new AbortController();\n\n\t\t\t\t\t\tconst events = batch;\n\t\t\t\t\t\tbatch = new Map();\n\t\t\t\t\t\ttimer = null;\n\n\t\t\t\t\t\tlet isCollectionChanged = false;\n\n\t\t\t\t\t\tfor (const event of events.values()) {\n\t\t\t\t\t\t\tconst filePath = event.relativeFilePath;\n\t\t\t\t\t\t\tconst id = createIdFromFilePath(filePath);\n\n\t\t\t\t\t\t\tdebug(`Processing \"${event.type}\" event for \"${id}\".`);\n\n\t\t\t\t\t\t\tswitch (event.type) {\n\t\t\t\t\t\t\t\tcase \"create\":\n\t\t\t\t\t\t\t\tcase \"update\": {\n\t\t\t\t\t\t\t\t\tisCollectionChanged ||= event.type === \"create\" || collection.data.has(id);\n\n\t\t\t\t\t\t\t\t\tconst absoluteFilePath = path.join(collection.directory, filePath);\n\n\t\t\t\t\t\t\t\t\tconst stats = await fs.stat(absoluteFilePath).catch((error: unknown) => {\n\t\t\t\t\t\t\t\t\t\tif (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n\t\t\t\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\tif (stats == null) {\n\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst { mtimeMs: timestamp } = stats;\n\n\t\t\t\t\t\t\t\t\tconst item: CollectionItem = { id, filePath, absoluteFilePath, timestamp };\n\n\t\t\t\t\t\t\t\t\tcollection.data.set(id, { item, content: null, document: null });\n\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tcase \"delete\": {\n\t\t\t\t\t\t\t\t\tisCollectionChanged ||= collection.data.has(id);\n\n\t\t\t\t\t\t\t\t\tcollection.data.delete(id);\n\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (isCollectionChanged) {\n\t\t\t\t\t\t\tawait generate(controller.signal);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, debounceDelayMs);\n\t\t\t\t},\n\t\t\t\t{ ignore },\n\t\t\t);\n\n\t\t\tsubscriptions.add(subscription);\n\t\t}\n\n\t\tasync function unsubscribe() {\n\t\t\tdebug(\"Cleaning up...\");\n\n\t\t\tif (timer != null) {\n\t\t\t\tclearTimeout(timer);\n\t\t\t}\n\t\t\ttimer = null;\n\n\t\t\tif (controller != null) {\n\t\t\t\tcontroller.abort();\n\t\t\t}\n\t\t\tcontroller = null;\n\n\t\t\tfor (const subscription of subscriptions) {\n\t\t\t\tawait subscription.unsubscribe();\n\t\t\t}\n\t\t\tsubscriptions.clear();\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\tprocess.once(\"SIGINT\", unsubscribe);\n\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\tprocess.once(\"SIGTERM\", unsubscribe);\n\n\t\treturn subscriptions;\n\t}\n\n\treturn {\n\t\tbuild,\n\t\twatch,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAM,QAAQ,SAAS;AAIvB,SAAS,kBAAkB,OAAuB;AACjD,QAAO,OAAO,WAAW,UAAU,OAAO,OAAO,OAAO;AACxD;AAED,SAAS,qBAAqB,UAA0B;CACvD,MAAM,SAAS,KAAK,MAAM;AAE1B,KAAI,OAAO,KAAK,kBAAkB,QACjC,QAAO,KAAK,SAAS,OAAO;AAG7B,QAAO,OAAO;AACd;AA+CD,SAAgB,iBAKf,QACiF;AACjF,QAAO;AACP;AAMD,SAAgB,aAAsC,QAAc;AACnE,QAAO;AACP;AAUD,IAAM,oBAAN,MAA2B;CAC1B,AAAQ;CACR;CACA;CAEA,YAAY,QAAc;AACzB,OAAK,OAAOA;CACZ;AACD;AAED,SAAS,wBAA2B,QAAoC;AACvE,QAAO,IAAI,kBAAqBA;AAChC;AAED,IAAM,mBAAN,MAA0B;CACzB,AAAQ;CACR;CACA;CAEA,YAAY,SAAiB;AAC5B,OAAK,UAAU;CACf;AACD;AAED,SAAS,uBAA0B,SAAsC;AACxE,QAAO,IAAI,iBAAoB;AAC/B;AAED,IAAM,aAAN,MAAoB;CACnB,AAAQ;CACR;CACA;CAEA,YAAY,SAAiB;AAC5B,OAAK,UAAU;CACf;AACD;AAED,SAAS,iBAAoB,SAAgC;AAC5D,QAAO,IAAI,WAAc;AACzB;AA+BD,MAAM,SAAS;AACf,MAAM,KAAK,IAAI,OAAO,KAAK,OAAO,SAAS;AAE3C,SAAS,UAER,OACA,gCACA,gBACsB;AACtB,OAAM;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OAAM,aAAa;AAEpB,iBAAc;EACd;AAGD,UAAQ,KAAK,UAAU;AAEvB,UAAQ,KAAK,WAAW;AAExB,SAAO;CACP;AAED,QAAO;EACN;EACA;EACA;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acdh-oeaw/content-lib",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -23,7 +23,8 @@
23
23
  "dependencies": {
24
24
  "@acdh-oeaw/lib": "0.3.4",
25
25
  "@parcel/watcher": "^2.5.1",
26
- "p-limit": "^7.0.0"
26
+ "p-limit": "^7.1.0",
27
+ "pluralize": "^8.0.0"
27
28
  },
28
29
  "devDependencies": {
29
30
  "@acdh-oeaw/eslint-config": "2.0.9",
@@ -32,6 +33,7 @@
32
33
  "@acdh-oeaw/tsconfig": "^1.5.1",
33
34
  "@acdh-oeaw/tsconfig-lib": "^1.3.0",
34
35
  "@types/node": "^22.17.2",
36
+ "@types/pluralize": "^0.0.33",
35
37
  "eslint": "9.33.0",
36
38
  "eslint-config-flat-gitignore": "2.1.0",
37
39
  "globals": "16.3.0",