@kubb/cli 3.0.0-alpha.3 → 3.0.0-alpha.31
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/README.md +13 -4
- package/dist/chunk-2UGBJEKD.js +209 -0
- package/dist/chunk-2UGBJEKD.js.map +1 -0
- package/dist/{chunk-NKSXZ2SM.cjs → chunk-WAXEQ7ZU.cjs} +1508 -4011
- package/dist/chunk-WAXEQ7ZU.cjs.map +1 -0
- package/dist/{generate-IC27XOTA.js → generate-5JRBGXVI.js} +44 -57
- package/dist/generate-5JRBGXVI.js.map +1 -0
- package/dist/generate-OSUA57KC.cjs +246 -0
- package/dist/generate-OSUA57KC.cjs.map +1 -0
- package/dist/index.cjs +26 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -6
- package/dist/index.d.ts +3 -6
- package/dist/index.js +11 -18
- package/dist/index.js.map +1 -1
- package/package.json +17 -18
- package/src/commands/generate.ts +33 -25
- package/src/generate.ts +84 -57
- package/src/index.ts +1 -1
- package/src/utils/Writables.ts +23 -0
- package/src/utils/executeHooks.ts +24 -44
- package/src/utils/getPlugins.ts +0 -10
- package/src/utils/getSummary.ts +13 -39
- package/src/utils/watcher.ts +5 -9
- package/bin/bkubb.cjs +0 -6
- package/dist/chunk-NKSXZ2SM.cjs.map +0 -1
- package/dist/chunk-VGYRBGKV.js +0 -252
- package/dist/chunk-VGYRBGKV.js.map +0 -1
- package/dist/generate-IC27XOTA.js.map +0 -1
- package/dist/generate-SW6IGE4J.cjs +0 -228
- package/dist/generate-SW6IGE4J.cjs.map +0 -1
- package/src/utils/OraWritable.ts +0 -22
- package/src/utils/spinner.ts +0 -5
- package/src/utils/writeLog.ts +0 -18
package/dist/index.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { defineCommand, runCommand, runMain } from "citty";
|
|
7
|
-
import getLatestVersion from "latest-version";
|
|
8
|
-
import { lt } from "semver";
|
|
9
|
-
import consola from "consola";
|
|
1
|
+
export { generate } from './chunk-2UGBJEKD.js';
|
|
2
|
+
import { defineCommand, runCommand, runMain } from 'citty';
|
|
3
|
+
import getLatestVersion from 'latest-version';
|
|
4
|
+
import { lt } from 'semver';
|
|
5
|
+
import consola from 'consola';
|
|
10
6
|
|
|
11
7
|
// package.json
|
|
12
|
-
var version = "3.0.0-alpha.
|
|
13
|
-
|
|
14
|
-
// src/index.ts
|
|
8
|
+
var version = "3.0.0-alpha.31";
|
|
15
9
|
var name = "kubb";
|
|
16
10
|
var main = defineCommand({
|
|
17
11
|
meta: {
|
|
@@ -37,20 +31,19 @@ Run \`npm install -g @kubb/cli\` to update`,
|
|
|
37
31
|
} catch (_e) {
|
|
38
32
|
}
|
|
39
33
|
if (rawArgs[0] !== "generate") {
|
|
40
|
-
const generateCommand = await import(
|
|
34
|
+
const generateCommand = await import('./generate-5JRBGXVI.js').then((r) => r.default);
|
|
41
35
|
await runCommand(generateCommand, { rawArgs });
|
|
42
36
|
process.exit(0);
|
|
43
37
|
}
|
|
44
38
|
},
|
|
45
39
|
subCommands: {
|
|
46
|
-
generate: () => import(
|
|
40
|
+
generate: () => import('./generate-5JRBGXVI.js').then((r) => r.default)
|
|
47
41
|
}
|
|
48
42
|
});
|
|
49
43
|
async function run(_argv) {
|
|
50
44
|
await runMain(main);
|
|
51
45
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
46
|
+
|
|
47
|
+
export { run };
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
56
49
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/index.ts"],"names":[],"mappings":";;;;;;;AAEE,IAAW,OAAA,GAAA,gBAAA,CAAA;ACKb,IAAM,IAAO,GAAA,MAAA,CAAA;AAEb,IAAM,OAAO,aAAc,CAAA;AAAA,EACzB,IAAM,EAAA;AAAA,IACJ,IAAA;AAAA,IACA,OAAA;AAAA,IACA,WAAa,EAAA,iBAAA;AAAA,GACf;AAAA,EACA,MAAM,KAAA,CAAM,EAAE,OAAA,EAAW,EAAA;AACvB,IAAI,IAAA;AACF,MAAM,MAAA,aAAA,GAAgB,MAAM,gBAAA,CAAiB,WAAW,CAAA,CAAA;AAExD,MAAI,IAAA,EAAA,CAAG,OAAS,EAAA,aAAa,CAAG,EAAA;AAC9B,QAAA,OAAA,CAAQ,GAAI,CAAA;AAAA,UACV,KAAO,EAAA,8BAAA;AAAA,UACP,OAAS,EAAA,CAAA,GAAA,EAAM,OAAO,CAAA,aAAA,EAAW,aAAa,CAAA;AAAA,0CAAA,CAAA;AAAA,UAE9C,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,CAAA;AAAA,YACT,WAAa,EAAA,QAAA;AAAA,YACb,WAAa,EAAA,SAAA;AAAA,WACf;AAAA,SACD,CAAA,CAAA;AAAA,OACH;AAAA,aACO,EAAI,EAAA;AAAA,KAAC;AAEd,IAAI,IAAA,OAAA,CAAQ,CAAC,CAAA,KAAM,UAAY,EAAA;AAE7B,MAAM,MAAA,eAAA,GAAkB,MAAM,OAAO,wBAAwB,EAAE,IAAK,CAAA,CAAC,CAAM,KAAA,CAAA,CAAE,OAAO,CAAA,CAAA;AAEpF,MAAA,MAAM,UAAW,CAAA,eAAA,EAAiB,EAAE,OAAA,EAAS,CAAA,CAAA;AAE7C,MAAA,OAAA,CAAQ,KAAK,CAAC,CAAA,CAAA;AAAA,KAChB;AAAA,GACF;AAAA,EACA,WAAa,EAAA;AAAA,IACX,QAAA,EAAU,MAAM,OAAO,wBAAwB,EAAE,IAAK,CAAA,CAAC,CAAM,KAAA,CAAA,CAAE,OAAO,CAAA;AAAA,GACxE;AACF,CAAC,CAAA,CAAA;AAED,eAAsB,IAAI,KAAiC,EAAA;AACzD,EAAA,MAAM,QAAQ,IAAI,CAAA,CAAA;AACpB","file":"index.js","sourcesContent":["{\n \"name\": \"@kubb/cli\",\n \"version\": \"3.0.0-alpha.31\",\n \"description\": \"Generator cli\",\n \"keywords\": [\n \"typescript\",\n \"plugins\",\n \"kubb\",\n \"codegen\",\n \"cli\"\n ],\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git://github.com/kubb-labs/kubb.git\",\n \"directory\": \"packages/cli\"\n },\n \"license\": \"MIT\",\n \"author\": \"Stijn Van Hulle <stijn@stijnvanhulle.be\",\n \"sideEffects\": false,\n \"type\": \"module\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"main\": \"dist/index.cjs\",\n \"module\": \"dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"bin\": {\n \"kubb\": \"bin/kubb.cjs\"\n },\n \"files\": [\n \"src\",\n \"dist\",\n \"bin\",\n \"!/**/**.test.**\",\n \"!/**/__tests__/**\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"clean\": \"npx rimraf ./dist\",\n \"lint\": \"bun biome lint .\",\n \"lint:fix\": \"bun biome lint --apply-unsafe .\",\n \"release\": \"pnpm publish --no-git-check\",\n \"release:canary\": \"bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check\",\n \"start\": \"tsup --watch\",\n \"test\": \"vitest --passWithNoTests\",\n \"typecheck\": \"tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false\"\n },\n \"dependencies\": {\n \"@kubb/core\": \"workspace:*\",\n \"bundle-require\": \"^5.0.0\",\n \"chokidar\": \"^4.0.1\",\n \"citty\": \"^0.1.6\",\n \"cli-progress\": \"^3.12.0\",\n \"consola\": \"^3.2.3\",\n \"cosmiconfig\": \"^9.0.0\",\n \"esbuild\": \"^0.23.1\",\n \"execa\": \"^9.4.0\",\n \"latest-version\": \"^9.0.0\",\n \"p-queue\": \"^8.0.1\",\n \"semver\": \"^7.6.3\",\n \"string-argv\": \"^0.3.2\",\n \"tinyrainbow\": \"^1.2.0\"\n },\n \"devDependencies\": {\n \"@kubb/config-ts\": \"workspace:*\",\n \"@kubb/config-tsup\": \"workspace:*\",\n \"@kubb/plugin-oas\": \"workspace:*\",\n \"@types/cli-progress\": \"^3.11.6\",\n \"@types/node\": \"^20.16.10\",\n \"@types/semver\": \"^7.5.8\",\n \"source-map-support\": \"^0.5.21\",\n \"tsup\": \"^8.3.0\",\n \"typescript\": \"^5.6.2\"\n },\n \"engines\": {\n \"node\": \">=20\"\n },\n \"preferGlobal\": true,\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org/\"\n }\n}\n","import { defineCommand, runCommand, runMain } from 'citty'\nimport getLatestVersion from 'latest-version'\nimport { lt } from 'semver'\n\nimport { version } from '../package.json'\nimport consola from 'consola'\n\nconst name = 'kubb'\n\nconst main = defineCommand({\n meta: {\n name,\n version,\n description: 'Kubb generation',\n },\n async setup({ rawArgs }) {\n try {\n const latestVersion = await getLatestVersion('@kubb/cli')\n\n if (lt(version, latestVersion)) {\n consola.box({\n title: 'Update available for `Kubb` ',\n message: `\\`v${version}\\` → \\`v${latestVersion}\\`\nRun \\`npm install -g @kubb/cli\\` to update`,\n style: {\n padding: 2,\n borderColor: 'yellow',\n borderStyle: 'rounded',\n },\n })\n }\n } catch (_e) {}\n\n if (rawArgs[0] !== 'generate') {\n // generate is not being used\n const generateCommand = await import('./commands/generate.ts').then((r) => r.default)\n\n await runCommand(generateCommand, { rawArgs })\n\n process.exit(0)\n }\n },\n subCommands: {\n generate: () => import('./commands/generate.ts').then((r) => r.default),\n },\n})\n\nexport async function run(_argv?: string[]): Promise<void> {\n await runMain(main)\n}\n\nexport { generate } from './generate.ts'\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/cli",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.31",
|
|
4
4
|
"description": "Generator cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -18,9 +18,6 @@
|
|
|
18
18
|
"author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"type": "module",
|
|
21
|
-
"main": "dist/index.cjs",
|
|
22
|
-
"module": "dist/index.js",
|
|
23
|
-
"types": "./dist/index.d.ts",
|
|
24
21
|
"exports": {
|
|
25
22
|
".": {
|
|
26
23
|
"import": "./dist/index.js",
|
|
@@ -28,9 +25,11 @@
|
|
|
28
25
|
"default": "./dist/index.cjs"
|
|
29
26
|
}
|
|
30
27
|
},
|
|
28
|
+
"main": "dist/index.cjs",
|
|
29
|
+
"module": "dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
31
|
"bin": {
|
|
32
|
-
"kubb": "bin/kubb.cjs"
|
|
33
|
-
"bkubb": "bin/bkubb.cjs"
|
|
32
|
+
"kubb": "bin/kubb.cjs"
|
|
34
33
|
},
|
|
35
34
|
"files": [
|
|
36
35
|
"src",
|
|
@@ -41,30 +40,30 @@
|
|
|
41
40
|
],
|
|
42
41
|
"dependencies": {
|
|
43
42
|
"bundle-require": "^5.0.0",
|
|
44
|
-
"chokidar": "^
|
|
43
|
+
"chokidar": "^4.0.1",
|
|
45
44
|
"citty": "^0.1.6",
|
|
45
|
+
"cli-progress": "^3.12.0",
|
|
46
46
|
"consola": "^3.2.3",
|
|
47
47
|
"cosmiconfig": "^9.0.0",
|
|
48
48
|
"esbuild": "^0.23.1",
|
|
49
|
-
"execa": "^9.
|
|
50
|
-
"js-runtime": "^0.0.8",
|
|
49
|
+
"execa": "^9.4.0",
|
|
51
50
|
"latest-version": "^9.0.0",
|
|
52
|
-
"
|
|
51
|
+
"p-queue": "^8.0.1",
|
|
53
52
|
"semver": "^7.6.3",
|
|
54
53
|
"string-argv": "^0.3.2",
|
|
55
54
|
"tinyrainbow": "^1.2.0",
|
|
56
|
-
"@kubb/core": "3.0.0-alpha.
|
|
57
|
-
"@kubb/fs": "3.0.0-alpha.3"
|
|
55
|
+
"@kubb/core": "3.0.0-alpha.31"
|
|
58
56
|
},
|
|
59
57
|
"devDependencies": {
|
|
60
|
-
"@types/
|
|
58
|
+
"@types/cli-progress": "^3.11.6",
|
|
59
|
+
"@types/node": "^20.16.10",
|
|
61
60
|
"@types/semver": "^7.5.8",
|
|
62
61
|
"source-map-support": "^0.5.21",
|
|
63
|
-
"tsup": "^8.
|
|
64
|
-
"typescript": "^5.
|
|
65
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
66
|
-
"@kubb/
|
|
67
|
-
"@kubb/
|
|
62
|
+
"tsup": "^8.3.0",
|
|
63
|
+
"typescript": "^5.6.2",
|
|
64
|
+
"@kubb/config-ts": "3.0.0-alpha.31",
|
|
65
|
+
"@kubb/plugin-oas": "3.0.0-alpha.31",
|
|
66
|
+
"@kubb/config-tsup": "3.0.0-alpha.31"
|
|
68
67
|
},
|
|
69
68
|
"engines": {
|
|
70
69
|
"node": ">=20"
|
package/src/commands/generate.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { LogLevel } from '@kubb/core/logger'
|
|
2
1
|
import { defineCommand, showUsage } from 'citty'
|
|
3
2
|
import type { ArgsDef, ParsedArgs } from 'citty'
|
|
4
3
|
import { execa } from 'execa'
|
|
5
4
|
import c from 'tinyrainbow'
|
|
6
5
|
|
|
7
|
-
import path from 'node:path'
|
|
8
6
|
import { getConfig } from '../utils/getConfig.ts'
|
|
9
7
|
import { getCosmiConfig } from '../utils/getCosmiConfig.ts'
|
|
10
|
-
import { spinner } from '../utils/spinner.ts'
|
|
11
8
|
import { startWatcher } from '../utils/watcher.ts'
|
|
12
9
|
|
|
10
|
+
import path from 'node:path'
|
|
11
|
+
import * as process from 'node:process'
|
|
13
12
|
import { PromiseManager, isInputPath } from '@kubb/core'
|
|
13
|
+
import { LogMapper, createLogger } from '@kubb/core/logger'
|
|
14
14
|
import { generate } from '../generate.ts'
|
|
15
15
|
|
|
16
|
+
declare global {
|
|
17
|
+
var isDevtoolsEnabled: any
|
|
18
|
+
}
|
|
19
|
+
|
|
16
20
|
const args = {
|
|
17
21
|
config: {
|
|
18
22
|
type: 'string',
|
|
@@ -23,8 +27,8 @@ const args = {
|
|
|
23
27
|
type: 'string',
|
|
24
28
|
description: 'Info, silent or debug',
|
|
25
29
|
alias: 'l',
|
|
26
|
-
default:
|
|
27
|
-
valueHint:
|
|
30
|
+
default: 'info',
|
|
31
|
+
valueHint: 'silent|info|debug',
|
|
28
32
|
},
|
|
29
33
|
watch: {
|
|
30
34
|
type: 'boolean',
|
|
@@ -32,12 +36,6 @@ const args = {
|
|
|
32
36
|
alias: 'w',
|
|
33
37
|
default: false,
|
|
34
38
|
},
|
|
35
|
-
bun: {
|
|
36
|
-
type: 'boolean',
|
|
37
|
-
description: 'Run Kubb with Bun',
|
|
38
|
-
alias: 'b',
|
|
39
|
-
default: false,
|
|
40
|
-
},
|
|
41
39
|
debug: {
|
|
42
40
|
type: 'boolean',
|
|
43
41
|
description: 'Override logLevel to debug',
|
|
@@ -60,10 +58,8 @@ const command = defineCommand({
|
|
|
60
58
|
description: "[input] Generate files based on a 'kubb.config.ts' file",
|
|
61
59
|
},
|
|
62
60
|
args,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
async run({ args }) {
|
|
61
|
+
async run(commandContext) {
|
|
62
|
+
const { args } = commandContext
|
|
67
63
|
const input = args._[0]
|
|
68
64
|
|
|
69
65
|
if (args.help) {
|
|
@@ -72,18 +68,18 @@ const command = defineCommand({
|
|
|
72
68
|
}
|
|
73
69
|
|
|
74
70
|
if (args.debug) {
|
|
75
|
-
args.logLevel =
|
|
71
|
+
args.logLevel = 'debug'
|
|
76
72
|
}
|
|
77
73
|
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3
|
|
75
|
+
const logger = createLogger({
|
|
76
|
+
logLevel,
|
|
77
|
+
})
|
|
80
78
|
|
|
81
|
-
|
|
82
|
-
return
|
|
83
|
-
}
|
|
79
|
+
logger.emit('start', 'Loading config')
|
|
84
80
|
|
|
85
81
|
const result = await getCosmiConfig('kubb', args.config)
|
|
86
|
-
|
|
82
|
+
logger.emit('success', `Config loaded(${c.dim(path.relative(process.cwd(), result.filepath))})`)
|
|
87
83
|
|
|
88
84
|
const config = await getConfig(result, args)
|
|
89
85
|
|
|
@@ -94,9 +90,8 @@ const command = defineCommand({
|
|
|
94
90
|
|
|
95
91
|
if (isInputPath(config)) {
|
|
96
92
|
return startWatcher([input || config.input.path], async (paths) => {
|
|
97
|
-
await generate({ config, args })
|
|
98
|
-
|
|
99
|
-
spinner.start(c.yellow(c.bold(`Watching for changes in ${paths.join(' and ')}`)))
|
|
93
|
+
await generate({ config, args, input })
|
|
94
|
+
logger.emit('start', c.yellow(c.bold(`Watching for changes in ${paths.join(' and ')}`)))
|
|
100
95
|
})
|
|
101
96
|
}
|
|
102
97
|
}
|
|
@@ -109,6 +104,19 @@ const command = defineCommand({
|
|
|
109
104
|
}
|
|
110
105
|
|
|
111
106
|
await generate({ input, config, args })
|
|
107
|
+
|
|
108
|
+
if (globalThis.isDevtoolsEnabled) {
|
|
109
|
+
const restart = await logger.consola?.prompt('Restart(could be used to validate the profiler)?', {
|
|
110
|
+
type: 'confirm',
|
|
111
|
+
initial: false,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
if (restart) {
|
|
115
|
+
await command.run?.(commandContext)
|
|
116
|
+
} else {
|
|
117
|
+
process.exit(1)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
112
120
|
},
|
|
113
121
|
})
|
|
114
122
|
|
package/src/generate.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogMapper } from '@kubb/core/logger'
|
|
2
2
|
|
|
3
3
|
import c from 'tinyrainbow'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { type Config, Warning, safeBuild } from '@kubb/core'
|
|
8
|
-
import { createConsola } from 'consola'
|
|
9
|
-
import type { Args } from './commands/generate.ts'
|
|
5
|
+
import { type Config, safeBuild } from '@kubb/core'
|
|
10
6
|
import { executeHooks } from './utils/executeHooks.ts'
|
|
11
7
|
import { getErrorCauses } from './utils/getErrorCauses.ts'
|
|
12
8
|
import { getSummary } from './utils/getSummary.ts'
|
|
13
|
-
|
|
9
|
+
|
|
10
|
+
import { createLogger } from '@kubb/core/logger'
|
|
11
|
+
import { Presets, SingleBar } from 'cli-progress'
|
|
12
|
+
import type { Args } from './commands/generate.ts'
|
|
14
13
|
|
|
15
14
|
type GenerateProps = {
|
|
16
15
|
input?: string
|
|
@@ -19,48 +18,49 @@ type GenerateProps = {
|
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
export async function generate({ input, config, args }: GenerateProps): Promise<void> {
|
|
22
|
-
const logLevel =
|
|
21
|
+
const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3
|
|
23
22
|
const logger = createLogger({
|
|
24
23
|
logLevel,
|
|
25
24
|
name: config.name,
|
|
26
|
-
spinner,
|
|
27
|
-
consola: createConsola({
|
|
28
|
-
level: LogMapper[logLevel] || 3,
|
|
29
|
-
}),
|
|
30
25
|
})
|
|
26
|
+
const { root = process.cwd(), ...userConfig } = config
|
|
27
|
+
const inputPath = input ?? ('path' in userConfig.input ? userConfig.input.path : undefined)
|
|
31
28
|
|
|
32
|
-
logger.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
29
|
+
if (logger.logLevel !== LogMapper.debug) {
|
|
30
|
+
const progressCache = new Map<string, SingleBar>()
|
|
31
|
+
|
|
32
|
+
logger.on('progress_start', ({ id, size, message = '' }) => {
|
|
33
|
+
logger.consola?.pauseLogs()
|
|
34
|
+
const payload = { id, message }
|
|
35
|
+
const progressBar = new SingleBar(
|
|
36
|
+
{
|
|
37
|
+
format: '{percentage}% {bar} {value}/{total} | {message}',
|
|
38
|
+
barsize: 30,
|
|
39
|
+
clearOnComplete: true,
|
|
40
|
+
emptyOnZero: true,
|
|
41
|
+
},
|
|
42
|
+
Presets.shades_grey,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
if (!progressCache.has(id)) {
|
|
46
|
+
progressCache.set(id, progressBar)
|
|
47
|
+
progressBar.start(size, 1, payload)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
logger.on('progress_stop', ({ id }) => {
|
|
52
|
+
progressCache.get(id)?.stop()
|
|
53
|
+
logger.consola?.resumeLogs()
|
|
54
|
+
})
|
|
51
55
|
|
|
52
|
-
|
|
56
|
+
logger.on('progressed', ({ id, message = '' }) => {
|
|
57
|
+
const payload = { id, message }
|
|
53
58
|
|
|
54
|
-
|
|
59
|
+
progressCache.get(id)?.increment(1, payload)
|
|
55
60
|
})
|
|
56
|
-
|
|
57
|
-
performanceOpserver.observe({ type: 'measure' })
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
const inputPath = input ?? ('path' in userConfig.input ? userConfig.input.path : undefined)
|
|
62
|
-
|
|
63
|
-
spinner.start(`🚀 Building ${logLevel !== 'silent' ? c.dim(inputPath) : ''}`)
|
|
63
|
+
logger.emit('start', `Building ${logger.logLevel !== LogMapper.silent ? c.dim(inputPath) : ''}`)
|
|
64
64
|
|
|
65
65
|
const definedConfig: Config = {
|
|
66
66
|
root,
|
|
@@ -73,37 +73,55 @@ export async function generate({ input, config, args }: GenerateProps): Promise<
|
|
|
73
73
|
: userConfig.input,
|
|
74
74
|
output: {
|
|
75
75
|
write: true,
|
|
76
|
+
barrelType: 'named',
|
|
77
|
+
extension() {
|
|
78
|
+
return {
|
|
79
|
+
'.ts': '.ts',
|
|
80
|
+
}
|
|
81
|
+
},
|
|
76
82
|
...userConfig.output,
|
|
77
83
|
},
|
|
78
84
|
}
|
|
79
|
-
const
|
|
85
|
+
const hrStart = process.hrtime()
|
|
86
|
+
const { pluginManager, files, error } = await safeBuild({
|
|
80
87
|
config: definedConfig,
|
|
81
88
|
logger,
|
|
82
89
|
})
|
|
83
90
|
|
|
91
|
+
if (logger.logLevel === LogMapper.debug) {
|
|
92
|
+
logger.consola?.start('Writing logs')
|
|
93
|
+
|
|
94
|
+
const logFiles = await logger.writeLogs()
|
|
95
|
+
|
|
96
|
+
logger.consola?.success(`Written logs: \n${logFiles.join('\n')}`)
|
|
97
|
+
}
|
|
98
|
+
|
|
84
99
|
const summary = getSummary({
|
|
100
|
+
filesCreated: files.length,
|
|
85
101
|
pluginManager,
|
|
86
102
|
config: definedConfig,
|
|
87
103
|
status: error ? 'failed' : 'success',
|
|
88
|
-
|
|
89
|
-
logger,
|
|
104
|
+
hrStart,
|
|
90
105
|
})
|
|
91
106
|
|
|
92
|
-
if (error) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
if (error && logger.consola) {
|
|
108
|
+
logger.consola?.resumeLogs()
|
|
109
|
+
logger.consola.error(`Build failed ${logger.logLevel !== LogMapper.silent ? c.dim(inputPath) : ''}`)
|
|
110
|
+
|
|
111
|
+
logger.consola.box({
|
|
112
|
+
title: `${config.name || ''}`,
|
|
113
|
+
message: summary.join(''),
|
|
114
|
+
style: {
|
|
115
|
+
padding: 2,
|
|
116
|
+
borderColor: 'red',
|
|
117
|
+
borderStyle: 'rounded',
|
|
118
|
+
},
|
|
119
|
+
})
|
|
102
120
|
|
|
103
121
|
const errors = getErrorCauses([error])
|
|
104
|
-
if (logger.consola && errors.length && logLevel ===
|
|
122
|
+
if (logger.consola && errors.length && logger.logLevel === LogMapper.debug) {
|
|
105
123
|
errors.forEach((err) => {
|
|
106
|
-
logger.consola
|
|
124
|
+
logger.consola?.error(err)
|
|
107
125
|
})
|
|
108
126
|
}
|
|
109
127
|
|
|
@@ -112,10 +130,19 @@ export async function generate({ input, config, args }: GenerateProps): Promise<
|
|
|
112
130
|
process.exit(0)
|
|
113
131
|
}
|
|
114
132
|
|
|
115
|
-
|
|
133
|
+
if (config.hooks) {
|
|
134
|
+
await executeHooks({ hooks: config.hooks, logger })
|
|
135
|
+
}
|
|
116
136
|
|
|
117
|
-
|
|
118
|
-
spinner.succeed(`🚀 Build completed ${logLevel !== 'silent' ? c.dim(inputPath) : ''}`)
|
|
137
|
+
logger.consola?.log(`⚡Build completed ${logger.logLevel !== LogMapper.silent ? c.dim(inputPath) : ''}`)
|
|
119
138
|
|
|
120
|
-
|
|
139
|
+
logger.consola?.box({
|
|
140
|
+
title: `${config.name || ''}`,
|
|
141
|
+
message: summary.join(''),
|
|
142
|
+
style: {
|
|
143
|
+
padding: 2,
|
|
144
|
+
borderColor: 'green',
|
|
145
|
+
borderStyle: 'rounded',
|
|
146
|
+
},
|
|
147
|
+
})
|
|
121
148
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { defineCommand, runCommand, runMain } from 'citty'
|
|
|
2
2
|
import getLatestVersion from 'latest-version'
|
|
3
3
|
import { lt } from 'semver'
|
|
4
4
|
|
|
5
|
-
import consola from 'consola'
|
|
6
5
|
import { version } from '../package.json'
|
|
6
|
+
import consola from 'consola'
|
|
7
7
|
|
|
8
8
|
const name = 'kubb'
|
|
9
9
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Writable } from 'node:stream'
|
|
2
|
+
|
|
3
|
+
import c from 'tinyrainbow'
|
|
4
|
+
|
|
5
|
+
import * as process from 'node:process'
|
|
6
|
+
import type { WritableOptions } from 'node:stream'
|
|
7
|
+
import type { ConsolaInstance } from 'consola'
|
|
8
|
+
|
|
9
|
+
export class ConsolaWritable extends Writable {
|
|
10
|
+
consola: ConsolaInstance | undefined
|
|
11
|
+
command: string
|
|
12
|
+
constructor(consola: ConsolaInstance | undefined, command: string, opts?: WritableOptions) {
|
|
13
|
+
super(opts)
|
|
14
|
+
|
|
15
|
+
this.command = command
|
|
16
|
+
this.consola = consola
|
|
17
|
+
}
|
|
18
|
+
_write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
|
|
19
|
+
process.stdout.write(`${c.dim(chunk?.toString())}`)
|
|
20
|
+
|
|
21
|
+
callback()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,65 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Logger } from '@kubb/core/logger'
|
|
2
2
|
import { execa } from 'execa'
|
|
3
3
|
import { parseArgsStringToArgv } from 'string-argv'
|
|
4
4
|
import c from 'tinyrainbow'
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import { spinner } from './spinner.ts'
|
|
6
|
+
import { ConsolaWritable } from './Writables.ts'
|
|
8
7
|
|
|
9
|
-
import type { Writable } from 'node:stream'
|
|
10
8
|
import type { Config } from '@kubb/core'
|
|
9
|
+
import { LogMapper } from '@kubb/core/logger'
|
|
10
|
+
import PQueue from 'p-queue'
|
|
11
11
|
|
|
12
12
|
type ExecutingHooksProps = {
|
|
13
|
-
hooks: Config['hooks']
|
|
14
|
-
|
|
13
|
+
hooks: NonNullable<Config['hooks']>
|
|
14
|
+
logger: Logger
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export async function executeHooks({ hooks,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
17
|
+
export async function executeHooks({ hooks, logger }: ExecutingHooksProps): Promise<void> {
|
|
18
|
+
const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done].filter(Boolean)
|
|
19
|
+
const queue = new PQueue({ concurrency: 1 })
|
|
21
20
|
|
|
22
|
-
const
|
|
21
|
+
const promises = commands.map(async (command) => {
|
|
22
|
+
const consolaWritable = new ConsolaWritable(logger.consola!, command)
|
|
23
|
+
const [cmd, ..._args] = [...parseArgsStringToArgv(command)]
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if (!cmd) {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const oraWritable = new OraWritable(spinner, command)
|
|
31
|
-
const abortController = new AbortController()
|
|
32
|
-
const [cmd, ..._args] = [...parseArgsStringToArgv(command)]
|
|
29
|
+
await queue.add(async () => {
|
|
30
|
+
logger?.emit('start', `Executing hook ${logger.logLevel !== LogMapper.silent ? c.dim(command) : ''}`)
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
return null
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
spinner.start(`Executing hook ${logLevel !== 'silent' ? c.dim(command) : ''}`)
|
|
39
|
-
|
|
40
|
-
const subProcess = await execa(cmd, _args, {
|
|
32
|
+
await execa(cmd, _args, {
|
|
41
33
|
detached: true,
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
stdout: logger?.logLevel === LogMapper.silent ? undefined : ['pipe', consolaWritable],
|
|
35
|
+
stripFinalNewline: true,
|
|
44
36
|
})
|
|
45
|
-
spinner.suffixText = ''
|
|
46
|
-
|
|
47
|
-
if (logLevel === LogLevel.silent) {
|
|
48
|
-
spinner.succeed(`Executing hook ${logLevel !== 'silent' ? c.dim(command) : ''}`)
|
|
49
|
-
|
|
50
|
-
if (subProcess) {
|
|
51
|
-
console.log(subProcess.stdout)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
37
|
|
|
55
|
-
|
|
56
|
-
return { subProcess, abort: abortController.abort.bind(abortController) }
|
|
38
|
+
logger?.emit('success', `Executed hook ${logger.logLevel !== LogMapper.silent ? c.dim(command) : ''}`)
|
|
57
39
|
})
|
|
58
|
-
|
|
40
|
+
})
|
|
59
41
|
|
|
60
|
-
await Promise.all(
|
|
42
|
+
await Promise.all(promises)
|
|
61
43
|
|
|
62
|
-
|
|
63
|
-
spinner.succeed('Executing hooks')
|
|
64
|
-
}
|
|
44
|
+
logger?.emit('success', 'Executed hooks')
|
|
65
45
|
}
|
package/src/utils/getPlugins.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { PackageManager } from '@kubb/core'
|
|
2
|
-
|
|
3
1
|
import type { UserConfig } from '@kubb/core'
|
|
4
2
|
|
|
5
3
|
function isJSONPlugins(plugins: UserConfig['plugins']) {
|
|
@@ -12,14 +10,6 @@ function isObjectPlugins(plugins: UserConfig['plugins']): plugins is any {
|
|
|
12
10
|
return plugins instanceof Object && !Array.isArray(plugins)
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
async function importPlugin(name: string, options: object): Promise<UserConfig['plugins']> {
|
|
16
|
-
const packageManager = new PackageManager(process.cwd())
|
|
17
|
-
|
|
18
|
-
const importedPlugin: any = process.env.NODE_ENV === 'test' ? await import(name) : await packageManager.import(name)
|
|
19
|
-
|
|
20
|
-
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
13
|
export function getPlugins(plugins: UserConfig['plugins']): Promise<UserConfig['plugins']> {
|
|
24
14
|
if (isObjectPlugins(plugins)) {
|
|
25
15
|
throw new Error('Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')
|