@@ -6,7 +6,7 @@ const util = require('../build/util.js')
66const buildReadme = require ( '../build/build-readme.js' )
77const root = path . join ( __dirname , '..' )
88const modulesId = process . env . UNI_MODULES_ID
9- // const modulesId = 'uni-icons '
9+ // const modulesId = 'uni-forms '
1010const comName = modulesId . replace ( / u n i - / , '' )
1111const comPath = path . join ( root , 'uni_modules' )
1212// console.error('upload.js - modulesId :' + modulesId);
@@ -44,47 +44,58 @@ if (modulesId === 'uni-ui') {
4444} else {
4545 // 将组件拷贝到临时目录
4646 util . copyDir ( getModulesPath ( modulesId ) , path . join ( tempExamplePath , 'uni_modules' , modulesId ) )
47- handlePageJson ( comName , tempExamplePath )
48- // 获取关联组件
49- if ( packageJson && packageJson . uni_modules && packageJson . uni_modules . dependencies . length > 0 ) {
50- relationComponents = packageJson . uni_modules . dependencies
51- }
52- // 同步依赖组件
53- if ( relationComponents && relationComponents . length > 0 ) {
54- relationComponents . reduce ( ( promise , item ) => {
55- return new Promise ( ( resolve , reject ) => {
56- util . copyDir ( getModulesPath ( item ) , path . join ( tempExamplePath , 'uni_modules' , item ) )
57- resolve ( )
58- } )
59- } , Promise . resolve ( [ ] ) ) . then ( res => {
60- // console.error('所有依赖组件同步完成');
61- setPageComponents ( modulesId , comName )
62- } ) . catch ( ( err ) => {
63- console . log ( 'error' , err ) ;
64- } )
65- } else {
66- setPageComponents ( modulesId , comName )
67- }
47+ handlePageJson ( comName , tempExamplePath )
48+ // 同步页面使用的组件
49+ setPageComponents ( modulesId , comName )
50+ // 同步组件依赖的组间
51+ syncRelyOn ( modulesId )
6852}
6953
7054function setPageComponents ( modulesId , comName ) {
7155 const pagePath = path . join ( root , 'pages' , 'vue' , comName , comName + '.vue' )
7256 const pageContent = fs . readFileSync ( pagePath ) . toString ( )
7357 const pageContents = getComName ( pageContent )
74- // console.error('组件名称:' + pageContents);
75-
7658 if ( pageContents . length > 0 ) {
77- pageContents . reduce ( ( promise , item ) => {
78- const inputPath = getModulesPath ( item )
59+ pageContents . reduce ( ( promise , item ) => {
60+ const inputPath = getModulesPath ( item )
7961 const exists = fs . existsSync ( inputPath )
80- if ( item === modulesId || ! exists ) return promise
81- return new Promise ( ( resolve , reject ) => {
82- util . copyDir ( inputPath , path . join ( tempExamplePath , 'uni_modules' , item ) )
62+ if ( item === modulesId || ! exists ) return promise
63+ return new Promise ( ( resolve , reject ) => {
64+ util . copyDir ( inputPath , path . join ( tempExamplePath , 'uni_modules' , item ) )
65+ resolve ( )
66+ } ) . then ( ( ) => {
67+ syncRelyOn ( item )
8368 } )
8469 } , Promise . resolve ( [ ] ) ) . then ( res => {
85- // console.error ('所有依赖组件同步完成');
70+ // console.log ('所有依赖组件同步完成');
8671 } )
8772 }
73+ }
74+
75+ function syncRelyOn ( modulesName ) {
76+ const packageJson = getPackage ( modulesName , comPath )
77+ let relationComponents = [ ]
78+ // 获取关联组件
79+ if ( packageJson && packageJson . uni_modules && packageJson . uni_modules . dependencies . length > 0 ) {
80+ relationComponents = packageJson . uni_modules . dependencies
81+ }
82+ // 同步依赖组件
83+ if ( relationComponents && relationComponents . length > 0 ) {
84+ return relationComponents . reduce ( ( promise , item ) => {
85+ return new Promise ( ( resolve , reject ) => {
86+ util . copyDir ( getModulesPath ( item ) , path . join ( tempExamplePath , 'uni_modules' , item ) )
87+ resolve ( )
88+ } ) . then ( ( ) => {
89+ syncRelyOn ( item )
90+ } )
91+ } , Promise . resolve ( [ ] ) ) . then ( res => {
92+ // console.error('所有依赖组件同步完成');
93+ // setPageComponents(modulesId, comName)
94+ } ) . catch ( ( err ) => {
95+ // console.log('error',err);
96+ } )
97+ }
98+ return Promise . resolve ( )
8899}
89100
90101/**
0 commit comments