upload-release-tools
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

介绍

主要用于封装了一些与 Docker 镜像打包、推送和远程服务器上传相关的操作。

  1. loginToDocker(host, port) 函数用于登录到远程 Docker 仓库。它首先检查 Docker 服务是否启动,然后提示用户输入镜像仓库的用户名和密码,并使用 docker login 命令登录到远程镜像仓库。

  2. execCommand(commands, config) 函数用于执行一组命令。它接受一个命令数组和一个配置对象作为参数,循环执行每个命令。如果命令中包含 Docker 相关的操作并且 Docker 尚未登录,则会先调用 loginToDocker 函数进行登录。

  3. execBeforeCheck(configuration) 函数用于在上传到服务器之前进行一些检查,比如校验 Node.js 版本是否符合约定的版本要求。

  4. uploadTools({ config, commands }) 函数是一个异步函数,它首先调用 execBeforeCheck 函数进行检查,然后调用 execCommand 函数执行命令。

这个封装的目的是将 Docker 相关的操作和上传到远程服务器的操作进行封装,使得代码更加模块化和可复用。通过调用 uploadTools 函数并传入配置和命令,可以方便地完成 Docker 镜像的打包、推送和远程服务器上传操作。

代码示例

// 在上面的介绍中使用此包需要按照如下方式传入对应的所需参数;
const uploadTools = require("upload-release-tools");
const config = {
  host: "", // 必传项  服务器 IP 例:127.0.0.1
  port: "", // 必传项  远程服务器端口 例:8888
  nodeVersion: "", // 选传项 项目依赖的 nodeVersion 例:14
};

const commands = ["npm run build"]; // 一些执行命令放在这里

uploadTools({ config, commands });

使用方式

npm i upload-release-tools

在 packeage.json 中配置

"scripts": {
"release": "node ./bin/release.js ",
}

在/bin/release.js 中添加:

const uploadTools = require("upload-release-tools");
const config = {
  host: "127.0.0.1",
  port: "8000",
  nodeVersion: "16",
};
const commands = ["npm run build", "docker build ..."];
uploadTools({ config, commands });

运行命令:

yarn release

git 代码地址:https://gitee.com/chen_yan1/release-tools

Readme

Keywords

none

Package Sidebar

Install

npm i upload-release-tools

Weekly Downloads

2

Version

1.0.3

License

ISC

Unpacked Size

6.68 kB

Total Files

4

Last publish

Collaborators

  • eliaukcy