import { PluginConfig } from '@tiejs/common' ; import { defaultPlugins } from './defaultPlugins' ; function sortPlugins ( pluginConfig ) { const tails = [ 'controller' , 'graphql' , 'event' , 'schedule' ] ; let head = [ ] ; let tail = [ ] ; for ( const item of pluginConfig ) { if ( tails . includes ( item . name ) ) { tail . push ( item ) ; } else { head . push ( item ) ; } } return [ ... head , ... tail ] . sort ( a => { if ( a . prepend ) return - 1 ; return 1 ; } ) ; } export function getPluginConfig ( pluginConfig = [ ] ) { if ( ! pluginConfig . length ) return defaultPlugins ; for ( const item of defaultPlugins ) { const find = pluginConfig . find ( i => i . name === item . name ) ; if ( find ) continue ; pluginConfig . unshift ( item ) ; } pluginConfig = sortPlugins ( pluginConfig ) ; return pluginConfig ; }