feat: 整理fes-plugin-built-in目录和文件名

This commit is contained in:
万纯 2020-12-01 20:54:59 +08:00
parent b3a73ab6c5
commit e1ea9aecac
17 changed files with 40 additions and 47 deletions

View File

@ -5,12 +5,12 @@ export default [
require.resolve('./plugins/registerMethods'),
// misc
require.resolve('./plugins/routes'),
require.resolve('./plugins/mics/routes'),
// generate files
require.resolve('./plugins/generateFiles/core/plugin'),
require.resolve('./plugins/generateFiles/core/routes'),
require.resolve('./plugins/generateFiles/core/fesExports'),
require.resolve('./plugins/generateFiles/core/exports'),
require.resolve('./plugins/generateFiles/fes'),
// bundle configs
@ -48,6 +48,6 @@ export default [
require.resolve('./plugins/features/vueLoader'),
// commands
require.resolve('./plugins/commands/build/build'),
require.resolve('./plugins/commands/dev/dev')
require.resolve('./plugins/commands/build'),
require.resolve('./plugins/commands/dev')
];

View File

@ -5,8 +5,8 @@ import {
cleanTmpPathExceptCache,
getBundleAndConfigs,
printFileSizes
} from '../buildDevUtils';
import generateFiles from '../generateFiles';
} from '../../../utils/buildDevUtils';
import generateFiles from '../../../utils/generateFiles';
const logger = new Logger('fes:plugin-built-in');

View File

@ -1,25 +1,18 @@
import { Server } from '@umijs/server';
import {
delay
} from '@umijs/utils';
import { delay } from '@umijs/utils';
import assert from 'assert';
import {
cleanTmpPathExceptCache,
getBundleAndConfigs
} from '../buildDevUtils';
import generateFiles from '../generateFiles';
import {
watchPkg
} from './watchPkg';
} from '../../../utils/buildDevUtils';
import generateFiles from '../../../utils/generateFiles';
import { watchPkg } from './watchPkg';
export default (api) => {
const {
env,
paths,
utils: {
chalk,
portfinder
}
utils: { chalk, portfinder }
} = api;
const unwatchs = [];
@ -80,16 +73,13 @@ export default (api) => {
// watch config change
const unwatchConfig = api.service.configInstance.watch({
userConfig: api.service.userConfig,
onChange: async ({
pluginChanged,
valueChanged
}) => {
onChange: async ({ pluginChanged, valueChanged }) => {
if (pluginChanged.length) {
console.log();
api.logger.info(
`Plugins of ${pluginChanged
.map(p => p.key)
.join(', ')} changed.`,
.join(', ')} changed.`
);
api.restartServer();
}
@ -98,17 +88,18 @@ export default (api) => {
let regenerateTmpFiles = false;
const fns = [];
const reloadConfigs = [];
valueChanged.forEach(({
key,
pluginId
}) => {
const {
valueChanged.forEach(({ key, pluginId }) => {
const { onChange } = api.service.plugins[pluginId].config || {};
if (
onChange
} = api.service.plugins[pluginId].config || {};
if (onChange === api.ConfigChangeType.regenerateTmpFiles) {
=== api.ConfigChangeType.regenerateTmpFiles
) {
regenerateTmpFiles = true;
}
if (!onChange || onChange === api.ConfigChangeType.reload) {
if (
!onChange
|| onChange === api.ConfigChangeType.reload
) {
reload = true;
reloadConfigs.push(key);
}
@ -119,7 +110,11 @@ export default (api) => {
if (reload) {
console.log();
api.logger.info(`Config ${reloadConfigs.join(', ')} changed.`);
api.logger.info(
`Config ${reloadConfigs.join(
', '
)} changed.`
);
api.restartServer();
} else {
api.service.userConfig = api.service.configInstance.getUserConfig();
@ -181,9 +176,7 @@ export default (api) => {
},
proxy: api.config.proxy,
beforeMiddlewares,
afterMiddlewares: [
...middlewares
],
afterMiddlewares: [...middlewares],
...(api.config.devServer || {})
});
const listenRet = await server.listen({
@ -202,7 +195,7 @@ export default (api) => {
fn() {
assert(
env === 'development',
'api.getPort() is only valid in development.',
'api.getPort() is only valid in development.'
);
return port;
}
@ -213,7 +206,7 @@ export default (api) => {
fn() {
assert(
env === 'development',
'api.getHostname() is only valid in development.',
'api.getHostname() is only valid in development.'
);
return hostname;
}
@ -224,7 +217,7 @@ export default (api) => {
fn() {
assert(
env === 'development',
'api.getServer() is only valid in development.',
'api.getServer() is only valid in development.'
);
return server;
}

View File

@ -63,14 +63,14 @@ export function generateExports({
export default function (api) {
api.onGenerateFiles(async () => {
const fesExports = await api.applyPlugins({
key: 'addFesExports',
key: 'addExports',
type: api.ApplyPluginsType.add,
initialValue: []
});
const fesExportsHook = {}; // repeated definition
api.writeTmpFile({
path: 'core/fesExports.js',
path: 'core/exports.js',
content:
`${fesExports
.map(item => generateExports({

View File

@ -1,7 +1,7 @@
import { readFileSync } from 'fs';
import { join } from 'path';
import { getFile, winPath } from '@umijs/utils';
import { runtimePath } from '../constants';
import { runtimePath } from '../../../../utils/constants';
export default function (api) {
const {
@ -54,7 +54,7 @@ export default function (api) {
});
});
api.addFesExports(() => ({
api.addExports(() => ({
specifiers: ['plugin'],
source: './plugin'
}));

View File

@ -4,7 +4,7 @@ import {
join
} from 'path';
import { routesToJSON } from '@webank/fes-core';
import { runtimePath } from '../constants';
import { runtimePath } from '../../../../utils/constants';
export default function (api) {
const {
@ -24,7 +24,7 @@ export default function (api) {
});
});
api.addFesExports(() => ({
api.addExports(() => ({
specifiers: ['router'],
source: './routes.js'
}));

View File

@ -1,7 +1,7 @@
import { readFileSync } from 'fs';
import { join } from 'path';
import { winPath } from '@umijs/utils';
import { runtimePath } from './constants';
import { runtimePath } from '../../../utils/constants';
export function importsToStr(
imports,

View File

@ -6,7 +6,7 @@ export default function (api) {
[
'onExit',
'onGenerateFiles',
'addFesExports',
'addExports',
'addRuntimePluginKey',
'addRuntimePlugin',
'addEntryImportsAhead',

View File

@ -55,7 +55,7 @@ export default (api) => {
});
});
api.addFesExports(() => [
api.addExports(() => [
{
exportAll: true,
source: `../${namespace}/request.js`