@visulima/cerebro 3.0.0-alpha.6 → 3.0.0-alpha.8
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/CHANGELOG.md +40 -0
- package/LICENSE.md +24 -24
- package/dist/commands/completion-command.js +203 -5
- package/dist/commands/help-command.js +3 -1
- package/dist/commands/readme-command.js +330 -32
- package/dist/commands/version-command.js +18 -1
- package/dist/index.js +7 -1
- package/dist/logger/create-pail-logger.js +34 -1
- package/dist/packem_chunks/has-new-version.js +259 -1
- package/dist/packem_shared/Cerebro-C2mnCyQf.js +3313 -0
- package/dist/packem_shared/VERBOSITY_QUIET-Dp46zlLW.js +10 -0
- package/dist/packem_shared/VisulimaError-DA7QsCxH.js +34 -0
- package/dist/packem_shared/cerebro-error-GmJ3jN7Q.js +16 -0
- package/dist/packem_shared/help-command-BY7rQUvM.js +249 -0
- package/dist/packem_shared/index-C2-8b3A4.js +259 -0
- package/dist/packem_shared/runtime-process-B6ZplyWn.js +187 -0
- package/dist/plugins/error-handler-plugin.js +636 -24
- package/dist/plugins/runtime-version-check-plugin.js +77 -1
- package/dist/plugins/update-notifier/update-notifier-plugin.js +517 -1
- package/package.json +8 -7
- package/dist/packem_shared/Cerebro-CI6nbG1o.js +0 -4
- package/dist/packem_shared/VERBOSITY_QUIET-XPultrIA.js +0 -1
- package/dist/packem_shared/VisulimaError-rZ7cJo5A.js +0 -1
- package/dist/packem_shared/cerebro-error-CXXSmFtP.js +0 -1
- package/dist/packem_shared/help-command-CIRIXN03.js +0 -1
- package/dist/packem_shared/index-DQ3pvLQH.js +0 -6
- package/dist/packem_shared/runtime-process-G-n-wOub.js +0 -1
|
@@ -1,36 +1,265 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
existsSync
|
|
22
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
23
|
+
const {
|
|
24
|
+
readFile,
|
|
25
|
+
mkdir,
|
|
26
|
+
writeFile
|
|
27
|
+
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
28
|
+
const {
|
|
29
|
+
resolve,
|
|
30
|
+
join,
|
|
31
|
+
dirname
|
|
32
|
+
} = __cjs_getBuiltinModule("node:path");
|
|
33
|
+
import GithubSlugger from 'github-slugger';
|
|
34
|
+
import { c as commandLineUsage } from '../packem_shared/index-C2-8b3A4.js';
|
|
35
|
+
import { g as getCwd, a as getVersions, b as getPlatform, c as getArch } from '../packem_shared/runtime-process-B6ZplyWn.js';
|
|
36
|
+
|
|
37
|
+
const slugger = new GithubSlugger();
|
|
38
|
+
const slugify = slugger.slug;
|
|
39
|
+
const compact = (array) => array.filter(Boolean);
|
|
40
|
+
const uniqBy = (array, keyFunction) => {
|
|
41
|
+
const seen = /* @__PURE__ */ new Set();
|
|
42
|
+
const result = [];
|
|
43
|
+
for (const item of array) {
|
|
44
|
+
const key = keyFunction(item);
|
|
45
|
+
if (!seen.has(key)) {
|
|
46
|
+
seen.add(key);
|
|
47
|
+
result.push(item);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
const formatCommandUsage = (command, cliName) => {
|
|
53
|
+
const fullPath = command.commandPath ? [...command.commandPath, command.name] : [command.name];
|
|
54
|
+
const commandId = fullPath.join(" ");
|
|
55
|
+
if (command.argument) {
|
|
56
|
+
const argumentName = command.argument.name?.toUpperCase() ?? "ARG";
|
|
57
|
+
const argumentString = command.argument.required ? argumentName : `[${argumentName}]`;
|
|
58
|
+
return `${cliName} ${commandId} ${argumentString}`;
|
|
59
|
+
}
|
|
60
|
+
return `${cliName} ${commandId}`;
|
|
61
|
+
};
|
|
62
|
+
const addEnvironmentVariables = (command, usageGroups) => {
|
|
63
|
+
if (!Array.isArray(command.env) || command.env.length === 0) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const visibleEnvVariables = command.env.filter((envVariable) => !envVariable.hidden);
|
|
67
|
+
if (visibleEnvVariables.length > 0) {
|
|
68
|
+
usageGroups.push({
|
|
69
|
+
content: visibleEnvVariables.map((envVariable) => [envVariable.name, envVariable.description ?? ""]),
|
|
70
|
+
header: " Environment Variables "
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const formatCommandHelp = (command, cliName) => {
|
|
75
|
+
const usageGroups = [];
|
|
76
|
+
const fullCommandPath = command.commandPath ? [...command.commandPath, command.name] : [command.name];
|
|
77
|
+
const commandDisplay = fullCommandPath.join(" ");
|
|
78
|
+
const hasArgument = Boolean(command.argument);
|
|
79
|
+
const hasOptions = Boolean(command.options);
|
|
80
|
+
usageGroups.push({
|
|
81
|
+
content: `${cliName} ${commandDisplay}${hasArgument ? " [positional arguments]" : ""}${hasOptions ? " [options]" : ""}`,
|
|
82
|
+
header: " Usage "
|
|
83
|
+
});
|
|
84
|
+
if (command.description) {
|
|
85
|
+
usageGroups.push({ content: command.description, header: " Description " });
|
|
86
|
+
}
|
|
87
|
+
if (command.argument) {
|
|
88
|
+
usageGroups.push({ header: "Command Positional Arguments", isArgument: true, optionList: [command.argument] });
|
|
89
|
+
}
|
|
90
|
+
if (Array.isArray(command.options) && command.options.length > 0) {
|
|
91
|
+
usageGroups.push({
|
|
92
|
+
header: " Command Options ",
|
|
93
|
+
optionList: command.options.filter(
|
|
94
|
+
(option) => typeof option === "object" && option !== null && (!("hidden" in option) || !option.hidden)
|
|
95
|
+
)
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
addEnvironmentVariables(command, usageGroups);
|
|
99
|
+
if (command.alias !== void 0 && command.alias.length > 0) {
|
|
100
|
+
const alias = Array.isArray(command.alias) ? command.alias : [command.alias];
|
|
101
|
+
usageGroups.splice(1, 0, {
|
|
102
|
+
content: alias,
|
|
103
|
+
header: "Alias(es)"
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(command.examples) && command.examples.length > 0) {
|
|
107
|
+
usageGroups.push({
|
|
108
|
+
content: command.examples,
|
|
109
|
+
header: "Examples"
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return commandLineUsage(usageGroups);
|
|
113
|
+
};
|
|
114
|
+
const renderCommand = (command, cliName) => {
|
|
115
|
+
const title = command.description?.trim().split("\n")[0] ?? "";
|
|
116
|
+
const usage = formatCommandUsage(command, cliName);
|
|
117
|
+
const helpText = formatCommandHelp(command, cliName);
|
|
118
|
+
return compact([`## \`${usage}\``, title, `\`\`\`
|
|
119
|
+
${helpText.trim()}
|
|
120
|
+
\`\`\``]).join("\n\n");
|
|
121
|
+
};
|
|
122
|
+
const generateUsage = (cliName, packageName, version, nodeVersion) => {
|
|
123
|
+
const versionFlags = ["--version", "-V"];
|
|
124
|
+
const versionFlagsString = `(${versionFlags.join("|")})`;
|
|
125
|
+
const platform = getPlatform();
|
|
126
|
+
const arch = getArch();
|
|
127
|
+
return `\`\`\`sh-session
|
|
128
|
+
$ npm install -g ${packageName}
|
|
129
|
+
$ ${cliName} COMMAND
|
|
9
130
|
running command...
|
|
10
|
-
$ ${
|
|
11
|
-
${
|
|
12
|
-
$ ${
|
|
131
|
+
$ ${cliName} ${versionFlagsString}
|
|
132
|
+
${packageName}/${version ?? "unknown"} ${platform}-${arch} node-v${nodeVersion}
|
|
133
|
+
$ ${cliName} --help [COMMAND]
|
|
13
134
|
USAGE
|
|
14
|
-
$ ${
|
|
135
|
+
$ ${cliName} COMMAND
|
|
15
136
|
...
|
|
16
137
|
\`\`\`
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
`)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
138
|
+
`;
|
|
139
|
+
};
|
|
140
|
+
const generateCommands = async (commands, cliName, _options) => {
|
|
141
|
+
const commandList = await Promise.all(
|
|
142
|
+
commands.map(async (command) => {
|
|
143
|
+
const usage = formatCommandUsage(command, cliName);
|
|
144
|
+
return `* [\`${usage}\`](#${await slugify(usage)})`;
|
|
145
|
+
})
|
|
146
|
+
);
|
|
147
|
+
const commandDocumentation = commands.map((command) => renderCommand(command, cliName)).map((s) => `${s.trim()}
|
|
148
|
+
`);
|
|
149
|
+
return [...commandList, "", ...commandDocumentation].join("\n").trim();
|
|
150
|
+
};
|
|
151
|
+
const writeFileWithDirectory = async (filePath, content) => {
|
|
152
|
+
const directory = dirname(filePath);
|
|
153
|
+
if (!existsSync(directory)) {
|
|
154
|
+
await mkdir(directory, { recursive: true });
|
|
155
|
+
}
|
|
156
|
+
await writeFile(filePath, content, "utf8");
|
|
157
|
+
};
|
|
158
|
+
const generateMultiCommands = async (commands, outputDirectory, cliName, options) => {
|
|
159
|
+
const groupedCommands = /* @__PURE__ */ new Map();
|
|
160
|
+
for (const command of commands) {
|
|
161
|
+
const group = command.group ?? "__Other";
|
|
162
|
+
const groupCommands = groupedCommands.get(group) ?? [];
|
|
163
|
+
groupCommands.push(command);
|
|
164
|
+
groupedCommands.set(group, groupCommands);
|
|
165
|
+
}
|
|
166
|
+
const groups = [...groupedCommands.entries()].map(([group, groupCommands]) => {
|
|
167
|
+
if (group === "__Other") {
|
|
168
|
+
return ["Other", groupCommands];
|
|
169
|
+
}
|
|
170
|
+
return [group, groupCommands];
|
|
171
|
+
});
|
|
172
|
+
await Promise.all(
|
|
173
|
+
groups.map(async ([group, groupCommands]) => {
|
|
174
|
+
const groupPath = group.replaceAll(":", "/");
|
|
175
|
+
const filePath = join(".", outputDirectory, `${groupPath}.md`);
|
|
176
|
+
const bin = `\`${cliName} ${group}\``;
|
|
177
|
+
const document = `${[
|
|
178
|
+
bin,
|
|
179
|
+
"=".repeat(bin.length),
|
|
180
|
+
"",
|
|
181
|
+
`Commands in the ${group} group.`,
|
|
182
|
+
"",
|
|
183
|
+
await generateCommands(groupCommands, cliName)
|
|
184
|
+
].join("\n").trim()}
|
|
185
|
+
`;
|
|
186
|
+
if (!options.dryRun) {
|
|
187
|
+
await writeFileWithDirectory(resolve(getCwd(), filePath), document);
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
const topicLinks = groups.map(([group]) => {
|
|
192
|
+
const groupPath = group.replaceAll(":", "/");
|
|
193
|
+
return `* [\`${cliName} ${group}\`](${outputDirectory}/${groupPath}.md)`;
|
|
194
|
+
});
|
|
195
|
+
return `${["# Command Topics\n", ...topicLinks].join("\n").trim()}
|
|
196
|
+
`;
|
|
197
|
+
};
|
|
198
|
+
const normalizeLineEndings = (text) => text.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
|
|
199
|
+
const generateTableOfContents = async (readme) => {
|
|
200
|
+
const normalizedReadme = normalizeLineEndings(readme);
|
|
201
|
+
const toc = await Promise.all(
|
|
202
|
+
normalizedReadme.split("\n").filter((line) => line.startsWith("# ")).map((line) => line.trim().slice(2)).map(async (line) => `* [${line}](#${await slugify(line)})`)
|
|
203
|
+
);
|
|
204
|
+
return toc.join("\n");
|
|
205
|
+
};
|
|
206
|
+
const escapeRegex = (string_) => string_.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
|
|
207
|
+
const replaceTag = (readme, tag, body) => {
|
|
208
|
+
const normalizedReadme = normalizeLineEndings(readme);
|
|
209
|
+
const tagStart = `<!-- ${tag} -->`;
|
|
210
|
+
const tagStop = `<!-- ${tag}stop -->`;
|
|
211
|
+
if (normalizedReadme.includes(tagStart) && normalizedReadme.includes(tagStop)) {
|
|
212
|
+
const escapedStart = escapeRegex(tagStart);
|
|
213
|
+
const escapedStop = escapeRegex(tagStop);
|
|
214
|
+
const tagPattern = new RegExp(String.raw`${escapedStart}(.|\n)*${escapedStop}`, "m");
|
|
215
|
+
return normalizedReadme.replace(tagPattern, `${tagStart}
|
|
216
|
+
${body}
|
|
217
|
+
${tagStop}`);
|
|
218
|
+
}
|
|
219
|
+
return normalizedReadme.replace(tagStart, `${tagStart}
|
|
220
|
+
${body}
|
|
221
|
+
${tagStop}`);
|
|
222
|
+
};
|
|
223
|
+
const readmeCommand = {
|
|
224
|
+
description: "Generate README documentation for CLI commands",
|
|
225
|
+
execute: async ({ logger, options, runtime }) => {
|
|
226
|
+
const cliName = runtime.getCliName();
|
|
227
|
+
const packageName = runtime.getPackageName() ?? cliName;
|
|
228
|
+
const packageVersion = runtime.getPackageVersion();
|
|
229
|
+
const versions = getVersions();
|
|
230
|
+
const nodeVersion = versions.node ?? "unknown";
|
|
231
|
+
const readmeOptions = {
|
|
232
|
+
aliases: options?.aliases,
|
|
233
|
+
dryRun: options?.dryRun,
|
|
234
|
+
multi: options?.multi,
|
|
235
|
+
outputDir: options?.outputDir ?? "docs",
|
|
236
|
+
readmePath: options?.readmePath ?? "README.md",
|
|
237
|
+
version: options?.version ?? packageVersion ?? void 0
|
|
238
|
+
};
|
|
239
|
+
const commandsMap = runtime.getCommands();
|
|
240
|
+
const commands = [...commandsMap.values()].filter((c) => !c.hidden).filter((c) => {
|
|
241
|
+
if (readmeOptions.aliases) {
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
return c.name === commandsMap.get(c.name)?.name;
|
|
245
|
+
}).toSorted((a, b) => {
|
|
246
|
+
const aPath = a.commandPath ? [...a.commandPath, a.name].join(" ") : a.name;
|
|
247
|
+
const bPath = b.commandPath ? [...b.commandPath, b.name].join(" ") : b.name;
|
|
248
|
+
return aPath.localeCompare(bPath);
|
|
249
|
+
});
|
|
250
|
+
const uniqueCommands = uniqBy(commands, (c) => {
|
|
251
|
+
const path = c.commandPath ? [...c.commandPath, c.name].join(" ") : c.name;
|
|
252
|
+
return path;
|
|
253
|
+
});
|
|
254
|
+
logger.debug(`Processing ${uniqueCommands.length} commands for README generation`);
|
|
255
|
+
let readme;
|
|
256
|
+
const readmePath = resolve(getCwd(), readmeOptions.readmePath ?? "README.md");
|
|
257
|
+
if (existsSync(readmePath)) {
|
|
258
|
+
const rawReadme = await readFile(readmePath, "utf8");
|
|
259
|
+
readme = normalizeLineEndings(rawReadme);
|
|
260
|
+
} else {
|
|
261
|
+
logger.warn(`README file not found at ${readmePath}, creating template`);
|
|
262
|
+
readme = `# ${packageName}
|
|
34
263
|
|
|
35
264
|
<!-- usage -->
|
|
36
265
|
<!-- usagestop -->
|
|
@@ -40,6 +269,75 @@ ${i}`)},"replaceTag"),se={description:"Generate README documentation for CLI com
|
|
|
40
269
|
|
|
41
270
|
<!-- toc -->
|
|
42
271
|
<!-- tocstop -->
|
|
43
|
-
`;
|
|
44
|
-
|
|
45
|
-
|
|
272
|
+
`;
|
|
273
|
+
}
|
|
274
|
+
const outputDirectory = readmeOptions.outputDir ?? "docs";
|
|
275
|
+
const version = readmeOptions.version ?? packageVersion ?? "unknown";
|
|
276
|
+
readme = replaceTag(readme, "usage", generateUsage(cliName, packageName, version, nodeVersion));
|
|
277
|
+
readme = replaceTag(
|
|
278
|
+
readme,
|
|
279
|
+
"commands",
|
|
280
|
+
readmeOptions.multi ? await generateMultiCommands(uniqueCommands, outputDirectory, cliName, readmeOptions) : await generateCommands(uniqueCommands, cliName)
|
|
281
|
+
);
|
|
282
|
+
readme = replaceTag(readme, "toc", await generateTableOfContents(readme));
|
|
283
|
+
readme = `${readme.trimEnd()}
|
|
284
|
+
`;
|
|
285
|
+
if (readmeOptions.dryRun) {
|
|
286
|
+
logger.info("Dry run mode - README not written");
|
|
287
|
+
logger.info(`Generated README content:
|
|
288
|
+
${readme}`);
|
|
289
|
+
} else {
|
|
290
|
+
await writeFileWithDirectory(readmePath, readme);
|
|
291
|
+
logger.info(`README generated successfully at ${readmePath}`);
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
name: "readme",
|
|
295
|
+
options: [
|
|
296
|
+
{
|
|
297
|
+
description: "Include aliases in command list",
|
|
298
|
+
name: "aliases",
|
|
299
|
+
type: Boolean
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
description: "Show what would be generated without writing files",
|
|
303
|
+
name: "dry-run",
|
|
304
|
+
type: Boolean
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
description: "Generate multi-file documentation by command groups",
|
|
308
|
+
name: "multi",
|
|
309
|
+
type: Boolean
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
description: "Maximum depth for nested topics when using multi-file mode",
|
|
313
|
+
name: "nested-topics-depth",
|
|
314
|
+
type: Number
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
description: "Output directory for multi-file documentation",
|
|
318
|
+
name: "output-dir",
|
|
319
|
+
type: String,
|
|
320
|
+
typeLabel: "{underline directory}"
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
description: "Path to README file to generate",
|
|
324
|
+
name: "readme-path",
|
|
325
|
+
type: String,
|
|
326
|
+
typeLabel: "{underline path}"
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
description: "Repository prefix for code links",
|
|
330
|
+
name: "repository-prefix",
|
|
331
|
+
type: String,
|
|
332
|
+
typeLabel: "{underline prefix}"
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
description: "Version to use in generated documentation",
|
|
336
|
+
name: "version",
|
|
337
|
+
type: String,
|
|
338
|
+
typeLabel: "{underline version}"
|
|
339
|
+
}
|
|
340
|
+
]
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
export { readmeCommand as default };
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
const versionCommand = {
|
|
2
|
+
alias: ["v", "V"],
|
|
3
|
+
description: "Output the version number",
|
|
4
|
+
execute: ({ logger, runtime }) => {
|
|
5
|
+
const version = runtime.getPackageVersion();
|
|
6
|
+
if (version === void 0) {
|
|
7
|
+
logger.warn("Unknown version");
|
|
8
|
+
logger.debug("The version number was not provided by the cli constructor.");
|
|
9
|
+
} else {
|
|
10
|
+
logger.info(version);
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
name: "version",
|
|
14
|
+
options: [],
|
|
15
|
+
usage: []
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { versionCommand as default };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { Cli } from './packem_shared/Cerebro-C2mnCyQf.js';
|
|
2
|
+
export { VERBOSITY_DEBUG, VERBOSITY_NORMAL, VERBOSITY_QUIET, VERBOSITY_VERBOSE } from './packem_shared/VERBOSITY_QUIET-Dp46zlLW.js';
|
|
3
|
+
export { VisulimaError } from './packem_shared/VisulimaError-DA7QsCxH.js';
|
|
4
|
+
|
|
5
|
+
const createCerebro = (name, options) => new Cli(name, options);
|
|
6
|
+
|
|
7
|
+
export { Cli as Cerebro, createCerebro };
|
|
@@ -1 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
import CallerProcessor from '@visulima/pail/processor/caller';
|
|
2
|
+
import MessageFormatterProcessor from '@visulima/pail/processor/message-formatter';
|
|
3
|
+
import { createPail } from '@visulima/pail/server';
|
|
4
|
+
import { VERBOSITY_DEBUG, VERBOSITY_QUIET } from '../packem_shared/VERBOSITY_QUIET-Dp46zlLW.js';
|
|
5
|
+
import { d as getEnv } from '../packem_shared/runtime-process-B6ZplyWn.js';
|
|
6
|
+
|
|
7
|
+
const createPailLogger = (options) => {
|
|
8
|
+
const cerebroLevelToPailLevel = {
|
|
9
|
+
16: "informational",
|
|
10
|
+
32: "informational",
|
|
11
|
+
64: "trace",
|
|
12
|
+
128: "debug",
|
|
13
|
+
256: "debug"
|
|
14
|
+
};
|
|
15
|
+
const processors = [new MessageFormatterProcessor()];
|
|
16
|
+
const env = getEnv();
|
|
17
|
+
const outputLevel = env.CEREBRO_OUTPUT_LEVEL;
|
|
18
|
+
if (outputLevel === String(128) || outputLevel === String(VERBOSITY_DEBUG)) {
|
|
19
|
+
processors.push(new CallerProcessor());
|
|
20
|
+
}
|
|
21
|
+
const envLogLevel = outputLevel && cerebroLevelToPailLevel[outputLevel] || "informational";
|
|
22
|
+
const loggerOptions = {
|
|
23
|
+
...options,
|
|
24
|
+
logLevel: options?.logLevel ?? envLogLevel,
|
|
25
|
+
processors: options?.processors ? [...processors, ...options.processors] : processors
|
|
26
|
+
};
|
|
27
|
+
const logger = createPail(loggerOptions);
|
|
28
|
+
if (outputLevel === String(VERBOSITY_QUIET)) {
|
|
29
|
+
logger.disable();
|
|
30
|
+
}
|
|
31
|
+
return logger;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { createPailLogger as default };
|