Command Line Tool
A command line tool (CLI) is a way of interacting with a program through text commands in a terminal. Qingkuai provides an official command line tool @qingkuai/cli. After installation it is invoked through the qingkuai command, and its capabilities are as follows:
init: initialize a new Qingkuai project in the working directory, with JavaScript and TypeScript templatesdev: start the dev server with instant hot module replacement (HMR)build: build the whole application or a component library into distributable outputpreview: start the preview server to preview the build output locallycheck: run syntax checks on component files and TypeScript files, with optional type checkingformat: format component files and other files supported by Prettierbuild-types: generate .d.ts declaration files for components and TypeScript files, used to expose types for library output
Installation
Install the CLI globally with a package manager:
- npm
- pnpm
- yarn
➜ npm install -g @qingkuai/cli
➜ pnpm add -g @qingkuai/cli
➜ yarn global add @qingkuai/cli
After installation, you can verify it by checking the version number:
➜ qingkuai -v
Output similar to the following means the installation succeeded:
Version 1.0.0
When you are unsure how a command works, add the --help (-h) option to any command to view its help:
For example, qingkuai init --help shows the complete usage of the init command, and qingkuai --help shows an overview of all commands.
init
Create a new Qingkuai application in the working directory:
➜ qingkuai init qingkuai-app
To initialize in an existing directory, pass .:
➜ qingkuai init .
The available options for this command:
| Option | Description | Default |
|---|---|---|
| --ts | Use the TypeScript template | — |
| --force | Allow writing into a non-empty target directory | — |
dev
Start the vite-based dev server with instant hot module replacement:
➜ qingkuai dev --port 5173 --open
The server's behavior can be adjusted with the following options:
| Option | Description | Default |
|---|---|---|
| --config | Specify the vite config file path | — |
| --mode | Set the environment mode for .env.[mode] files (e.g. staging) | development |
| --port | Set the server port | 5173 |
| --host | Set the server host | — |
| --open | Open the browser when the server starts | — |
build
Build the application or a component library into distributable output; running it directly builds the whole application with index.html as the entry:
➜ qingkuai build
Passing a component file as a positional argument enters library mode, where --format sets the output format and --name sets the global variable name for the umd and iife formats, falling back to the name field in package.json:
➜ qingkuai build src/components/Button.qk --format es,cjs,umd
➜ qingkuai build src/components/Button.qk --format iife --name MyButton
The build behavior can be adjusted with the following options:
| Option | Description | Default |
|---|---|---|
| --out, -o | Set the build output directory | dist |
| --config | Specify the vite config file path | — |
| --mode | Set the environment mode for .env.[mode] files (e.g. staging) | production |
| --sourcemap | Generate sourcemap files | false |
| --minify | Minify the build output | true |
| --format | Library output format (comma-separated), one of: es, cjs, umd, iife | es |
| --name | Global variable name for the umd and iife formats | — |
| --oneline | Output diagnostics in a single-line format | — |
preview
Preview the output of build locally through vite's preview server; the build must be completed first, and an error is reported when the output directory does not exist:
➜ qingkuai build && qingkuai preview --open
The preview server's behavior can be adjusted with the following options:
| Option | Description | Default |
|---|---|---|
| --config | Specify the vite config file path | — |
| --mode | Set the environment mode for .env.[mode] files (e.g. staging) | production |
| --port | Set the preview server port | 4173 |
| --host | Set the preview server host | — |
| --open | Open the browser when the server starts | — |
check
Run syntax checks on Qingkuai component files and TypeScript files:
➜ qingkuai check src
Adding the --types option additionally runs type checking:
➜ qingkuai check --types src
Positional arguments accept one or more files or directories, and the process exits with a non-zero code when errors exist:
➜ qingkuai check --types src/components/Button.qk src/utils/*
The available options for this command:
| Option | Description | Default |
|---|---|---|
| --types | Run type checking | — |
| --oneline | Output diagnostics in a single-line format | — |
| --project | Specify the tsconfig.json / jsconfig.json path | — |
| --strict | Enable strict mode | false |
| --allow-js | Allow processing JS files | false |
| --skip-lib-check | Skip type checking of library files | false |
| --allow-const-reactive | Allow const declarations to be marked as reactive | true |
| --lib | Specify library type definitions (comma-separated) | — |
| --type-packages | Specify @types package names (comma-separated) | — |
| --module-resolution | Module resolution strategy, one of: classic, node, node16, nodenext, bundler | nodenext |
| --jsx | JSX handling mode, one of: preserve, react, react-jsx, react-jsxdev, react-native | preserve |
format
Based on Prettier and prettier-plugin-qingkuai, formats component files and other files supported by Prettier, printing the result to standard output by default:
➜ qingkuai format src
Add --write to write the result back to the files:
➜ qingkuai format src --write
Add --check to only check whether there are files waiting to be formatted:
➜ qingkuai format src --check
CLI flags take priority over the configuration file; the available options for this command:
| Option | Description | Default |
|---|---|---|
| --check | Only check whether there are files waiting to be formatted, without writing back | — |
| --write | Write the formatting result back to the files | — |
| --print-width | Maximum printed line width | 80 |
| --tab-width | Indentation width | 2 |
| --use-tabs | Indent with tabs | false |
| --semi | Add semicolons at the end of statements | true |
| --single-quote | Use single quotes instead of double quotes | false |
| --trailing-comma | Trailing comma style | all |
| --bracket-spacing | Spaces inside object literals | true |
| --arrow-parens | Parentheses around a single arrow function parameter | always |
| --end-of-line | End of line character | lf |
| --quote-props | Quoting style for object properties | as-needed |
| --single-attribute-per-line | One attribute per line | false |
| --prose-wrap | Line wrapping of Markdown prose | preserve |
| --html-whitespace-sensitivity | HTML whitespace sensitivity | css |
| --space-around-interpolation | Insert spaces around interpolation blocks | true |
| --self-close-empty-slot | Convert empty slot tags to self-closing form | true |
| --component-tag-format | Naming style of component tags, one of: camel, kebab | kebab |
| --component-attribute-format | Naming style of component attributes, one of: camel, kebab | kebab |
build-types
Generate the corresponding .d.ts declaration files for TypeScript and Qingkuai component files, used to expose types when building library output:
➜ qingkuai build-types src --out dist/types
The generated declaration files mirror the source file structure and are usually emitted into a temporary directory as intermediate output, then bundled into a single declaration entry file with api-extractor or rollup-plugin-dts.
The available options for this command:
| Option | Description | Default |
|---|---|---|
| --out, -o | Set the output directory for the declaration files | Follows tsconfig |
| --project | Specify the tsconfig.json / jsconfig.json path | — |
| --allow-js | Allow processing JS files | false |
| --skip-lib-check | Skip type checking of library files | false |
| --lib | Specify library type definitions (comma-separated) | — |
| --type-packages | Specify @types package names (comma-separated) | — |
| --module-resolution | Module resolution strategy, one of: classic, node, node16, nodenext, bundler | nodenext |
| --jsx | JSX handling mode, one of: preserve, react, react-jsx, react-jsxdev, react-native | preserve |
| --oneline | Output diagnostics in a single-line format | — |
Using Upstream Tools
Since the project's dependencies do not directly include Vite or Prettier, the CLI package re-exports the type definitions and methods of these upstream tools; when writing configuration files, import them from the CLI package instead of adding them as project dependencies — this avoids version conflicts and automatically picks up upstream tool updates when the CLI is upgraded:
// vite.config.ts
import { defineConfig } from "@qingkuai/cli/vite"
export default defineConfig({
server: {
port: 3000
}
})
The CLI automatically injects the vite-plugin-qingkuai plugin, so there is no need to add it manually in the config file.
// prettier.config.ts
import type { Config } from "@qingkuai/cli/prettier"
const config: Config = {
printWidth: 100,
singleQuote: true,
spaceAroundInterpolation: true
}
export default config
The re-exported TypeScript is usually not aimed at configuration files but at build scripts and similar scenarios. For example, the following script resolves all source files covered by tsconfig.json and can serve as the foundation of a custom build pipeline:
// scripts/list-files.mjs
import ts from "@qingkuai/cli/typescript"
const configFile = ts.readConfigFile("tsconfig.json", ts.sys.readFile)
const parsed = ts.parseJsonConfigFileContent(
configFile.config,
ts.sys,
process.cwd()
)
// Print all source files covered by the tsconfig
console.log(parsed.fileNames)