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

@via-cli/init-command

v0.0.2

Published

via-cli init command

Readme

@via-cli/init-command

Via CLI 项目初始化命令

功能特性

  • ✨ 支持多种项目模板选择
  • 🔄 智能缓存管理(自动下载和更新模板)
  • 🎯 本地模板路径支持(用于开发测试)
  • 📦 当前支持的模板类型:
    • TypeScript 工具库
    • Vue 3 组件库

使用方法

基本用法

# 交互式创建项目
via-cli init my-project

# 使用帮助
via-cli init

开发模式(使用本地模板)

在开发和测试阶段,可以使用 --targetPath 参数指定本地模板路径:

# 使用本地 TypeScript 工具库模板
via-cli init my-utils --targetPath /path/to/templates/ts-utils-temp/index.js

# 使用本地 Vue 组件库模板  
via-cli init my-comps --targetPath /path/to/templates/vue-bu-temp/index.js

生产模式(使用远程模板)

模板发布到 npm 后,不指定 targetPath 即可自动从远程下载:

# 自动下载模板到缓存目录
via-cli init my-project

# 后续使用会检查更新
via-cli init another-project

工作流程

使用本地模板(targetPath)

  1. 用户执行命令:via-cli init my-project --targetPath /local/template/index.js
  2. 选择模板类型(交互式选择)
  3. 直接使用指定的本地模板路径
  4. 执行模板的 index.js 生成项目
  5. 项目创建完成

使用远程模板(缓存管理)

  1. 用户执行命令:via-cli init my-project
  2. 选择模板类型(交互式选择)
  3. 检查缓存目录(~/.via-cli/dependencies/
    • 如果模板已存在:检查并更新到最新版本
    • 如果模板不存在:从 npm 下载模板
  4. 执行缓存中的模板 index.js
  5. 项目创建完成

模板结构要求

每个模板包需要:

  1. package.json 配置:
{
  "name": "@via-cli/xxx-lib",
  "version": "x.x.x",
  "type": "module",
  "main": "index.js"
}
  1. index.js 入口文件:
    • 必须是 ES Module 格式
    • 实现项目生成逻辑
    • 支持通过环境变量接收参数:
      • PROJECT_NAME: 项目名称
      • PACKAGES_DIR: 输出目录

环境变量

  • CLI_TARGET_PATH: 本地模板路径(用于开发测试)
  • CLI_HOME_PATH: CLI 主目录(默认:~/.via-cli
  • PROJECT_NAME: 传递给模板的项目名称
  • PACKAGES_DIR: 传递给模板的输出目录

缓存目录结构

~/.via-cli/
  └── dependencies/
      └── node_modules/
          ├── @via-cli/ts-utils-lib/
          │   ├── index.js
          │   └── package.json
          └── @via-cli/vue-bu-lib/
              ├── index.js
              └── package.json

测试指南

测试本地模板

# 进入测试目录
cd f:\test-cli

# 测试 TypeScript 工具库模板
via-cli init test-utils \
  --targetPath f:\study\via-cli-study\via-cli-dev\templates\ts-utils-temp\index.js

# 测试 Vue 组件库模板
via-cli init test-comps \
  --targetPath f:\study\via-cli-study\via-cli-dev\templates\vue-bu-temp\index.js

测试远程模板(需要先发布模板到 npm)

# 不指定 targetPath,会自动从 npm 下载
via-cli init my-project

# 第二次使用会检查更新
via-cli init another-project

开发说明

添加新模板

  1. templates/ 目录创建新模板
  2. InitCommand 类的 templates 数组中添加配置:
{
  name: "新模板名称",
  packageName: "@via-cli/new-template-lib",
  description: "模板描述",
  type: "模板类型"
}
  1. 发布模板到 npm(可选,本地测试不需要)

调试模式

# 开启 verbose 日志
via-cli init my-project --debug

# 查看详细执行流程
via-cli init my-project --debug --targetPath /local/template/index.js

常见问题

Q: targetPath 应该指向什么?

A: 应该指向模板的 index.js 文件完整路径。

Q: 为什么要先测试 targetPath 模式?

A: 因为模板包还未发布到 npm,使用本地路径可以直接测试模板功能。

Q: 缓存的模板如何更新?

A: 每次使用都会自动检查并更新到最新版本。

Q: 如何清理缓存?

A: 使用 via-cli cache clear 命令清理所有缓存。

License

ISC