@@ -33,7 +33,7 @@ const loadEntryFile = async path => {
3333 try {
3434 const packageJson = await loadPackageJson ( path )
3535 let entryFilePath = join ( path , 'entry.js' )
36- if ( packageJson ) entryFilePath = join ( path , packageJson . main )
36+ if ( packageJson && typeof packageJson . main === 'string' ) entryFilePath = join ( path , packageJson . main )
3737
3838 const result = await cosmiconfig ( 'template' ) . load ( entryFilePath )
3939 const config = checkConfig ( result . config )
@@ -55,7 +55,7 @@ const loadEntryFile = async path => {
5555}
5656
5757
58- module . exports = async ( repository , version ) => {
58+ module . exports = async ( repository , version , load = false ) => {
5959 const milirc = await loadMilirc ( )
6060
6161 if ( ! repository ) {
@@ -80,34 +80,31 @@ module.exports = async (repository, version) => {
8080 interactionSHA1 : '' ,
8181 }
8282
83- if ( ! repository ) return config
83+ if ( ! load ) return config
8484
8585 const localStoragePath = await getLocalStoragePath ( config . repository , config . version )
8686 if ( ! await fs . pathExists ( localStoragePath ) ) return config
8787
8888 const packageJson = await loadPackageJson ( localStoragePath )
89- try {
90- const entryFile = await loadEntryFile ( localStoragePath )
91- config . name = entryFile . name || packageJson . name || ''
92- config . version = version
93- config . engines = entryFile . engines
9489
95- config . path = join ( localStoragePath , entryFile . path )
96- if ( ! await isDirectory ( config . path ) ) throwError ( 'The template path should be a folder' )
90+ const entryFile = await loadEntryFile ( localStoragePath )
91+ config . name = entryFile . name || packageJson . name || ''
92+ config . version = version
93+ config . engines = entryFile . engines
9794
98- config . rules = entryFile . rules . map ( rule => {
99- rule . path = join ( localStoragePath , rule . path )
100- return formatRule ( rule )
101- } )
95+ config . path = join ( localStoragePath , entryFile . path )
96+ if ( ! await isDirectory ( config . path ) ) throwError ( 'The template path should be a folder' )
10297
103- config . interaction = entryFile . interaction
104- config . interactionSHA1 = sha1 ( JSON . stringify ( entryFile . interaction ) )
105- config . hooks = formatHooks ( entryFile . hooks )
98+ config . rules = entryFile . rules . map ( rule => {
99+ rule . path = join ( localStoragePath , rule . path )
100+ return formatRule ( rule )
101+ } )
106102
107- config . files = await searchFile ( config )
108- config . status = 'loaded'
109- return config
110- } catch ( e ) {
111- return config
112- }
103+ config . interaction = entryFile . interaction
104+ config . interactionSHA1 = sha1 ( JSON . stringify ( entryFile . interaction ) )
105+ config . hooks = formatHooks ( entryFile . hooks )
106+
107+ config . files = await searchFile ( config )
108+ config . status = 'loaded'
109+ return config
113110}
0 commit comments