# @zenflux/cli

Latest version **0.1.43** (published 2026-01-19) · 0 weekly downloads

## Install

```sh
npm install @zenflux/cli
pnpm add @zenflux/cli
yarn add @zenflux/cli
bun add @zenflux/cli
```

Provides the command `@z-cli`.

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.43 |
| Published | 2026-01-19 |
| First published | 2023-10-12 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 24 |
| Unpacked size | 284.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | inewlegend |

## Links

- npm: https://www.npmjs.com/package/@zenflux/cli
- npm.io page: https://npm.io/package/@zenflux/cli

## Dependencies (24)

- [acorn](https://npm.io/package/acorn.md) ^8.15.0
- [tslib](https://npm.io/package/tslib.md) ^2.6.2
- [pacote](https://npm.io/package/pacote.md) ^21.0.3
- [rollup](https://npm.io/package/rollup.md) ^4.9.1
- [semver](https://npm.io/package/semver.md) ^7.6.3
- [blessed](https://npm.io/package/blessed.md) ^0.1.81
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.3
- [@swc/core](https://npm.io/package/@swc/core.md) latest
- [verdaccio](https://npm.io/package/verdaccio.md) ^5.29.2
- [libnpmpack](https://npm.io/package/libnpmpack.md) ^9.0.9
- [node-fetch](https://npm.io/package/node-fetch.md) ^3.3.2
- [typescript](https://npm.io/package/typescript.md) latest
- [magic-string](https://npm.io/package/magic-string.md) ^0.30.5
- [npm-packlist](https://npm.io/package/npm-packlist.md) ^10.0.3
- [libnpmpublish](https://npm.io/package/libnpmpublish.md) ^11.1.2
- [@zenflux/utils](https://npm.io/package/@zenflux/utils.md) 0.1.24
- [@zenflux/worker](https://npm.io/package/@zenflux/worker.md) 0.0.25
- [@verdaccio/config](https://npm.io/package/@verdaccio/config.md) next
- [@verdaccio/node-api](https://npm.io/package/@verdaccio/node-api.md) next
- [@zenflux/typescript-vm](https://npm.io/package/@zenflux/typescript-vm.md) 0.1.23
- [@rollup/plugin-commonjs](https://npm.io/package/@rollup/plugin-commonjs.md) latest
- [@microsoft/api-extractor](https://npm.io/package/@microsoft/api-extractor.md) ^7.53.2
- [@zenflux/tsconfig-to-swc](https://npm.io/package/@zenflux/tsconfig-to-swc.md) 0.1.20
- [@rollup/plugin-node-resolve](https://npm.io/package/@rollup/plugin-node-resolve.md) latest

## Recent versions

- 0.1.43 (latest) — 2026-01-19
- 0.1.42 — 2025-12-11
- 0.1.41 — 2025-11-21
- 0.1.40 — 2025-11-21
- 0.1.39 — 2025-11-20
- 0.1.38 — 2025-11-20
- 0.1.37 — 2025-11-20
- 0.1.36 — 2025-11-20
- 0.1.35 — 2025-11-20
- 0.1.34 — 2025-11-20
- 0.1.33 — 2025-11-20
- 0.1.32 — 2025-11-20
- 0.1.31 — 2025-11-19
- 0.1.30 — 2025-11-19
- 0.1.29 — 2025-11-19
- … 32 more at https://npm.io/package/@zenflux/cli/versions

## README

# @zenflux/cli

## 📍 Overview

The repository contains a CLI tool called `@z-cli` that offers functionalities related to building, publishing, watching **monorepo** workspaces, and generating projects from templates.

It utilizes technologies like `Babel`, `Rollup`, `TypeScript`, `SWC` and `Verdaccio`.

The tool is designed to simplify the development process by providing a command-line interface with various commands for managing and building projects. It includes modules for handling npm registry operations.

The tool's value proposition lies in its ability to automate repetitive tasks and streamline project workflows, ultimately enhancing developer productivity.

## 🛠️ Installation
Via package manager, `bun install @zenflux/cli`

---

## 📦 Features

The CLI provides several commands, each starting with the `@` symbol.

These commands are designed to help you manage and build your projects efficiently.

### Building Projects

* The CLI tool provides a command for building projects.
* It utilizes technologies such as `SWC`, `Rollup`, `ApiExtractor`, and more to bundle and transpile code for distribution.
* Developers can use this feature to create distribution-ready packages.
* When workspace has multiple packages, the tool can build all packages or a specific package, with support of multiple formats and extension.
* It can also generate declaration files and handle external dependencies.
* Utilizing multithreading, the tool can build multiple packages simultaneously, improving performance.


- **CLI Commands**: `@build` `@watch` `@typecheck`
  <br /><br />

- **Default Behavior** ( without  arguments ): `@z-cli @build` `@z-cli @watch` `@z-cli @typecheck`
    - Current working directory is **workspace**: Builds all packages in the workspace
    - Current working directory is **package**: Build the current package
      <br /><br />

- **CLI Options**
    - **--config:**
        - Description: Specify a custom config file
        - Examples:
            - `--config <config-file-name>`
            - `--config zenflux.test.config.ts`
              <br /><br />
    - **--workspace:**
        - Description: Run for a specific workspace
        - Examples:
            - `--workspace <company@package-name>`
            - `--workspace <package-name>`
            - `--workspace <package-name-a>, <package-name-b>`
            - `--workspace "prefix-*", "react-*"`
              <br /><br />

    - **--dev:**
        - Description: Run in development mode
        - Behaviors:
            - Shows all api-exporter diagnostics
            - No minification
            - Loads a different tsconfig file: `tsconfig.{format}.dev.json` or `tsconfig.dev.json`
            - Sets `process.env.NODE_ENV` to `development`
              <br /><br />
    - **--haltOnDiagnosticError:**
        - Description: Halt on typescript diagnostic error
        - Behaviors:
            - Kill the process if typescript diagnostic error occurred
              <br /><br />
    - **--no-diagnostic:**
        - Description: Disable typescript diagnostics
        - Behaviors:
            - No typescript diagnostics
              <br /><br />
    - **--no-declaration:**
        - Description: Disable declaration file generation
        - Behaviors:
            - No declaration file generation
            - No api-exporter will be used
              <br /><br />

- **Configuration file (`zenflux.config.ts`)**;
    - `format`:
        - Array of formats to build, eg:```[ "es", "cjs", "umd" ]```
    - `extensions`:
        - Array of extensions to build, eg: ```[ ".ts", ".js" ]```
    - `inputPath`:
        - Path to the input file
    - `outputName`:
        - Name of the output package
    - `outputFileName`:
        - Name of the output file
    - `inputDtsPath` (**optional**):
        - Path to the input dts file
    - `outputDtsPath` (**optional**):
        - Path to the output dts file
    - `globals` (**optional**):
        - Object that will be used as globals, eg: `{ jquery: "jQuery" }`
    - `external` (**optional**):
        - Array of external packages, packages that should not be bundled, eg: `react-dom`
    - `enableCustomLoader` (**optional**):
      - Enables zCustomLoader, (moduleForwarding depended on this)
    - `enableCjsAsyncWrap` (**optional**):
      - Enables cjs top level async wrap
    - `moduleForwarding`
        - This property is an object that maps module names to their respective paths. It is used to redirect module imports to different locations, which can be particularly useful in a monorepo setup.
          <br />
          The keys of the object represent the module names that you want to redirect. The values are another object that maps the source module path to the target module path.

          For example:
          ```ts
          moduleForwarding: {
              "@zenflux/react-reconciler": {
                  "@zenflux/react-scheduler": "@zenflux/react-scheduler/mock",
              },
              "@zenflux/react-noop-renderer": {
                  "@zenflux/react-scheduler": "@zenflux/react-scheduler/mock",
              }
          }
          ```
          In the above example, whenever the `@zenflux/react-reconciler` module imports `@zenflux/react-scheduler`, it will be redirected to `@zenflux/react-scheduler/mock`.
          <br />The same goes for `@zenflux/react-noop-renderer`.
          <br />This allows you to substitute certain modules with others, which can be especially useful for testing or development purposes.
          <br /><br />

- **Single Configuration**
     ```ts
     import type { IZConfig } from "@zenflux/cli";

     const config: IZConfig = {
         format: [ "es", "cjs" ],

         extensions: [ ".ts" ],

         inputPath: "src/index.ts",

         outputName: "@my-mono-repo/demo-package",
         outputFileName: "zenflux-core",

         inputDtsPath: "dist/src/index.d.ts",
         outputDtsPath: "dist/demo-package.d.ts",

         globals: {
             jquery: "jQuery",
         },

         external: [
             "react-dom",
         ],
     };

     export default config;
     ```
<br />

- **Multi Configuration**
  <br /><br />
  Each key in the configs object represents a package in your workspace.
  The key should match the name of the package.
  The `$defaults` key is optional and can be used to define default configurations that apply to all packages.
  These defaults can be overridden by package-specific configurations.
  Each package-specific configuration is an object that follows the `IZConfigInMulti` interface. This includes properties like:
  <br /><br />
- `inputPath`
- `outputFileName`
- `format`
- `extensions`
  <br /><br />
- This format allows you to manage configurations for multiple packages in a centralized manner, making it easier to maintain and update configurations as your workspace grows.
    - Example
      ```ts
      import type { IZConfigs } from "@zenflux/cli";

      const configs: IZConfigs = {
          $defaults: {
              format: [ "es", "cjs" ],
              extensions: [ ".ts" ],
          },
          "@zenflux/react-scheduler": {
              inputPath: "src/index.ts",
              outputFileName: "zenflux-react-scheduler",
              inputDtsPath: "dist/src/index.d.ts",
              outputDtsPath: "dist/zenflux-react-scheduler.d.ts",
          },
          "@zenflux/react-scheduler/mock": {
              inputPath: "src/index.mock.ts",
              outputFileName: "zenflux-react-scheduler.mock",
              inputDtsPath: "dist/src/index.mock.d.ts",
              outputDtsPath: "dist/zenflux-react-scheduler.mock.d.ts",
          }
      };

      export default configs;
      ```

<br /><br />
- **Typescript configuration** - `tsconfig.json`
    - Fallback flow:
        - `--dev`
            - `tsconfig.{format}.dev.json`
            - `tsconfig.dev.json`
        - Regular
            - `tsconfig.{format}.json`
            - `tsconfig.json`

<details>
<summary style="padding: 20px">Flow</summary>

- **Initialization**: The run method begins by retrieving the configurations using the `getConfigs` method and the configuration paths using the `getConfigsPaths` method.
    - **Configuration Retrieval**: It loads the `zenflux.config.ts` for each package and creates a `TZBuildOptions` object. It assigns the index of the current configuration to the thread property of the `TZBuildOptions` object if the number of configurations is greater than `DEFAULT_MIN_SINGLE_BUILD_CONFIGS`.
    - **Configuration Loop**: For each configuration path, it reads the TypeScript configuration using the `zTSConfigRead` method, performs pre-diagnostics using the `zTSPreDiagnostics` method, and loads the relevant `tsconfig.{format}.json`.
    - **Package Build**: For each package format, it builds the package and fires the `onBuiltFormat` callback if provided in `zenflux.config.ts`.
    - **Post-Build**: After building all configurations, for each configuration path, it begins the creation of declaration files and creates them using the `zTSCreateDeclaration` method.
    - **Declaration File Consolidation**: It then merges all the declaration files into a single declaration file per package using the `zApiExporter` method, if `inputDtsPath` and `outputDtsPath` are provided in `zenflux.config.ts`.
    - **Api-Extractor**: The `zApiExporter` method bundles multiple declaration files into a single declaration file. This operation eases usage for the package consumers. If operating in development mode, it also generates a diagnostics log for each package with paths like: `${ projectPath }/log/api-extractor-diagnostics.${ buildOutputFileName }.log`
      <br /><br />
    - **@watch**
        - **Initialization**: The `@watch` command starts by retrieving the configurations for each package in your workspace. These configurations are defined in the `zenflux.config.ts` file of each package.
        - **Watcher Creation**: It sets up a file watcher using the `chokidar.watch` method. This watcher monitors the files in your workspace for any changes.
        - **Configuration Loop**: For each package configuration, it creates a separate build process. This means that each package in your workspace has its own independent build process that runs whenever a file in that package changes.
        - **Rollup Configuration**: For each package, it creates a Rollup configuration. This configuration defines how the package should be bundled.
        - **Watcher Setup**: It sets up a watcher for each package. When the watcher detects a change in a package, it triggers the build process for that package. To avoid triggering multiple builds for rapid successive changes, the build process is debounced using the `debounce` function.
        - **Change Detection**: Whenever a file in a package changes, the watcher triggers the build process for that package. The build process is triggered after a delay to ensure that multiple rapid changes do not trigger multiple builds.
        - **Post-Build**: After each build process, it performs TypeScript pre-diagnostics for all configurations. This helps to catch and report any TypeScript errors that might have been introduced during the changes.
        - **Watch Method**: The `watch` method is used to set up a watcher for a specific package. It triggers a build process whenever a change is detected in the package. The build process is debounced to avoid triggering multiple builds for rapid successive changes.
        - **Debounce Function**: The `debounce` function ensures that the build process is not triggered more than once within a specified delay.
          <br />&nbsp;&nbsp;&nbsp;This is useful to avoid triggering multiple builds for rapid successive changes.
          <br />&nbsp;&nbsp;&nbsp;The debounce function works by delaying the execution of the build process until a certain amount of time has passed without any new changes being detected. This ensures that if multiple changes are made in quick succession, the build process will only be triggered once, after the last change.
          <br /><br />
</details>

---

### Type Checking Projects

The CLI tool provides a command for performing TypeScript type checking across workspace packages without building or generating declarations.

* The `@typecheck` command runs TypeScript's type checking on your code to catch type errors early in development.
* It supports checking all packages in a workspace or specific packages using workspace filtering.
* For single packages, it runs type checking synchronously for faster feedback.
* For multiple packages, it utilizes parallel execution to check packages simultaneously, improving performance.
* The command uses the main `tsconfig.json` file in each package (not format-specific configs).

- **CLI Commands**: `@typecheck`
  <br /><br />

- **Default Behavior**: `@z-cli @typecheck`
    - Current working directory is **workspace**: Typechecks all packages in the workspace
    - Current working directory is **package**: Typecheck the current package
      <br /><br />

- **CLI Options**
    - **--workspace:**
        - Description: Run for a specific workspace
        - Examples:
            - `--workspace <company@package-name>`
            - `--workspace <package-name>`
            - `--workspace <package-name-a>, <package-name-b>`
            - `--workspace "prefix-*", "react-*"`
              <br /><br />

    - **--haltOnDiagnosticError:**
        - Description: Halt on typescript diagnostic error
        - Behaviors:
            - Kill the process if typescript diagnostic error occurred
              <br /><br />

    - **--config:**
        - Description: Specify a custom config file
        - Examples:
            - `--config <config-file-name>`
            - `--config zenflux.test.config.ts`
              <br /><br />

- **Examples**
    - `@z-cli @typecheck` - Typecheck all packages in workspace
    - `@z-cli @typecheck --workspace "react-*"` - Typecheck packages matching pattern
    - `@z-cli @typecheck --workspace zenflux-cli` - Typecheck specific package
    - `@z-cli @typecheck --haltOnDiagnosticError` - Stop on first type error

---

### Publishing Packages

The tool supports publishing npm packages to a registry. It includes features for configuring and publishing packages, ensuring they are available for installation by other developers. Developers can manage and publish their packages with ease.

- **CLI Commands**: `@publish`
- **Default Behavior**: `@z-cli @publish`
    - Trying to publish all publishable packages in the workspace (select able by console menu)

- **CLI Options**
    - **[package-name]:**
        - Description: Specify package(s) to publish directly, skipping interactive selection
        - Examples:
            - `@z-cli @publish @zenflux/core`
            - `@z-cli @publish @zenflux/core,@zenflux/cli`
          <br /><br />
    - **--token:**
        - Description: Specify an npm authentication token for publishing
        - Examples:
            - `--token=npm_xxxxxxxxxxxx`
            - `--token npm_xxxxxxxxxxxx`
        - Note: Token can also be set via `NPM_TOKEN` environment variable or `.npmrc` file
        - Priority: `--token` flag > `NPM_TOKEN` env > `.npmrc` file
          <br /><br />

- **Flow**:
    - Determining if local npm will be used
    - Determining if the package is publishable
    - Asking the user for packages to publish
    - Replacing **workspace:** dependency ranges with concrete semver versions
        - Uses the just-bumped local version when the dependency is part of the current publish batch
        - Falls back to the latest version from the npm registry if no local version is available
    - Showing the user the packages/files that will be published
    - Asking the user for confirmation, and publishing the packages
      <br /><br />

---

### Generating Projects from Templates

The tool supports generating new projects from predefined templates stored in the `templates/` directory.

- **CLI Commands**: `@generate`
- **Default Behavior**: `@z-cli @generate`
    - Lists all available templates from `templates/*`
    - Prompts for template variable values (defined in `zenflux.template-vars.txt`)
    - Lets user select target workspace from `package.json` workspaces
    - Prompts for project name
    - Copies template files with variable replacement to selected workspace
      <br /><br />

- **Template Variable Format** (`zenflux.template-vars.txt`):
    ```
    $${@zenflux/project-name}$$,eg: @zenflux/react-commander
    $${project-name}$$,eg: react-commander
    $$server_port_number$$,eg 8080
    ```
    - Format: `$${variable-name}$$,eg: example-value`
    - Variables are replaced throughout all template files during generation
      <br /><br />

- **Examples**:
    - `@z-cli @generate` - Start interactive template generation
      <br /><br />

---

### Registry Operations

The tool handles interactions with npm registries, creating a local npm registry for testing and development purposes

- **CLI Commands**: `@registry`
  <br /><br />

- **Sub Commands**:
    - **@server:**
        - Description: Starts a local npm registry server.
        - Usage: `@z-cli @registry @server`
          <br /><br />
    - **@use:**
        - Description: Use npm with custom configuration, which will be forwarded to the local npm server.
        - Arguments:
            - `id`: Id of the npm registry server, can be obtained using: `@registry @list` command
            - `command`: A npm command to execute against the registry
        - Examples:
            - `@z-cli @registry @use npm <id> <command>`
            - `@z-cli @registry @use npm 4a1a whoami`
            - `@z-cli @registry @use npm 4a1a install`
    - **@list:**
        - Description: List all online npm registry servers.
        - Usage: `@z-cli @registry @list`
    - **@clean:**
        - Description: Delete current npm registry server and '.npmrc' token.
        - Usage: `@z-cli @registry @clean`
          <br /><br />

<br /><br />

---

### Global arguments
- **--zvm-verbose:** Log [tsnode-vm](https://github.com/ZenFlux/zenflux/tree/main/packages/zenflux-tsnode-vm) verbose, shows modules resolution

- **--verbose:** Log verbose

- **--help:** Show help

---
## 📸 Screenshots

`@z-cli @build --workspace "react-*" --no-diagnostic --no-declaration`

![image](https://github.com/ZenFlux/zenflux/assets/10234691/9b074d4f-d2cd-4d4e-ae8e-aab0a8802faa)
*Building all React packages without diagnostics and declaration files.*

`@z-cli @watch --workspace "react-*" --no-diagnostic --no-declaration`

![image](https://github.com/ZenFlux/zenflux/assets/10234691/7443dfde-dc1b-47dd-b735-a509393125e9)
*Watching all React packages without diagnostics and declaration files.*

`@z-cli @watch --workspace "react-*" --verbose`

![image](https://github.com/ZenFlux/zenflux/assets/10234691/47dce715-f1a3-4309-a924-4e704894a35f)
*Verbose mode for watching all React packages.*

---
_Source: https://npm.io/package/@zenflux/cli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
