@riotprompt/riotprompt 0.0.1

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.
Files changed (129) hide show
  1. package/.gitcarve/config.yaml +10 -0
  2. package/.gitcarve/context/content.md +11 -0
  3. package/.markdown-doctest-setup.mjs +23 -0
  4. package/.nvmrc +1 -0
  5. package/LICENSE +190 -0
  6. package/README.md +513 -0
  7. package/dist/builder.cjs +152 -0
  8. package/dist/builder.cjs.map +1 -0
  9. package/dist/builder.d.ts +37 -0
  10. package/dist/builder.js +148 -0
  11. package/dist/builder.js.map +1 -0
  12. package/dist/chat.cjs +26 -0
  13. package/dist/chat.cjs.map +1 -0
  14. package/dist/chat.d.ts +14 -0
  15. package/dist/chat.js +21 -0
  16. package/dist/chat.js.map +1 -0
  17. package/dist/constants.cjs +34 -0
  18. package/dist/constants.cjs.map +1 -0
  19. package/dist/constants.d.ts +13 -0
  20. package/dist/constants.js +23 -0
  21. package/dist/constants.js.map +1 -0
  22. package/dist/formatter.cjs +139 -0
  23. package/dist/formatter.cjs.map +1 -0
  24. package/dist/formatter.d.ts +88 -0
  25. package/dist/formatter.js +131 -0
  26. package/dist/formatter.js.map +1 -0
  27. package/dist/items/content.cjs +14 -0
  28. package/dist/items/content.cjs.map +1 -0
  29. package/dist/items/content.d.ts +3 -0
  30. package/dist/items/content.js +10 -0
  31. package/dist/items/content.js.map +1 -0
  32. package/dist/items/context.cjs +13 -0
  33. package/dist/items/context.cjs.map +1 -0
  34. package/dist/items/context.d.ts +3 -0
  35. package/dist/items/context.js +9 -0
  36. package/dist/items/context.js.map +1 -0
  37. package/dist/items/instruction.cjs +13 -0
  38. package/dist/items/instruction.cjs.map +1 -0
  39. package/dist/items/instruction.d.ts +3 -0
  40. package/dist/items/instruction.js +9 -0
  41. package/dist/items/instruction.js.map +1 -0
  42. package/dist/items/parameters.cjs +53 -0
  43. package/dist/items/parameters.cjs.map +1 -0
  44. package/dist/items/parameters.d.ts +5 -0
  45. package/dist/items/parameters.js +47 -0
  46. package/dist/items/parameters.js.map +1 -0
  47. package/dist/items/section.cjs +120 -0
  48. package/dist/items/section.cjs.map +1 -0
  49. package/dist/items/section.d.ts +33 -0
  50. package/dist/items/section.js +115 -0
  51. package/dist/items/section.js.map +1 -0
  52. package/dist/items/trait.cjs +13 -0
  53. package/dist/items/trait.cjs.map +1 -0
  54. package/dist/items/trait.d.ts +3 -0
  55. package/dist/items/trait.js +9 -0
  56. package/dist/items/trait.js.map +1 -0
  57. package/dist/items/weighted.cjs +27 -0
  58. package/dist/items/weighted.cjs.map +1 -0
  59. package/dist/items/weighted.d.ts +24 -0
  60. package/dist/items/weighted.js +22 -0
  61. package/dist/items/weighted.js.map +1 -0
  62. package/dist/loader.cjs +167 -0
  63. package/dist/loader.cjs.map +1 -0
  64. package/dist/loader.d.ts +35 -0
  65. package/dist/loader.js +161 -0
  66. package/dist/loader.js.map +1 -0
  67. package/dist/logger.cjs +51 -0
  68. package/dist/logger.cjs.map +1 -0
  69. package/dist/logger.d.ts +11 -0
  70. package/dist/logger.js +46 -0
  71. package/dist/logger.js.map +1 -0
  72. package/dist/override.cjs +109 -0
  73. package/dist/override.cjs.map +1 -0
  74. package/dist/override.d.ts +31 -0
  75. package/dist/override.js +105 -0
  76. package/dist/override.js.map +1 -0
  77. package/dist/parse/markdown.cjs +114 -0
  78. package/dist/parse/markdown.cjs.map +1 -0
  79. package/dist/parse/markdown.d.ts +3 -0
  80. package/dist/parse/markdown.js +110 -0
  81. package/dist/parse/markdown.js.map +1 -0
  82. package/dist/parse/text.cjs +33 -0
  83. package/dist/parse/text.cjs.map +1 -0
  84. package/dist/parse/text.d.ts +3 -0
  85. package/dist/parse/text.js +29 -0
  86. package/dist/parse/text.js.map +1 -0
  87. package/dist/parser.cjs +99 -0
  88. package/dist/parser.cjs.map +1 -0
  89. package/dist/parser.d.ts +21 -0
  90. package/dist/parser.js +75 -0
  91. package/dist/parser.js.map +1 -0
  92. package/dist/prompt.cjs +15 -0
  93. package/dist/prompt.cjs.map +1 -0
  94. package/dist/prompt.d.ts +16 -0
  95. package/dist/prompt.js +11 -0
  96. package/dist/prompt.js.map +1 -0
  97. package/dist/riotprompt.cjs +1359 -0
  98. package/dist/riotprompt.cjs.map +1 -0
  99. package/dist/riotprompt.d.ts +25 -0
  100. package/dist/riotprompt.js +21 -0
  101. package/dist/riotprompt.js.map +1 -0
  102. package/dist/util/general.cjs +52 -0
  103. package/dist/util/general.cjs.map +1 -0
  104. package/dist/util/general.d.ts +4 -0
  105. package/dist/util/general.js +47 -0
  106. package/dist/util/general.js.map +1 -0
  107. package/dist/util/markdown.cjs +115 -0
  108. package/dist/util/markdown.cjs.map +1 -0
  109. package/dist/util/markdown.d.ts +7 -0
  110. package/dist/util/markdown.js +111 -0
  111. package/dist/util/markdown.js.map +1 -0
  112. package/dist/util/storage.cjs +155 -0
  113. package/dist/util/storage.cjs.map +1 -0
  114. package/dist/util/storage.d.ts +32 -0
  115. package/dist/util/storage.js +132 -0
  116. package/dist/util/storage.js.map +1 -0
  117. package/dist/util/text.cjs +42 -0
  118. package/dist/util/text.cjs.map +1 -0
  119. package/dist/util/text.d.ts +1 -0
  120. package/dist/util/text.js +38 -0
  121. package/dist/util/text.js.map +1 -0
  122. package/docs/loader.md +237 -0
  123. package/docs/override.md +323 -0
  124. package/docs/parser.md +130 -0
  125. package/eslint.config.mjs +82 -0
  126. package/nodemon.json +14 -0
  127. package/package.json +72 -0
  128. package/vite.config.ts +114 -0
  129. package/vitest.config.ts +25 -0
