UNPKG

create-component-template

Version:
97 lines (80 loc) 3.16 kB
'use strict'; var _regenerator = require('babel-runtime/regenerator'); var _regenerator2 = _interopRequireDefault(_regenerator); var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var path = require('path'); var importConfig = require('./importer'); var _require = require('../utils/pathing'), getAppRootDir = _require.getAppRootDir; /** * @param {Object} configFile * @param {string} appRootDir * @param {string} componentName * @param {string} componentPath * @returns templatePathsArray */ var mapTemplatePaths = function mapTemplatePaths(configFile, appRootDir, componentName, componentPath) { return configFile.templates.map(function (template) { var folderName = template.folderName || ''; return { filePath: path.join(appRootDir, componentPath, componentName, folderName, template.fileName || componentName + template.extension), templatePath: '' + path.join(path.isAbsolute(configFile.templatesDirectory) ? '' : appRootDir, // Only use a root dir if required configFile.templatesDirectory, template.templateName) }; }); }; /** * @param {Object} configFile * @param {string} appRootDir * @param {string} componentName * @param {string} componentPath * @returns folderPathsArray */ var mapFolderPaths = function mapFolderPaths(configFile, appRootDir, componentName, componentPath) { return configFile.templates.map(function (_ref) { var folderName = _ref.folderName; if (folderName) { return path.join(appRootDir, componentPath, componentName, folderName); } }).filter(function (folder) { return folder; }); }; /** * @param {string} configPath * @param {string} componentName * @param {string} componentPath * @returns folderPathsArray */ var mapConfigWithTemplates = function () { var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(configPath, componentName, componentPath) { var appRootDir, configFile, folderPaths, templatePaths; return _regenerator2.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: appRootDir = getAppRootDir(); _context.next = 3; return importConfig(appRootDir, configPath); case 3: configFile = _context.sent; folderPaths = mapFolderPaths(configFile, appRootDir, componentName, componentPath); templatePaths = mapTemplatePaths(configFile, appRootDir, componentName, componentPath); return _context.abrupt('return', { templatePaths: templatePaths, folderPaths: folderPaths }); case 7: case 'end': return _context.stop(); } } }, _callee, undefined); })); return function mapConfigWithTemplates(_x, _x2, _x3) { return _ref2.apply(this, arguments); }; }(); module.exports = mapConfigWithTemplates;