@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/dist/index.js CHANGED
@@ -1,17 +1,11 @@
1
- import {
2
- generate
3
- } from "./chunk-VGYRBGKV.js";
4
-
5
- // src/index.ts
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.3";
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("./generate-IC27XOTA.js").then((r) => r.default);
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("./generate-IC27XOTA.js").then((r) => r.default)
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
- export {
53
- generate,
54
- run
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","../package.json"],"sourcesContent":["import { defineCommand, runCommand, runMain } from 'citty'\nimport getLatestVersion from 'latest-version'\nimport { lt } from 'semver'\n\nimport consola from 'consola'\nimport { version } from '../package.json'\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","{\n \"name\": \"@kubb/cli\",\n \"version\": \"3.0.0-alpha.3\",\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 \"main\": \"dist/index.cjs\",\n \"module\": \"dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"bin\": {\n \"kubb\": \"bin/kubb.cjs\",\n \"bkubb\": \"bin/bkubb.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 \"@kubb/fs\": \"workspace:*\",\n \"bundle-require\": \"^5.0.0\",\n \"chokidar\": \"^3.6.0\",\n \"citty\": \"^0.1.6\",\n \"consola\": \"^3.2.3\",\n \"cosmiconfig\": \"^9.0.0\",\n \"esbuild\": \"^0.23.1\",\n \"execa\": \"^9.3.1\",\n \"js-runtime\": \"^0.0.8\",\n \"latest-version\": \"^9.0.0\",\n \"ora\": \"^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/node\": \"^20.16.1\",\n \"@types/semver\": \"^7.5.8\",\n \"source-map-support\": \"^0.5.21\",\n \"tsup\": \"^8.2.4\",\n \"typescript\": \"^5.5.4\"\n },\n \"engines\": {\n \"node\": \">=20\"\n },\n \"preferGlobal\": true,\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org/\"\n }\n}\n"],"mappings":";;;;;AAAA,SAAS,eAAe,YAAY,eAAe;AACnD,OAAO,sBAAsB;AAC7B,SAAS,UAAU;AAEnB,OAAO,aAAa;;;ACFlB,cAAW;;;ADKb,IAAM,OAAO;AAEb,IAAM,OAAO,cAAc;AAAA,EACzB,MAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,aAAa;AAAA,EACf;AAAA,EACA,MAAM,MAAM,EAAE,QAAQ,GAAG;AACvB,QAAI;AACF,YAAM,gBAAgB,MAAM,iBAAiB,WAAW;AAExD,UAAI,GAAG,SAAS,aAAa,GAAG;AAC9B,gBAAQ,IAAI;AAAA,UACV,OAAO;AAAA,UACP,SAAS,MAAM,OAAO,gBAAW,aAAa;AAAA;AAAA,UAE9C,OAAO;AAAA,YACL,SAAS;AAAA,YACT,aAAa;AAAA,YACb,aAAa;AAAA,UACf;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF,SAAS,IAAI;AAAA,IAAC;AAEd,QAAI,QAAQ,CAAC,MAAM,YAAY;AAE7B,YAAM,kBAAkB,MAAM,OAAO,wBAAwB,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO;AAEpF,YAAM,WAAW,iBAAiB,EAAE,QAAQ,CAAC;AAE7C,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AAAA,EACA,aAAa;AAAA,IACX,UAAU,MAAM,OAAO,wBAAwB,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO;AAAA,EACxE;AACF,CAAC;AAED,eAAsB,IAAI,OAAiC;AACzD,QAAM,QAAQ,IAAI;AACpB;","names":[]}
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",
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": "^3.6.0",
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.3.1",
50
- "js-runtime": "^0.0.8",
49
+ "execa": "^9.4.0",
51
50
  "latest-version": "^9.0.0",
52
- "ora": "^8.0.1",
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.3",
57
- "@kubb/fs": "3.0.0-alpha.3"
55
+ "@kubb/core": "3.0.0-alpha.31"
58
56
  },
