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 such as isPromise, isURL, createJSDocBlockText, cache,...
  • createPlugin functionality to set up a plugin.
  • defineConfig functionality to set up the kubb.config.js file.
  • Abstract classes for plugins
    • Generator which contains the base with a getter for options and a build function.
  • Managers classes as the base for all logic

Installation

shell
bun add @kubb/core
shell
pnpm add @kubb/core
shell
npm install @kubb/core
shell
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 })

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,
})

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.