@kubb/cli 4.3.1 → 4.4.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/{chunk-DWy1uDak.cjs → chunk-CUT6urMc.cjs} +0 -9
- package/dist/{generate-BvnEYuGd.cjs → generate-C-LME3FT.cjs} +4 -4
- package/dist/generate-C-LME3FT.cjs.map +1 -0
- package/dist/generate-CUHrQxq3.cjs +280 -0
- package/dist/generate-CUHrQxq3.cjs.map +1 -0
- package/dist/generate-ChOKW4hA.js +271 -0
- package/dist/generate-ChOKW4hA.js.map +1 -0
- package/dist/{generate-MZHwytlj.js → generate-to5Shevn.js} +3 -3
- package/dist/generate-to5Shevn.js.map +1 -0
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/{mcp-CLmIdoaC.cjs → mcp-cORMfOlp.cjs} +2 -2
- package/dist/{mcp-CLmIdoaC.cjs.map → mcp-cORMfOlp.cjs.map} +1 -1
- package/dist/{validate-DNbDDWp4.cjs → validate-CvKz5F6R.cjs} +2 -2
- package/dist/{validate-DNbDDWp4.cjs.map → validate-CvKz5F6R.cjs.map} +1 -1
- package/package.json +5 -5
- package/src/runners/generate.ts +8 -6
- package/src/utils/getCosmiConfig.ts +1 -1
- package/dist/generate-BvnEYuGd.cjs.map +0 -1
- package/dist/generate-Cc3YLh0Y.js +0 -6632
- package/dist/generate-Cc3YLh0Y.js.map +0 -1
- package/dist/generate-MZHwytlj.js.map +0 -1
- package/dist/generate-z0xL-KdK.cjs +0 -6624
- package/dist/generate-z0xL-KdK.cjs.map +0 -1
|
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJS = (cb, mod) => function() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
8
|
var __copyProps = (to, from, except, desc) => {
|
|
12
9
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
10
|
key = keys[i];
|
|
@@ -25,12 +22,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
22
|
|
|
26
23
|
//#endregion
|
|
27
24
|
|
|
28
|
-
Object.defineProperty(exports, '__commonJS', {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
get: function () {
|
|
31
|
-
return __commonJS;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
25
|
Object.defineProperty(exports, '__toESM', {
|
|
35
26
|
enumerable: true,
|
|
36
27
|
get: function () {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
2
|
let citty = require("citty");
|
|
3
3
|
citty = require_chunk.__toESM(citty);
|
|
4
4
|
let node_path = require("node:path");
|
|
@@ -71,7 +71,7 @@ const tsLoader = async (configFile) => {
|
|
|
71
71
|
return await (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, {
|
|
72
72
|
jsx: {
|
|
73
73
|
runtime: "automatic",
|
|
74
|
-
importSource: "@kubb/react"
|
|
74
|
+
importSource: "@kubb/react-fabric"
|
|
75
75
|
},
|
|
76
76
|
sourceMaps: true
|
|
77
77
|
}).import(configFile, { default: true });
|
|
@@ -174,7 +174,7 @@ const command = (0, citty.defineCommand)({
|
|
|
174
174
|
if (args.help) return (0, citty.showUsage)(command);
|
|
175
175
|
if (args.debug) args.logLevel = "debug";
|
|
176
176
|
const logger = (0, __kubb_core_logger.createLogger)({ logLevel: __kubb_core_logger.LogMapper[args.logLevel] || 3 });
|
|
177
|
-
const { generate } = await Promise.resolve().then(() => require("./generate-
|
|
177
|
+
const { generate } = await Promise.resolve().then(() => require("./generate-CUHrQxq3.cjs"));
|
|
178
178
|
logger.emit("start", "Loading config");
|
|
179
179
|
const result = await getCosmiConfig("kubb", args.config);
|
|
180
180
|
logger.emit("success", `Config loaded(${picocolors.default.dim(node_path.default.relative(node_process.cwd(), result.filepath))})`);
|
|
@@ -221,4 +221,4 @@ var generate_default = command;
|
|
|
221
221
|
|
|
222
222
|
//#endregion
|
|
223
223
|
exports.default = generate_default;
|
|
224
|
-
//# sourceMappingURL=generate-
|
|
224
|
+
//# sourceMappingURL=generate-C-LME3FT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-C-LME3FT.cjs","names":["results: Array<Config>","path","pc","LogMapper","pc","path","process","PromiseManager"],"sources":["../src/utils/getPlugins.ts","../src/utils/getConfig.ts","../src/utils/getCosmiConfig.ts","../src/utils/watcher.ts","../src/commands/generate.ts"],"sourcesContent":["import type { UserConfig } from '@kubb/core'\n\nfunction isJSONPlugins(plugins: UserConfig['plugins']) {\n return !!(plugins as any)?.some((plugin: any) => {\n return Array.isArray(plugin) && typeof plugin?.at(0) === 'string'\n })\n}\n\nfunction isObjectPlugins(plugins: UserConfig['plugins']): plugins is any {\n return plugins instanceof Object && !Array.isArray(plugins)\n}\n\nexport function getPlugins(plugins: UserConfig['plugins']): Promise<UserConfig['plugins']> {\n if (isObjectPlugins(plugins)) {\n throw new Error('Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')\n }\n\n if (isJSONPlugins(plugins)) {\n throw new Error('JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')\n }\n\n return Promise.resolve(plugins)\n}\n","import { isPromise } from '@kubb/core/utils'\n\nimport { getPlugins } from './getPlugins.ts'\n\nimport type { Config, UserConfig } from '@kubb/core'\nimport type { Args } from '../commands/generate.ts'\nimport type { CosmiconfigResult } from './getCosmiConfig.ts'\n\n/**\n * Converting UserConfig to Config without a change in the object beside the JSON convert.\n */\nexport async function getConfig(result: CosmiconfigResult, args: Args): Promise<Array<Config> | Config> {\n const config = result?.config\n let kubbUserConfig = Promise.resolve(config) as Promise<UserConfig | Array<UserConfig>>\n\n // for ts or js files\n if (typeof config === 'function') {\n const possiblePromise = config(args)\n if (isPromise(possiblePromise)) {\n kubbUserConfig = possiblePromise\n }\n kubbUserConfig = Promise.resolve(possiblePromise)\n }\n\n let JSONConfig = await kubbUserConfig\n\n if (Array.isArray(JSONConfig)) {\n const results: Array<Config> = []\n\n for (const item of JSONConfig) {\n const plugins = item.plugins ? await getPlugins(item.plugins) : undefined\n\n results.push({\n ...item,\n plugins,\n } as Config)\n }\n\n return results\n }\n\n JSONConfig = {\n ...JSONConfig,\n plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : undefined,\n }\n\n return JSONConfig as Config\n}\n","import type { defineConfig, UserConfig } from '@kubb/core'\nimport { cosmiconfig } from 'cosmiconfig'\nimport { createJiti } from 'jiti'\n\nexport type CosmiconfigResult = {\n filepath: string\n isEmpty?: boolean\n config: ReturnType<typeof defineConfig> | UserConfig\n}\n\nconst tsLoader = async (configFile: string) => {\n const jiti = createJiti(import.meta.url, {\n jsx: {\n runtime: 'automatic',\n importSource: '@kubb/react-fabric',\n },\n sourceMaps: true,\n })\n\n const mod = await jiti.import(configFile, { default: true })\n\n return mod\n}\n\nexport async function getCosmiConfig(moduleName: string, config?: string): Promise<CosmiconfigResult> {\n const searchPlaces = [\n 'package.json',\n `.${moduleName}rc`,\n `.${moduleName}rc.json`,\n `.${moduleName}rc.yaml`,\n `.${moduleName}rc.yml`,\n\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.js`,\n `.${moduleName}rc.mjs`,\n `.${moduleName}rc.cjs`,\n\n `${moduleName}.config.ts`,\n `${moduleName}.config.js`,\n `${moduleName}.config.mjs`,\n `${moduleName}.config.cjs`,\n ]\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n searchPlaces: [\n ...searchPlaces.map((searchPlace) => {\n return `.config/${searchPlace}`\n }),\n ...searchPlaces.map((searchPlace) => {\n return `configs/${searchPlace}`\n }),\n ...searchPlaces,\n ],\n loaders: {\n '.ts': tsLoader,\n },\n })\n\n const result = config ? await explorer.load(config) : await explorer.search()\n\n if (result?.isEmpty || !result || !result.config) {\n throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')\n }\n\n return result as CosmiconfigResult\n}\n","import { createLogger } from '@kubb/core/logger'\nimport pc from 'picocolors'\n\nexport async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {\n const { watch } = await import('chokidar')\n const logger = createLogger()\n\n const ignored = '**/{.git,node_modules}/**'\n\n const watcher = watch(path, {\n ignorePermissionErrors: true,\n ignored,\n })\n watcher.on('all', (type, file) => {\n logger?.emit('info', pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))\n\n try {\n cb(path)\n } catch (_e) {\n logger?.emit('warning', pc.red('Watcher failed'))\n }\n })\n}\n","import path from 'node:path'\nimport * as process from 'node:process'\nimport { isInputPath, PromiseManager } from '@kubb/core'\nimport { createLogger, LogMapper } from '@kubb/core/logger'\nimport type { ArgsDef, ParsedArgs } from 'citty'\nimport { defineCommand, showUsage } from 'citty'\nimport type { SingleBar } from 'cli-progress'\nimport pc from 'picocolors'\nimport { getConfig } from '../utils/getConfig.ts'\nimport { getCosmiConfig } from '../utils/getCosmiConfig.ts'\nimport { startWatcher } from '../utils/watcher.ts'\n\ndeclare global {\n var isDevtoolsEnabled: any\n}\n\nconst args = {\n config: {\n type: 'string',\n description: 'Path to the Kubb config',\n alias: 'c',\n },\n logLevel: {\n type: 'string',\n description: 'Info, silent or debug',\n alias: 'l',\n default: 'info',\n valueHint: 'silent|info|debug',\n },\n watch: {\n type: 'boolean',\n description: 'Watch mode based on the input file',\n alias: 'w',\n default: false,\n },\n debug: {\n type: 'boolean',\n description: 'Override logLevel to debug',\n alias: 'd',\n default: false,\n },\n help: {\n type: 'boolean',\n description: 'Show help',\n alias: 'h',\n default: false,\n },\n} as const satisfies ArgsDef\n\nexport type Args = ParsedArgs<typeof args>\n\nconst command = defineCommand({\n meta: {\n name: 'generate',\n description: \"[input] Generate files based on a 'kubb.config.ts' file\",\n },\n args,\n async run(commandContext) {\n const progressCache = new Map<string, SingleBar>()\n\n const { args } = commandContext\n\n const input = args._[0]\n\n if (args.help) {\n return showUsage(command)\n }\n\n if (args.debug) {\n args.logLevel = 'debug'\n }\n\n const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3\n const logger = createLogger({\n logLevel,\n })\n const { generate } = await import('../runners/generate.ts')\n\n logger.emit('start', 'Loading config')\n\n const result = await getCosmiConfig('kubb', args.config)\n logger.emit('success', `Config loaded(${pc.dim(path.relative(process.cwd(), result.filepath))})`)\n\n const config = await getConfig(result, args)\n\n const start = async () => {\n if (Array.isArray(config)) {\n const promiseManager = new PromiseManager()\n const promises = config.map((c) => () => {\n progressCache.clear()\n\n return generate({\n input,\n config: c,\n args,\n progressCache,\n })\n })\n\n await promiseManager.run('seq', promises)\n return\n }\n\n progressCache.clear()\n\n await generate({\n input,\n config,\n progressCache,\n args,\n })\n\n return\n }\n\n if (args.watch) {\n if (Array.isArray(config)) {\n throw new Error('Cannot use watcher with multiple Configs(array)')\n }\n\n if (isInputPath(config)) {\n return startWatcher([input || config.input.path], async (paths) => {\n await start()\n logger.emit('start', pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))\n })\n }\n }\n\n await start()\n\n if (globalThis.isDevtoolsEnabled) {\n const canRestart = await logger.consola?.prompt('Restart(could be used to validate the profiler)?', {\n type: 'confirm',\n initial: false,\n })\n\n if (canRestart) {\n await start()\n } else {\n process.exit(1)\n }\n }\n },\n})\n\nexport default command\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,cAAc,SAAgC;AACrD,QAAO,CAAC,CAAE,SAAiB,MAAM,WAAgB;AAC/C,SAAO,MAAM,Q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AW,kBAMb,KALmB,MAAM,OAAO,SAAS,OAAO,oDAAoD;GAClG,MAAM;GACN,SAAS;GACV,CAAC,CAGA,OAAM,OAAO;MAEb,cAAQ,KAAK,EAAE;;CAItB,CAAC;AAEF,uBAAe"}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
node_path = require_chunk.__toESM(node_path);
|
|
4
|
+
let node_process = require("node:process");
|
|
5
|
+
node_process = require_chunk.__toESM(node_process);
|
|
6
|
+
let __kubb_core = require("@kubb/core");
|
|
7
|
+
__kubb_core = require_chunk.__toESM(__kubb_core);
|
|
8
|
+
let __kubb_core_logger = require("@kubb/core/logger");
|
|
9
|
+
__kubb_core_logger = require_chunk.__toESM(__kubb_core_logger);
|
|
10
|
+
let picocolors = require("picocolors");
|
|
11
|
+
picocolors = require_chunk.__toESM(picocolors);
|
|
12
|
+
let cli_progress = require("cli-progress");
|
|
13
|
+
cli_progress = require_chunk.__toESM(cli_progress);
|
|
14
|
+
let execa = require("execa");
|
|
15
|
+
execa = require_chunk.__toESM(execa);
|
|
16
|
+
let string_argv = require("string-argv");
|
|
17
|
+
string_argv = require_chunk.__toESM(string_argv);
|
|
18
|
+
let node_stream = require("node:stream");
|
|
19
|
+
node_stream = require_chunk.__toESM(node_stream);
|
|
20
|
+
|
|
21
|
+
//#region src/utils/Writables.ts
|
|
22
|
+
var ConsolaWritable = class extends node_stream.Writable {
|
|
23
|
+
consola;
|
|
24
|
+
command;
|
|
25
|
+
constructor(consola, command, opts) {
|
|
26
|
+
super(opts);
|
|
27
|
+
this.command = command;
|
|
28
|
+
this.consola = consola;
|
|
29
|
+
}
|
|
30
|
+
_write(chunk, _encoding, callback) {
|
|
31
|
+
node_process.stdout.write(`${picocolors.default.dim(chunk?.toString())}`);
|
|
32
|
+
callback();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/utils/executeHooks.ts
|
|
38
|
+
async function executeHooks({ hooks, logger }) {
|
|
39
|
+
const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done].filter(Boolean);
|
|
40
|
+
for (const command of commands) {
|
|
41
|
+
const consolaWritable = new ConsolaWritable(logger.consola, command);
|
|
42
|
+
const [cmd, ..._args] = [...(0, string_argv.parseArgsStringToArgv)(command)];
|
|
43
|
+
if (!cmd) continue;
|
|
44
|
+
logger?.emit("start", `Executing hook ${logger.logLevel !== __kubb_core_logger.LogMapper.silent ? picocolors.default.dim(command) : ""}`);
|
|
45
|
+
await (0, execa.execa)(cmd, _args, {
|
|
46
|
+
detached: true,
|
|
47
|
+
stdout: logger?.logLevel === __kubb_core_logger.LogMapper.silent ? void 0 : ["pipe", consolaWritable],
|
|
48
|
+
stripFinalNewline: true
|
|
49
|
+
});
|
|
50
|
+
logger?.emit("success", `Executed hook ${logger.logLevel !== __kubb_core_logger.LogMapper.silent ? picocolors.default.dim(command) : ""}`);
|
|
51
|
+
}
|
|
52
|
+
logger?.emit("success", "Executed hooks");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/utils/getErrorCauses.ts
|
|
57
|
+
function getErrorCauses(errors) {
|
|
58
|
+
return errors.reduce((prev, error) => {
|
|
59
|
+
const causedError = error?.cause;
|
|
60
|
+
if (causedError) {
|
|
61
|
+
prev = [...prev, ...getErrorCauses([causedError])];
|
|
62
|
+
return prev;
|
|
63
|
+
}
|
|
64
|
+
prev = [...prev, error];
|
|
65
|
+
return prev;
|
|
66
|
+
}, []).filter(Boolean);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/utils/parseHrtimeToSeconds.ts
|
|
71
|
+
function parseHrtimeToSeconds(hrtime) {
|
|
72
|
+
return (hrtime[0] + hrtime[1] / 1e9).toFixed(3);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/utils/getSummary.ts
|
|
77
|
+
function getSummary({ pluginManager, filesCreated, status, hrStart, config }) {
|
|
78
|
+
const logs = /* @__PURE__ */ new Set();
|
|
79
|
+
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrStart));
|
|
80
|
+
const buildStartPlugins = pluginManager.executed.filter((item) => item.hookName === "buildStart" && item.plugin.name !== "core").map((item) => item.plugin.name);
|
|
81
|
+
const buildEndPlugins = pluginManager.executed.filter((item) => item.hookName === "buildEnd" && item.plugin.name !== "core").map((item) => item.plugin.name);
|
|
82
|
+
const failedPlugins = config.plugins?.filter((plugin) => !buildEndPlugins.includes(plugin.name))?.map((plugin) => plugin.name);
|
|
83
|
+
const pluginsCount = config.plugins?.length || 0;
|
|
84
|
+
const meta = {
|
|
85
|
+
plugins: status === "success" ? `${picocolors.default.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${picocolors.default.red(`${failedPlugins?.length ?? 1} failed`)}, ${pluginsCount} total`,
|
|
86
|
+
pluginsFailed: status === "failed" ? failedPlugins?.map((name) => (0, __kubb_core_logger.randomCliColour)(name))?.join(", ") : void 0,
|
|
87
|
+
filesCreated,
|
|
88
|
+
time: `${picocolors.default.yellow(`${elapsedSeconds}s`)}`,
|
|
89
|
+
output: node_path.default.isAbsolute(config.root) ? node_path.default.resolve(config.root, config.output.path) : config.root
|
|
90
|
+
};
|
|
91
|
+
logs.add([
|
|
92
|
+
[`${picocolors.default.bold("Plugins:")} ${meta.plugins}`, true],
|
|
93
|
+
[`${picocolors.default.dim("Failed:")} ${meta.pluginsFailed || "none"}`, !!meta.pluginsFailed],
|
|
94
|
+
[`${picocolors.default.bold("Generated:")} ${meta.filesCreated} files in ${meta.time}`, true],
|
|
95
|
+
[`${picocolors.default.bold("Output:")} ${meta.output}`, true]
|
|
96
|
+
].map((item) => {
|
|
97
|
+
if (item.at(1)) return item.at(0);
|
|
98
|
+
}).filter(Boolean).join("\n"));
|
|
99
|
+
return [...logs];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/runners/generate.ts
|
|
104
|
+
async function generate({ input, config, progressCache, args }) {
|
|
105
|
+
const hrStart = node_process.default.hrtime();
|
|
106
|
+
const logger = (0, __kubb_core_logger.createLogger)({
|
|
107
|
+
logLevel: __kubb_core_logger.LogMapper[args.logLevel] || 3,
|
|
108
|
+
name: config.name
|
|
109
|
+
});
|
|
110
|
+
const { root = node_process.default.cwd(),...userConfig } = config;
|
|
111
|
+
const inputPath = input ?? ("path" in userConfig.input ? userConfig.input.path : void 0);
|
|
112
|
+
if (logger.logLevel !== __kubb_core_logger.LogMapper.debug) {
|
|
113
|
+
logger.on("progress_start", ({ id, size, message = "" }) => {
|
|
114
|
+
logger.consola?.pauseLogs();
|
|
115
|
+
const payload = {
|
|
116
|
+
id,
|
|
117
|
+
message
|
|
118
|
+
};
|
|
119
|
+
const progressBar = new cli_progress.SingleBar({
|
|
120
|
+
format: "{percentage}% {bar} {value}/{total} | {message}",
|
|
121
|
+
barsize: 30,
|
|
122
|
+
clearOnComplete: true,
|
|
123
|
+
emptyOnZero: true
|
|
124
|
+
}, cli_progress.Presets.shades_grey);
|
|
125
|
+
if (!progressCache.has(id)) {
|
|
126
|
+
progressCache.set(id, progressBar);
|
|
127
|
+
progressBar.start(size, 1, payload);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
logger.on("progress_stop", ({ id }) => {
|
|
131
|
+
progressCache.get(id)?.stop();
|
|
132
|
+
logger.consola?.resumeLogs();
|
|
133
|
+
});
|
|
134
|
+
logger.on("progressed", ({ id, message = "" }) => {
|
|
135
|
+
const payload = {
|
|
136
|
+
id,
|
|
137
|
+
message
|
|
138
|
+
};
|
|
139
|
+
progressCache.get(id)?.increment(1, payload);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
const definedConfig = {
|
|
143
|
+
root,
|
|
144
|
+
...userConfig,
|
|
145
|
+
input: inputPath ? {
|
|
146
|
+
...userConfig.input,
|
|
147
|
+
path: inputPath
|
|
148
|
+
} : userConfig.input,
|
|
149
|
+
output: {
|
|
150
|
+
write: true,
|
|
151
|
+
barrelType: "named",
|
|
152
|
+
extension: { ".ts": ".ts" },
|
|
153
|
+
format: "prettier",
|
|
154
|
+
...userConfig.output
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const { fabric, pluginManager } = await (0, __kubb_core.setup)({
|
|
158
|
+
config: definedConfig,
|
|
159
|
+
logger
|
|
160
|
+
});
|
|
161
|
+
logger.emit("start", `Building ${logger.logLevel !== __kubb_core_logger.LogMapper.silent ? picocolors.default.dim(inputPath) : ""}`);
|
|
162
|
+
const { files, error } = await (0, __kubb_core.safeBuild)({
|
|
163
|
+
config: definedConfig,
|
|
164
|
+
logger
|
|
165
|
+
}, {
|
|
166
|
+
pluginManager,
|
|
167
|
+
fabric
|
|
168
|
+
});
|
|
169
|
+
if (logger.logLevel === __kubb_core_logger.LogMapper.debug) {
|
|
170
|
+
logger.consola?.start("Writing logs");
|
|
171
|
+
const logFiles = await logger.writeLogs();
|
|
172
|
+
logger.consola?.success(`Written logs: \n${logFiles.join("\n")}`);
|
|
173
|
+
}
|
|
174
|
+
const summary = getSummary({
|
|
175
|
+
filesCreated: files.length,
|
|
176
|
+
pluginManager,
|
|
177
|
+
config: definedConfig,
|
|
178
|
+
status: error ? "failed" : "success",
|
|
179
|
+
hrStart
|
|
180
|
+
});
|
|
181
|
+
if (error && logger.consola) {
|
|
182
|
+
logger.consola?.resumeLogs();
|
|
183
|
+
logger.consola.error(`Build failed ${logger.logLevel !== __kubb_core_logger.LogMapper.silent ? picocolors.default.dim(inputPath) : ""}`);
|
|
184
|
+
logger.consola.box({
|
|
185
|
+
title: `${config.name || ""}`,
|
|
186
|
+
message: summary.join(""),
|
|
187
|
+
style: {
|
|
188
|
+
padding: 2,
|
|
189
|
+
borderColor: "red",
|
|
190
|
+
borderStyle: "rounded"
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
const errors = getErrorCauses([error]);
|
|
194
|
+
if (logger.consola && errors.length && logger.logLevel === __kubb_core_logger.LogMapper.debug) errors.forEach((err) => {
|
|
195
|
+
logger.consola?.error(err);
|
|
196
|
+
});
|
|
197
|
+
logger.consola?.error(error);
|
|
198
|
+
node_process.default.exit(1);
|
|
199
|
+
}
|
|
200
|
+
if (config.output.format === "prettier") {
|
|
201
|
+
logger?.emit("start", `Formatting with ${config.output.format}`);
|
|
202
|
+
try {
|
|
203
|
+
await (0, execa.execa)("prettier", [
|
|
204
|
+
"--ignore-unknown",
|
|
205
|
+
"--write",
|
|
206
|
+
node_path.default.resolve(definedConfig.root, definedConfig.output.path)
|
|
207
|
+
]);
|
|
208
|
+
} catch (e) {
|
|
209
|
+
logger.consola?.warn("Prettier not found");
|
|
210
|
+
logger.consola?.error(e);
|
|
211
|
+
}
|
|
212
|
+
logger?.emit("success", `Formatted with ${config.output.format}`);
|
|
213
|
+
}
|
|
214
|
+
if (config.output.format === "biome") {
|
|
215
|
+
logger?.emit("start", `Formatting with ${config.output.format}`);
|
|
216
|
+
try {
|
|
217
|
+
await (0, execa.execa)("biome", [
|
|
218
|
+
"format",
|
|
219
|
+
"--write",
|
|
220
|
+
node_path.default.resolve(definedConfig.root, definedConfig.output.path)
|
|
221
|
+
]);
|
|
222
|
+
} catch (e) {
|
|
223
|
+
logger.consola?.warn("Biome not found");
|
|
224
|
+
logger.consola?.error(e);
|
|
225
|
+
}
|
|
226
|
+
logger?.emit("success", `Formatted with ${config.output.format}`);
|
|
227
|
+
}
|
|
228
|
+
if (config.output.lint === "eslint") {
|
|
229
|
+
logger?.emit("start", `Linting with ${config.output.format}`);
|
|
230
|
+
try {
|
|
231
|
+
await (0, execa.execa)("eslint", [node_path.default.resolve(definedConfig.root, definedConfig.output.path), "--fix"]);
|
|
232
|
+
} catch (e) {
|
|
233
|
+
logger.consola?.warn("Eslint not found");
|
|
234
|
+
logger.consola?.error(e);
|
|
235
|
+
}
|
|
236
|
+
logger?.emit("success", `Linted with ${config.output.format}`);
|
|
237
|
+
}
|
|
238
|
+
if (config.output.lint === "biome") {
|
|
239
|
+
logger?.emit("start", `Linting with ${config.output.format}`);
|
|
240
|
+
try {
|
|
241
|
+
await (0, execa.execa)("biome", [
|
|
242
|
+
"lint",
|
|
243
|
+
"--fix",
|
|
244
|
+
node_path.default.resolve(definedConfig.root, definedConfig.output.path)
|
|
245
|
+
]);
|
|
246
|
+
} catch (e) {
|
|
247
|
+
logger.consola?.warn("Biome not found");
|
|
248
|
+
logger.consola?.error(e);
|
|
249
|
+
}
|
|
250
|
+
logger?.emit("success", `Linted with ${config.output.format}`);
|
|
251
|
+
}
|
|
252
|
+
if (config.output.lint === "oxlint") {
|
|
253
|
+
logger?.emit("start", `Linting with ${config.output.format}`);
|
|
254
|
+
try {
|
|
255
|
+
await (0, execa.execa)("oxlint", ["--fix", node_path.default.resolve(definedConfig.root, definedConfig.output.path)]);
|
|
256
|
+
} catch (e) {
|
|
257
|
+
logger.consola?.warn("Oxlint not found");
|
|
258
|
+
logger.consola?.error(e);
|
|
259
|
+
}
|
|
260
|
+
logger?.emit("success", `Linted with ${config.output.format}`);
|
|
261
|
+
}
|
|
262
|
+
if (config.hooks) await executeHooks({
|
|
263
|
+
hooks: config.hooks,
|
|
264
|
+
logger
|
|
265
|
+
});
|
|
266
|
+
logger.consola?.log(`⚡Build completed ${logger.logLevel !== __kubb_core_logger.LogMapper.silent ? picocolors.default.dim(inputPath) : ""}`);
|
|
267
|
+
logger.consola?.box({
|
|
268
|
+
title: `${config.name || ""}`,
|
|
269
|
+
message: summary.join(""),
|
|
270
|
+
style: {
|
|
271
|
+
padding: 2,
|
|
272
|
+
borderColor: "green",
|
|
273
|
+
borderStyle: "rounded"
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
//#endregion
|
|
279
|
+
exports.generate = generate;
|
|
280
|
+
//# sourceMappingURL=generate-CUHrQxq3.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-CUHrQxq3.cjs","names":["Writable","pc","LogMapper","pc","pc","path","process","LogMapper","SingleBar","Presets","definedConfig: Config","pc","path"],"sources":["../src/utils/Writables.ts","../src/utils/executeHooks.ts","../src/utils/getErrorCauses.ts","../src/utils/parseHrtimeToSeconds.ts","../src/utils/getSummary.ts","../src/runners/generate.ts"],"sourcesContent":["import { Writable } from 'node:stream'\n\nimport pc from 'picocolors'\n\nimport * as process from 'node:process'\nimport type { WritableOptions } from 'node:stream'\nimport type { ConsolaInstance } from 'consola'\n\nexport class ConsolaWritable extends Writable {\n consola: ConsolaInstance | undefined\n command: string\n constructor(consola: ConsolaInstance | undefined, command: string, opts?: WritableOptions) {\n super(opts)\n\n this.command = command\n this.consola = consola\n }\n _write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n process.stdout.write(`${pc.dim(chunk?.toString())}`)\n\n callback()\n }\n}\n","import type { Logger } from '@kubb/core/logger'\nimport { execa } from 'execa'\nimport { parseArgsStringToArgv } from 'string-argv'\nimport pc from 'picocolors'\n\nimport { ConsolaWritable } from './Writables.ts'\n\nimport type { Config } from '@kubb/core'\nimport { LogMapper } from '@kubb/core/logger'\n\ntype ExecutingHooksProps = {\n hooks: NonNullable<Config['hooks']>\n logger: Logger\n}\n\nexport async function executeHooks({ hooks, logger }: ExecutingHooksProps): Promise<void> {\n const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done].filter(Boolean)\n\n for (const command of commands) {\n const consolaWritable = new ConsolaWritable(logger.consola!, command)\n const [cmd, ..._args] = [...parseArgsStringToArgv(command)]\n\n if (!cmd) {\n continue\n }\n\n logger?.emit('start', `Executing hook ${logger.logLevel !== LogMapper.silent ? pc.dim(command) : ''}`)\n\n await execa(cmd, _args, {\n detached: true,\n stdout: logger?.logLevel === LogMapper.silent ? undefined : ['pipe', consolaWritable],\n stripFinalNewline: true,\n })\n\n logger?.emit('success', `Executed hook ${logger.logLevel !== LogMapper.silent ? pc.dim(command) : ''}`)\n }\n\n logger?.emit('success', 'Executed hooks')\n}\n","export function getErrorCauses(errors: Error[]): Error[] {\n return errors\n .reduce((prev, error) => {\n const causedError = error?.cause as Error\n if (causedError) {\n prev = [...prev, ...getErrorCauses([causedError])]\n return prev\n }\n prev = [...prev, error]\n\n return prev\n }, [] as Error[])\n .filter(Boolean)\n}\n","export function parseHrtimeToSeconds(hrtime: [number, number]): string {\n const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3)\n return seconds\n}\n","import path from 'node:path'\n\nimport { randomCliColour } from '@kubb/core/logger'\n\nimport pc from 'picocolors'\n\nimport { parseHrtimeToSeconds } from './parseHrtimeToSeconds.ts'\n\nimport type { Config, PluginManager } from '@kubb/core'\n\ntype SummaryProps = {\n pluginManager: PluginManager\n status: 'success' | 'failed'\n hrStart: [number, number]\n filesCreated: number\n config: Config\n}\n\nexport function getSummary({ pluginManager, filesCreated, status, hrStart, config }: SummaryProps): string[] {\n const logs = new Set<string>()\n const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrStart))\n\n const buildStartPlugins = pluginManager.executed\n .filter((item) => item.hookName === 'buildStart' && item.plugin.name !== 'core')\n .map((item) => item.plugin.name)\n\n const buildEndPlugins = pluginManager.executed.filter((item) => item.hookName === 'buildEnd' && item.plugin.name !== 'core').map((item) => item.plugin.name)\n\n const failedPlugins = config.plugins?.filter((plugin) => !buildEndPlugins.includes(plugin.name))?.map((plugin) => plugin.name)\n const pluginsCount = config.plugins?.length || 0\n\n const meta = {\n plugins:\n status === 'success'\n ? `${pc.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total`\n : `${pc.red(`${failedPlugins?.length ?? 1} failed`)}, ${pluginsCount} total`,\n pluginsFailed: status === 'failed' ? failedPlugins?.map((name) => randomCliColour(name))?.join(', ') : undefined,\n filesCreated: filesCreated,\n time: `${pc.yellow(`${elapsedSeconds}s`)}`,\n output: path.isAbsolute(config.root) ? path.resolve(config.root, config.output.path) : config.root,\n } as const\n\n logs.add(\n [\n [`${pc.bold('Plugins:')} ${meta.plugins}`, true],\n [`${pc.dim('Failed:')} ${meta.pluginsFailed || 'none'}`, !!meta.pluginsFailed],\n [`${pc.bold('Generated:')} ${meta.filesCreated} files in ${meta.time}`, true],\n [`${pc.bold('Output:')} ${meta.output}`, true],\n ]\n .map((item) => {\n if (item.at(1)) {\n return item.at(0)\n }\n return undefined\n })\n .filter(Boolean)\n .join('\\n'),\n )\n\n return [...logs]\n}\n","import path from 'node:path'\nimport process from 'node:process'\nimport { type Config, safeBuild, setup } from '@kubb/core'\nimport { createLogger, LogMapper } from '@kubb/core/logger'\nimport { Presets, SingleBar } from 'cli-progress'\nimport { execa } from 'execa'\nimport pc from 'picocolors'\nimport type { Args } from '../commands/generate.ts'\nimport { executeHooks } from '../utils/executeHooks.ts'\nimport { getErrorCauses } from '../utils/getErrorCauses.ts'\nimport { getSummary } from '../utils/getSummary.ts'\n\ntype GenerateProps = {\n input?: string\n config: Config\n args: Args\n progressCache: Map<string, SingleBar>\n}\n\nexport async function generate({ input, config, progressCache, args }: GenerateProps): Promise<void> {\n const hrStart = process.hrtime()\n const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3\n\n const logger = createLogger({\n logLevel,\n name: config.name,\n })\n\n const { root = process.cwd(), ...userConfig } = config\n const inputPath = input ?? ('path' in userConfig.input ? userConfig.input.path : undefined)\n\n if (logger.logLevel !== LogMapper.debug) {\n logger.on('progress_start', ({ id, size, message = '' }) => {\n logger.consola?.pauseLogs()\n const payload = { id, message }\n const progressBar = new SingleBar(\n {\n format: '{percentage}% {bar} {value}/{total} | {message}',\n barsize: 30,\n clearOnComplete: true,\n emptyOnZero: true,\n },\n Presets.shades_grey,\n )\n\n if (!progressCache.has(id)) {\n progressCache.set(id, progressBar)\n progressBar.start(size, 1, payload)\n }\n })\n\n logger.on('progress_stop', ({ id }) => {\n progressCache.get(id)?.stop()\n logger.consola?.resumeLogs()\n })\n\n logger.on('progressed', ({ id, message = '' }) => {\n const payload = { id, message }\n\n progressCache.get(id)?.increment(1, payload)\n })\n }\n\n const definedConfig: Config = {\n root,\n ...userConfig,\n input: inputPath\n ? {\n ...userConfig.input,\n path: inputPath,\n }\n : userConfig.input,\n output: {\n write: true,\n barrelType: 'named',\n extension: {\n '.ts': '.ts',\n },\n format: 'prettier',\n ...userConfig.output,\n },\n }\n\n const { fabric, pluginManager } = await setup({\n config: definedConfig,\n logger,\n })\n\n logger.emit('start', `Building ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)\n\n const { files, error } = await safeBuild(\n {\n config: definedConfig,\n logger,\n },\n { pluginManager, fabric },\n )\n\n if (logger.logLevel === LogMapper.debug) {\n logger.consola?.start('Writing logs')\n\n const logFiles = await logger.writeLogs()\n\n logger.consola?.success(`Written logs: \\n${logFiles.join('\\n')}`)\n }\n\n const summary = getSummary({\n filesCreated: files.length,\n pluginManager,\n config: definedConfig,\n status: error ? 'failed' : 'success',\n hrStart,\n })\n\n if (error && logger.consola) {\n logger.consola?.resumeLogs()\n logger.consola.error(`Build failed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)\n\n logger.consola.box({\n title: `${config.name || ''}`,\n message: summary.join(''),\n style: {\n padding: 2,\n borderColor: 'red',\n borderStyle: 'rounded',\n },\n })\n\n const errors = getErrorCauses([error])\n if (logger.consola && errors.length && logger.logLevel === LogMapper.debug) {\n errors.forEach((err) => {\n logger.consola?.error(err)\n })\n }\n\n logger.consola?.error(error)\n\n process.exit(1)\n }\n\n // formatting\n if (config.output.format === 'prettier') {\n logger?.emit('start', `Formatting with ${config.output.format}`)\n\n try {\n await execa('prettier', ['--ignore-unknown', '--write', path.resolve(definedConfig.root, definedConfig.output.path)])\n } catch (e) {\n logger.consola?.warn('Prettier not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Formatted with ${config.output.format}`)\n }\n\n if (config.output.format === 'biome') {\n logger?.emit('start', `Formatting with ${config.output.format}`)\n\n try {\n await execa('biome', ['format', '--write', path.resolve(definedConfig.root, definedConfig.output.path)])\n } catch (e) {\n logger.consola?.warn('Biome not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Formatted with ${config.output.format}`)\n }\n\n // linting\n if (config.output.lint === 'eslint') {\n logger?.emit('start', `Linting with ${config.output.format}`)\n\n try {\n await execa('eslint', [path.resolve(definedConfig.root, definedConfig.output.path), '--fix'])\n } catch (e) {\n logger.consola?.warn('Eslint not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Linted with ${config.output.format}`)\n }\n\n if (config.output.lint === 'biome') {\n logger?.emit('start', `Linting with ${config.output.format}`)\n\n try {\n await execa('biome', ['lint', '--fix', path.resolve(definedConfig.root, definedConfig.output.path)])\n } catch (e) {\n logger.consola?.warn('Biome not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Linted with ${config.output.format}`)\n }\n\n if (config.output.lint === 'oxlint') {\n logger?.emit('start', `Linting with ${config.output.format}`)\n\n try {\n await execa('oxlint', ['--fix', path.resolve(definedConfig.root, definedConfig.output.path)])\n } catch (e) {\n logger.consola?.warn('Oxlint not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Linted with ${config.output.format}`)\n }\n\n if (config.hooks) {\n await executeHooks({ hooks: config.hooks, logger })\n }\n\n logger.consola?.log(`⚡Build completed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)\n\n logger.consola?.box({\n title: `${config.name || ''}`,\n message: summary.join(''),\n style: {\n padding: 2,\n borderColor: 'green',\n borderStyle: 'rounded',\n },\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAQA,IAAa,kBAAb,cAAqCA,qBAAS;CAC5C;CACA;CACA,YAAY,SAAsC,SAAiB,MAAwB;AACzF,QAAM,KAAK;AAEX,OAAK,UAAU;AACf,OAAK,UAAU;;CAEjB,OAAO,OAAY,WAA2B,UAAgD;AAC5F,eAAQ,OAAO,MAA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CAAC,SAASA,kBAAK,QAAQ,cAAc,MAAM,cAAc,OAAO,KAAK,CAAC,CAAC;WACtF,GAAG;AACV,UAAO,SAAS,KAAK,mBAAmB;AACxC,UAAO,SAAS,MAAM,EAAE;;AAG1B,UAAQ,KAAK,WAAW,eAAe,OAAO,OAAO,SAAS;;AAGhE,KAAI,OAAO,MACT,OAAM,aAAa;EAAE,OAAO,OAAO;EAAO;EAAQ,CAAC;AAGrD,QAAO,SAAS,IAAI,oBAAoB,OAAO,aAAaL,6BAAU,SAASI,mBAAG,IAAI,UAAW,GAAG,KAAK;AAEzG,QAAO,SAAS,IAAI;EAClB,OAAO,GAAG,OAAO,QAAQ;EACzB,SAAS,QAAQ,KAAK,GAAG;EACzB,OAAO;GACL,SAAS;GACT,aAAa;GACb,aAAa;GACd;EACF,CAAC"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import * as process$2 from "node:process";
|
|
3
|
+
import process$1 from "node:process";
|
|
4
|
+
import { safeBuild, setup } from "@kubb/core";
|
|
5
|
+
import { LogMapper, createLogger, randomCliColour } from "@kubb/core/logger";
|
|
6
|
+
import pc from "picocolors";
|
|
7
|
+
import { Presets, SingleBar } from "cli-progress";
|
|
8
|
+
import { execa } from "execa";
|
|
9
|
+
import { parseArgsStringToArgv } from "string-argv";
|
|
10
|
+
import { Writable } from "node:stream";
|
|
11
|
+
|
|
12
|
+
//#region src/utils/Writables.ts
|
|
13
|
+
var ConsolaWritable = class extends Writable {
|
|
14
|
+
consola;
|
|
15
|
+
command;
|
|
16
|
+
constructor(consola, command, opts) {
|
|
17
|
+
super(opts);
|
|
18
|
+
this.command = command;
|
|
19
|
+
this.consola = consola;
|
|
20
|
+
}
|
|
21
|
+
_write(chunk, _encoding, callback) {
|
|
22
|
+
process$2.stdout.write(`${pc.dim(chunk?.toString())}`);
|
|
23
|
+
callback();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/utils/executeHooks.ts
|
|
29
|
+
async function executeHooks({ hooks, logger }) {
|
|
30
|
+
const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done].filter(Boolean);
|
|
31
|
+
for (const command of commands) {
|
|
32
|
+
const consolaWritable = new ConsolaWritable(logger.consola, command);
|
|
33
|
+
const [cmd, ..._args] = [...parseArgsStringToArgv(command)];
|
|
34
|
+
if (!cmd) continue;
|
|
35
|
+
logger?.emit("start", `Executing hook ${logger.logLevel !== LogMapper.silent ? pc.dim(command) : ""}`);
|
|
36
|
+
await execa(cmd, _args, {
|
|
37
|
+
detached: true,
|
|
38
|
+
stdout: logger?.logLevel === LogMapper.silent ? void 0 : ["pipe", consolaWritable],
|
|
39
|
+
stripFinalNewline: true
|
|
40
|
+
});
|
|
41
|
+
logger?.emit("success", `Executed hook ${logger.logLevel !== LogMapper.silent ? pc.dim(command) : ""}`);
|
|
42
|
+
}
|
|
43
|
+
logger?.emit("success", "Executed hooks");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/utils/getErrorCauses.ts
|
|
48
|
+
function getErrorCauses(errors) {
|
|
49
|
+
return errors.reduce((prev, error) => {
|
|
50
|
+
const causedError = error?.cause;
|
|
51
|
+
if (causedError) {
|
|
52
|
+
prev = [...prev, ...getErrorCauses([causedError])];
|
|
53
|
+
return prev;
|
|
54
|
+
}
|
|
55
|
+
prev = [...prev, error];
|
|
56
|
+
return prev;
|
|
57
|
+
}, []).filter(Boolean);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/utils/parseHrtimeToSeconds.ts
|
|
62
|
+
function parseHrtimeToSeconds(hrtime) {
|
|
63
|
+
return (hrtime[0] + hrtime[1] / 1e9).toFixed(3);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/utils/getSummary.ts
|
|
68
|
+
function getSummary({ pluginManager, filesCreated, status, hrStart, config }) {
|
|
69
|
+
const logs = /* @__PURE__ */ new Set();
|
|
70
|
+
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrStart));
|
|
71
|
+
const buildStartPlugins = pluginManager.executed.filter((item) => item.hookName === "buildStart" && item.plugin.name !== "core").map((item) => item.plugin.name);
|
|
72
|
+
const buildEndPlugins = pluginManager.executed.filter((item) => item.hookName === "buildEnd" && item.plugin.name !== "core").map((item) => item.plugin.name);
|
|
73
|
+
const failedPlugins = config.plugins?.filter((plugin) => !buildEndPlugins.includes(plugin.name))?.map((plugin) => plugin.name);
|
|
74
|
+
const pluginsCount = config.plugins?.length || 0;
|
|
75
|
+
const meta = {
|
|
76
|
+
plugins: status === "success" ? `${pc.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc.red(`${failedPlugins?.length ?? 1} failed`)}, ${pluginsCount} total`,
|
|
77
|
+
pluginsFailed: status === "failed" ? failedPlugins?.map((name) => randomCliColour(name))?.join(", ") : void 0,
|
|
78
|
+
filesCreated,
|
|
79
|
+
time: `${pc.yellow(`${elapsedSeconds}s`)}`,
|
|
80
|
+
output: path.isAbsolute(config.root) ? path.resolve(config.root, config.output.path) : config.root
|
|
81
|
+
};
|
|
82
|
+
logs.add([
|
|
83
|
+
[`${pc.bold("Plugins:")} ${meta.plugins}`, true],
|
|
84
|
+
[`${pc.dim("Failed:")} ${meta.pluginsFailed || "none"}`, !!meta.pluginsFailed],
|
|
85
|
+
[`${pc.bold("Generated:")} ${meta.filesCreated} files in ${meta.time}`, true],
|
|
86
|
+
[`${pc.bold("Output:")} ${meta.output}`, true]
|
|
87
|
+
].map((item) => {
|
|
88
|
+
if (item.at(1)) return item.at(0);
|
|
89
|
+
}).filter(Boolean).join("\n"));
|
|
90
|
+
return [...logs];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/runners/generate.ts
|
|
95
|
+
async function generate({ input, config, progressCache, args }) {
|
|
96
|
+
const hrStart = process$1.hrtime();
|
|
97
|
+
const logger = createLogger({
|
|
98
|
+
logLevel: LogMapper[args.logLevel] || 3,
|
|
99
|
+
name: config.name
|
|
100
|
+
});
|
|
101
|
+
const { root = process$1.cwd(),...userConfig } = config;
|
|
102
|
+
const inputPath = input ?? ("path" in userConfig.input ? userConfig.input.path : void 0);
|
|
103
|
+
if (logger.logLevel !== LogMapper.debug) {
|
|
104
|
+
logger.on("progress_start", ({ id, size, message = "" }) => {
|
|
105
|
+
logger.consola?.pauseLogs();
|
|
106
|
+
const payload = {
|
|
107
|
+
id,
|
|
108
|
+
message
|
|
109
|
+
};
|
|
110
|
+
const progressBar = new SingleBar({
|
|
111
|
+
format: "{percentage}% {bar} {value}/{total} | {message}",
|
|
112
|
+
barsize: 30,
|
|
113
|
+
clearOnComplete: true,
|
|
114
|
+
emptyOnZero: true
|
|
115
|
+
}, Presets.shades_grey);
|
|
116
|
+
if (!progressCache.has(id)) {
|
|
117
|
+
progressCache.set(id, progressBar);
|
|
118
|
+
progressBar.start(size, 1, payload);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
logger.on("progress_stop", ({ id }) => {
|
|
122
|
+
progressCache.get(id)?.stop();
|
|
123
|
+
logger.consola?.resumeLogs();
|
|
124
|
+
});
|
|
125
|
+
logger.on("progressed", ({ id, message = "" }) => {
|
|
126
|
+
const payload = {
|
|
127
|
+
id,
|
|
128
|
+
message
|
|
129
|
+
};
|
|
130
|
+
progressCache.get(id)?.increment(1, payload);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const definedConfig = {
|
|
134
|
+
root,
|
|
135
|
+
...userConfig,
|
|
136
|
+
input: inputPath ? {
|
|
137
|
+
...userConfig.input,
|
|
138
|
+
path: inputPath
|
|
139
|
+
} : userConfig.input,
|
|
140
|
+
output: {
|
|
141
|
+
write: true,
|
|
142
|
+
barrelType: "named",
|
|
143
|
+
extension: { ".ts": ".ts" },
|
|
144
|
+
format: "prettier",
|
|
145
|
+
...userConfig.output
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const { fabric, pluginManager } = await setup({
|
|
149
|
+
config: definedConfig,
|
|
150
|
+
logger
|
|
151
|
+
});
|
|
152
|
+
logger.emit("start", `Building ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath) : ""}`);
|
|
153
|
+
const { files, error } = await safeBuild({
|
|
154
|
+
config: definedConfig,
|
|
155
|
+
logger
|
|
156
|
+
}, {
|
|
157
|
+
pluginManager,
|
|
158
|
+
fabric
|
|
159
|
+
});
|
|
160
|
+
if (logger.logLevel === LogMapper.debug) {
|
|
161
|
+
logger.consola?.start("Writing logs");
|
|
162
|
+
const logFiles = await logger.writeLogs();
|
|
163
|
+
logger.consola?.success(`Written logs: \n${logFiles.join("\n")}`);
|
|
164
|
+
}
|
|
165
|
+
const summary = getSummary({
|
|
166
|
+
filesCreated: files.length,
|
|
167
|
+
pluginManager,
|
|
168
|
+
config: definedConfig,
|
|
169
|
+
status: error ? "failed" : "success",
|
|
170
|
+
hrStart
|
|
171
|
+
});
|
|
172
|
+
if (error && logger.consola) {
|
|
173
|
+
logger.consola?.resumeLogs();
|
|
174
|
+
logger.consola.error(`Build failed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath) : ""}`);
|
|
175
|
+
logger.consola.box({
|
|
176
|
+
title: `${config.name || ""}`,
|
|
177
|
+
message: summary.join(""),
|
|
178
|
+
style: {
|
|
179
|
+
padding: 2,
|
|
180
|
+
borderColor: "red",
|
|
181
|
+
borderStyle: "rounded"
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
const errors = getErrorCauses([error]);
|
|
185
|
+
if (logger.consola && errors.length && logger.logLevel === LogMapper.debug) errors.forEach((err) => {
|
|
186
|
+
logger.consola?.error(err);
|
|
187
|
+
});
|
|
188
|
+
logger.consola?.error(error);
|
|
189
|
+
process$1.exit(1);
|
|
190
|
+
}
|
|
191
|
+
if (config.output.format === "prettier") {
|
|
192
|
+
logger?.emit("start", `Formatting with ${config.output.format}`);
|
|
193
|
+
try {
|
|
194
|
+
await execa("prettier", [
|
|
195
|
+
"--ignore-unknown",
|
|
196
|
+
"--write",
|
|
197
|
+
path.resolve(definedConfig.root, definedConfig.output.path)
|
|
198
|
+
]);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
logger.consola?.warn("Prettier not found");
|
|
201
|
+
logger.consola?.error(e);
|
|
202
|
+
}
|
|
203
|
+
logger?.emit("success", `Formatted with ${config.output.format}`);
|
|
204
|
+
}
|
|
205
|
+
if (config.output.format === "biome") {
|
|
206
|
+
logger?.emit("start", `Formatting with ${config.output.format}`);
|
|
207
|
+
try {
|
|
208
|
+
await execa("biome", [
|
|
209
|
+
"format",
|
|
210
|
+
"--write",
|
|
211
|
+
path.resolve(definedConfig.root, definedConfig.output.path)
|
|
212
|
+
]);
|
|
213
|
+
} catch (e) {
|
|
214
|
+
logger.consola?.warn("Biome not found");
|
|
215
|
+
logger.consola?.error(e);
|
|
216
|
+
}
|
|
217
|
+
logger?.emit("success", `Formatted with ${config.output.format}`);
|
|
218
|
+
}
|
|
219
|
+
if (config.output.lint === "eslint") {
|
|
220
|
+
logger?.emit("start", `Linting with ${config.output.format}`);
|
|
221
|
+
try {
|
|
222
|
+
await execa("eslint", [path.resolve(definedConfig.root, definedConfig.output.path), "--fix"]);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
logger.consola?.warn("Eslint not found");
|
|
225
|
+
logger.consola?.error(e);
|
|
226
|
+
}
|
|
227
|
+
logger?.emit("success", `Linted with ${config.output.format}`);
|
|
228
|
+
}
|
|
229
|
+
if (config.output.lint === "biome") {
|
|
230
|
+
logger?.emit("start", `Linting with ${config.output.format}`);
|
|
231
|
+
try {
|
|
232
|
+
await execa("biome", [
|
|
233
|
+
"lint",
|
|
234
|
+
"--fix",
|
|
235
|
+
path.resolve(definedConfig.root, definedConfig.output.path)
|
|
236
|
+
]);
|
|
237
|
+
} catch (e) {
|
|
238
|
+
logger.consola?.warn("Biome not found");
|
|
239
|
+
logger.consola?.error(e);
|
|
240
|
+
}
|
|
241
|
+
logger?.emit("success", `Linted with ${config.output.format}`);
|
|
242
|
+
}
|
|
243
|
+
if (config.output.lint === "oxlint") {
|
|
244
|
+
logger?.emit("start", `Linting with ${config.output.format}`);
|
|
245
|
+
try {
|
|
246
|
+
await execa("oxlint", ["--fix", path.resolve(definedConfig.root, definedConfig.output.path)]);
|
|
247
|
+
} catch (e) {
|
|
248
|
+
logger.consola?.warn("Oxlint not found");
|
|
249
|
+
logger.consola?.error(e);
|
|
250
|
+
}
|
|
251
|
+
logger?.emit("success", `Linted with ${config.output.format}`);
|
|
252
|
+
}
|
|
253
|
+
if (config.hooks) await executeHooks({
|
|
254
|
+
hooks: config.hooks,
|
|
255
|
+
logger
|
|
256
|
+
});
|
|
257
|
+
logger.consola?.log(`⚡Build completed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath) : ""}`);
|
|
258
|
+
logger.consola?.box({
|
|
259
|
+
title: `${config.name || ""}`,
|
|
260
|
+
message: summary.join(""),
|
|
261
|
+
style: {
|
|
262
|
+
padding: 2,
|
|
263
|
+
borderColor: "green",
|
|
264
|
+
borderStyle: "rounded"
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
//#endregion
|
|
270
|
+
export { generate };
|
|
271
|
+
//# sourceMappingURL=generate-ChOKW4hA.js.map
|