@oipage/cli 0.3.0 → 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +11 -11
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +76 -47
- package/LICENSE +20 -20
- package/README.md +204 -132
- package/bin/WebSocket/decodeWsFrame.js +43 -43
- package/bin/WebSocket/encodeWsFrame.js +28 -28
- package/bin/WebSocket/headersToJSON.js +26 -26
- package/bin/WebSocket/index.js +106 -106
- package/bin/data/mineTypes.json +108 -104
- package/bin/disk.js +42 -42
- package/bin/help.js +63 -55
- package/bin/intercept.js +15 -15
- package/bin/network.js +21 -21
- package/bin/notebook/data.js +185 -0
- package/bin/notebook/index.js +168 -9
- package/bin/proxy.js +82 -82
- package/bin/run +146 -146
- package/bin/serve.js +455 -318
- package/bin/template/404.html +184 -184
- package/bin/tools/deleteEmptyFolder.js +33 -33
- package/bin/tools/format.js +75 -75
- package/bin/tools/isBinary.js +83 -83
- package/bin/tools/moduleForm.js +548 -0
- package/bin/tools/network.js +42 -42
- package/bin/tools/openBrowser.js +34 -34
- package/bin/tools/resolve404.js +98 -98
- package/bin/tools/resolveImport.js +278 -97
- package/bin/tools/resolvePackage.js +412 -0
- package/bin/website-htmls/components/ui-select-file/index.html +8 -8
- package/bin/website-htmls/components/ui-select-file/index.js +42 -42
- package/bin/website-htmls/components/ui-select-file/index.scss +44 -44
- package/bin/website-htmls/dialogs/imageSize/index.html +54 -54
- package/bin/website-htmls/dialogs/imageSize/index.js +53 -53
- package/bin/website-htmls/dialogs/imageSize/index.scss +140 -140
- package/bin/website-htmls/dialogs/index.js +52 -52
- package/bin/website-htmls/images/addFile.svg +1 -1
- package/bin/website-htmls/images/img-to-pdf.svg +1 -1
- package/bin/website-htmls/index.html +17 -17
- package/bin/website-htmls/main.js +13 -13
- package/bin/website-htmls/pages/App/index.html +6 -6
- package/bin/website-htmls/pages/App/index.js +22 -22
- package/bin/website-htmls/pages/App/index.scss +43 -43
- package/bin/website-htmls/pages/appStore/index.html +7 -7
- package/bin/website-htmls/pages/appStore/index.js +19 -19
- package/bin/website-htmls/pages/appStore/index.scss +54 -54
- package/bin/website-htmls/pages/chart/index.html +8 -8
- package/bin/website-htmls/pages/chart/index.js +72 -72
- package/bin/website-htmls/pages/chart/index.scss +71 -71
- package/bin/website-htmls/pages/home/index.html +19 -19
- package/bin/website-htmls/pages/home/index.js +19 -19
- package/bin/website-htmls/pages/home/index.scss +87 -87
- package/bin/website-htmls/pages/image-editor/index.html +27 -27
- package/bin/website-htmls/pages/image-editor/index.js +106 -106
- package/bin/website-htmls/pages/image-editor/index.scss +69 -69
- package/bin/website-htmls/pages/img-to-pdf/index.html +3 -3
- package/bin/website-htmls/pages/img-to-pdf/index.js +44 -44
- package/bin/website-htmls/pages/img-to-pdf/index.scss +9 -9
- package/bin/website-htmls/pages/recorder-screen/index.html +15 -15
- package/bin/website-htmls/pages/recorder-screen/index.js +227 -227
- package/bin/website-htmls/pages/recorder-screen/index.scss +52 -52
- package/bin/website-htmls/router.config.js +29 -29
- package/bin/website-htmls/styles/common.css +44 -44
- package/bin/website-htmls/styles/normalize.css +94 -94
- package/bin/website-plugins/intercept/chart.js +33 -33
- package/bin/website-plugins/intercept/getPackage.js +17 -17
- package/bin/website-plugins/intercept/head.js +8 -8
- package/bin/website-plugins/intercept/index.js +4 -8
- package/bin/website-plugins/loader/index.js +11 -11
- package/bin/website-plugins/loader/oipage-html-loader.js +7 -7
- package/bin/website-plugins/loader/oipage-scss-loader.js +149 -149
- package/docs/css/base.css +122 -0
- package/docs/css/components.css +180 -0
- package/docs/css/layout.css +295 -0
- package/docs/css/responsive.css +49 -0
- package/docs/images/file-list.webp +0 -0
- package/docs/images/logo-topbar.svg +5 -0
- package/docs/images/logo.png +0 -0
- package/docs/images/logo.svg +6 -0
- package/docs/images/manual.webp +0 -0
- package/docs/images/terminal-serve.webp +0 -0
- package/docs/index.html +1392 -0
- package/docs/js/copy.js +37 -0
- package/docs/js/nav.js +111 -0
- package/docs/js/search.js +241 -0
- package/docs/js/theme.js +17 -0
- package/package.json +42 -42
- package/src/index.js +26 -29
- package/types/serve.d.ts +83 -83
- package/bin/website-plugins/intercept/oipage-vislite-intercept.js +0 -56
- package/bin/website-plugins/intercept/oipage-zipaper-intercept.js +0 -37
- package/docs/config.md +0 -107
package/bin/help.js
CHANGED
|
@@ -1,56 +1,64 @@
|
|
|
1
|
-
const packageValue = require("../package.json");
|
|
2
|
-
|
|
3
|
-
module.exports = function () {
|
|
4
|
-
console.log(`\x1b[36m
|
|
5
|
-
@oipage/cli@v${packageValue.version}
|
|
6
|
-
|
|
7
|
-
可以使用的命令如下:
|
|
8
|
-
|
|
9
|
-
【1】oipage-cli serve 开发服务器
|
|
10
|
-
--port|-p [端口号]
|
|
11
|
-
默认8080
|
|
12
|
-
--baseUrl [文件夹地址]
|
|
13
|
-
服务器根目录
|
|
14
|
-
--open
|
|
15
|
-
自动打开浏览器
|
|
16
|
-
(也可以设置打开地址,比如 oipage-cli serve --open docs/index.html)
|
|
17
|
-
--website [true|false]
|
|
18
|
-
是否开启应用市场(默认true表示开启)
|
|
19
|
-
--config|-c [配置文件地址]
|
|
20
|
-
设置配置文件,相对地址是相对当前命令行
|
|
21
|
-
--cache [true|false]
|
|
22
|
-
是否启用304(默认true表示开启)
|
|
23
|
-
(eg: oipage-cli serve -p 20000 )
|
|
24
|
-
--proxy [转发前缀] [转发地址]
|
|
25
|
-
(注意:转发前缀会被替换为空,相当于设置了 pathRewrite: { '^/myapi': '' })
|
|
26
|
-
(eg: oipage-cli serve --open --proxy /myapi http://localhost:20000/myapi)
|
|
27
|
-
--gzip [true|false]
|
|
28
|
-
是否开启gzip(默认true表示开启)
|
|
29
|
-
|
|
30
|
-
【2】oipage-cli notebook 快速笔记
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
--
|
|
42
|
-
|
|
43
|
-
--
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
--
|
|
52
|
-
|
|
53
|
-
(eg: oipage-cli
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
const packageValue = require("../package.json");
|
|
2
|
+
|
|
3
|
+
module.exports = function () {
|
|
4
|
+
console.log(`\x1b[36m
|
|
5
|
+
@oipage/cli@v${packageValue.version}
|
|
6
|
+
|
|
7
|
+
可以使用的命令如下:
|
|
8
|
+
|
|
9
|
+
【1】oipage-cli serve 开发服务器
|
|
10
|
+
--port|-p [端口号]
|
|
11
|
+
默认8080
|
|
12
|
+
--baseUrl [文件夹地址]
|
|
13
|
+
服务器根目录
|
|
14
|
+
--open
|
|
15
|
+
自动打开浏览器
|
|
16
|
+
(也可以设置打开地址,比如 oipage-cli serve --open docs/index.html)
|
|
17
|
+
--website [true|false]
|
|
18
|
+
是否开启应用市场(默认true表示开启)
|
|
19
|
+
--config|-c [配置文件地址]
|
|
20
|
+
设置配置文件,相对地址是相对当前命令行
|
|
21
|
+
--cache [true|false]
|
|
22
|
+
是否启用304(默认true表示开启)
|
|
23
|
+
(eg: oipage-cli serve -p 20000 )
|
|
24
|
+
--proxy [转发前缀] [转发地址]
|
|
25
|
+
(注意:转发前缀会被替换为空,相当于设置了 pathRewrite: { '^/myapi': '' })
|
|
26
|
+
(eg: oipage-cli serve --open --proxy /myapi http://localhost:20000/myapi)
|
|
27
|
+
--gzip [true|false]
|
|
28
|
+
是否开启gzip(默认true表示开启)
|
|
29
|
+
|
|
30
|
+
【2】oipage-cli notebook 快速笔记
|
|
31
|
+
oipage-cli notebook
|
|
32
|
+
列出分类与用法
|
|
33
|
+
oipage-cli notebook [分类]
|
|
34
|
+
查看某一类的全部命令,如 git、mysql、docker、nginx 等
|
|
35
|
+
oipage-cli notebook [关键词]
|
|
36
|
+
按关键词搜,命令和说明都搜,如:oipage-cli notebook 端口
|
|
37
|
+
oipage-cli notebook all
|
|
38
|
+
全部打印出来
|
|
39
|
+
|
|
40
|
+
【3】oipage-cli disk 磁盘操作
|
|
41
|
+
--force|-f
|
|
42
|
+
强制执行,如果目标地址已有内容,会直接强制删除已有内容
|
|
43
|
+
--delete|-d [文件或文件夹地址]
|
|
44
|
+
删除文件或文件夹
|
|
45
|
+
--delempty [文件夹地址]
|
|
46
|
+
删除空文件夹
|
|
47
|
+
--move|-m [源地址] [软链接地址]
|
|
48
|
+
移动文件或文件夹
|
|
49
|
+
--copy|-c [源地址] [目标地址]
|
|
50
|
+
复制文件或文件夹
|
|
51
|
+
--link|-l [源地址] [软链接地址]
|
|
52
|
+
创建磁盘链接
|
|
53
|
+
(eg: oipage-cli disk -m ./test.js ~/test.js -f )
|
|
54
|
+
|
|
55
|
+
【4】oipage-cli run "任务一" "任务二" ... 运行多命令
|
|
56
|
+
( 如果希望动态给任务传递参数,可以查看: https://github.com/oi-contrib/OIPage/issues/5 )
|
|
57
|
+
|
|
58
|
+
【5】oipage-cli network 网络相关
|
|
59
|
+
--log
|
|
60
|
+
打印网络信息
|
|
61
|
+
(eg: oipage-cli network --log )
|
|
62
|
+
\x1b[0m`);
|
|
63
|
+
|
|
56
64
|
};
|
package/bin/intercept.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
exports.doIntercept = function (url, intercept, request, response, wsHandler) {
|
|
2
|
-
for (let item of intercept) {
|
|
3
|
-
if (item.test.test(url)) {
|
|
4
|
-
item.handler(request, response, wsHandler);
|
|
5
|
-
return true;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
exports.testIntercept = function (url, intercept) {
|
|
11
|
-
for (let item of intercept) {
|
|
12
|
-
if (item.test.test(url)) {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
exports.doIntercept = function (url, intercept, request, response, wsHandler) {
|
|
2
|
+
for (let item of intercept) {
|
|
3
|
+
if (item.test.test(url)) {
|
|
4
|
+
item.handler(request, response, wsHandler);
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.testIntercept = function (url, intercept) {
|
|
11
|
+
for (let item of intercept) {
|
|
12
|
+
if (item.test.test(url)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
16
|
}
|
package/bin/network.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
const networkInfo = require("./tools/network");
|
|
2
|
-
|
|
3
|
-
module.exports = function (config) {
|
|
4
|
-
let info = networkInfo(true);
|
|
5
|
-
|
|
6
|
-
// 执行一个个任务
|
|
7
|
-
for (let i = 0; i < config.value.length; i++) {
|
|
8
|
-
|
|
9
|
-
// 打印信息
|
|
10
|
-
if (config.value[i].name === "--log") {
|
|
11
|
-
|
|
12
|
-
for (let iptype of ["IPv4", "IPv6"]) {
|
|
13
|
-
console.log("\n" + iptype);
|
|
14
|
-
for (let i = 0; i < info[iptype].length; i++) {
|
|
15
|
-
console.log(" \x1b[1m\x1b[32m" + info[iptype][i].address + "\x1b[0m " + info[iptype][i].mac);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
console.log("");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
const networkInfo = require("./tools/network");
|
|
2
|
+
|
|
3
|
+
module.exports = function (config) {
|
|
4
|
+
let info = networkInfo(true);
|
|
5
|
+
|
|
6
|
+
// 执行一个个任务
|
|
7
|
+
for (let i = 0; i < config.value.length; i++) {
|
|
8
|
+
|
|
9
|
+
// 打印信息
|
|
10
|
+
if (config.value[i].name === "--log") {
|
|
11
|
+
|
|
12
|
+
for (let iptype of ["IPv4", "IPv6"]) {
|
|
13
|
+
console.log("\n" + iptype);
|
|
14
|
+
for (let i = 0; i < info[iptype].length; i++) {
|
|
15
|
+
console.log(" \x1b[1m\x1b[32m" + info[iptype][i].address + "\x1b[0m " + info[iptype][i].mac);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
console.log("");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
22
|
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/* ============================================================
|
|
2
|
+
notebook 数据:常用但记不住的命令
|
|
3
|
+
每条为 [命令, 说明],说明尽量短,方便一行读完
|
|
4
|
+
============================================================ */
|
|
5
|
+
|
|
6
|
+
module.exports = [
|
|
7
|
+
{
|
|
8
|
+
key: "linux",
|
|
9
|
+
title: "Linux",
|
|
10
|
+
aliases: ["linux", "ubuntu", "centos", "debian", "shell", "服务器"],
|
|
11
|
+
note: "进程、端口、文件、磁盘、权限、服务",
|
|
12
|
+
items: [
|
|
13
|
+
["lsof -i :[端口]", "查占用这个端口的进程"],
|
|
14
|
+
["ps aux | grep [关键字]", "按关键字查进程"],
|
|
15
|
+
["kill -9 [PID]", "强制结束进程"],
|
|
16
|
+
["top -p [PID]", "盯住单个进程的资源占用"],
|
|
17
|
+
["free -h", "看内存用了多少"],
|
|
18
|
+
["df -h", "看磁盘剩余空间"],
|
|
19
|
+
["du -sh *", "看当前目录各项占多大"],
|
|
20
|
+
["tar -czf [包].tar.gz [目录]", "打包并 gzip 压缩"],
|
|
21
|
+
["tar -xzf [包].tar.gz", "解压 tar.gz"],
|
|
22
|
+
["chmod 755 [文件]", "改权限:可读可写可执行"],
|
|
23
|
+
["chown -R [用户]:[组] [目录]", "递归改归属"],
|
|
24
|
+
["ln -s [源] [链接]", "建软链接"],
|
|
25
|
+
["find . -name \"*.log\" -mtime +7", "找 7 天前的日志"],
|
|
26
|
+
["grep -rn \"[关键字]\" [目录]", "递归搜文件内容"],
|
|
27
|
+
["sed -n '10,20p' [文件]", "只看第 10 到 20 行"],
|
|
28
|
+
["tail -f [日志]", "实时跟日志"],
|
|
29
|
+
["nohup [命令] > out.log 2>&1 &", "后台跑,输出留在日志里"],
|
|
30
|
+
["ssh -p [端口] [用户]@[主机]", "远程登录"],
|
|
31
|
+
["scp [文件] [用户]@[主机]:[路径]", "传文件到远端"],
|
|
32
|
+
["systemctl status [服务]", "看服务状态"],
|
|
33
|
+
["journalctl -u [服务] -f", "实时跟服务日志"],
|
|
34
|
+
["crontab -e", "编辑定时任务"]
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "mac",
|
|
39
|
+
title: "macOS",
|
|
40
|
+
aliases: ["mac", "macos", "osx", "darwin", "苹果"],
|
|
41
|
+
note: "访达、剪贴板、Homebrew、launchd、系统设置",
|
|
42
|
+
items: [
|
|
43
|
+
["lsof -i :[端口]", "查端口占用(和 Linux 一样)"],
|
|
44
|
+
["open .", "用访达打开当前目录"],
|
|
45
|
+
["open -a \"Google Chrome\" [文件]", "指定某个应用打开"],
|
|
46
|
+
["pbcopy < [文件]", "把文件内容复制到剪贴板"],
|
|
47
|
+
["pbpaste > [文件]", "把剪贴板内容写进文件"],
|
|
48
|
+
["brew install [包]", "装命令行工具"],
|
|
49
|
+
["brew services list", "看 brew 管着的后台服务"],
|
|
50
|
+
["mdfind [关键字]", "全盘快速搜文件"],
|
|
51
|
+
["launchctl list | grep [关键字]", "看 launchd 服务"],
|
|
52
|
+
["sudo lsof -i -P | grep LISTEN", "看所有监听中的端口"],
|
|
53
|
+
["sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder", "刷新 DNS 缓存"],
|
|
54
|
+
["defaults write [域] [键] -bool true", "改应用偏好设置"],
|
|
55
|
+
["xattr -d com.apple.quarantine [文件]", "去掉下载文件的隔离标记"],
|
|
56
|
+
["softwareupdate -l", "查系统更新"]
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: "windows",
|
|
61
|
+
title: "Windows",
|
|
62
|
+
aliases: ["windows", "win", "cmd", "powershell", "微软"],
|
|
63
|
+
note: "cmd 为主,个别注明 PowerShell",
|
|
64
|
+
items: [
|
|
65
|
+
["netstat -ano | findstr :[端口]", "查端口和对应 PID"],
|
|
66
|
+
["tasklist | findstr [关键字]", "按关键字查进程"],
|
|
67
|
+
["taskkill /PID [PID] /F", "强制结束进程"],
|
|
68
|
+
["dir /a", "列目录,含隐藏项"],
|
|
69
|
+
["type [文件]", "看文件内容"],
|
|
70
|
+
["where [命令]", "查命令装在哪个路径"],
|
|
71
|
+
["findstr /s /i \"[关键字]\" *.*", "递归搜文件内容"],
|
|
72
|
+
["ipconfig /all", "看本机网络配置"],
|
|
73
|
+
["set", "看当前环境变量"],
|
|
74
|
+
["setx [变量] [值]", "永久写环境变量"],
|
|
75
|
+
["mklink /D [链接] [目标]", "建目录软链,需管理员"],
|
|
76
|
+
["robocopy [源] [目标] /MIR", "镜像同步,会删目标多余文件"],
|
|
77
|
+
["sfc /scannow", "扫系统文件并尝试修复"],
|
|
78
|
+
["chkdsk C: /f", "检查修复磁盘,需重启"],
|
|
79
|
+
["winget install [包]", "装软件"],
|
|
80
|
+
["powershell -c \"Get-Process | Sort CPU -desc | Select -First 5\"", "看 CPU 前五的进程"],
|
|
81
|
+
["cls", "清屏"]
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
key: "mysql",
|
|
86
|
+
title: "MySQL",
|
|
87
|
+
aliases: ["mysql", "sql", "数据库", "db"],
|
|
88
|
+
note: "登录、表结构、查询、备份、权限",
|
|
89
|
+
items: [
|
|
90
|
+
["mysql -u [用户] -p -h [主机] -P [端口]", "登录,回车后再输密码"],
|
|
91
|
+
["show databases;", "列出所有库"],
|
|
92
|
+
["use [库];", "切换到某个库"],
|
|
93
|
+
["show tables;", "列出当前库的表"],
|
|
94
|
+
["desc [表];", "看表结构"],
|
|
95
|
+
["select * from [表] limit 10;", "看前 10 行"],
|
|
96
|
+
["select count(*) from [表];", "统计行数"],
|
|
97
|
+
["explain [SQL];", "看这条 SQL 的执行计划"],
|
|
98
|
+
["show processlist;", "看当前有哪些连接"],
|
|
99
|
+
["kill [连接ID];", "断开某个连接"],
|
|
100
|
+
["show variables like '%[关键字]%';", "查配置项"],
|
|
101
|
+
["show index from [表];", "看表上的索引"],
|
|
102
|
+
["show create table [表]\\G", "看完整建表语句"],
|
|
103
|
+
["create database [库] default charset utf8mb4;", "建库,字符集用 utf8mb4"],
|
|
104
|
+
["alter table [表] add [列] [类型];", "给表加字段"],
|
|
105
|
+
["mysqldump -u [用户] -p [库] > [文件].sql", "导出整个库"],
|
|
106
|
+
["mysql -u [用户] -p [库] < [文件].sql", "导入 sql 文件"],
|
|
107
|
+
["grant all on [库].* to '[用户]'@'%';", "给用户授权"],
|
|
108
|
+
["truncate table [表];", "清空表,不可回滚"]
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
key: "git",
|
|
113
|
+
title: "Git",
|
|
114
|
+
aliases: ["git", "版本", "提交", "分支"],
|
|
115
|
+
note: "提交、分支、撤销、同步、排查",
|
|
116
|
+
items: [
|
|
117
|
+
["git clone [地址]", "克隆仓库"],
|
|
118
|
+
["git status", "看当前改动"],
|
|
119
|
+
["git add .", "暂存全部改动"],
|
|
120
|
+
["git commit -m \"说明\"", "提交"],
|
|
121
|
+
["git commit --amend -m \"说明\"", "改上一条提交的信息"],
|
|
122
|
+
["git log --oneline --graph --all", "看提交和分支图"],
|
|
123
|
+
["git diff", "看还没暂存的改动"],
|
|
124
|
+
["git diff --staged", "看已暂存的改动"],
|
|
125
|
+
["git switch -c [分支]", "建并切到新分支"],
|
|
126
|
+
["git checkout -b [分支]", "同上,旧写法"],
|
|
127
|
+
["git branch -a", "看本地与远程分支"],
|
|
128
|
+
["git merge [分支]", "把分支合并进来"],
|
|
129
|
+
["git rebase [分支]", "变基到某个分支"],
|
|
130
|
+
["git stash", "把手头改动先收起来"],
|
|
131
|
+
["git stash pop", "把收起来的改动放回来"],
|
|
132
|
+
["git reset --soft HEAD~1", "撤销提交,改动留在工作区"],
|
|
133
|
+
["git reset --hard [提交]", "撤销到某个提交,改动全丢,慎用"],
|
|
134
|
+
["git revert [提交]", "撤销某个提交,用新提交抵消"],
|
|
135
|
+
["git remote -v", "看远程地址"],
|
|
136
|
+
["git push -u origin [分支]", "首次推送并绑定上游"],
|
|
137
|
+
["git pull --rebase", "拉取并变基,历史更干净"],
|
|
138
|
+
["git cherry-pick [提交]", "把某个提交摘过来"],
|
|
139
|
+
["git blame [文件]", "看每行是谁改的"],
|
|
140
|
+
["git reflog", "找回误删的提交"],
|
|
141
|
+
["git clean -fd", "清掉未跟踪的文件,慎用"],
|
|
142
|
+
["git config --global user.name \"[名字]\"", "配提交身份"]
|
|
143
|
+
]
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
key: "docker",
|
|
147
|
+
title: "Docker",
|
|
148
|
+
aliases: ["docker", "容器", "镜像", "compose"],
|
|
149
|
+
note: "容器、镜像、compose、清理",
|
|
150
|
+
items: [
|
|
151
|
+
["docker ps -a", "看所有容器,含已停的"],
|
|
152
|
+
["docker images", "看本地镜像"],
|
|
153
|
+
["docker run -d -p 8080:80 --name [名字] [镜像]", "起容器并把端口映射出来"],
|
|
154
|
+
["docker logs -f [容器]", "实时看容器日志"],
|
|
155
|
+
["docker exec -it [容器] sh", "进容器里执行命令"],
|
|
156
|
+
["docker stop [容器]", "停容器"],
|
|
157
|
+
["docker rm -f [容器]", "删容器,先强停再删"],
|
|
158
|
+
["docker rmi [镜像]", "删镜像"],
|
|
159
|
+
["docker inspect [容器]", "看容器的完整配置"],
|
|
160
|
+
["docker stats", "实时看容器资源占用"],
|
|
161
|
+
["docker compose up -d", "后台起整套编排"],
|
|
162
|
+
["docker compose down", "停掉并删除编排容器"],
|
|
163
|
+
["docker compose logs -f [服务]", "跟某个服务的日志"],
|
|
164
|
+
["docker build -t [标签] .", "按 Dockerfile 构建镜像"],
|
|
165
|
+
["docker system df", "看镜像、容器占了多少磁盘"],
|
|
166
|
+
["docker system prune -a", "清无用容器和镜像,慎用"]
|
|
167
|
+
]
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
key: "nginx",
|
|
171
|
+
title: "Nginx",
|
|
172
|
+
aliases: ["nginx", "反向代理", "代理"],
|
|
173
|
+
note: "配置检查、重载、日志、重启",
|
|
174
|
+
items: [
|
|
175
|
+
["nginx -t", "检查配置语法对不对"],
|
|
176
|
+
["nginx -T", "检查并打印完整生效配置"],
|
|
177
|
+
["nginx -s reload", "平滑重载,不丢连接"],
|
|
178
|
+
["nginx -s quit", "优雅退出"],
|
|
179
|
+
["nginx -s reopen", "重开日志文件,配合切割"],
|
|
180
|
+
["tail -f /var/log/nginx/error.log", "实时看错误日志"],
|
|
181
|
+
["tail -f /var/log/nginx/access.log", "实时看访问日志"],
|
|
182
|
+
["systemctl restart nginx", "整个服务重启"]
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
];
|
package/bin/notebook/index.js
CHANGED
|
@@ -1,9 +1,168 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
/* ============================================================
|
|
2
|
+
oipage-cli notebook:常用命令速查
|
|
3
|
+
不带参数看分类,给分类名看整组,给关键词就全量搜
|
|
4
|
+
============================================================ */
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const groups = require("./data.js");
|
|
9
|
+
|
|
10
|
+
const useColor = !process.env.NO_COLOR && (process.stdout.isTTY || process.env.FORCE_COLOR);
|
|
11
|
+
|
|
12
|
+
const paint = function (code, text) {
|
|
13
|
+
return useColor ? "\x1b[" + code + "m" + text + "\x1b[0m" : String(text);
|
|
14
|
+
};
|
|
15
|
+
const accent = text => paint("36", text);
|
|
16
|
+
const strong = text => paint("1;36", text);
|
|
17
|
+
const faint = text => paint("2", text);
|
|
18
|
+
|
|
19
|
+
// 中文、全角字符在终端里占两格,补空格时要按显示宽度算
|
|
20
|
+
const WIDE = /[\u1100-\u115F\u2E80-\uA4CF\uAC00-\uD7A3\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFF60\uFFE0-\uFFE6\u{1F300}-\u{1FAFF}]/u;
|
|
21
|
+
|
|
22
|
+
const width = function (text) {
|
|
23
|
+
let value = 0;
|
|
24
|
+
for (const ch of text) value += WIDE.test(ch) ? 2 : 1;
|
|
25
|
+
return value;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const pad = function (text, size) {
|
|
29
|
+
return text + " ".repeat(Math.max(2, size - width(text) + 2));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const total = groups.reduce((sum, group) => sum + group.items.length, 0);
|
|
33
|
+
|
|
34
|
+
const overview = function () {
|
|
35
|
+
console.log("");
|
|
36
|
+
console.log(strong("oipage-cli notebook") + faint(" · " + groups.length + " 类 / " + total + " 条常用命令"));
|
|
37
|
+
console.log("");
|
|
38
|
+
|
|
39
|
+
console.log(faint("用法"));
|
|
40
|
+
const usages = [
|
|
41
|
+
["oipage-cli notebook", "列出分类"],
|
|
42
|
+
["oipage-cli notebook git", "看某类的全部命令"],
|
|
43
|
+
["oipage-cli notebook 端口", "按关键词搜,命令和说明都搜"],
|
|
44
|
+
["oipage-cli notebook all", "全部打印出来"]
|
|
45
|
+
];
|
|
46
|
+
usages.forEach(function (row) {
|
|
47
|
+
console.log(" " + accent(pad(row[0], 26)) + faint(row[1]));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
console.log("");
|
|
51
|
+
console.log(faint("分类"));
|
|
52
|
+
groups.forEach(function (group) {
|
|
53
|
+
console.log(" " + accent(pad(group.key, 9)) +
|
|
54
|
+
faint(pad(group.items.length + " 条", 7)) +
|
|
55
|
+
faint(group.note));
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
console.log("");
|
|
59
|
+
console.log(faint("想不起来命令怎么写,直接搜关键词,比如:") + " " +
|
|
60
|
+
accent("oipage-cli notebook 端口") + faint(" / ") + accent("oipage-cli notebook 撤销"));
|
|
61
|
+
console.log("");
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const printGroup = function (group, items) {
|
|
65
|
+
console.log("");
|
|
66
|
+
console.log(strong(group.title) + faint(" " + items.length + " 条 · " + group.note));
|
|
67
|
+
console.log("");
|
|
68
|
+
|
|
69
|
+
// 命令列按最长的一条对齐,太长就单独占一行,说明挪到下一行
|
|
70
|
+
let col = 0;
|
|
71
|
+
items.forEach(function (item) {
|
|
72
|
+
col = Math.max(col, width(item[0]));
|
|
73
|
+
});
|
|
74
|
+
col = Math.min(col, 44);
|
|
75
|
+
|
|
76
|
+
items.forEach(function (item) {
|
|
77
|
+
if (width(item[0]) > col) {
|
|
78
|
+
console.log(" " + accent(item[0]));
|
|
79
|
+
console.log(" " + faint(item[1]));
|
|
80
|
+
} else {
|
|
81
|
+
console.log(" " + accent(pad(item[0], col)) + faint(item[1]));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
console.log("");
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// 命中位置越"像命令的用途"越靠前:说明 > 命令 > 分类名
|
|
88
|
+
const score = function (group, command, text, terms) {
|
|
89
|
+
const groupText = (group.title + " " + group.aliases.join(" ")).toLowerCase();
|
|
90
|
+
const commandText = command.toLowerCase();
|
|
91
|
+
const descText = text.toLowerCase();
|
|
92
|
+
|
|
93
|
+
let value = 0;
|
|
94
|
+
for (const term of terms) {
|
|
95
|
+
if (descText.indexOf(term) !== -1) value += 3;
|
|
96
|
+
else if (commandText.indexOf(term) !== -1) value += 2;
|
|
97
|
+
else if (groupText.indexOf(term) !== -1) value += 1;
|
|
98
|
+
else return 0;
|
|
99
|
+
}
|
|
100
|
+
return value;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const search = function (terms, query, scope) {
|
|
104
|
+
const pool = scope ? [scope] : groups;
|
|
105
|
+
const results = pool.map(function (group) {
|
|
106
|
+
return {
|
|
107
|
+
group: group,
|
|
108
|
+
items: group.items
|
|
109
|
+
.map(item => ({ item: item, score: score(group, item[0], item[1], terms) }))
|
|
110
|
+
.filter(row => row.score > 0)
|
|
111
|
+
.sort((a, b) => b.score - a.score)
|
|
112
|
+
.map(row => row.item)
|
|
113
|
+
};
|
|
114
|
+
}).filter(result => result.items.length);
|
|
115
|
+
|
|
116
|
+
console.log("");
|
|
117
|
+
console.log(strong("「" + query + "」") + faint(" 命中 " +
|
|
118
|
+
results.reduce((sum, result) => sum + result.items.length, 0) + " 条"));
|
|
119
|
+
|
|
120
|
+
if (!results.length) {
|
|
121
|
+
console.log("");
|
|
122
|
+
console.log(" 没找到。可以换个词,或者看全部:" + accent("oipage-cli notebook all"));
|
|
123
|
+
console.log("");
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
results.forEach(function (result) {
|
|
128
|
+
printGroup(result.group, result.items);
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
module.exports = function (config) {
|
|
133
|
+
|
|
134
|
+
// formatArgv 把位置参数统一放在 args 里
|
|
135
|
+
const args = config.args || [];
|
|
136
|
+
|
|
137
|
+
if (!args.length) {
|
|
138
|
+
overview();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const first = args[0].toLowerCase();
|
|
143
|
+
|
|
144
|
+
if (first === "all" || first === "全部") {
|
|
145
|
+
groups.forEach(group => printGroup(group, group.items));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const scope = groups.filter(function (group) {
|
|
150
|
+
return group.key === first || group.aliases.indexOf(first) !== -1;
|
|
151
|
+
})[0];
|
|
152
|
+
|
|
153
|
+
if (scope && args.length === 1) {
|
|
154
|
+
printGroup(scope, scope.items);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const words = scope ? args.slice(1) : args;
|
|
159
|
+
const query = words.join(" ");
|
|
160
|
+
const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
161
|
+
|
|
162
|
+
if (!terms.length) {
|
|
163
|
+
overview();
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
search(terms, query, scope);
|
|
168
|
+
};
|