执行过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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
 
var _co = _interopRequireDefault(require("co"));
 
var _path = _interopRequireDefault(require("path"));
 
var _fs = _interopRequireDefault(require("fs"));
 
var _globby = _interopRequireDefault(require("globby"));
 
var _commonActionInterfaceCheck = _interopRequireDefault(require("./_common-action-interface-check"));
 
var _commonActionAddFile = _interopRequireDefault(require("./_common-action-add-file"));
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
const defaultConfig = {
  verbose: true
};
 
var _default = _co.default.wrap(function* (data, userConfig, plop) {
  // shallow-merge default config and input config
  const cfg = Object.assign({}, defaultConfig, userConfig); // check the common action interface attributes. skip path check because it's NA
 
  const interfaceTestResult = (0, _commonActionInterfaceCheck.default)(cfg, {
    checkPath: false
  });
 
  if (interfaceTestResult !== true) {
    throw interfaceTestResult;
  } // check that destination (instead of path) is a string value
 
 
  const dest = cfg.destination;
 
  if (typeof dest !== 'string' || dest.length === 0) {
    throw `Invalid destination "${dest}"`;
  }
 
  if (cfg.base) {
    cfg.base = plop.renderString(cfg.base, data);
  }
 
  if (typeof cfg.templateFiles === 'function') {
    cfg.templateFiles = cfg.templateFiles();
  }
 
  cfg.templateFiles = [].concat(cfg.templateFiles) // Ensure `cfg.templateFiles` is an array, even if a string is passed.
  .map(file => plop.renderString(file, data)); // render the paths as hbs templates
 
  const templateFiles = resolveTemplateFiles(cfg.templateFiles, cfg.base, cfg.globOptions, plop);
  const filesAdded = [];
 
  for (let templateFile of templateFiles) {
    const absTemplatePath = _path.default.resolve(plop.getPlopfilePath(), templateFile);
 
    const fileCfg = Object.assign({}, cfg, {
      path: resolvePath(cfg.destination, templateFile, cfg.base),
      templateFile: absTemplatePath
    });
    const addedPath = yield (0, _commonActionAddFile.default)(data, fileCfg, plop);
    filesAdded.push(addedPath);
  }
 
  const summary = `${filesAdded.length} files added`;
  if (!cfg.verbose) return summary;else return `${summary}\n -> ${filesAdded.join('\n -> ')}`;
});
 
exports.default = _default;
 
function resolveTemplateFiles(templateFilesGlob, basePath, globOptions, plop) {
  globOptions = Object.assign({
    cwd: plop.getPlopfilePath()
  }, globOptions);
  return _globby.default.sync(templateFilesGlob, Object.assign({
    nobrace: true
  }, globOptions)).filter(isUnder(basePath)).filter(isAbsoluteOrRelativeFileTo(plop.getPlopfilePath()));
}
 
function isAbsoluteOrRelativeFileTo(relativePath) {
  const isFile = file => _fs.default.existsSync(file) && _fs.default.lstatSync(file).isFile();
 
  return file => isFile(file) || isFile(_path.default.join(relativePath, file));
}
 
function isUnder(basePath = '') {
  return path => path.startsWith(basePath);
}
 
function resolvePath(destination, file, rootPath) {
  return toUnix(_path.default.join(destination, dropFileRootPath(file, rootPath)));
}
 
function toUnix(path) {
  return !path.sep || path.sep === '\\' ? path.replace(/\\/g, '/') : path;
}
 
function dropFileRootPath(file, rootPath) {
  return rootPath ? file.replace(rootPath, '') : dropFileRootFolder(file);
}
 
function dropFileRootFolder(file) {
  const fileParts = _path.default.normalize(file).split(_path.default.sep);
 
  fileParts.shift();
  return fileParts.join(_path.default.sep);
}