node-automator 1.4.16 → 1.4.18
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/README.md +3 -3
- package/commands/compress.js +4 -4
- package/package.json +1 -1
- package/utils/base64_tool.js +51 -5
- package/utils/file_tool.js +0 -8
package/README.md
CHANGED
|
@@ -10,15 +10,15 @@ $ node . ./examples/print_env.yml
|
|
|
10
10
|
## Npx
|
|
11
11
|
> You can pass encoded configuration content instead of a file path
|
|
12
12
|
```js
|
|
13
|
-
function
|
|
14
|
-
return
|
|
13
|
+
function base64_encode(input) {
|
|
14
|
+
return Buffer.from(input).toString('base64');
|
|
15
15
|
}
|
|
16
16
|
var configuration = `
|
|
17
17
|
- type: print
|
|
18
18
|
data:
|
|
19
19
|
content: Hello, I'm <<USERNAME>>
|
|
20
20
|
`;
|
|
21
|
-
console.log(
|
|
21
|
+
console.log(base64_encode(configuration));
|
|
22
22
|
// output: Ci0gdHlwZTogcHJpbnQKICBkYXRhOgogICAgY29udGVudDogSGVsbG8sIEknbSA8PFVTRVJOQU1FPj4K
|
|
23
23
|
```
|
|
24
24
|
> then you can use npx to run any configuration
|
package/commands/compress.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const { get_fst_file, get_full_path, move } = require('../utils/file_tool');
|
|
3
3
|
const { BaseCommand } = require("./base");
|
|
4
|
+
const { readFileSync } = require('fs');
|
|
4
5
|
|
|
5
6
|
class CompressCommand extends BaseCommand {
|
|
6
7
|
async execute() {
|
|
@@ -8,7 +9,6 @@ class CompressCommand extends BaseCommand {
|
|
|
8
9
|
const data = this.selfData;
|
|
9
10
|
const src = get_fst_file(data.src);
|
|
10
11
|
const dst = get_full_path(data.dst, "FILE");
|
|
11
|
-
const tmp = path.join(this.shareData.AUTOMATOR_SCRATCH, path.basename(src));
|
|
12
12
|
let format = data.format;
|
|
13
13
|
if (!format) {
|
|
14
14
|
format = dst.split(".").pop();
|
|
@@ -18,9 +18,9 @@ class CompressCommand extends BaseCommand {
|
|
|
18
18
|
format = "jpeg";
|
|
19
19
|
}
|
|
20
20
|
const options = data.options;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const fileContent = readFileSync(src);
|
|
22
|
+
await sharp(fileContent)[format](options)
|
|
23
|
+
.toFile(dst);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
package/package.json
CHANGED
package/utils/base64_tool.js
CHANGED
|
@@ -1,13 +1,59 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
1
|
+
function utf8_encode(string) {
|
|
2
|
+
string = string.replace(/\r\n/g, "\n");
|
|
3
|
+
var utftext = "";
|
|
4
|
+
for (var n = 0; n < string.length; n++) {
|
|
5
|
+
var c = string.charCodeAt(n);
|
|
6
|
+
if (c < 128) {
|
|
7
|
+
utftext += String.fromCharCode(c);
|
|
8
|
+
} else if ((c > 127) && (c < 2048)) {
|
|
9
|
+
utftext += String.fromCharCode((c >> 6) | 192);
|
|
10
|
+
utftext += String.fromCharCode((c & 63) | 128);
|
|
11
|
+
} else {
|
|
12
|
+
utftext += String.fromCharCode((c >> 12) | 224);
|
|
13
|
+
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
|
14
|
+
utftext += String.fromCharCode((c & 63) | 128);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
return utftext;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function utf8_decode(utftext) {
|
|
22
|
+
var string = "";
|
|
23
|
+
var i = 0;
|
|
24
|
+
var c = 0;
|
|
25
|
+
var c2 = 0;
|
|
26
|
+
var c3 = 0;
|
|
27
|
+
while (i < utftext.length) {
|
|
28
|
+
c = utftext.charCodeAt(i);
|
|
29
|
+
if (c < 128) {
|
|
30
|
+
string += String.fromCharCode(c);
|
|
31
|
+
i++;
|
|
32
|
+
} else if ((c > 191) && (c < 224)) {
|
|
33
|
+
c2 = utftext.charCodeAt(i + 1);
|
|
34
|
+
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
|
35
|
+
i += 2;
|
|
36
|
+
} else {
|
|
37
|
+
c2 = utftext.charCodeAt(i + 1);
|
|
38
|
+
c3 = utftext.charCodeAt(i + 2);
|
|
39
|
+
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
|
40
|
+
i += 3;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return string;
|
|
3
44
|
}
|
|
4
45
|
|
|
5
|
-
function encode(
|
|
6
|
-
return btoa(
|
|
46
|
+
function encode(string) {
|
|
47
|
+
return btoa(utf8_encode(string));
|
|
7
48
|
}
|
|
8
49
|
|
|
50
|
+
function decode(string) {
|
|
51
|
+
return utf8_decode(atob(string));
|
|
52
|
+
}
|
|
9
53
|
|
|
10
54
|
module.exports = {
|
|
11
|
-
|
|
55
|
+
utf8_encode,
|
|
56
|
+
utf8_decode,
|
|
12
57
|
encode,
|
|
58
|
+
decode,
|
|
13
59
|
};
|
package/utils/file_tool.js
CHANGED
|
@@ -311,10 +311,6 @@ async function copy(src, dst, base, options) {
|
|
|
311
311
|
actual_files.push(src);
|
|
312
312
|
}
|
|
313
313
|
await new Promise(resolve => {
|
|
314
|
-
// 如果存在,先删除
|
|
315
|
-
if (fs.existsSync(dstFile)) {
|
|
316
|
-
fs.unlinkSync(dstFile);
|
|
317
|
-
}
|
|
318
314
|
// !options.overwrite ? fs.constants.COPYFILE_EXCL : 0
|
|
319
315
|
fs.copyFile(src, dstFile, 0, (err) => {
|
|
320
316
|
if (err) {
|
|
@@ -388,10 +384,6 @@ async function move(src, dst, base, options) {
|
|
|
388
384
|
if (!options.overwrite && fs.existsSync(dstFile)) {
|
|
389
385
|
resolve();
|
|
390
386
|
} else {
|
|
391
|
-
// 如果存在,先删除
|
|
392
|
-
if (fs.existsSync(dstFile)) {
|
|
393
|
-
fs.unlinkSync(dstFile);
|
|
394
|
-
}
|
|
395
387
|
fs.copyFile(src, dstFile, 0, (err) => {
|
|
396
388
|
if (err) {
|
|
397
389
|
throw (err);
|