1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.getRenderedTemplatePath = getRenderedTemplatePath;
|
7 | exports.getTemplate = getTemplate;
|
8 | exports.getRenderedTemplate = getRenderedTemplate;
|
9 | exports.throwStringifiedError = exports.getRelativeToBasePath = exports.makeDestPath = exports.normalizePath = void 0;
|
10 |
|
11 | var _path = _interopRequireDefault(require("path"));
|
12 |
|
13 | var fspp = _interopRequireWildcard(require("../fs-promise-proxy"));
|
14 |
|
15 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
16 |
|
17 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
18 |
|
19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20 |
|
21 | const getFullData = (data, cfg) => Object.assign({}, cfg.data, data);
|
22 |
|
23 | const normalizePath = path => {
|
24 | return !path.sep || path.sep === '\\' ? path.replace(/\\/g, '/') : path;
|
25 | };
|
26 |
|
27 | exports.normalizePath = normalizePath;
|
28 |
|
29 | const makeDestPath = (data, cfg, plop) => {
|
30 | return _path.default.resolve(plop.getDestBasePath(), plop.renderString(normalizePath(cfg.path) || '', getFullData(data, cfg)));
|
31 | };
|
32 |
|
33 | exports.makeDestPath = makeDestPath;
|
34 |
|
35 | function getRenderedTemplatePath(data, cfg, plop) {
|
36 | if (cfg.templateFile) {
|
37 | const absTemplatePath = _path.default.resolve(plop.getPlopfilePath(), cfg.templateFile);
|
38 |
|
39 | return plop.renderString(normalizePath(absTemplatePath), getFullData(data, cfg));
|
40 | }
|
41 |
|
42 | return null;
|
43 | }
|
44 |
|
45 | function* getTemplate(data, cfg, plop) {
|
46 | const makeTmplPath = p => _path.default.resolve(plop.getPlopfilePath(), p);
|
47 |
|
48 | let {
|
49 | template
|
50 | } = cfg;
|
51 |
|
52 | if (cfg.templateFile) {
|
53 | template = yield fspp.readFile(makeTmplPath(cfg.templateFile));
|
54 | }
|
55 |
|
56 | if (template == null) {
|
57 | template = '';
|
58 | }
|
59 |
|
60 | return template;
|
61 | }
|
62 |
|
63 | function* getRenderedTemplate(data, cfg, plop) {
|
64 | const template = yield getTemplate(data, cfg, plop);
|
65 | return plop.renderString(template, getFullData(data, cfg));
|
66 | }
|
67 |
|
68 | const getRelativeToBasePath = (filePath, plop) => filePath.replace(_path.default.resolve(plop.getDestBasePath()), '');
|
69 |
|
70 | exports.getRelativeToBasePath = getRelativeToBasePath;
|
71 |
|
72 | const throwStringifiedError = err => {
|
73 | if (typeof err === 'string') {
|
74 | throw err;
|
75 | } else {
|
76 | throw err.message || JSON.stringify(err);
|
77 | }
|
78 | };
|
79 |
|
80 | exports.throwStringifiedError = throwStringifiedError; |
\ | No newline at end of file |