You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							52 lines
						
					
					
						
							2.8 KiB
						
					
					
				
			
		
		
	
	
							52 lines
						
					
					
						
							2.8 KiB
						
					
					
				"use strict";
 | 
						|
 | 
						|
Object.defineProperty(exports, "__esModule", {
 | 
						|
  value: true
 | 
						|
});
 | 
						|
exports.default = void 0;
 | 
						|
 | 
						|
var path = _interopRequireWildcard(require("path"));
 | 
						|
 | 
						|
var _slash = _interopRequireDefault(require("slash"));
 | 
						|
 | 
						|
var _adminjs = _interopRequireDefault(require("../../adminjs"));
 | 
						|
 | 
						|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 | 
						|
 | 
						|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
 | 
						|
 | 
						|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
 | 
						|
 | 
						|
/**
 | 
						|
 * Generates entry file for all UsersComponents.
 | 
						|
 * Entry consists of 3 parts:
 | 
						|
 * 1. Setup AdminJS.UserComponents map.
 | 
						|
 * 2. List of all environmental variables passed to AdminJS in configuration option.
 | 
						|
 * 3. Imports of user components defined by ComponentLoader.
 | 
						|
 *
 | 
						|
 * @param {AdminJS}    admin
 | 
						|
 * @param {String}      entryPath  path to folder where entry file is located
 | 
						|
 * @return {String}     content of an entry file
 | 
						|
 *
 | 
						|
 * @private
 | 
						|
 */
 | 
						|
const generateUserComponentEntry = (admin, entryPath) => {
 | 
						|
  const {
 | 
						|
    env = {}
 | 
						|
  } = admin.options;
 | 
						|
 | 
						|
  admin.componentLoader.__unsafe_merge(_adminjs.default.__unsafe_staticComponentLoader);
 | 
						|
 | 
						|
  const components = admin.componentLoader.getComponents();
 | 
						|
  const absoluteEntryPath = path.resolve(entryPath);
 | 
						|
  const setupPart = 'AdminJS.UserComponents = {}\n';
 | 
						|
  const envPart = Object.keys(env).map(envKey => `AdminJS.env.${envKey} = ${JSON.stringify(env[envKey])}\n`).join('');
 | 
						|
  const componentsPart = Object.keys(components || {}).map(componentId => {
 | 
						|
    const componentUrl = path.relative(absoluteEntryPath, components[componentId]);
 | 
						|
    return [`import ${componentId} from '${(0, _slash.default)(componentUrl)}'`, `AdminJS.UserComponents.${componentId} = ${componentId}`].join('\n');
 | 
						|
  }).join('\n');
 | 
						|
  return setupPart + envPart + componentsPart;
 | 
						|
};
 | 
						|
 | 
						|
var _default = generateUserComponentEntry;
 | 
						|
exports.default = _default; |