执行过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
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = addFile;
 
var _path = _interopRequireDefault(require("path"));
 
var _del = _interopRequireDefault(require("del"));
 
var _commonActionUtils = require("./_common-action-utils");
 
var _isbinaryfile = _interopRequireDefault(require("isbinaryfile"));
 
var fspp = _interopRequireWildcard(require("../fs-promise-proxy"));
 
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 }; }
 
function* addFile(data, cfg, plop) {
  const fileDestPath = (0, _commonActionUtils.makeDestPath)(data, cfg, plop);
  const {
    force,
    skipIfExists = false
  } = cfg;
 
  try {
    // check path
    let destExists = yield fspp.fileExists(fileDestPath); // if we are forcing and the file already exists, delete the file
 
    if (force === true && destExists) {
      yield (0, _del.default)([fileDestPath]);
      destExists = false;
    } // we can't create files where one already exists
 
 
    if (destExists) {
      if (skipIfExists) {
        return `[SKIPPED] ${fileDestPath} (exists)`;
      }
 
      throw `File already exists\n -> ${fileDestPath}`;
    } else {
      yield fspp.makeDir(_path.default.dirname(fileDestPath));
      const absTemplatePath = cfg.templateFile && _path.default.resolve(plop.getPlopfilePath(), cfg.templateFile) || null;
 
      if (absTemplatePath != null && _isbinaryfile.default.sync(absTemplatePath)) {
        const rawTemplate = yield fspp.readFileRaw(cfg.templateFile);
        yield fspp.writeFileRaw(fileDestPath, rawTemplate);
      } else {
        const renderedTemplate = yield (0, _commonActionUtils.getRenderedTemplate)(data, cfg, plop);
        yield fspp.writeFile(fileDestPath, renderedTemplate);
      } // keep the executable flags
 
 
      if (absTemplatePath != null) {
        const sourceStats = yield fspp.stat(absTemplatePath);
        const destStats = yield fspp.stat(fileDestPath);
        const executableFlags = sourceStats.mode & (fspp.constants.S_IXUSR | fspp.constants.S_IXGRP | fspp.constants.S_IXOTH);
        yield fspp.chmod(fileDestPath, destStats.mode | executableFlags);
      }
    } // return the added file path (relative to the destination path)
 
 
    return (0, _commonActionUtils.getRelativeToBasePath)(fileDestPath, plop);
  } catch (err) {
    (0, _commonActionUtils.throwStringifiedError)(err);
  }
}