import Alipay from './program' ; import type { IPluginContext } from '@tarojs/service' ; export { Alipay } ; let registedModifyPageTemplate = false ; export default ( ctx ) => { ctx . registerPlatform ( { name : 'alipay' , useConfigName : 'mini' , async fn ( { config } ) { ! registedModifyPageTemplate && modifyPageTemplate ( ctx ) ; const program = new Alipay ( ctx , config ) ; await program . start ( ) ; } } ) ; } ; function getIsBuildPluginPath ( filePath , isBuildPlugin ) { return isBuildPlugin ? `plugin/${ filePath }` : filePath ; } function modifyPageTemplate ( ctx ) { registedModifyPageTemplate = true ; ctx . modifyBuildAssets ( ( { assets , miniPlugin } ) => { const pages = [ ] ; miniPlugin . pages . forEach ( page => { const config = miniPlugin . filesConfig [ miniPlugin . getConfigFilePath ( page . name ) ] . content ; if ( ! page . isNative && config ?. hasOwnProperty ( 'usingComponents' ) && Object . keys ( config . usingComponents ) . length ) { pages . push ( page . name ) ; } } ) ; if ( ! pages . length ) return ; const baseXml = assets [ getIsBuildPluginPath ( 'base.axml' , miniPlugin . options . isBuildPlugin ) ] . source ( ) ; pages . forEach ( page => { const templateName = `${ page }.axml` ; const assetsItem = assets [ templateName ] ; const src = assetsItem . _value ? assetsItem . _value . toString ( ) : assetsItem . source ( ) ; let relativePath ; const templateCaller = src . replace ( /<import src="(.*)base\.axml"\/>/ , function ( _ , $1 ) { relativePath = $1 ; return '' ; } ) ; const main = baseXml . replace ( /<import-sjs name="xs" from="(.*)utils.sjs" \/>/ , function ( ) { return `<import-sjs name="xs" from="${ relativePath }utils.sjs" />` ; } ) ; const res = `${ templateCaller }
${ main }` ; assets [ templateName ] = { size : ( ) => res . length , source : ( ) => res } ; } ) ; if ( miniPlugin . options . isBuildPlugin ) { const miniProjectJSONStr = JSON . stringify ( { miniprogramRoot : 'miniprogram' , pluginRoot : 'plugin' , compileType : 'plugin' } , null , 2 ) ; assets [ 'mini.project.json' ] = { size : ( ) => miniProjectJSONStr . length , source : ( ) => miniProjectJSONStr } ; const pluginJSON = JSON . parse ( assets [ '/plugin/plugin.json' ] . source ( ) ) ; pluginJSON . publicPages = pluginJSON . pages ; delete pluginJSON . pages ; const pluginJSONStr = JSON . stringify ( pluginJSON , null , 2 ) ; assets [ '/plugin/plugin.json' ] = { size : ( ) => pluginJSONStr . length , source : ( ) => pluginJSONStr } ; } } ) ; }