@zzclub/z-cli 0.8.0 → 1.0.1
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/LICENSE +20 -20
- package/dist/commands/config.d.ts +9 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +33 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/set.d.ts +11 -0
- package/dist/commands/set.d.ts.map +1 -0
- package/dist/commands/set.js +43 -0
- package/dist/commands/set.js.map +1 -0
- package/dist/commands/tiny/compressor.d.ts +11 -0
- package/dist/commands/tiny/compressor.d.ts.map +1 -0
- package/dist/commands/tiny/compressor.js +46 -0
- package/dist/commands/tiny/compressor.js.map +1 -0
- package/dist/commands/tiny/file-processor.d.ts +40 -0
- package/dist/commands/tiny/file-processor.d.ts.map +1 -0
- package/dist/commands/tiny/file-processor.js +137 -0
- package/dist/commands/tiny/file-processor.js.map +1 -0
- package/dist/commands/tiny/index.d.ts +15 -0
- package/dist/commands/tiny/index.d.ts.map +1 -0
- package/dist/commands/tiny/index.js +55 -0
- package/dist/commands/tiny/index.js.map +1 -0
- package/dist/commands/tiny/types.d.ts +55 -0
- package/dist/commands/tiny/types.d.ts.map +1 -0
- package/dist/commands/tiny/types.js +5 -0
- package/dist/commands/tiny/types.js.map +1 -0
- package/dist/core/config-manager.d.ts +38 -0
- package/dist/core/config-manager.d.ts.map +1 -0
- package/dist/core/config-manager.js +87 -0
- package/dist/core/config-manager.js.map +1 -0
- package/dist/core/logger.d.ts +17 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +30 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +177 -0
- package/dist/index.js.map +1 -0
- package/dist/types/config.d.ts +32 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +18 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +34 -19
- package/readme.md +426 -0
- package/CHANGELOG.md +0 -223
- package/README.md +0 -329
- package/src/command/config.js +0 -97
- package/src/command/i18n.js +0 -318
- package/src/command/index.js +0 -30
- package/src/command/picgo.js +0 -122
- package/src/command/replace.js +0 -81
- package/src/command/set.js +0 -47
- package/src/command/tiny.js +0 -328
- package/src/command/translate.js +0 -344
- package/src/config.json +0 -16
- package/src/index.js +0 -31
- package/src/translate-api/index.js +0 -77
- package/src/translate-api/md5.js +0 -231
- package/src/utils/common.js +0 -218
- package/src/utils/file.js +0 -61
- package/src/utils/picgo.js +0 -149
package/src/utils/picgo.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import ora from "ora";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import { getFileInfo } from "./file.js";
|
|
5
|
-
import sharp from "sharp";
|
|
6
|
-
import chalk from "chalk";
|
|
7
|
-
// 检查文件是否超过最大值, 或不满足最小值
|
|
8
|
-
export const checkFileSize = (filePath, { max, min }) => {
|
|
9
|
-
const fileInfo = getFileInfo(filePath);
|
|
10
|
-
if (!fileInfo.fileName) {
|
|
11
|
-
return {
|
|
12
|
-
ok: false,
|
|
13
|
-
msg: "文件不存在",
|
|
14
|
-
fileInfo: {},
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
const { rawFileSize: fileSize, fileName } = fileInfo;
|
|
18
|
-
const kbValue = fileSize / 1024;
|
|
19
|
-
if (max && kbValue > max) {
|
|
20
|
-
return {
|
|
21
|
-
ok: false,
|
|
22
|
-
msg: `文件[${fileName}](${kbValue.toFixed(1)}kb)大小超过${max}kb`,
|
|
23
|
-
fileInfo,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
if (min && kbValue < min) {
|
|
27
|
-
return {
|
|
28
|
-
ok: false,
|
|
29
|
-
msg: `文件[${fileName}](${kbValue.toFixed(1)}kb)大小低于${min}kb`,
|
|
30
|
-
fileInfo,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
ok: true,
|
|
36
|
-
msg: "ok",
|
|
37
|
-
fileInfo,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// 检测所有文件, 并过滤出可以被上传的文件
|
|
42
|
-
export const checkFileSizeAndFilter = (filePaths, { max, min }) => {
|
|
43
|
-
const okFiles = [],
|
|
44
|
-
errFiles = [];
|
|
45
|
-
if (filePaths && filePaths.length) {
|
|
46
|
-
filePaths.forEach((filePath) => {
|
|
47
|
-
let checkInfo = checkFileSize(filePath, { max, min });
|
|
48
|
-
// 是一个文件, 并且可以被sharp处理, 则上传
|
|
49
|
-
if (checkInfo.ok) {
|
|
50
|
-
if (sharp(filePath)[checkInfo.fileInfo.fileType]) {
|
|
51
|
-
okFiles.push(filePath);
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
errFiles.push({
|
|
55
|
-
errFile: filePath,
|
|
56
|
-
fileInfo: checkInfo.fileInfo,
|
|
57
|
-
errMsg: checkInfo.msg,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
okFiles,
|
|
64
|
-
errFiles,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// 请求picgo
|
|
69
|
-
export const requestPicGo = async (files) => {
|
|
70
|
-
let spinner = ora();
|
|
71
|
-
if (!files || !files.length) {
|
|
72
|
-
spinner.fail(`上传失败: 未指定文件`);
|
|
73
|
-
process.exit(1);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
spinner.start("正在上传");
|
|
77
|
-
let picgoRes = await axios
|
|
78
|
-
.post("http://127.0.0.1:36677/upload", {
|
|
79
|
-
list: files,
|
|
80
|
-
})
|
|
81
|
-
.catch((err) => {
|
|
82
|
-
spinner.fail("上传失败!请启动PicGo后重试!");
|
|
83
|
-
process.exit(1);
|
|
84
|
-
});
|
|
85
|
-
// 成功
|
|
86
|
-
if (picgoRes.data && picgoRes.data.success) {
|
|
87
|
-
spinner.succeed(`上传成功 ${chalk.green(picgoRes.data.result.length)} 个!`);
|
|
88
|
-
// 返回上传后的url列表
|
|
89
|
-
return picgoRes.data.result;
|
|
90
|
-
} else {
|
|
91
|
-
spinner.fail(`上传失败: ${picgoRes.data.message}`);
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// 上传文件
|
|
97
|
-
export const uploadFileByPicGo = async (file, option) => {
|
|
98
|
-
const spinner = ora();
|
|
99
|
-
let filePth = path.resolve(process.cwd(), file);
|
|
100
|
-
let checkResult = checkFileSize(filePth, { max: option.max });
|
|
101
|
-
if (checkResult.ok) {
|
|
102
|
-
let fileUrls = await requestPicGo([filePth]);
|
|
103
|
-
spinner.succeed(`上传地址: \n ${fileUrls.join("\n")}`);
|
|
104
|
-
} else {
|
|
105
|
-
spinner.fail(`上传失败: ${checkResult.msg}`);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// 批量上传文件
|
|
110
|
-
export const batchUploadByPicGo = async (files, option) => {
|
|
111
|
-
const spinner = ora();
|
|
112
|
-
const { okFiles, errFiles } = checkFileSizeAndFilter(files, {
|
|
113
|
-
max: option.max,
|
|
114
|
-
});
|
|
115
|
-
if (!okFiles.length) {
|
|
116
|
-
spinner.fail(
|
|
117
|
-
`该目录下没有${
|
|
118
|
-
option.condition ? "名称含有[" + option.condition + "]的" : ""
|
|
119
|
-
}图片文件(<=${option.max}kb)可以上传`
|
|
120
|
-
);
|
|
121
|
-
process.exit(1);
|
|
122
|
-
}
|
|
123
|
-
const fileUrls = await requestPicGo(okFiles);
|
|
124
|
-
// 如果要替换, 重新组装map
|
|
125
|
-
if (option.replace) {
|
|
126
|
-
option.replaceMaps = option.replaceMaps.map((item) => {
|
|
127
|
-
// obsidian里的文件名带空格, 所以需要编码一下
|
|
128
|
-
// 因为上传后的url里空格被编码了
|
|
129
|
-
let uploadedUrl = fileUrls.find(
|
|
130
|
-
(url) => url.indexOf(encodeURIComponent(item.newText)) !== -1
|
|
131
|
-
);
|
|
132
|
-
return {
|
|
133
|
-
text: item.text,
|
|
134
|
-
newText: uploadedUrl ? `` : "",
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
spinner.succeed(`上传地址: \n${fileUrls.join("\n")}`);
|
|
139
|
-
let realErrFiles = errFiles.filter(
|
|
140
|
-
(item) => item.fileInfo && item.fileInfo.fileName
|
|
141
|
-
);
|
|
142
|
-
if (realErrFiles.length) {
|
|
143
|
-
spinner.fail(
|
|
144
|
-
`未上传 ${chalk.red(realErrFiles.length)} 个: \n${realErrFiles
|
|
145
|
-
.map((item) => item.errMsg)
|
|
146
|
-
.join("\n")}`
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
};
|