Skip to content

Commit

Permalink
Merge pull request #6 from zuoxiaobai/v1.0.0
Browse files Browse the repository at this point in the history
V1.0.0
  • Loading branch information
dev-zuo authored Nov 7, 2022
2 parents 21c78f7 + 2fae2f4 commit c77493a
Show file tree
Hide file tree
Showing 24 changed files with 17,819 additions and 39 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ module.exports = {
rules: {
"prettier/prettier": "error",
},
ignorePatterns: ["frontend/static/*"],
};
16 changes: 13 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@
# CHANGELOG

## 0.3.2

- fix:  修复 log \n 被忽略显示异常的问题,增加推荐的部署 shell 脚本内容
## 0.3.1

## 0.3.1

- feat: 使用 prompt 将端口、密码改为询问方式输入

## 0.3.0

- feat: 使用 pm2 改造服务,防止 terminal 中断后进程被杀掉

## 0.2.2

- fix: npm 官网 github 链接更正
- fix: socket.io cdn 链接在服务器上运行时异常,将 cdn 替换为官方 cdn

## 0.2.0

- feat: 新增 socket 实时输出部署 log
- feat: 启动命令增加端口、密码参数配置
- feat: 引入session, 新增部署接口鉴权、前端登录功能
- feat: 对页面 UI 进行简单修改, 优化提示, 提高 log 展示性能
- feat: 引入session, 新增部署接口鉴权、前端登录功能
- feat: 对页面 UI 进行简单修改, 优化提示, 提高 log 展示性能
- feat: 部署 log 加时间戳
- chore: 去掉默认的 ES Module,使用默认的 CommonJS

## 0.1.4

- 初步完成自动化部署功能
- koa 提供自动化部署监听服务,请求接口服务,直接开始部署、执行shell脚本。部署完成后在前端页面显示部署 log
- 命令行工具支持 zuodeploy start 开启服务
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# zuo-deploy
用 js 写一个 CI、CD 工具,实现细节文档: [Vue + Node.js 从 0 到 1 实现自动化部署工具](https://juejin.cn/post/7070921715492061214)

![version-v0.3.1](https://img.shields.io/badge/version-v0.3.1-yellow.svg) ![license-MIT](https://img.shields.io/badge/license-MIT-green.svg)
用 js 写一个 CI、CD 工具,实现细节文档: [Vue + Node.js 从 0 到 1 实现自动化部署工具](http://www.zuo11.com/blog/2022/2/zuo_deploy_think.html)

![version-v0.3.1](https://img.shields.io/badge/version-v0.3.1-yellow.svg) ![license-MIT](https://img.shields.io/badge/license-MIT-green.svg)

npm package

[![NPM](https://nodei.co/npm/zuo-deploy.png)](https://npmjs.org/package/zuo-deploy)

## 使用

```bash
# 全局安装
npm install zuo-deploy pm2 -g
Expand Down Expand Up @@ -37,19 +40,23 @@ zuoblog init --disable-dev-server

echo "部署完成!"
```

![docImages/deploy-log.png](./docImages/deploy-log.png)

## 服务 log 查询

zuodeploy start 会用 pm2 开启一个 zuodeploy 服务,再次执行 zuodeploy start 会删除原服务,再次开启新服务。**如果开启失败,重新运行一次命令即可**

```bash
# 查看 log
pm2 log
pm2 log zuodeploy --lines 1000 # 指定行
```


## 其他

### 推荐部署脚本

```bash
echo "开始部署..."

Expand All @@ -68,6 +75,7 @@ git log -1

echo "部署完成!"
```

### eslint+prettier

```bash
Expand All @@ -87,12 +95,16 @@ npm install eslint-plugin-prettier --save-dev # 将 prettier 以插件形式集
```

### pm2 相关

防止 terminal node xx.js 进程被杀掉,使用 pm2 像守护进程一样后台执行

```js
pm2 stop zuodeoploy
pm2 start src/index.js -n 'zuodeoploy'
```

跨文件传参, 文件读写

## License

MIT
2 changes: 1 addition & 1 deletion args.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"port":7777,"password":"888888"}
{"port":"7777","password":"123"}
47 changes: 27 additions & 20 deletions bin/zuodeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,33 @@ program.version(require("../package.json").version);
program
.command("start")
.description("开启部署监听服务") // description + action 可防止查找 command拼接文件
.action(async () => {
const args = await prompts([
{
type: "number",
name: "port",
initial: 7777,
message: "请指定部署服务监听端口:",
validate: (value) =>
value !== "" && (value < 3000 || value > 10000)
? `端口号必须在 3000 - 10000 之间`
: true,
},
{
type: "password",
name: "password",
initial: "888888",
message: "请设置登录密码(默认:888888)",
validate: (value) => (value.length < 6 ? `密码需要 6 位以上` : true),
},
]);
.option("-p, --port <port>", "指定部署服务监听端口")
.option("-w, --password <key>", "设置登录密码")
.action(async (options) => {
let { port, password } = options;
const args =
port && password
? { port, password }
: await prompts([
{
type: "number",
name: "port",
initial: 7777,
message: "请指定部署服务监听端口:",
validate: (value) =>
value !== "" && (value < 3000 || value > 10000)
? `端口号必须在 3000 - 10000 之间`
: true,
},
{
type: "password",
name: "password",
initial: "888888",
message: "请设置登录密码(默认:888888)",
validate: (value) =>
value.length < 6 ? `密码需要 6 位以上` : true,
},
]);
require("./start")(args); // args 为 { port: 7777, password: '888888' }
});

Expand Down
1 change: 1 addition & 0 deletions demo/args.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"port":7777,"password":"888888"}
1 change: 1 addition & 0 deletions demo/c.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pwd
1 change: 1 addition & 0 deletions demo/chmod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ls
2 changes: 2 additions & 0 deletions demo/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git pull
npm run build
1 change: 1 addition & 0 deletions demo/temp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sudo nginx
Loading

0 comments on commit c77493a

Please sign in to comment.