mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-10-14 10:52:28 +08:00
39 lines
937 B
TypeScript
39 lines
937 B
TypeScript
import type { IPluginAPI } from '@fesjs/shared';
|
|
|
|
import { dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import pkg from '../package.json' assert { type: 'json' };
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
|
|
export default (api: IPluginAPI) => {
|
|
api.addRuntimePluginKey(() => 'request');
|
|
|
|
const namespace = 'plugin-request';
|
|
const absoluteFilePath = `${namespace}/request.js`;
|
|
|
|
let generatedOnce = false;
|
|
api.onGenerateFiles(() => {
|
|
if (generatedOnce) {
|
|
return;
|
|
}
|
|
generatedOnce = true;
|
|
api.copyTmpFiles({
|
|
namespace,
|
|
path: join(__dirname, 'template'),
|
|
});
|
|
});
|
|
|
|
api.addPluginExports(() => [
|
|
{
|
|
exportAll: true,
|
|
source: absoluteFilePath,
|
|
},
|
|
]);
|
|
|
|
api.addConfigType(() => ({
|
|
source: pkg.name,
|
|
}));
|
|
};
|