chore: support running multiple application processes simultaneously in development mode

This commit is contained in:
chenos 2024-11-05 10:23:40 +08:00
parent 2f1a9100a0
commit f92717e1cd
9 changed files with 28 additions and 25 deletions

View File

@ -37,6 +37,7 @@ export default defineConfig({
`,
},
],
cacheDirectoryPath: process.env.APP_CLIENT_CACHE_DIR || `node_modules/.cache`,
outputPath: path.resolve(__dirname, '../dist/client'),
hash: true,
alias: {

View File

@ -38,16 +38,16 @@ module.exports = (cli) => {
depth: 1, // 只监听第一层目录
});
await fs.promises.mkdir(path.dirname(process.env.WATCH_FILE), { recursive: true });
watcher
.on('addDir', async (pathname) => {
generatePlugins();
const file = path.resolve(process.cwd(), 'storage/app.watch.ts');
await fs.promises.writeFile(file, `export const watchId = '${uid()}';`, 'utf-8');
await fs.promises.writeFile(process.env.WATCH_FILE, `export const watchId = '${uid()}';`, 'utf-8');
})
.on('unlinkDir', async (pathname) => {
generatePlugins();
const file = path.resolve(process.cwd(), 'storage/app.watch.ts');
await fs.promises.writeFile(file, `export const watchId = '${uid()}';`, 'utf-8');
await fs.promises.writeFile(process.env.WATCH_FILE, `export const watchId = '${uid()}';`, 'utf-8');
});
promptForTs();

View File

@ -350,6 +350,7 @@ exports.initEnv = function initEnv() {
LOGGER_BASE_PATH: 'storage/logs',
APP_SERVER_BASE_URL: '',
APP_PUBLIC_PATH: '/',
WATCH_FILE: resolve(process.cwd(), 'storage/app.watch.ts'),
};
if (

View File

@ -1023,5 +1023,6 @@
"When the Label exceeds the width": "字段标题超出宽度时",
"Line break": "换行",
"Ellipsis": "省略",
"Set block layout": "设置区块布局"
"Set block layout": "设置区块布局",
"Add & Update": "添加 & 更新"
}

View File

@ -27,7 +27,7 @@ export const PluginAddModal: FC<IPluginFormProps> = ({ onClose, isShow }) => {
const [type, setType] = useState<'npm' | 'upload' | 'url'>('npm');
return (
<Modal onCancel={() => onClose()} footer={null} destroyOnClose title={t('Add & update')} width={580} open={isShow}>
<Modal onCancel={() => onClose()} footer={null} destroyOnClose title={t('Add & Update')} width={580} open={isShow}>
{/* <label style={{ fontWeight: 'bold' }}>{t('Source')}:</label> */}
<div style={{ marginTop: theme.marginLG, marginBottom: theme.marginLG }}>
<Radio.Group optionType="button" defaultValue={type} onChange={(e) => setType(e.target.value)}>

View File

@ -311,7 +311,7 @@ export class Gateway extends EventEmitter {
if (!process.env.IS_DEV_CMD) {
return;
}
const file = resolve(process.cwd(), 'storage/app.watch.ts');
const file = process.env.WATCH_FILE;
if (!fs.existsSync(file)) {
await fs.promises.writeFile(file, `export const watchId = '${uid()}';`, 'utf-8');
}

View File

@ -16,7 +16,6 @@ import { randomUUID } from 'crypto';
import fs from 'fs';
import i18next from 'i18next';
import bodyParser from 'koa-bodyparser';
import { resolve } from 'path';
import { createHistogram, RecordableHistogram } from 'perf_hooks';
import Application, { ApplicationOptions } from './application';
import { dataWrapping } from './middlewares/data-wrapping';
@ -124,8 +123,7 @@ export const getCommandFullName = (command: Command) => {
/* istanbul ignore next -- @preserve */
export const tsxRerunning = async () => {
const file = resolve(process.cwd(), 'storage/app.watch.ts');
await fs.promises.writeFile(file, `export const watchId = '${uid()}';`, 'utf-8');
await fs.promises.writeFile(process.env.WATCH_FILE, `export const watchId = '${uid()}';`, 'utf-8');
};
/* istanbul ignore next -- @preserve */

View File

@ -32,6 +32,19 @@ async function trim(packageNames: string[]) {
return names;
}
const excludes = [
'@nocobase/plugin-audit-logs',
'@nocobase/plugin-backup-restore',
'@nocobase/plugin-charts',
'@nocobase/plugin-disable-pm-add',
'@nocobase/plugin-mobile-client',
'@nocobase/plugin-mock-collections',
'@nocobase/plugin-multi-app-share-collection',
'@nocobase/plugin-notifications',
'@nocobase/plugin-snapshot-field',
'@nocobase/plugin-workflow-test',
];
export async function findPackageNames() {
const patterns = [
'./packages/plugins/*/package.json',
@ -52,23 +65,11 @@ export async function findPackageNames() {
return packageJson.name;
}),
);
const excludes = [
'@nocobase/plugin-audit-logs',
'@nocobase/plugin-backup-restore',
'@nocobase/plugin-charts',
'@nocobase/plugin-disable-pm-add',
'@nocobase/plugin-mobile-client',
'@nocobase/plugin-mock-collections',
'@nocobase/plugin-multi-app-share-collection',
'@nocobase/plugin-notifications',
'@nocobase/plugin-snapshot-field',
'@nocobase/plugin-workflow-test',
];
const nocobasePlugins = await findNocobasePlugins();
const { APPEND_PRESET_BUILT_IN_PLUGINS = '', APPEND_PRESET_LOCAL_PLUGINS = '' } = process.env;
return trim(
_.difference(packageNames, excludes)
.filter(Boolean)
packageNames
.filter((pkg) => pkg && !excludes.includes(pkg))
.concat(nocobasePlugins)
.concat(splitNames(APPEND_PRESET_BUILT_IN_PLUGINS))
.concat(splitNames(APPEND_PRESET_LOCAL_PLUGINS)),
@ -89,7 +90,7 @@ async function findNocobasePlugins() {
try {
const packageJson = await getPackageJson();
const pluginNames = Object.keys(packageJson.dependencies).filter((name) => name.startsWith('@nocobase/plugin-'));
return trim(pluginNames);
return trim(pluginNames.filter((pkg) => pkg && !excludes.includes(pkg)));
} catch (error) {
return [];
}

1
storage/.gitignore vendored
View File

@ -7,3 +7,4 @@ app-upgrading
/verdaccio/storage
libs
scripts
.cache