node-automator 1.4.28 → 1.4.29
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/commands/compress.js +1 -1
- package/commands/mgr.js +2 -0
- package/commands/tinify.js +45 -0
- package/index.js +1 -0
- package/package.json +2 -1
package/commands/compress.js
CHANGED
package/commands/mgr.js
CHANGED
|
@@ -137,6 +137,7 @@ const { MergeFileCommand } = require("./merge_file");
|
|
|
137
137
|
const { ZipFolderCommand } = require("./zip_folder");
|
|
138
138
|
const { EncryptCommand } = require('./encrypt');
|
|
139
139
|
const { DecryptCommand } = require('./decrypt');
|
|
140
|
+
const { TinifyCommand } = require('./tinify');
|
|
140
141
|
|
|
141
142
|
const globalData = {
|
|
142
143
|
executed_cfg: [], // 执行过的配置文件
|
|
@@ -525,6 +526,7 @@ function init() {
|
|
|
525
526
|
register("zip_folder", ZipFolderCommand, false);
|
|
526
527
|
register("encrypt", EncryptCommand, false);
|
|
527
528
|
register("decrypt", DecryptCommand, false);
|
|
529
|
+
register("tinify", TinifyCommand, false);
|
|
528
530
|
}
|
|
529
531
|
|
|
530
532
|
module.exports = {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const { BaseCommand } = require("./base");
|
|
2
|
+
const tinify = require("tinify");
|
|
3
|
+
const Jimp = require("jimp");
|
|
4
|
+
const { get_fst_file, get_full_path } = require('../utils/file_tool');
|
|
5
|
+
const { dirname } = require('node:path');
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
|
|
8
|
+
class TinifyCommand extends BaseCommand {
|
|
9
|
+
async execute() {
|
|
10
|
+
const data = this.selfData;
|
|
11
|
+
tinify.key = data.api_key;
|
|
12
|
+
const src = get_fst_file(data.src);
|
|
13
|
+
const dstFile = get_full_path(data.dst, "FILE");
|
|
14
|
+
fs.copyFileSync(src, dstFile);
|
|
15
|
+
const dstDir = dirname(dstFile);
|
|
16
|
+
if (!fs.existsSync(dstDir)) {
|
|
17
|
+
fs.mkdirSync(dstDir, { recursive: true });
|
|
18
|
+
}
|
|
19
|
+
let tinifyData = tinify.fromFile(src);
|
|
20
|
+
if (data.resize) {
|
|
21
|
+
const { w, h, scale } = data.resize;
|
|
22
|
+
if (w && h) {
|
|
23
|
+
tinifyData = tinifyData.resize({
|
|
24
|
+
method: "fit",
|
|
25
|
+
width: w,
|
|
26
|
+
height: h,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (scale && scale != 1) {
|
|
30
|
+
const result = await Jimp.read(dstFile);
|
|
31
|
+
const width = result.getWidth();
|
|
32
|
+
tinifyData = tinifyData.scale({
|
|
33
|
+
method: "scale",
|
|
34
|
+
width: width * scale,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
await tinifyData.toFile(dstFile);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = {
|
|
44
|
+
TinifyCommand,
|
|
45
|
+
};
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-automator",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.29",
|
|
4
4
|
"description": "Execute automation with yaml configuration(compatible with json)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"spreadsheet-column": "^1.1.1",
|
|
66
66
|
"strip-json-comments": "^3.1.1",
|
|
67
67
|
"temp": "^0.9.4",
|
|
68
|
+
"tinify": "^1.8.2",
|
|
68
69
|
"typescript-plus": "^3.1.5",
|
|
69
70
|
"websocket": "^1.0.34",
|
|
70
71
|
"xlsx": "^0.17.0",
|