node-automator 1.4.0 → 1.4.2

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.
@@ -11,7 +11,8 @@ const {
11
11
  } = require('../utils/log_tool');
12
12
  const {
13
13
  parse,
14
- stringify
14
+ stringify,
15
+ processRename
15
16
  } = require('../utils/file_tool');
16
17
 
17
18
  class BackupCommand extends BaseCommand {
@@ -30,7 +31,9 @@ class BackupCommand extends BaseCommand {
30
31
  sourceType,
31
32
  backupFormat,
32
33
  backupFilename,
33
- backupEncoding
34
+ backupRename,
35
+ backupEncoding,
36
+ backupPrettify,
34
37
  } = bakCfg;
35
38
  const filepath = path.join(sourceFolder, filename);
36
39
  let backupPath = path.join(backupFolder, backupFilename || filename);
@@ -50,6 +53,13 @@ class BackupCommand extends BaseCommand {
50
53
  if (backupFormat) {
51
54
  backupData = await stringify(backupData, backupFormat);
52
55
  }
56
+ if (backupPrettify) {
57
+ backupData = await parse(backupData, backupPrettify.from);
58
+ backupData = await stringify(backupData, backupPrettify.to);
59
+ }
60
+ if (backupRename) {
61
+ backupPath = processRename(backupPath, backupRename, backupData);
62
+ }
53
63
  const backupDir = path.dirname(backupPath);
54
64
  // 创建目录
55
65
  if (!fs.existsSync(backupDir)) {
@@ -89,7 +99,7 @@ class BackupCommand extends BaseCommand {
89
99
  });
90
100
  if (bakCfg) {
91
101
  backup(bakCfg, filename).then(() => {
92
- !quiet && success(`${filename} 备份成功`);
102
+ !(quiet || bakCfg.quiet) && success(`${filename} 备份成功`);
93
103
  })
94
104
  .catch(err => {
95
105
  error(`${filename} 备份异常 ${err}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-automator",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Execute automation with yaml configuration(compatible with json)",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -16,6 +16,8 @@ const iconv = require('iconv-lite');
16
16
  const chardet = require("chardet");
17
17
  const { get_full_path } = require("../commands/share_data");
18
18
  const { parse, stringify } = require("./parse_tool");
19
+ const { hash } = require('./hash_tool');
20
+ const { formatDate } = require('./transform_tool');
19
21
  /**
20
22
  *
21
23
  * @param {Array | string} src
@@ -213,7 +215,7 @@ async function read_cfg(src, type, options) {
213
215
  return parse(content, type, options);
214
216
  }
215
217
 
216
- function processRename(fullpath, params) {
218
+ function processRename(fullpath, params, content) {
217
219
  if (!params) return fullpath;
218
220
  let dirname = path.dirname(fullpath);
219
221
  switch (typeof params) {
@@ -244,6 +246,8 @@ function processRename(fullpath, params) {
244
246
  if (params.dir_suffix) dirname = dirname + params.dir_suffix;
245
247
  if (params.base_prefix) basename = params.base_prefix + basename;
246
248
  if (params.base_suffix) basename = basename + params.base_suffix;
249
+ if (params.hash_suffix) basename = basename + "." + hash(content).substring(0, 8);
250
+ if (params.time_suffix) basename = basename + "." + formatDate(new Date(), "YYYYMMDDhhmmss");
247
251
  return path.join(dirname, basename + extname);
248
252
  }
249
253
  }
@@ -289,7 +293,7 @@ async function copy(src, dst, base, options) {
289
293
  } else {
290
294
  dstFile = path.join(dst, path.relative(base, src));
291
295
  }
292
- dstFile = processRename(dstFile, options.rename);
296
+ dstFile = processRename(dstFile, options.rename, fs.readFileSync(src));
293
297
  let dstDir = path.dirname(dstFile);
294
298
  if (!fs.existsSync(dstDir) || !fs.lstatSync(dstDir).isDirectory()) {
295
299
  try {