UNPKG

@nokecy/umi-plugin-erp-common

Version:

erp-common

65 lines (56 loc) 2.19 kB
import { IApi } from 'umi'; import { join } from 'path'; import getContextContent from './utils/getContextContent'; import getSettingProviderContent from './utils/getErpCommonProviderContent'; import getSettingContent from './utils/getErpCommonContent'; import getRootContainerContent from './utils/getRootContainerContent'; import { checkIfHasDefaultExporting } from './utils'; const erpCommon_DIR = 'plugin-abp-erp-common'; // plugin-erpCommon 插件创建临时文件的专有文件夹 export default function (api: IApi) { const umiTmpDir = api.paths.absTmpPath; const srcDir = api.paths.absSrcPath; const erpCommonFilePath = api.utils.winPath(join(srcDir!, 'erpCommon')); api.describe({ key: "abperpcommon", enableBy: api.EnableBy.register, }) api.onGenerateFiles(() => { // 判断 erpCommon 工厂函数存在并且 default 暴露了一个函数 if (checkIfHasDefaultExporting(erpCommonFilePath)) { // 创建 erpCommon 的 context 以便跨组件传递 erpCommon 实例 api.writeTmpFile({ path: `${erpCommon_DIR}/context.ts`, content: getContextContent(), }); // 创建 erpCommonProvider,1. 生成 erpCommon 实例; 2. 传给 context 的 Provider api.writeTmpFile({ path: `${erpCommon_DIR}/erpCommonProvider.ts`, content: getSettingProviderContent(api.utils), }); // 创建 erpCommon 的 hook api.writeTmpFile({ path: `${erpCommon_DIR}/erpCommon.tsx`, content: getSettingContent(), }); // 生成 rootContainer 运行时配置 api.writeTmpFile({ path: `${erpCommon_DIR}/rootContainer.ts`, content: getRootContainerContent(), }); } }); if (checkIfHasDefaultExporting(erpCommonFilePath)) { // 增加 rootContainer 运行时配置 api.addRuntimePlugin({ fn: () => api.utils.winPath(join(umiTmpDir!, erpCommon_DIR, 'rootContainer.ts')), stage: -1 }); api.addUmiExports(() => [ { exportAll: true, source: `../${erpCommon_DIR}/erpCommon`, }, ]); api.addTmpGenerateWatcherPaths(() => [ `${erpCommonFilePath}.ts`, `${erpCommonFilePath}.js`, ]); } }