执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
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
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
 
var _co = _interopRequireDefault(require("co"));
 
var fspp = _interopRequireWildcard(require("../fs-promise-proxy"));
 
var _commonActionUtils = require("./_common-action-utils");
 
var _commonActionInterfaceCheck = _interopRequireDefault(require("./_common-action-interface-check"));
 
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
const doAppend = function* (data, cfg, plop, fileData) {
  const stringToAppend = yield (0, _commonActionUtils.getRenderedTemplate)(data, cfg, plop); // if the appended string should be unique (default),
  // remove any occurence of it (but only if pattern would match)
 
  if (cfg.unique !== false && new RegExp(cfg.pattern).test(fileData)) {
    // only remove after "pattern", so that we remove not too much accidentally
    const parts = fileData.split(cfg.pattern);
    const lastPart = parts[parts.length - 1];
    const lastPartWithoutDuplicates = lastPart.replace(new RegExp(stringToAppend, 'g'), '');
    fileData = fileData.replace(lastPart, lastPartWithoutDuplicates);
  }
 
  const {
    separator = '\n'
  } = cfg; // add the appended string to the end of the "fileData" if "pattern"
  // was not provided, i.e. null or false
 
  if (!cfg.pattern) {
    // make sure to add a "separator" if "fileData" is not empty
    if (fileData.length > 0) {
      fileData += separator;
    }
 
    return fileData + stringToAppend;
  }
 
  return fileData.replace(cfg.pattern, '$&' + separator + stringToAppend);
};
 
var _default = _co.default.wrap(function* (data, cfg, plop) {
  const interfaceTestResult = (0, _commonActionInterfaceCheck.default)(cfg);
 
  if (interfaceTestResult !== true) {
    throw interfaceTestResult;
  }
 
  const fileDestPath = (0, _commonActionUtils.makeDestPath)(data, cfg, plop);
 
  try {
    // check path
    const pathExists = yield fspp.fileExists(fileDestPath);
 
    if (!pathExists) {
      throw 'File does not exists';
    } else {
      let fileData = yield fspp.readFile(fileDestPath);
      fileData = yield doAppend(data, cfg, plop, fileData);
      yield fspp.writeFile(fileDestPath, fileData);
    }
 
    return (0, _commonActionUtils.getRelativeToBasePath)(fileDestPath, plop);
  } catch (err) {
    (0, _commonActionUtils.throwStringifiedError)(err);
  }
});
 
exports.default = _default;