15815213711
2024-08-26 67b8b6731811983447e053d4396b3708c14dfe3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
 
const path = require('path');
const fs = require('fs');
const fsPro = require('fs-extra');
const chalk = require('chalk');
const Utils = require('../lib/utils');
 
/**
 * 资源替换
 */
 
 module.exports = {
  
  /**
   * 执行
   */  
  run(options = {}) {
    const warnTips = chalk.bgYellow('Warning') + ': This command is deprecated. Use move instead !';
    console.log(warnTips);
 
    console.log('[ee-bin] [rd] Start moving resources');
    const homeDir = process.cwd();
    let { dist, target, config } = options;
 
    let distDir = './frontend/dist';
    let targetDir = './public/dist';
 
    // 命令行优先
    if (dist) {
      distDir = dist;
    }
    if (target) {
      targetDir = target;
    }
 
    // 如果命令行没参数,从bin config 获取
    if (!dist && !target) {
      const hasConfig = Utils.checkConfig(config);
      if (hasConfig) {
        const cfg = Utils.loadConfig(config);
        if (cfg.rd && cfg.rd.dist) {
          distDir = cfg.rd.dist;
        }
        if (cfg.rd && cfg.rd.target) {
          targetDir = cfg.rd.target;
        }
      }   
    }
 
    const sourceDir = path.join(homeDir, distDir);
    if (!fs.existsSync(sourceDir)) {
      const errorTips = chalk.bgRed('Error') + ' Frontend resource does not exist, please build !';
      console.error(errorTips);
      return
    }
    
    // 清空历史资源 并 复制到ee资源目录
    const eeResourceDir = path.join(homeDir, targetDir);
    if (!fs.existsSync(eeResourceDir)) {
      fs.mkdirSync(eeResourceDir, {recursive: true, mode: 0o777});
    } else {
      this._rmFolder(eeResourceDir);
      console.log('[ee-bin] [rd] Clear history resources:', eeResourceDir);
    }
 
    fsPro.copySync(sourceDir, eeResourceDir);
    console.log('[ee-bin] [rd] Copy a resource to:', eeResourceDir);
    console.log('[ee-bin] [rd] End');
  },
 
  /**
   * 删除文件夹
   */
  _rmFolder(folder) {
    const nodeVersion = (process.versions && process.versions.node) || null;
    if (nodeVersion && Utils.compareVersion(nodeVersion, '14.14.0') == 1) {
      fs.rmSync(folder, {recursive: true});
    } else {
      fs.rmdirSync(folder, {recursive: true});
    }
  },
}