Skip to content

@kubb/core 🦙 ​

The core contains the building blocks for all plugins.

Features ​

  • Read and write to the file-system(Windows, Mac and Linux support).
  • Format code/source with Prettier.
  • Types needed to create a plugin and the types needed for the lifecycle/pluginManager.
  • Basic utilities as isPromise, isURL, createJSDocBlockText, cache, ...
  • createPlugin functionality to setup a plugin.
  • defineConfig functionality to setup the kubb.config.js file.
  • Abstract classes for plugins
    • Generator which contains the base with getter for options and a build function.
    • SchemaGenerator which is a layer on top of Generator.
  • Managers classes as the base for all logic
    • FileManager which is used to store all files before those are getting saved to the file-system.
    • PluginManager which contains the logic of when which plugin can be triggerd, see pluginManager.

Installation ​

shell
bun add @kubb/core
bun add @kubb/core
shell
pnpm add @kubb/core
pnpm add @kubb/core
shell
npm install @kubb/core
npm install @kubb/core
shell
yarn add @kubb/core
yarn add @kubb/core

Usage ​

Simple example ​

typescript
import { build } from '@kubb/core'
import type { File } from '@kubb/core'

const files: File[] = await build({ config })
import { build } from '@kubb/core'
import type { File } from '@kubb/core'

const files: File[] = await build({ config })

Advanced example ​

typescript
import { build } from '@kubb/core'
import type { BuildOptions, File } from '@kubb/core'

const spinner = ora({
  color: 'blue',
  text: pc.blue('Generating files'),
}).start()

const logger: BuildOptions['logger'] = {
  log(message, logLevel) {
    if (logLevel === 'error') {
      spinner.fail(message)
    }
    spinner[logLevel](message)
  },
  spinner,
}

const files: File[] = await build({
  config: {
    ...config,
    root: config.root || process.cwd(),
  },
  mode: options.mode || 'development',
  logger,
})
import { build } from '@kubb/core'
import type { BuildOptions, File } from '@kubb/core'

const spinner = ora({
  color: 'blue',
  text: pc.blue('Generating files'),
}).start()

const logger: BuildOptions['logger'] = {
  log(message, logLevel) {
    if (logLevel === 'error') {
      spinner.fail(message)
    }
    spinner[logLevel](message)
  },
  spinner,
}

const files: File[] = await build({
  config: {
    ...config,
    root: config.root || process.cwd(),
  },
  mode: options.mode || 'development',
  logger,
})

Start the build process based on a defined config(see UserConfig type). This will trigger the different plugins and their created lifecycle methods.

Released under the MIT License.