npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

done-coding-template

v0.8.7

Published

预编译命令行工具

Downloads

29

Readme

@done-coding/cli-template

模板编译命令行工具 - 基于 Lodash 模板引擎的文件预编译工具

npm version License: MIT

安装

独立安装

npm install @done-coding/cli-template
# 或
pnpm add @done-coding/cli-template

作为 done-coding CLI 的一部分

npm install -g @done-coding/cli
# 然后使用
DC template [command]

快速开始

# 独立使用
dc-template [command]

# 作为主 CLI 的子命令
DC template [command]

# 查看帮助
dc-template --help

功能特性

  • 模板编译: 基于 Lodash 模板引擎编译模板文件
  • 📁 批量处理: 支持批量编译多个模板文件
  • 🔧 配置管理: 支持配置文件管理编译规则
  • 🔄 回滚功能: 支持编译结果的回滚操作
  • 📝 Markdown 支持: 支持 Markdown 代码块处理
  • 🎯 多种输出模式: 支持覆盖、追加、替换等输出模式及对应的逆操作(回滚)

API 文档

基础命令

dc-template init

初始化配置文件

# 创建默认配置文件
dc-template init

dc-template (默认命令)

编译模板

# 使用默认配置编译模板
dc-template

# 指定模板文件和输出文件
dc-template -i template.hbs -o output.txt

# 指定环境数据文件
dc-template -e data.json

# 指定输出模式
dc-template -m append

dc-template batch

批量编译模板

# 批量编译模板
dc-template batch

# 启用批量处理模式
dc-template -b true

命令选项

  • -e, --env: 环境数据文件 JSON 文件相对路径(优先级高于 envData)
  • -E, --envData: 环境变量数据(JSON 字符串)
  • -i, --input: 模板文件相对路径(优先级高于 inputTemplate)
  • -I, --inputData: 模板数据
  • -o, --output: 输出文件路径
  • -m, --mode: 输出模式,可选值:overwrite(默认)、appendreplacereturn
  • -b, --batch: 是否批量处理,默认为 false
  • -R, --rootDir: 运行目录
  • -C, --configPath: 配置文件相对路径,默认为 ./.done-coding/template.json
  • --rollbackDelAskAsYes: 回滚删除询问默认 yes(即不再额外询问,直接认为同意),默认为 false
  • --rollbackDelNullFile: 回滚时是否删除空文件,默认为 false
  • -d, --dealMarkdown: (检测是 markdown)是否处理(单个)代码块包裹,默认为 false
  • -r, --rollback: 是否回滚,默认为 false

使用示例

基础使用场景

# 1. 初始化配置
dc-template init

# 2. 编译单个模板
dc-template -i template.hbs -o output.html

# 3. 使用环境数据文件
dc-template -i template.hbs -o output.html -e data.json

# 4. 批量编译模板
dc-template batch

不同输出模式

# 覆盖模式(默认)
dc-template -i template.hbs -o output.txt -m overwrite

# 追加模式
dc-template -i template.hbs -o output.txt -m append

# 替换模式
dc-template -i template.hbs -o output.txt -m replace

# 返回模式(不写入文件)
dc-template -i template.hbs -m return

回滚操作

# 执行回滚
dc-template -r true

# 回滚时自动确认删除
dc-template -r true --rollbackDelAskAsYes true

# 回滚时删除空文件
dc-template -r true --rollbackDelNullFile true

Markdown 处理

# 处理 Markdown 代码块
dc-template -i template.md -o output.md -d true

作为主 CLI 的一部分

# Windows 系统
dc template init
dc template -i template.hbs -o output.txt
dc template batch

# macOS/Linux 系统
DC template init
DC template -i template.hbs -o output.txt
DC template batch

配置

通过 dc-template init 命令可以初始化配置文件 .done-coding/template.json

具体的配置选项需要查看初始化后生成的配置文件内容。

编程接口

本包提供了编程接口,具体的导出内容请查看包的类型定义文件。

故障排除

常见问题

Q: 配置文件找不到

# 检查配置文件是否存在
ls -la .done-coding/template.json

# 重新初始化配置
dc-template init

Q: 模板编译失败

# 检查模板文件是否存在
ls -la template.hbs

# 检查环境数据文件格式
cat data.json | jq .

# 验证模板语法
dc-template -i template.hbs -m return

Q: 回滚失败

# 检查是否有可回滚的操作
dc-template -r true

# 强制回滚并删除空文件
dc-template -r true --rollbackDelNullFile true

调试模式

# 查看版本信息
dc-template --version

# 查看帮助信息
dc-template --help

贡献指南

我们欢迎贡献!请遵循以下步骤:

  1. Fork 本仓库
  2. 创建功能分支:git checkout -b feature/amazing-feature
  3. 提交更改:git commit -m "feat: add amazing feature"
  4. 推送分支:git push origin feature/amazing-feature
  5. 创建 Pull Request

开发环境设置

# 克隆仓库
git clone https://gitee.com/done-coding/done-coding-cli.git
cd done-coding-cli/packages/template

# 安装依赖
pnpm install

# 开发模式
pnpm dev

# 构建
pnpm build

# 本地开发测试
node es/cli.mjs --help

# 注意:本地使用 node + 入口文件,发布后使用 bin 命令名
# 功能完全一致,只是调用方式不同

许可证

MIT © JustSoSu

相关链接