UNPKG

cybertron-utils

Version:
48 lines (42 loc) 1.54 kB
const fs = require( 'fs' ); const path = require( 'path' ); const config = require(path.resolve(process.cwd(), './src/config')); const pkg = require( path.resolve(process.cwd(), './package.json' )); const COMPONENT_SRC_PATH = path.resolve( __dirname, '../src' ); module.exports = function getComponents (componentHash) { const uploadComponents = []; if ( componentHash ) { for ( let key in componentHash ) { const curr = config[key]; if(!curr) throw new Error("请检查config.js文件是否错误!") const { version } = curr; const installInfo = { ...componentHash[key], version, dependencies: { ...pkg.dependencies } }; uploadComponents.push( installInfo ); } } else { for ( let key in config ) { const curr = config[key]; const { version } = curr; // 检查是否存在文件 if ( !fs.existsSync( path.resolve( COMPONENT_SRC_PATH, key, './js/index.jsx' ) ) ) { console.warn( `没有找到${key}入口文件!` ); } else { const installInfo = { name: key, version, dependencies: { ...pkg.dependencies } }; uploadComponents.push( installInfo ); } } } return uploadComponents; }