@dashnex/cli

中文文档
0.9.0发布于 2026/11/07UNLICENSEDTypeScriptES Module近 30 天下载 2737

Command-line interface for DashNex framework

原始使用文档
文档目录9 节
  1. Installation
  2. Usage
  3. Commands
  4. Sessions
  5. Options
  6. Developing a marketplace module
  7. Creating your own command
  8. 1. Write a handler
  9. 2. CliCommandConfig shape

@dashnex/cli

Command-line interface for the DashNex framework. This CLI tool provides essential commands for managing DashNex projects, including module building, database operations, and migrations. It searches for all @dashnex/* modules in node_modules folder, and loads commands from them.

Each module can add a command to CLI. Read more here

Installation

npm install -g @dashnex/cli

Update to the latest stable version later with dashnex update — it reinstalls the CLI with the same package manager (npm or pnpm) and package (dashnex or @dashnex/cli) it was installed with.

Usage

dashnex <command> [options]

Commands

CommandDescription
versionDisplay the version of the CLI
updateUpdate the CLI to the latest stable version, using the npm or pnpm global install it came from
loginLog in to your DashNex account
logoutLog out and remove local credentials
switchSwitch to another business
whoamiShow the logged-in business (with its ID), user and session file
devRun the development server (run in DashNex application folder); -p/--port, -H/--host, --https
checkRun build-time validations (run in DashNex application folder)
installInstall dependencies using pnpm or npm (run in DashNex application folder)
app createCreate a new DashNex application
app pullPull existing application to specified folder
app pushPush local application to DashNex
app deleteDelete application from DashNex
app deployDeploy application to DashNex
app statusShow the business, application ID, status, URL and session file
app clearDelete local dependencies, caches and build output
secrets listList all secret names bound to the worker
secrets setCreate or update a secret
secrets deleteDelete a secret
module initCreate a reserved marketplace module in packages/ from the module template (run in DashNex application folder)
module submit <package>Build, publish and submit a marketplace module for review (run in DashNex application folder)

Sessions

The session lives in .dashnex/settings.json. Commands use the nearest one, looking in the current folder first and then in each parent folder; files are never merged. An application folder with its own .dashnex/settings.json therefore has its own session, independent of the one in your home folder. login, logout, switch, whoami and app status all act on that same file and print its path.

The CLI keeps its session under two keys and leaves every other key in the file alone:

{
  "business": { "token": "…", "refreshToken": "…", "id": "103602" },
  "id": { "token": "…", "refreshToken": "…", "expiresAt": 1793270400000 }
}

business is the token for the selected business; id is the DashNex ID session switch uses. Files written by CLI 0.7.x and older (flat token, businessId, idToken… keys) are still read and are moved into this layout the next time the CLI saves the file.

Inside an application, the CLI checks the session against the BUSINESS_ID (and, where it matters, APPLICATION_ID) of the application. Each ID is read from the first of .env.production, .env.development and .env that names it. app push, app deploy, app delete, app pull, app tail, secrets and module commands that use the session (such as db migrate --remote) refuse to run for another business. whoami and app status show a warning instead.

Options

login:

  • --business <id> — Business ID to select
  • --no-browser — Print the sign-in URL instead of opening a browser

Sign-in goes through DashNex ID in your browser: approve the request, copy the code you are shown, and paste it back into the CLI. Codes are valid for 10 minutes and can only be used once.

Inside an application, login selects the business named by BUSINESS_ID (unless --business is given; see Sessions), and switches to it when the current session is for another business.

logout:

Removes the session from the settings file the other commands use (see Sessions) and prints its path.

switch:

  • [businessId] — Business to switch to; without it, pick from the list of your businesses

Re-uses the DashNex ID session saved by dashnex login, so no new sign-in is needed.

dev:

  • -p, --port <port> — Port for the dev server (falls back to the PORT env var, then 3000)
  • -H, --host <host> — Host/interface to bind, e.g. 0.0.0.0 when the app runs inside Docker (falls back to the HOST env var, then localhost). With --https the certificate also covers this host.
  • --https — Serve over HTTPS with a locally trusted certificate. Uses mkcert from your PATH, or downloads it once into ~/.dashnex/mkcert, installs the local CA (may prompt for your password) and writes localhost.pem + localhost-key.pem into the app's .dashnex/certificates/ folder (never committed). Falls back to HTTP if that fails.

app create:

  • --subdomain <subdomain> — Subdomain
  • -t, --template <template> — Template, optional (name@branch-or-tag)

app pull:

  • -y, --yes — Skip prompts and child commands

app push:

  • --deploy / --no-deploy — Auto-deploy or skip deploy after push
  • --no-check — Skip pre-push checks

app delete:

  • -y, --yes — Skip confirmation prompt

app clear:

  • -y, --yes — Skip all prompts

Removes node_modules (including the vite cache), the generated src/dashnex registry and dist. Interactively it then asks separately whether to delete the local database (.wrangler), since that is the one target holding data a rebuild cannot restore. With -y/--ci there is nobody to ask, so the database is cleared along with everything else.

secrets set:

  • --name <name> — Secret name (prompted if omitted)
  • --value <value> — Secret value (prompted with masked input if omitted)

secrets delete:

  • --name <name> — Secret name (prompted if omitted)

module init:

  • [address] — Module to create, e.g. crm or @acme/crm. Without it, a single missing reserved module is created directly; with several, you pick one of them and only that module is created. If your business holds the same address in two namespaces (an older @dashnex/crm and a newer @acme/crm), pass the full package name
  • --all — Create every reserved module that is not in packages/ yet
  • --ci — No prompts. With several missing modules, pass an address or --all

module submit:

  • <address> — Module to submit, e.g. crm or @acme/crm. Pass the full package name when your business holds the address in two namespaces
  • --ci — Disable spinner (CI mode)

Developing a marketplace module

Marketplace modules are npm packages that extend your DashNex application. A module is published under your business's own namespace, e.g. @acme/crm (acme is the namespace, crm the address). Modules reserved before namespaces existed keep their @dashnex/<address> name. To build one:

  1. Join the Developers program and reserve a module name on business.dashnex.com.
  2. Deploy your application once. This writes the DashNex registry .npmrc.
  3. Run dashnex app pull in the application folder.
  4. Run dashnex module init. It creates packages/<address> from the module template, sets the package name to the reserved one (@<namespace>/<address>), points the template's translation namespace and /template page and API paths at the module, and links the module into your application's package.json.
  5. Build and develop: cd packages/<address> && pnpm install && pnpm build, then dashnex install && dashnex dev in the application folder.
  6. When the module is ready, run dashnex module submit @<namespace>/<address> (a bare <address> also works when you hold it in one namespace). The package name in packages/<address>/package.json must match the reservation. It builds and publishes the module to the DashNex registry under the review dist-tag, then submits the version for review (latest moves only once the version is approved). The local version must be higher than the last submitted one, and no other version may be in review.

The pulled application's .npmrc is copied into the module folder for publishing. It maps your namespace (@<namespace>:registry=) to the DashNex registry; the CLI publishes to that registry, falling back to the @dashnex:registry line. The file is gitignored in the module folder, and the CLI never puts the registry token on a command line.

Creating your own command

The CLI auto-discovers commands from every installed @dashnex/* module (and your app). To add a command, a module exports a default array of CliCommandConfig from src/commands/index.ts. On startup the CLI looks for the command file in each module, in this order:

  1. dist/commands/index.js — the built package (published modules)
  2. src/commands/index.ts — linked / in-development modules
  3. src/commands/index.js

It imports the file and reads its default export (an array), or a named commands export as a fallback. Discovered commands are registered at the top level, so a command named report is invoked as dashnex report.

1. Write a handler

A handler is a CliCommand — any object with an async execute(options) method. options is a single object merging the parsed flags (by their long name), positional arguments (by name), and inherited parent options.

// src/commands/index.ts
import type { CliCommand, CliCommandConfig } from '@dashnex/types'

class ReportCommand implements CliCommand {
  async execute(options: { format: string; out?: string; name?: string; ci?: boolean }) {
    console.log(`Generating ${options.format} report for ${options.name ?? 'all'}…`)
    // ...do the work
  }
}

const commands: CliCommandConfig[] = [
  {
    name: 'report',
    description: 'Generate a report',
    arguments: [
      { name: 'name', description: 'Target name', required: false },
    ],
    options: [
      { flags: '-f, --format <format>', description: 'Output format', defaultValue: 'json' },
      { flags: '-o, --out <path>', description: 'Write to a file' },
    ],
    handler: new ReportCommand(),
  },
]

export default commands

Now dashnex report acme --format csv -o ./acme.csv calls execute({ name: 'acme', format: 'csv', out: './acme.csv', ci: false }).

2. CliCommandConfig shape

FieldTypeDescription
namestringThe command word (dashnex <name>). Required.
descriptionstringShown in --help. Required.
handlerCliCommandObject with execute(options): Promise<void>. Required (use a no-op when the command only groups subcommands).
argumentsCliArgument[]Positional args: { name, description, required?, defaultValue? }. Rendered as <name> (required) or [name] (optional).
optionsCliOption[]Flags: { flags, description, defaultValue? } — flags uses commander syntax, e.g. -f, --format <format>.
subcommandsCliCommandConfig[]Nested commands (e.g. dashnex mymodule sync). A parent with subcommands prints help when run alone.

Notes:

  • A --ci flag is added to every command automatically (disables spinners / interactive prompts); read it as options.ci.
  • Errors thrown from execute are reported and exit with code 1; throwing a user-interrupt is handled gracefully.
  • Publish step: make sure your build emits dist/commands/index.js and that dist is in the package's files, so the command ships with the module.

版本与发布记录

@dashnex/cli 共发布 84 个版本,首次发布于 2026/02/13;过去 12 个月发布了 84 个版本。

版本发布日期距今
0.9.0latest2026/11/074 天前
0.8.112026/11/047 天前
0.8.102026/11/047 天前
0.8.92026/11/047 天前
0.8.82026/11/047 天前
0.8.72026/11/047 天前

关于 @dashnex/cli 的常见问题

@dashnex/cli 是什么?

Command-line interface for DashNex framework

如何安装 @dashnex/cli?

在项目目录运行 npm install @dashnex/cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 dashnex,可以用 npx dashnex 直接运行。

@dashnex/cli 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dashnex/cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dashnex/cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dashnex/cli 可以商用吗?

@dashnex/cli 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@dashnex/cli 的下载量有多少?

根据 npm 官方下载统计,@dashnex/cli 在 2026/10/12 – 2026/11/10 这 30 天内被下载 2,737 次,日均约 91 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dashnex/cli 还在维护吗?

最新版本 0.9.0 发布于 2026/11/07(4 天前);至今共发布 84 个版本,其中过去 12 个月发布了 84 个;首次发布于 2026/02/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。