59
57
  "devDependencies": {
60
- "@types/node": "^20.16.1",
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.2.4",
64
- "typescript": "^5.5.4",
65
- "@kubb/config-ts": "3.0.0-alpha.3",
66
- "@kubb/config-tsup": "3.0.0-alpha.3",
67
- "@kubb/plugin-oas": "3.0.0-alpha.3"
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"
@@ -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: LogLevel.info,
27
- valueHint: `${LogLevel.silent}|${LogLevel.info}|${LogLevel.debug}`,
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
- setup() {
64
- spinner.start('🔍 Loading config')
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 = LogLevel.debug
71
+ args.logLevel = 'debug'
76
72
  }
77
73
 
78
- if (args.bun) {
79
- const command = process.argv.splice(2).filter((item) => item !== '--bun')
74
+ const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3
75
+ const logger = createLogger({
76
+ logLevel,
77
+ })
80
78
 
81
- await execa('bkubb', command, { stdout: process.stdout, stderr: process.stderr })
82
- return
83
- }
79
+ logger.emit('start', 'Loading config')
84
80
 
85
81
  const result = await getCosmiConfig('kubb', args.config)
86
- spinner.succeed(`🔍 Config loaded(${c.dim(path.relative(process.cwd(), result.filepath))})`)
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
- spinner.spinner = 'simpleDotsScrolling'
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 { LogLevel, LogMapper, createLogger, randomCliColour } from '@kubb/core/logger'
1
+ import { LogMapper } from '@kubb/core/logger'
2
2
 
3
3
  import c from 'tinyrainbow'
4
4
 
5
- import { spinner } from './utils/spinner.ts'
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
- import { writeLog } from './utils/writeLog.ts'
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 = (args.logLevel as LogLevel) || LogLevel.silent
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.on('debug', async (messages: string[]) => {
33
- if (logLevel === LogLevel.debug) {
34
- await writeLog(messages.join('\n'))
35
- }
36
- })
37
-
38
- logger.consola?.wrapConsole()
39
-
40
- if (logger.name) {
41
- spinner.prefixText = randomCliColour(logger.name)
42
- }
43
-
44
- const hrstart = process.hrtime()
45
-
46
- if (args.logLevel === LogLevel.debug) {
47
- const { performance, PerformanceObserver } = await import('node:perf_hooks')
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
- const performanceOpserver = new PerformanceObserver((items) => {
50
- const message = `${items.getEntries()[0]?.duration.toFixed(0)}ms`
51
+ logger.on('progress_stop', ({ id }) => {
52
+ progressCache.get(id)?.stop()
53
+ logger.consola?.resumeLogs()
54
+ })
51
55
 
52
- spinner.suffixText = c.yellow(message)
56
+ logger.on('progressed', ({ id, message = '' }) => {
57
+ const payload = { id, message }
53
58
 
54
- performance.clearMarks()
59
+ progressCache.get(id)?.increment(1, payload)
55
60
  })
56
-
57
- performanceOpserver.observe({ type: 'measure' })
58
61
  }
59
62
 
60
- const { root = process.cwd(), ...userConfig } = config
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 { pluginManager, error } = await safeBuild({
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
- hrstart,
89
- logger,
104
+ hrStart,
90
105
  })
91
106
 
92
- if (error) {
93
- spinner.suffixText = ''
94
- spinner.fail(`🚀 Build failed ${logLevel !== 'silent' ? c.dim(inputPath) : ''}`)
95
-
96
- console.log(summary.join(''))
97
-
98
- if (error instanceof Warning) {
99
- spinner.warn(c.yellow(error.message))
100
- process.exit(0)
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 === LogLevel.debug) {
122
+ if (logger.consola && errors.length && logger.logLevel === LogMapper.debug) {
105
123
  errors.forEach((err) => {
106
- logger.consola!.error(err)
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
- await executeHooks({ hooks: config.hooks, logLevel })
133
+ if (config.hooks) {
134
+ await executeHooks({ hooks: config.hooks, logger })
135
+ }
116
136
 
117
- spinner.suffixText = ''
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
- console.log(summary.join(''))
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 { LogLevel } from '@kubb/core/logger'
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 { OraWritable } from './OraWritable.ts'
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
- logLevel: LogLevel
13
+ hooks: NonNullable<Config['hooks']>
14
+ logger: Logger
15
15
  }
16
16
 
17
- export async function executeHooks({ hooks, logLevel }: ExecutingHooksProps): Promise<void> {
18
- if (!hooks?.done) {
19
- return
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 commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done]
21
+ const promises = commands.map(async (command) => {
22
+ const consolaWritable = new ConsolaWritable(logger.consola!, command)
23
+ const [cmd, ..._args] = [...parseArgsStringToArgv(command)]
23
24
 
24
- if (logLevel === LogLevel.silent) {
25
- spinner.start('Executing hooks')
26
- }
25
+ if (!cmd) {
26
+ return null
27
+ }
27
28
 
28
- const executers = commands
29
- .map(async (command) => {
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
- if (!cmd) {
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
- cancelSignal: abortController.signal,
43
- stdout: ['pipe', oraWritable],
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
- oraWritable.destroy()
56
- return { subProcess, abort: abortController.abort.bind(abortController) }
38
+ logger?.emit('success', `Executed hook ${logger.logLevel !== LogMapper.silent ? c.dim(command) : ''}`)
57
39
  })
58
- .filter(Boolean)
40
+ })
59
41
 
60
- await Promise.all(executers)
42
+ await Promise.all(promises)
61
43
 
62
- if (logLevel === LogLevel.silent) {
63
- spinner.succeed('Executing hooks')
64
- }
44
+ logger?.emit('success', 'Executed hooks')
65
45
  }
@@ -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')