@feature-sliced/cli

中文文档
1.0.0发布于 2024/01/15ISCES Module近 30 天下载 4788

Utility to quickly generate layers, slices, and segments from Feature-Sliced Design.

原始使用文档
文档目录4 节
  1. Installation
  2. Usage
  3. Credits
  4. License

@feature-sliced/cli

npm version Static checks and tests

Utility to quickly generate layers, slices, and segments from Feature-Sliced Design.

Installation

npm add -g @feature-sliced/cli

This will create a global binary fsd. You can install this CLI locally as well, but then you will need to use npx to run it.

Usage

Generate the Entities layer with a client slice that contains an index file and two segments, ui and api:

fsd entities client --segments ui api

Or, for short:

fsd e client -s ui,api

If you have at least one slice in your project already, the CLI will know where to generate. Otherwise, it will generate in the current folder, or you can specify the location yourself with the --root or -r option.

Other examples
  • Generate the Widgets layer with a bottom-bar slice that has an index file and segments ui and api in the src/ folder:

    fsd w bottom-bar -s ui api -r src
    fsd widget bottom-bar -s ui,api -r src
    fsd widgets bottom-bar --segments ui,api -r src
    

    Produces:

    • src/widgets/bottom-bar/index.(js|ts) (depending on your project)
    • src/widgets/bottom-bar/ui/
    • src/widgets/bottom-bar/api/
  • Generate the Features layer with a slice employee/employee-record inside a slice group employee:

    fsd f employee/employee-record
    fsd feat employee/employee-record
    

    In a detected FSD root[^1] or current folder, produces:

    • features/employee/employee-record/index.(js|ts) (depending on your project)
  • Generate the Entities layer with a user slice inside the src/lib folder, creating it if necessary:

    fsd e user -r ./src/lib
    fsd entity user --root ./src/lib
    

    Produces:

    • src/lib/entities/user/index.(js|ts) (depending on your project)
  • Generate the Pages layer with slices edit-note and note-list, each containing segments ui and api:

    fsd p edit-note note-list -s ui, api
    fsd page edit-note, note-list -s ui api
    

    In a detected FSD root[^1] or current folder, produces:

    • pages/edit-note/index.(js|ts) (depending on your project)
    • pages/edit-note/ui/
    • pages/edit-note/api/
    • pages/note-list/index.(js|ts)
    • pages/note-list/ui/
    • pages/note-list/api/
  • Generate the Shared layer with segments ui and api and an index file for each segment:

    fsd s ui api
    fsd s -s ui api
    fsd shared ui -s api
    

    In a detected FSD root[^1] or current folder, produces:

    • shared/ui/index.(js|ts)
    • shared/api/index.(js|ts)

Credits

Big thanks to a community member Agent_RBY_ for implementing most of the generating and detecting logic.

License

The source code of this project is distributed under the terms of the ISC license. It's like MIT, but better. Click here to learn what that means.

[^1]: An FSD root is the folder that contains slices in Feature-Sliced Design. There can be several independent roots in one project.

版本与发布记录

@feature-sliced/cli 共发布 3 个版本,首次发布于 2023/12/03;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2024/01/152 年前
1.0.0-beta.22023/12/032 年前
1.0.0-beta.12023/12/032 年前

关于 @feature-sliced/cli 的常见问题

@feature-sliced/cli 是什么?

Utility to quickly generate layers, slices, and segments from Feature-Sliced Design.

如何安装 @feature-sliced/cli?

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

@feature-sliced/cli 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/feature-sliced__cli 是否存在。

@feature-sliced/cli 支持 ESM 还是 CommonJS?

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

@feature-sliced/cli 可以商用吗?

@feature-sliced/cli 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@feature-sliced/cli 的下载量有多少?

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

@feature-sliced/cli 还在维护吗?

最新版本 1.0.0 发布于 2024/01/15(2 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/12/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。