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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tecace/ace-cli

v0.0.9

Published

cli核心模块

Readme

@tecace/ace-cli

description

ace-cli 脚手架:基于 typescript 开发,核心模块、工具包、命令包分层管理,独立部署,自动更新,npm 包缓存,拥有高扩展性和维护性。

install

npm install -g @tecace/[email protected]

usage

用户目录 userhome 和存储目录

注意:下文中使用 ${userhome} 指代用户目录

注意:下文中使用 ${userhome} 指代用户目录

注意:下文中使用 ${userhome} 指代用户目录

用户目录

userdir: https://www.npmjs.com/package/userdir?activeTab=readme

存储路径是基于 userdir 工具获取到的 home 目录

import { userdir } from 'userdir';
const userhome = userdir(); // Windows: C:\Users\username MACOS: /Users/username

默认缓存路径

命令包,模板包的下载与缓存由核心模块控制,默认会缓存在 ${userhome}/.ace-cli

修改位于用户目录下缓存路径

在 ${userhome} 下新建.cli_env 文件,写入 CLI_HOME_PATH = '.my-cli'

最终缓存路径会被改为 ${userhome}/.my-cli

# userhone/.cli_env
HOME_PATH = '.my-cli'

插件化机制

脚手架自带默认自带了 init 命令,调用方法

ace-cli init <project_name>

可以通过脚手架提供的插件化机制去扩展新的命令,不用改动原有代码

在${userhome}/.cli_env 文件下新增命令

格式 1:COMMANDS_命令名称大写 = 命令,命令描述,线上 online ,包名@版本名

格式 2:COMMANDS_命令名称大写 = 命令,命令描述,本地 local ,本地包的绝对地址

例子如下所示:

COMMANDS_CLEAN = clean,clean cache,online,@tecace/[email protected]
COMMANDS_GENERATE = generate,description of generate command,local,/Users/ace0220/commands/generate

自定义命令开发

    • 第一步首先如上示例所示,在${userhome}/.cli_env 新增命令,env 中的 key 如果与命令相关,一定要以 COMMANDS_开头。
    • 每个命令的业务逻辑都可以是一个 package,package.json 中必须有 main 属性,指向 index.js 文件
    • 命令业务逻辑开发可以使用 typescript 开发,但是打包后的 index 代码必须为 commonjs 规范
    • 命令的业务逻辑继承于@tecace/model-command 的 Command 类
    • 必须实现两个方法,init 方法和 exec 方法
    • 必须对外暴露一个 export default 方法
import { Command } from '@tecace/model-command';
import { aceLog } from '@tecace/ace-log';
class CleanCommand extends Command {
  // 将参数传入父类
  constructor(argv) {
    super(argv);
  }
  // 必须实现init方法
  init() {
    aceLog.log('verbose', 'cleancommand', 'init');
  }
  // 必须实现exec方法
  async exec() {
    aceLog.log('verbose', 'cleancommand', 'exec');
  }
}

export default function clean() {
  return new CleanCommand(arguments);
}

完成以上步骤之后,执行 ace-cli 就可以看到新指令的存在

ace0220@ace-mbp cli-test % ace-cli
ace-cli info version: 0.0.6
ace-cli info Home path: /Users/ace0220/.ace-cli
Usage: ace-cli <command> [options]

Options:
  -V, --version                 output the version number
  -d, --debug                   debug mode (default: false)
  -lc, --localPath <localPath>  Specifies the local command file path (default: "")
  -h, --help                    display help for command
# 这里显示可以使用的Command和描述,显示出了clean 命令
Commands:
  init [options] [projectName]
  clean                         clean cache
  help [command]                display help for command

开发新命令流程参考

可以参考笔者的 clean 命令的开发

github:https://github.com/ACE0220/tecace/tree/main/ace-cli/commands/clean npm: https://www.npmjs.com/package/@tecace/command-clean

笔者采用 typescript 开发,打包工具使用的是 rollup,打包后的代码是 commonjs 规范