@lcap/builder
Version:
lcap builder utils
84 lines (83 loc) • 3.91 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const fast_glob_1 = __importDefault(require("fast-glob"));
const gen_nasl_component_config_1 = __importStar(require("./gen-nasl-component-config"));
const component_path_1 = require("../../utils/component-path");
const logger_1 = __importDefault(require("../../utils/logger"));
function genNaslUIConfig({ rootPath, assetsPublicPath, components, framework, }) {
const packageInfo = fs_extra_1.default.readJSONSync(path_1.default.join(rootPath, 'package.json'));
const libInfo = [packageInfo.name, '@', packageInfo.version].join('');
const waitParseList = [];
if (components && components.length > 0) {
components.forEach((extConfig) => {
const componentRootDir = packageInfo.name === '@lcap/mobile-ui' ? 'src-vusion/components' : 'src/components';
const { componentDir } = (0, component_path_1.getComponentPathInfo)(extConfig.name, rootPath, componentRootDir);
const apiPath = extConfig.apiPath ? path_1.default.join(rootPath, componentRootDir, extConfig.apiPath) : path_1.default.join(componentDir, 'api.ts');
if (!fs_extra_1.default.existsSync(apiPath)) {
logger_1.default.error(`未找到组件 ${extConfig.name} 的描述文件(api.ts)`);
return;
}
waitParseList.push({
apiPath,
extConfig,
});
});
}
else {
fast_glob_1.default.sync('src/**/api.ts', { cwd: rootPath, absolute: true }).forEach((apiPath) => {
waitParseList.push({
apiPath,
extConfig: {},
});
});
}
const componentConfigs = [];
waitParseList.forEach(({ apiPath, extConfig }) => {
const componentConfig = (0, gen_nasl_component_config_1.default)({
apiPath,
assetsPublicPath,
rootPath,
extraConfig: extConfig,
libInfo,
framework,
});
const projectAssetPath = 'assets';
if (componentConfig.icon && componentConfig.icon.indexOf('.') !== -1 && fs_extra_1.default.existsSync(path_1.default.join(rootPath, projectAssetPath, componentConfig.icon))) {
componentConfig.icon = `${assetsPublicPath}/${libInfo}/${projectAssetPath}/${componentConfig.icon}`;
}
if (componentConfig) {
componentConfigs.push(componentConfig);
}
});
(0, gen_nasl_component_config_1.processComponentConfigExtends)(componentConfigs);
return componentConfigs;
}
exports.default = genNaslUIConfig;