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

@xiawang1024/build-docker

v2.2.3

Published

一个用于简化 Docker 镜像构建的命令行工具。

Readme

build-docker

一个用于简化 Docker 镜像构建的命令行工具。

简介

build-docker 是一个 Node.js 命令行工具,旨在帮助开发者更便捷地构建 Docker 镜像。它支持交互式提示,允许用户自定义镜像名称和标签,并自动生成 Dockerfile、.dockerignore 和 nginx.conf 文件。该工具还支持直接构建镜像并将其推送到 Harbor 镜像仓库。

安装

npm install -g @xiawang1024/build-docker

使用

build-docker [options]

选项

  • -p, --project-path <path>: 项目路径,默认为当前目录 (.)。
  • -i, --image-name <name>: Docker 镜像名称。默认为 package.json 中的 name 字段。
  • -t, --image-tag <tag>: Docker 镜像标签。
  • --no-prompt: 禁用交互式提示。
  • --build: 直接构建镜像,不生成文件。

示例

  1. 交互式构建镜像 (推荐):

    build-docker

    运行后,会提示你选择镜像标签,并输入镜像名称,最后会确认是否构建和推送镜像。

  2. 指定镜像名称和标签,并禁用交互式提示:

    build-docker -i my-app -t latest --no-prompt

    这将使用 my-app 作为镜像名称,latest 作为镜像标签,并直接开始构建。

  3. 指定项目路径:

    build-docker -p /path/to/my/project

    指定项目路径后,会在该项目路径下生成 Dockerfile 和其他相关文件,并在该路径下构建镜像。

  4. 只构建镜像,不生成文件:

     build-docker -i my-app -t latest --build

    直接构建镜像,不生成 Dockerfile 和其他相关文件。

注意事项

  • 确保你的项目目录下存在 package.json 文件。
  • 构建镜像前,请确保已经安装 Docker。
  • 默认情况下,镜像会推送到 harbor.hndt.com/front/xiaw1024 命名空间下的 Harbor 镜像仓库。
  • 如果使用 --no-prompt 选项,必须同时提供镜像名称和标签。
  • 如果使用 --build 选项,会直接构建镜像,不会生成 Dockerfile.dockerignorenginx.conf 文件。

交互式提示

如果没有提供 --no-prompt 选项,build-docker 会以交互式方式提示你:

  1. 选择 Docker 镜像标签: 默认选项为 latest, 也可选择 develop
  2. 输入镜像名称: 默认为 package.json 中的 name 字段,可以自定义。
  3. 确认构建: 确认是否构建并推送镜像到 Harbor 镜像仓库。

目录结构

├── node_modules
├── package.json
├── package-lock.json
├── templates
│   ├── .dockerignore
│   ├── Dockerfile
│   └── nginx.conf
└── index.js

在项目路径下,会生成以下文件

├── Dockerfile
├── .dockerignore
└── nginx.conf

依赖

  • Commander.js: 用于解析命令行参数。
  • Inquirer.js: 用于创建交互式命令行界面。
  • Chalk: 用于美化终端输出。
  • Node.js 内置模块:fs/promises, path, url, child_process

License

MIT