UNPKG

@areslabs/alita-core

Version:

alita-core

100 lines (74 loc) 3.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLibCompInfos = getLibCompInfos; exports.extChildComp = exports.allBaseComp = exports.jsxPropsMap = exports.textComp = exports.packageInfos = void 0; var fse = _interopRequireWildcard(require("fs-extra")); var path = _interopRequireWildcard(require("path")); var _myResolve = require("./myResolve"); var _configure = _interopRequireDefault(require("../configure")); var _util = require("./util"); var _constants = require("../constants"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; 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; } const packageInfos = {}; /*Text节点,一般来说只要官方的Text组件*/ exports.packageInfos = packageInfos; const textComp = new Set(['Text']); /*属性是JSX片段,包括方法返回JSX片段等,Alita需要特殊处理这些属性*/ exports.textComp = textComp; const jsxPropsMap = {}; /*所有基本组件,包括RN官方组件,基本组件和自定义组件 Alita在转化的时候有一些区别*/ exports.jsxPropsMap = jsxPropsMap; const allBaseComp = new Set([]); /*需要处理children 为childrencpt的集合*/ exports.allBaseComp = allBaseComp; const extChildComp = new Set([]); exports.extChildComp = extChildComp; function getLibCompInfos(idens, JSXElements, filepath, relativePath) { const packagePath = (0, _util.getLibPath)(relativePath); // 动画组件 AnimatedView 会退化为view if (packagePath === '@areslabs/wx-animated') return; if (!packageInfos[packagePath]) { const pajPath = (0, _myResolve.syncResolve)(path.dirname(filepath), `${packagePath}/package.json`); const json = fse.readJSONSync(pajPath); if (!json.wxComponents) { packageInfos[packagePath] = {}; return; } packageInfos[packagePath] = { dirname: path.dirname(pajPath), aliasPackName: _configure.default.resolve.alias[packagePath] || packagePath, wxComponents: json.wxComponents }; const components = json.wxComponents.components; if (packagePath === 'react-native') { components.forEach(comp => { _constants.RNCOMPSET.add(comp.name); }); } for (let i = 0; i < components.length; i++) { const comp = components[i]; const { name, base = true, needOperateChildren, jsxProps, isText } = comp; if (needOperateChildren === true) { extChildComp.add(name); } if (base === true) { allBaseComp.add(name); } if (jsxProps) { jsxPropsMap[name] = jsxProps; } if (isText === true) { textComp.add(name); } } } }