package/dist/loader.js ADDED
@@ -0,0 +1,161 @@
1
+ import path__default from 'path';
2
+ import { z } from 'zod';
3
+ import { DEFAULT_IGNORE_PATTERNS } from './constants.js';
4
+ import { ParametersSchema } from './items/parameters.js';
5
+ import { create as create$2, SectionOptionsSchema } from './items/section.js';
6
+ import { DEFAULT_LOGGER, wrapLogger } from './logger.js';
7
+ import './items/weighted.js';
8
+ import './formatter.js';
9
+ import './parser.js';
10
+ import './override.js';
11
+ import './builder.js';
12
+ import { create as create$1 } from './util/storage.js';
13
+
14
+ const OptionsSchema = z.object({
15
+ logger: z.any().optional().default(DEFAULT_LOGGER),
16
+ ignorePatterns: z.array(z.string()).optional().default(DEFAULT_IGNORE_PATTERNS),
17
+ parameters: ParametersSchema.optional().default({})
18
+ });
19
+ /**
20
+ * Extracts the first header from Markdown text
21
+ * @param markdownText The Markdown text to parse
22
+ * @returns The first header found in the Markdown or null if none is found
23
+ */ function extractFirstHeader(markdownText) {
24
+ // Regular expression to match Markdown headers (# Header, ## Header, etc.)
25
+ const headerRegex = /^(#{1,6})\s+(.+?)(?:\n|$)/m;
26
+ const match = markdownText.match(headerRegex);
27
+ if (match && match[2]) {
28
+ return match[2].trim();
29
+ }
30
+ return null;
31
+ }
32
+ /**
33
+ * Removes the first header from Markdown text
34
+ * @param markdownText The Markdown text to process
35
+ * @returns The Markdown text without the first header
36
+ */ function removeFirstHeader(markdownText) {
37
+ // Regular expression to match Markdown headers (# Header, ## Header, etc.)
38
+ const headerRegex = /^(#{1,6})\s+(.+?)(?:\n|$)/m;
39
+ const match = markdownText.match(headerRegex);
40
+ if (match) {
41
+ return markdownText.replace(headerRegex, '').trim();
42
+ }
43
+ return markdownText;
44
+ }
45
+ const create = (loaderOptions)=>{
46
+ const options = OptionsSchema.parse(loaderOptions || {});
47
+ const parameters = options.parameters;
48
+ const logger = wrapLogger(options.logger, 'Loader');
49
+ const ignorePatterns = options.ignorePatterns;
50
+ const loadOptions = (sectionOptions = {})=>{
51
+ const currentOptions = SectionOptionsSchema.parse(sectionOptions);
52
+ return {
53
+ ...currentOptions,
54
+ parameters: {
55
+ ...parameters,
56
+ ...currentOptions.parameters
57
+ }
58
+ };
59
+ };
60
+ /**
61
+ * Loads context from the provided directories and returns instruction sections
62
+ *
63
+ * @param contextDirectories Directories containing context files
64
+ * @returns Array of instruction sections loaded from context directories
65
+ */ const load = async (contextDirectories = [], options = {})=>{
66
+ const sectionOptions = loadOptions(options);
67
+ logger.debug(`Loading context from ${contextDirectories}`);
68
+ const contextSections = [];
69
+ if (!contextDirectories || contextDirectories.length === 0) {
70
+ logger.debug(`No context directories provided, returning empty context`);
71
+ return contextSections;
72
+ }
73
+ const storage = create$1({
74
+ log: logger.debug
75
+ });
76
+ // Add context sections from each directory
77
+ for (const contextDir of contextDirectories){
78
+ try {
79
+ const dirName = path__default.basename(contextDir);
80
+ logger.debug(`Processing context directory ${dirName}`);
81
+ let mainContextSection;
82
+ // First check if there's a context.md file
83
+ const contextFile = path__default.join(contextDir, 'context.md');
84
+ if (await storage.exists(contextFile)) {
85
+ logger.debug(`Found context.md file in ${contextDir}`);
86
+ const mainContextContent = await storage.readFile(contextFile, 'utf8');
87
+ // Extract the first header from the Markdown content
88
+ const firstHeader = extractFirstHeader(mainContextContent);
89
+ // Use the header from context.md as the section title, or fallback to directory name
90
+ const sectionTitle = firstHeader || dirName;
91
+ mainContextSection = create$2({
92
+ ...sectionOptions,
93
+ title: sectionTitle
94
+ });
95
+ // Add content without the header
96
+ if (firstHeader) {
97
+ mainContextSection.add(removeFirstHeader(mainContextContent), {
98
+ ...sectionOptions
99
+ });
100
+ } else {
101
+ mainContextSection.add(mainContextContent, {
102
+ ...sectionOptions
103
+ });
104
+ }
105
+ } else {
106
+ // If no context.md exists, use directory name as title
107
+ mainContextSection = create$2({
108
+ ...sectionOptions,
109
+ title: dirName
110
+ });
111
+ }
112
+ // Get all other files in the directory
113
+ const files = await storage.listFiles(contextDir);
114
+ const ignorePatternsRegex = ignorePatterns.map((pattern)=>new RegExp(pattern, 'i'));
115
+ const filteredFiles = files.filter((file)=>!ignorePatternsRegex.some((regex)=>regex.test(file)));
116
+ for (const file of filteredFiles){
117
+ // Skip the context.md file as it's already processed
118
+ if (file === 'context.md') continue;
119
+ logger.debug(`Processing file ${file} in ${contextDir}`);
120
+ const filePath = path__default.join(contextDir, file);
121
+ if (await storage.isFile(filePath)) {
122
+ const fileContent = await storage.readFile(filePath, 'utf8');
123
+ let sectionName = file;
124
+ let contentToAdd = fileContent;
125
+ // Extract header if it exists
126
+ if (file.endsWith('.md')) {
127
+ const fileHeader = extractFirstHeader(fileContent);
128
+ if (fileHeader) {
129
+ sectionName = fileHeader;
130
+ // Remove the header from the content
131
+ contentToAdd = removeFirstHeader(fileContent);
132
+ }
133
+ }
134
+ // Create a subsection with the extracted name
135
+ const fileSection = create$2({
136
+ ...sectionOptions,
137
+ title: sectionName
138
+ });
139
+ fileSection.add(contentToAdd, {
140
+ ...sectionOptions
141
+ });
142
+ // Add this file section to the main context section
143
+ mainContextSection.add(fileSection, {
144
+ ...sectionOptions
145
+ });
146
+ }
147
+ }
148
+ contextSections.push(mainContextSection);
149
+ } catch (error) {
150
+ logger.error(`Error processing context directory ${contextDir}: ${error}`);
151
+ }
152
+ }
153
+ return contextSections;
154
+ };
155
+ return {
156
+ load
157
+ };
158
+ };
159
+
160
+ export { create, extractFirstHeader, removeFirstHeader };
161
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sources":["../src/loader.ts"],"sourcesContent":["import path from \"path\";\nimport { z } from \"zod\";\nimport { DEFAULT_IGNORE_PATTERNS } from \"./constants\";\nimport { ParametersSchema } from \"./items/parameters\";\nimport { SectionOptions, SectionOptionsSchema } from \"./items/section\";\nimport { DEFAULT_LOGGER, wrapLogger } from \"./logger\";\nimport { Section, Weighted, createSection } from \"./riotprompt\";\nimport * as Storage from \"./util/storage\";\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n ignorePatterns: z.array(z.string()).optional().default(DEFAULT_IGNORE_PATTERNS),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n load: <T extends Weighted>(contextDirectories?: string[], options?: SectionOptions) => Promise<Section<T>[]>;\n}\n\n/**\n * Extracts the first header from Markdown text\n * @param markdownText The Markdown text to parse\n * @returns The first header found in the Markdown or null if none is found\n */\nexport function extractFirstHeader(markdownText: string): string | null {\n // Regular expression to match Markdown headers (# Header, ## Header, etc.)\n const headerRegex = /^(#{1,6})\\s+(.+?)(?:\\n|$)/m;\n const match = markdownText.match(headerRegex);\n\n if (match && match[2]) {\n return match[2].trim();\n }\n\n return null;\n}\n\n/**\n * Removes the first header from Markdown text\n * @param markdownText The Markdown text to process\n * @returns The Markdown text without the first header\n */\nexport function removeFirstHeader(markdownText: string): string {\n // Regular expression to match Markdown headers (# Header, ## Header, etc.)\n const headerRegex = /^(#{1,6})\\s+(.+?)(?:\\n|$)/m;\n const match = markdownText.match(headerRegex);\n\n if (match) {\n return markdownText.replace(headerRegex, '').trim();\n }\n\n return markdownText;\n}\n\nexport const create = (loaderOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(loaderOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Loader');\n const ignorePatterns = options.ignorePatterns;\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n /**\n * Loads context from the provided directories and returns instruction sections\n * \n * @param contextDirectories Directories containing context files\n * @returns Array of instruction sections loaded from context directories\n */\n const load = async<T extends Weighted>(\n contextDirectories: string[] = [],\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>[]> => {\n const sectionOptions = loadOptions(options);\n\n logger.debug(`Loading context from ${contextDirectories}`);\n const contextSections: Section<T>[] = [];\n\n if (!contextDirectories || contextDirectories.length === 0) {\n logger.debug(`No context directories provided, returning empty context`);\n return contextSections;\n }\n\n const storage = Storage.create({ log: logger.debug });\n\n // Add context sections from each directory\n for (const contextDir of contextDirectories) {\n try {\n const dirName = path.basename(contextDir);\n logger.debug(`Processing context directory ${dirName}`);\n let mainContextSection: Section<T>;\n\n // First check if there's a context.md file\n const contextFile = path.join(contextDir, 'context.md');\n\n if (await storage.exists(contextFile)) {\n logger.debug(`Found context.md file in ${contextDir}`);\n const mainContextContent = await storage.readFile(contextFile, 'utf8');\n // Extract the first header from the Markdown content\n const firstHeader = extractFirstHeader(mainContextContent);\n\n // Use the header from context.md as the section title, or fallback to directory name\n const sectionTitle = firstHeader || dirName;\n mainContextSection = createSection<T>({ ...sectionOptions, title: sectionTitle });\n\n // Add content without the header\n if (firstHeader) {\n mainContextSection.add(removeFirstHeader(mainContextContent), { ...sectionOptions });\n } else {\n mainContextSection.add(mainContextContent, { ...sectionOptions });\n }\n } else {\n // If no context.md exists, use directory name as title\n mainContextSection = createSection<T>({ ...sectionOptions, title: dirName });\n }\n\n // Get all other files in the directory\n const files = await storage.listFiles(contextDir);\n const ignorePatternsRegex = ignorePatterns.map(pattern => new RegExp(pattern, 'i'));\n\n const filteredFiles = files.filter(file =>\n !ignorePatternsRegex.some(regex => regex.test(file))\n );\n\n for (const file of filteredFiles) {\n // Skip the context.md file as it's already processed\n if (file === 'context.md') continue;\n\n logger.debug(`Processing file ${file} in ${contextDir}`);\n const filePath = path.join(contextDir, file);\n if (await storage.isFile(filePath)) {\n const fileContent = await storage.readFile(filePath, 'utf8');\n let sectionName = file;\n let contentToAdd = fileContent;\n\n // Extract header if it exists\n if (file.endsWith('.md')) {\n const fileHeader = extractFirstHeader(fileContent);\n if (fileHeader) {\n sectionName = fileHeader;\n // Remove the header from the content\n contentToAdd = removeFirstHeader(fileContent);\n }\n }\n\n // Create a subsection with the extracted name\n const fileSection = createSection<T>({ ...sectionOptions, title: sectionName });\n fileSection.add(contentToAdd, { ...sectionOptions });\n\n // Add this file section to the main context section\n mainContextSection.add(fileSection as unknown as T, { ...sectionOptions });\n }\n }\n\n contextSections.push(mainContextSection);\n } catch (error) {\n logger.error(`Error processing context directory ${contextDir}: ${error}`);\n }\n }\n\n return contextSections;\n }\n\n\n return {\n load\n }\n}\n"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","ignorePatterns","array","string","DEFAULT_IGNORE_PATTERNS","parameters","ParametersSchema","extractFirstHeader","markdownText","headerRegex","match","trim","removeFirstHeader","replace","create","loaderOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","load","contextDirectories","debug","contextSections","length","storage","Storage","log","contextDir","dirName","path","basename","mainContextSection","contextFile","join","exists","mainContextContent","readFile","firstHeader","sectionTitle","createSection","title","add","files","listFiles","ignorePatternsRegex","map","pattern","RegExp","filteredFiles","filter","file","some","regex","test","filePath","isFile","fileContent","sectionName","contentToAdd","endsWith","fileHeader","fileSection","push","error"],"mappings":";;;;;;;;;;;;;AASA,MAAMA,aAAAA,GAAgBC,CAAEC,CAAAA,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;IACnCC,cAAgBP,EAAAA,CAAAA,CAAEQ,KAAK,CAACR,CAAAA,CAAES,MAAM,EAAIL,CAAAA,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAACK,uBAAAA,CAAAA;AACvDC,IAAAA,UAAAA,EAAYC,gBAAiBR,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAUA;;;;IAKO,SAASQ,kBAAAA,CAAmBC,YAAoB,EAAA;;AAEnD,IAAA,MAAMC,WAAc,GAAA,4BAAA;IACpB,MAAMC,KAAAA,GAAQF,YAAaE,CAAAA,KAAK,CAACD,WAAAA,CAAAA;AAEjC,IAAA,IAAIC,KAASA,IAAAA,KAAK,CAAC,CAAA,CAAE,EAAE;AACnB,QAAA,OAAOA,KAAK,CAAC,CAAE,CAAA,CAACC,IAAI,EAAA;AACxB;IAEA,OAAO,IAAA;AACX;AAEA;;;;IAKO,SAASC,iBAAAA,CAAkBJ,YAAoB,EAAA;;AAElD,IAAA,MAAMC,WAAc,GAAA,4BA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YAAAA,GAAelD,iBAAkBgD,CAAAA,WAAAA,CAAAA;AACrC;AACJ;;AAGA,wBAAA,MAAMK,cAActB,QAAiB,CAAA;AAAE,4BAAA,GAAGvB,cAAc;4BAAEwB,KAAOiB,EAAAA;AAAY,yBAAA,CAAA;wBAC7EI,WAAYpB,CAAAA,GAAG,CAACiB,YAAc,EAAA;AAAE,4BAAA,GAAG1C;AAAe,yBAAA,CAAA;;wBAGlDe,kBAAmBU,CAAAA,GAAG,CAACoB,WAA6B,EAAA;AAAE,4BAAA,GAAG7C;AAAe,yBAAA,CAAA;AAC5E;AACJ;AAEAM,gBAAAA,eAAAA,CAAgBwC,IAAI,CAAC/B,kBAAAA,CAAAA;AACzB,aAAA,CAAE,OAAOgC,KAAO,EAAA;gBACZvE,MAAOuE,CAAAA,KAAK,CAAC,CAAC,mCAAmC,EAAEpC,UAAW,CAAA,EAAE,EAAEoC,KAAO,CAAA,CAAA,CAAA;AAC7E;AACJ;QAEA,OAAOzC,eAAAA;AACX,KAAA;IAGA,OAAO;AACHH,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const constants = require('./constants.cjs');
6
+
7
+ const DEFAULT_LOGGER = {
8
+ name: 'default',
9
+ debug: (message, ...args)=>console.debug(message, ...args),
10
+ info: (message, ...args)=>console.info(message, ...args),
11
+ warn: (message, ...args)=>console.warn(message, ...args),
12
+ error: (message, ...args)=>console.error(message, ...args),
13
+ verbose: (message, ...args)=>console.log(message, ...args),
14
+ silly: (message, ...args)=>console.log(message, ...args)
15
+ };
16
+ const wrapLogger = (toWrap, name)=>{
17
+ const requiredMethods = [
18
+ 'debug',
19
+ 'info',
20
+ 'warn',
21
+ 'error',
22
+ 'verbose',
23
+ 'silly'
24
+ ];
25
+ const missingMethods = requiredMethods.filter((method)=>typeof toWrap[method] !== 'function');
26
+ if (missingMethods.length > 0) {
27
+ throw new Error(`Logger is missing required methods: ${missingMethods.join(', ')}`);
28
+ }
29
+ const log = (level, message, ...args)=>{
30
+ message = `[${constants.LIBRARY_NAME}] ${name ? `[${name}]` : ''}: ${message}`;
31
+ if (level === 'debug') toWrap.debug(message, ...args);
32
+ else if (level === 'info') toWrap.info(message, ...args);
33
+ else if (level === 'warn') toWrap.warn(message, ...args);
34
+ else if (level === 'error') toWrap.error(message, ...args);
35
+ else if (level === 'verbose') toWrap.verbose(message, ...args);
36
+ else if (level === 'silly') toWrap.silly(message, ...args);
37
+ };
38
+ return {
39
+ name: 'wrapped',
40
+ debug: (message, ...args)=>log('debug', message, ...args),
41
+ info: (message, ...args)=>log('info', message, ...args),
42
+ warn: (message, ...args)=>log('warn', message, ...args),
43
+ error: (message, ...args)=>log('error', message, ...args),
44
+ verbose: (message, ...args)=>log('verbose', message, ...args),
45
+ silly: (message, ...args)=>log('silly', message, ...args)
46
+ };
47
+ };
48
+
49
+ exports.DEFAULT_LOGGER = DEFAULT_LOGGER;
50
+ exports.wrapLogger = wrapLogger;
51
+ //# sourceMappingURL=logger.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.cjs","sources":["../src/logger.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { LIBRARY_NAME } from \"./constants\";\n\nexport interface Logger {\n name: string;\n debug: (message: string, ...args: any[]) => void;\n info: (message: string, ...args: any[]) => void;\n warn: (message: string, ...args: any[]) => void;\n error: (message: string, ...args: any[]) => void;\n verbose: (message: string, ...args: any[]) => void;\n silly: (message: string, ...args: any[]) => void;\n}\n\nexport const DEFAULT_LOGGER: Logger = {\n name: 'default',\n debug: (message: string, ...args: any[]) => console.debug(message, ...args),\n info: (message: string, ...args: any[]) => console.info(message, ...args),\n warn: (message: string, ...args: any[]) => console.warn(message, ...args),\n error: (message: string, ...args: any[]) => console.error(message, ...args),\n verbose: (message: string, ...args: any[]) => console.log(message, ...args),\n silly: (message: string, ...args: any[]) => console.log(message, ...args),\n}\n\nexport const wrapLogger = (toWrap: Logger, name?: string): Logger => {\n\n const requiredMethods: (keyof Logger)[] = ['debug', 'info', 'warn', 'error', 'verbose', 'silly'];\n const missingMethods = requiredMethods.filter(method => typeof toWrap[method] !== 'function');\n\n if (missingMethods.length > 0) {\n throw new Error(`Logger is missing required methods: ${missingMethods.join(', ')}`);\n }\n\n const log = (level: keyof Logger, message: string, ...args: any[]) => {\n message = `[${LIBRARY_NAME}] ${name ? `[${name}]` : ''}: ${message}`;\n\n if (level === 'debug') toWrap.debug(message, ...args);\n else if (level === 'info') toWrap.info(message, ...args);\n else if (level === 'warn') toWrap.warn(message, ...args);\n else if (level === 'error') toWrap.error(message, ...args);\n else if (level === 'verbose') toWrap.verbose(message, ...args);\n else if (level === 'silly') toWrap.silly(message, ...args);\n }\n\n return {\n name: 'wrapped',\n debug: (message: string, ...args: any[]) => log('debug', message, ...args),\n info: (message: string, ...args: any[]) => log('info', message, ...args),\n warn: (message: string, ...args: any[]) => log('warn', message, ...args),\n error: (message: string, ...args: any[]) => log('error', message, ...args),\n verbose: (message: string, ...args: any[]) => log('verbose', message, ...args),\n silly: (message: string, ...args: any[]) => log('silly', message, ...args),\n }\n}"],"names":["DEFAULT_LOGGER","name","debug","message","args","console","info","warn","error","verbose","log","silly","wrapLogger","toWrap","requiredMethods","missingMethods","filter","method","length","Error","join","level","LIBRARY_NAME"],"mappings":";;;;;;MAaaA,cAAyB,GAAA;IAClCC,IAAM,EAAA,SAAA;AACNC,IAAAA,KAAAA,EAAO,CAACC,OAAiB,EAAA,GAAGC,OAAgBC,OAAQH,CAAAA,KAAK,CAACC,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACtEE,IAAAA,IAAAA,EAAM,CAACH,OAAiB,EAAA,GAAGC,OAAgBC,OAAQC,CAAAA,IAAI,CAACH,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACpEG,IAAAA,IAAAA,EAAM,CAACJ,OAAiB,EAAA,GAAGC,OAAgBC,OAAQE,C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A,GAAAA,CAAI,WAAWP,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACzEO,QAAAA,KAAAA,EAAO,CAACR,OAAiB,EAAA,GAAGC,IAAgBM,GAAAA,GAAAA,CAAI,SAASP,OAAYC,EAAAA,GAAAA,IAAAA;AACzE,KAAA;AACJ;;;;;"}
@@ -0,0 +1,11 @@
1
+ export interface Logger {
2
+ name: string;
3
+ debug: (message: string, ...args: any[]) => void;
4
+ info: (message: string, ...args: any[]) => void;
5
+ warn: (message: string, ...args: any[]) => void;
6
+ error: (message: string, ...args: any[]) => void;
7
+ verbose: (message: string, ...args: any[]) => void;
8
+ silly: (message: string, ...args: any[]) => void;
9
+ }
10
+ export declare const DEFAULT_LOGGER: Logger;
11
+ export declare const wrapLogger: (toWrap: Logger, name?: string) => Logger;
package/dist/logger.js ADDED
@@ -0,0 +1,46 @@
1
+ import { LIBRARY_NAME } from './constants.js';
2
+
3
+ const DEFAULT_LOGGER = {
4
+ name: 'default',
5
+ debug: (message, ...args)=>console.debug(message, ...args),
6
+ info: (message, ...args)=>console.info(message, ...args),
7
+ warn: (message, ...args)=>console.warn(message, ...args),
8
+ error: (message, ...args)=>console.error(message, ...args),
9
+ verbose: (message, ...args)=>console.log(message, ...args),
10
+ silly: (message, ...args)=>console.log(message, ...args)
11
+ };
12
+ const wrapLogger = (toWrap, name)=>{
13
+ const requiredMethods = [
14
+ 'debug',
15
+ 'info',
16
+ 'warn',
17
+ 'error',
18
+ 'verbose',
19
+ 'silly'
20
+ ];
21
+ const missingMethods = requiredMethods.filter((method)=>typeof toWrap[method] !== 'function');
22
+ if (missingMethods.length > 0) {
23
+ throw new Error(`Logger is missing required methods: ${missingMethods.join(', ')}`);
24
+ }
25
+ const log = (level, message, ...args)=>{
26
+ message = `[${LIBRARY_NAME}] ${name ? `[${name}]` : ''}: ${message}`;
27
+ if (level === 'debug') toWrap.debug(message, ...args);
28
+ else if (level === 'info') toWrap.info(message, ...args);
29
+ else if (level === 'warn') toWrap.warn(message, ...args);
30
+ else if (level === 'error') toWrap.error(message, ...args);
31
+ else if (level === 'verbose') toWrap.verbose(message, ...args);
32
+ else if (level === 'silly') toWrap.silly(message, ...args);
33
+ };
34
+ return {
35
+ name: 'wrapped',
36
+ debug: (message, ...args)=>log('debug', message, ...args),
37
+ info: (message, ...args)=>log('info', message, ...args),
38
+ warn: (message, ...args)=>log('warn', message, ...args),
39
+ error: (message, ...args)=>log('error', message, ...args),
40
+ verbose: (message, ...args)=>log('verbose', message, ...args),
41
+ silly: (message, ...args)=>log('silly', message, ...args)
42
+ };
43
+ };
44
+
45
+ export { DEFAULT_LOGGER, wrapLogger };
46
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sources":["../src/logger.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { LIBRARY_NAME } from \"./constants\";\n\nexport interface Logger {\n name: string;\n debug: (message: string, ...args: any[]) => void;\n info: (message: string, ...args: any[]) => void;\n warn: (message: string, ...args: any[]) => void;\n error: (message: string, ...args: any[]) => void;\n verbose: (message: string, ...args: any[]) => void;\n silly: (message: string, ...args: any[]) => void;\n}\n\nexport const DEFAULT_LOGGER: Logger = {\n name: 'default',\n debug: (message: string, ...args: any[]) => console.debug(message, ...args),\n info: (message: string, ...args: any[]) => console.info(message, ...args),\n warn: (message: string, ...args: any[]) => console.warn(message, ...args),\n error: (message: string, ...args: any[]) => console.error(message, ...args),\n verbose: (message: string, ...args: any[]) => console.log(message, ...args),\n silly: (message: string, ...args: any[]) => console.log(message, ...args),\n}\n\nexport const wrapLogger = (toWrap: Logger, name?: string): Logger => {\n\n const requiredMethods: (keyof Logger)[] = ['debug', 'info', 'warn', 'error', 'verbose', 'silly'];\n const missingMethods = requiredMethods.filter(method => typeof toWrap[method] !== 'function');\n\n if (missingMethods.length > 0) {\n throw new Error(`Logger is missing required methods: ${missingMethods.join(', ')}`);\n }\n\n const log = (level: keyof Logger, message: string, ...args: any[]) => {\n message = `[${LIBRARY_NAME}] ${name ? `[${name}]` : ''}: ${message}`;\n\n if (level === 'debug') toWrap.debug(message, ...args);\n else if (level === 'info') toWrap.info(message, ...args);\n else if (level === 'warn') toWrap.warn(message, ...args);\n else if (level === 'error') toWrap.error(message, ...args);\n else if (level === 'verbose') toWrap.verbose(message, ...args);\n else if (level === 'silly') toWrap.silly(message, ...args);\n }\n\n return {\n name: 'wrapped',\n debug: (message: string, ...args: any[]) => log('debug', message, ...args),\n info: (message: string, ...args: any[]) => log('info', message, ...args),\n warn: (message: string, ...args: any[]) => log('warn', message, ...args),\n error: (message: string, ...args: any[]) => log('error', message, ...args),\n verbose: (message: string, ...args: any[]) => log('verbose', message, ...args),\n silly: (message: string, ...args: any[]) => log('silly', message, ...args),\n }\n}"],"names":["DEFAULT_LOGGER","name","debug","message","args","console","info","warn","error","verbose","log","silly","wrapLogger","toWrap","requiredMethods","missingMethods","filter","method","length","Error","join","level","LIBRARY_NAME"],"mappings":";;MAaaA,cAAyB,GAAA;IAClCC,IAAM,EAAA,SAAA;AACNC,IAAAA,KAAAA,EAAO,CAACC,OAAiB,EAAA,GAAGC,OAAgBC,OAAQH,CAAAA,KAAK,CAACC,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACtEE,IAAAA,IAAAA,EAAM,CAACH,OAAiB,EAAA,GAAGC,OAAgBC,OAAQC,CAAAA,IAAI,CAACH,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACpEG,IAAAA,IAAAA,EAAM,CAACJ,OAAiB,EAAA,GAAGC,OAAgBC,OAAQE,CAAAA,IAAI,CAACJ,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACpEI,IAAAA,KAAAA,EAAO,CAACL,OAAiB,EAAA,GAAGC,OAAgBC,OAAQG,CAAAA,KAAK,CAACL,OAAYC,EAAAA,GAAAA,IAAAA,CAAAA;AACtEK,IAAAA,OAAAA,EAAS,CAACN,OAAiB,EAAA,GAAGC,OAAgBC,OAAQK,CAAAA,GAAG,CAACP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ag, { value: 'Module' });
4
+
5
+ const path = require('path');
6
+ const zod = require('zod');
7
+ const parameters = require('./items/parameters.cjs');
8
+ const section = require('./items/section.cjs');
9
+ const logger = require('./logger.cjs');
10
+ require('./items/weighted.cjs');
11
+ const formatter = require('./formatter.cjs');
12
+ const parser = require('./parser.cjs');
13
+ require('./loader.cjs');
14
+ require('./builder.cjs');
15
+ const storage = require('./util/storage.cjs');
16
+
17
+ const OptionsSchema = zod.z.object({
18
+ logger: zod.z.any().optional().default(logger.DEFAULT_LOGGER),
19
+ configDir: zod.z.string().default('./overrides'),
20
+ overrides: zod.z.boolean().default(false),
21
+ parameters: parameters.ParametersSchema.optional().default({})
22
+ });
23
+ const create = (overrideOptions = {})=>{
24
+ const options = OptionsSchema.parse(overrideOptions);
25
+ const parameters = options.parameters;
26
+ const logger$1 = logger.wrapLogger(options === null || options === void 0 ? void 0 : options.logger, 'Override');
27
+ const storage$1 = storage.create({
28
+ log: logger$1.debug
29
+ });
30
+ const loadOptions = (sectionOptions = {})=>{
31
+ const currentOptions = section.SectionOptionsSchema.parse(sectionOptions);
32
+ return {
33
+ ...currentOptions,
34
+ parameters: {
35
+ ...parameters,
36
+ ...currentOptions.parameters
37
+ }
38
+ };
39
+ };
40
+ const override = async (overrideFile, section, sectionOptions = {})=>{
41
+ const currentSectionOptions = loadOptions(sectionOptions);
42
+ const baseFile = path.join(options.configDir, overrideFile);
43
+ const preFile = baseFile.replace('.md', '-pre.md');
44
+ const postFile = baseFile.replace('.md', '-post.md');
45
+ const response = {};
46
+ if (await storage$1.exists(preFile)) {
47
+ logger$1.silly('Found pre file %s', preFile);
48
+ const parser$1 = parser.create({
49
+ logger: logger$1
50
+ });
51
+ response.prepend = await parser$1.parseFile(preFile, currentSectionOptions);
52
+ }
53
+ if (await storage$1.exists(postFile)) {
54
+ logger$1.silly('Found post file %s', postFile);
55
+ const parser$1 = parser.create({
56
+ logger: logger$1
57
+ });
58
+ response.append = await parser$1.parseFile(postFile, currentSectionOptions);
59
+ }
60
+ if (await storage$1.exists(baseFile)) {
61
+ logger$1.silly('Found base file %s', baseFile);
62
+ if (options.overrides) {
63
+ logger$1.warn('WARNING: Core directives are being overwritten by custom configuration');
64
+ const parser$1 = parser.create({
65
+ logger: logger$1
66
+ });
67
+ response.override = await parser$1.parseFile(baseFile, currentSectionOptions);
68
+ } else {
69
+ logger$1.error('ERROR: Core directives are being overwritten by custom configuration');
70
+ throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
71
+ }
72
+ }
73
+ return response;
74
+ };
75
+ const customize = async (overrideFile, section, sectionOptions = {})=>{
76
+ const currentSectionOptions = loadOptions(sectionOptions);
77
+ const { overrideContent, prepend, append } = await override(overrideFile, section, currentSectionOptions);
78
+ let finalSection = section;
79
+ if (overrideContent) {
80
+ if (options.overrides) {
81
+ logger$1.warn('Override found, replacing content from file %s', overrideContent);
82
+ finalSection = overrideContent;
83
+ } else {
84
+ logger$1.error('ERROR: Core directives are being overwritten by custom configuration');
85
+ throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
86
+ }
87
+ }
88
+ if (prepend) {
89
+ logger$1.silly('Prepend found, adding to content from file %s', prepend);
90
+ finalSection = finalSection.prepend(prepend);
91
+ }
92
+ if (append) {
93
+ logger$1.silly('Append found, adding to content from file %s', append);
94
+ finalSection = finalSection.append(append);
95
+ }
96
+ const formatter$1 = formatter.create({
97
+ logger: logger$1
98
+ });
99
+ logger$1.silly('Final section %s:\n\n%s\n\n', logger$1.name, formatter$1.format(finalSection));
100
+ return finalSection;
101
+ };
102
+ return {
103
+ override,
104
+ customize
105
+ };
106
+ };
107
+
108
+ exports.create = create;
109
+ //# sourceMappingURL=override.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"override.cjs","sources":["../src/override.ts"],"sourcesContent":["import path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { SectionOptions, SectionOptionsSchema } from './items/section';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { Formatter, Parser, Section, Weighted } from './riotprompt';\nimport * as Storage from './util/storage';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n configDir: z.string().default('./overrides'),\n overrides: z.boolean().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n customize: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<Section<T>>;\n override: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) =>\n Promise<{ override?: Section<T>, prepend?: Section<T>, append?: Section<T> }>;\n}\n\nexport const create = (overrideOptions: OptionsParam = {}): Instance => {\n const options: Required<Options> = OptionsSchema.parse(overrideOptions) as Required<Options>;\n\n const parameters = options.parameters;\n\n const logger = wrapLogger(options?.logger, 'Override');\n const storage = Storage.create({ log: logger.debug });\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const override = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<{ override?: Section<T>, prepend?: Section<T>, append?: Section<T> }> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const baseFile = path.join(options.configDir, overrideFile);\n const preFile = baseFile.replace('.md', '-pre.md');\n const postFile = baseFile.replace('.md', '-post.md');\n\n const response: { override?: Section<T>, prepend?: Section<T>, append?: Section<T> } = {};\n\n if (await storage.exists(preFile)) {\n logger.silly('Found pre file %s', preFile);\n const parser = Parser.create({ logger });\n response.prepend = await parser.parseFile<T>(preFile, currentSectionOptions);\n }\n\n if (await storage.exists(postFile)) {\n logger.silly('Found post file %s', postFile);\n const parser = Parser.create({ logger });\n response.append = await parser.parseFile<T>(postFile, currentSectionOptions);\n }\n\n if (await storage.exists(baseFile)) {\n logger.silly('Found base file %s', baseFile);\n if (options.overrides) {\n logger.warn('WARNING: Core directives are being overwritten by custom configuration');\n const parser = Parser.create({ logger });\n response.override = await parser.parseFile<T>(baseFile, currentSectionOptions);\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n return response;\n }\n\n const customize = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const { overrideContent, prepend, append }: { overrideContent?: Section<T>, prepend?: Section<T>, append?: Section<T> } = await override(overrideFile, section, currentSectionOptions);\n let finalSection: Section<T> = section;\n\n if (overrideContent) {\n if (options.overrides) {\n logger.warn('Override found, replacing content from file %s', overrideContent);\n finalSection = overrideContent;\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n if (prepend) {\n logger.silly('Prepend found, adding to content from file %s', prepend);\n finalSection = finalSection.prepend(prepend);\n }\n\n if (append) {\n logger.silly('Append found, adding to content from file %s', append);\n finalSection = finalSection.append(append);\n }\n\n const formatter = Formatter.create({ logger });\n logger.silly('Final section %s:\\n\\n%s\\n\\n', logger.name, formatter.format(finalSection));\n\n return finalSection;\n }\n\n return {\n override,\n customize,\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","configDir","string","overrides","boolean","parameters","ParametersSchema","create","overrideOptions","options","parse","wrapLogger","storage","Storage","log","debug","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","override","overrideFile","section","currentSectionOptions","baseFile","path","join","preFile","replace","postFile","response","exists","silly","parser","Parser","prepend","parseFile","append","war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AIE,MAAQ,EAAA;YACRzC,QAAOoC,CAAAA,KAAK,CAAC,8CAAgDK,EAAAA,MAAAA,CAAAA;YAC7DM,YAAeA,GAAAA,YAAAA,CAAaN,MAAM,CAACA,MAAAA,CAAAA;AACvC;QAEA,MAAMO,WAAAA,GAAYC,gBAAgB,CAAC;AAAEjD,oBAAAA;AAAO,SAAA,CAAA;QAC5CA,QAAOoC,CAAAA,KAAK,CAAC,6BAA+BpC,EAAAA,QAAAA,CAAOkD,IAAI,EAAEF,WAAAA,CAAUG,MAAM,CAACJ,YAAAA,CAAAA,CAAAA;QAE1E,OAAOA,YAAAA;AACX,KAAA;IAEA,OAAO;AACHvB,QAAAA,QAAAA;AACAqB,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -0,0 +1,31 @@
1
+ import { z } from 'zod';
2
+ import { SectionOptions } from './items/section';
3
+ import { Section, Weighted } from './riotprompt';
4
+ declare const OptionsSchema: z.ZodObject<{
5
+ logger: z.ZodDefault<z.ZodOptional<z.ZodAny>>;
6
+ configDir: z.ZodDefault<z.ZodString>;
7
+ overrides: z.ZodDefault<z.ZodBoolean>;
8
+ parameters: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, "many">]>>>>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ parameters: Record<string, string | number | boolean | (string | number | boolean)[]>;
11
+ configDir: string;
12
+ overrides: boolean;
13
+ logger?: any;
14
+ }, {
15
+ parameters?: Record<string, string | number | boolean | (string | number | boolean)[]> | undefined;
16
+ logger?: any;
17
+ configDir?: string | undefined;
18
+ overrides?: boolean | undefined;
19
+ }>;
20
+ export type Options = z.infer<typeof OptionsSchema>;
21
+ export type OptionsParam = Partial<Options>;
22
+ export interface Instance {
23
+ customize: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<Section<T>>;
24
+ override: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<{
25
+ override?: Section<T>;
26
+ prepend?: Section<T>;
27
+ append?: Section<T>;
28
+ }>;
29
+ }
30
+ export declare const create: (overrideOptions?: OptionsParam) => Instance;
31
+ export {};
@@ -0,0 +1,105 @@
1
+ import path__default from 'path';
2
+ import { z } from 'zod';
3
+ import { ParametersSchema } from './items/parameters.js';
4
+ import { SectionOptionsSchema } from './items/section.js';
5
+ import { DEFAULT_LOGGER, wrapLogger } from './logger.js';
6
+ import './items/weighted.js';
7
+ import { create as create$1 } from './formatter.js';
8
+ import { create as create$3 } from './parser.js';
9
+ import './loader.js';
10
+ import './builder.js';
11
+ import { create as create$2 } from './util/storage.js';
12
+
13
+ const OptionsSchema = z.object({
14
+ logger: z.any().optional().default(DEFAULT_LOGGER),
15
+ configDir: z.string().default('./overrides'),
16
+ overrides: z.boolean().default(false),
17
+ parameters: ParametersSchema.optional().default({})
18
+ });
19
+ const create = (overrideOptions = {})=>{
20
+ const options = OptionsSchema.parse(overrideOptions);
21
+ const parameters = options.parameters;
22
+ const logger = wrapLogger(options === null || options === void 0 ? void 0 : options.logger, 'Override');
23
+ const storage = create$2({
24
+ log: logger.debug
25
+ });
26
+ const loadOptions = (sectionOptions = {})=>{
27
+ const currentOptions = SectionOptionsSchema.parse(sectionOptions);
28
+ return {
29
+ ...currentOptions,
30
+ parameters: {
31
+ ...parameters,
32
+ ...currentOptions.parameters
33
+ }
34
+ };
35
+ };
36
+ const override = async (overrideFile, section, sectionOptions = {})=>{
37
+ const currentSectionOptions = loadOptions(sectionOptions);
38
+ const baseFile = path__default.join(options.configDir, overrideFile);
39
+ const preFile = baseFile.replace('.md', '-pre.md');
40
+ const postFile = baseFile.replace('.md', '-post.md');
41
+ const response = {};
42
+ if (await storage.exists(preFile)) {
43
+ logger.silly('Found pre file %s', preFile);
44
+ const parser$1 = create$3({
45
+ logger
46
+ });
47
+ response.prepend = await parser$1.parseFile(preFile, currentSectionOptions);
48
+ }
49
+ if (await storage.exists(postFile)) {
50
+ logger.silly('Found post file %s', postFile);
51
+ const parser$1 = create$3({
52
+ logger
53
+ });
54
+ response.append = await parser$1.parseFile(postFile, currentSectionOptions);
55
+ }
56
+ if (await storage.exists(baseFile)) {
57
+ logger.silly('Found base file %s', baseFile);
58
+ if (options.overrides) {
59
+ logger.warn('WARNING: Core directives are being overwritten by custom configuration');
60
+ const parser$1 = create$3({
61
+ logger
62
+ });
63
+ response.override = await parser$1.parseFile(baseFile, currentSectionOptions);
64
+ } else {
65
+ logger.error('ERROR: Core directives are being overwritten by custom configuration');
66
+ throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
67
+ }
68
+ }
69
+ return response;
70
+ };
71
+ const customize = async (overrideFile, section, sectionOptions = {})=>{
72
+ const currentSectionOptions = loadOptions(sectionOptions);
73
+ const { overrideContent, prepend, append } = await override(overrideFile, section, currentSectionOptions);
74
+ let finalSection = section;
75
+ if (overrideContent) {
76
+ if (options.overrides) {
77
+ logger.warn('Override found, replacing content from file %s', overrideContent);
78
+ finalSection = overrideContent;
79
+ } else {
80
+ logger.error('ERROR: Core directives are being overwritten by custom configuration');
81
+ throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');
82
+ }
83
+ }
84
+ if (prepend) {
85
+ logger.silly('Prepend found, adding to content from file %s', prepend);
86
+ finalSection = finalSection.prepend(prepend);
87
+ }
88
+ if (append) {
89
+ logger.silly('Append found, adding to content from file %s', append);
90
+ finalSection = finalSection.append(append);
91
+ }
92
+ const formatter$1 = create$1({
93
+ logger
94
+ });
95
+ logger.silly('Final section %s:\n\n%s\n\n', logger.name, formatter$1.format(finalSection));
96
+ return finalSection;
97
+ };
98
+ return {
99
+ override,
100
+ customize
101
+ };
102
+ };
103
+
104
+ export { create };
105
+ //# sourceMappingURL=override.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"override.js","sources":["../src/override.ts"],"sourcesContent":["import path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { SectionOptions, SectionOptionsSchema } from './items/section';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { Formatter, Parser, Section, Weighted } from './riotprompt';\nimport * as Storage from './util/storage';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n configDir: z.string().default('./overrides'),\n overrides: z.boolean().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n customize: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<Section<T>>;\n override: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) =>\n Promise<{ override?: Section<T>, prepend?: Section<T>, append?: Section<T> }>;\n}\n\nexport const create = (overrideOptions: OptionsParam = {}): Instance => {\n const options: Required<Options> = OptionsSchema.parse(overrideOptions) as Required<Options>;\n\n const parameters = options.parameters;\n\n const logger = wrapLogger(options?.logger, 'Override');\n const storage = Storage.create({ log: logger.debug });\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const override = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<{ override?: Section<T>, prepend?: Section<T>, append?: Section<T> }> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const baseFile = path.join(options.configDir, overrideFile);\n const preFile = baseFile.replace('.md', '-pre.md');\n const postFile = baseFile.replace('.md', '-post.md');\n\n const response: { override?: Section<T>, prepend?: Section<T>, append?: Section<T> } = {};\n\n if (await storage.exists(preFile)) {\n logger.silly('Found pre file %s', preFile);\n const parser = Parser.create({ logger });\n response.prepend = await parser.parseFile<T>(preFile, currentSectionOptions);\n }\n\n if (await storage.exists(postFile)) {\n logger.silly('Found post file %s', postFile);\n const parser = Parser.create({ logger });\n response.append = await parser.parseFile<T>(postFile, currentSectionOptions);\n }\n\n if (await storage.exists(baseFile)) {\n logger.silly('Found base file %s', baseFile);\n if (options.overrides) {\n logger.warn('WARNING: Core directives are being overwritten by custom configuration');\n const parser = Parser.create({ logger });\n response.override = await parser.parseFile<T>(baseFile, currentSectionOptions);\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n return response;\n }\n\n const customize = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const { overrideContent, prepend, append }: { overrideContent?: Section<T>, prepend?: Section<T>, append?: Section<T> } = await override(overrideFile, section, currentSectionOptions);\n let finalSection: Section<T> = section;\n\n if (overrideContent) {\n if (options.overrides) {\n logger.warn('Override found, replacing content from file %s', overrideContent);\n finalSection = overrideContent;\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n if (prepend) {\n logger.silly('Prepend found, adding to content from file %s', prepend);\n finalSection = finalSection.prepend(prepend);\n }\n\n if (append) {\n logger.silly('Append found, adding to content from file %s', append);\n finalSection = finalSection.append(append);\n }\n\n const formatter = Formatter.create({ logger });\n logger.silly('Final section %s:\\n\\n%s\\n\\n', logger.name, formatter.format(finalSection));\n\n return finalSection;\n }\n\n return {\n override,\n customize,\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","configDir","string","overrides","boolean","parameters","ParametersSchema","create","overrideOptions","options","parse","wrapLogger","storage","Storage","log","debug","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","override","overrideFile","section","currentSectionOptions","baseFile","path","join","preFile","replace","postFile","response","exists","silly","parser","Parser","prepend","parseFile","append","warn","error","Error","customize","overrideContent","finalSection","formatter","Formatter","name","format"],"mappings":";;;;;;;;;;;;AAQA,MAAMA,aAAAA,GAAgBC,CAAEC,CAAAA,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,SAAAA,EAAWP,CAAEQ,CAAAA,MAAM,EAAGH,CAAAA,OAAO,CAAC,aAAA,CAAA;AAC9BI,IAAAA,SAAAA,EAAWT,CAAEU,CAAAA,OAAO,EAAGL,CAAAA,OAAO,CAAC,KAAA,CAAA;AAC/BM,IAAAA,UAAAA,EAAYC,gBAAiBR,CAAAA,QAAQ,EAAGC,CAAAA,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAYaQ,MAAAA,MAAAA,GAAS,CAACC,eAAAA,GAAgC,EAAE,GAAA;IACrD,MAAMC,OAAAA,GAA6BhB,aAAciB,CAAAA,KAAK,CAACF,eAAAA,CAAAA;IAEvD,MAAMH,UAAAA,GAAaI,QAAQJ,UAAU;AAErC,IAAA,MAAMT,SAASe,UAAWF,CAAAA,OAAAA,KAAAA,IAAAA,IAAAA,OAAAA,KAAAA,MAAAA,GAAAA,MAAAA,GAAAA,OAAAA,CAASb,MAAM,EAAE,UAAA,CAAA;IAC3C,MAAMgB,OAAAA,GAAUC,QAAc,CAAC;AAAEC,QAAAA,GAAAA,EAAKlB,OAAOmB;AAAM,KAAA,CAAA;AAEnD,IAAA,MAAMC,WAAc,GAAA,CAACC,cAA0C,GAAA,EAAE,GAAA;QAC7D,MAAMC,cAAAA,GAAiBC,oBAAqBT,CAAAA,KAAK,CAACO,cAAAA,CAAAA;QAClD,OAAO;AACH,YAAA,GAAGC,cAAc;YACjBb,UAAY,EAAA;AACR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