diff --git a/packages/core/cli/src/plugin-generator.js b/packages/core/cli/src/plugin-generator.js index b9d86a939..7321e09ec 100644 --- a/packages/core/cli/src/plugin-generator.js +++ b/packages/core/cli/src/plugin-generator.js @@ -37,7 +37,7 @@ class PluginGenerator extends Generator { const packageVersion = await getProjectVersion(); return { ...this.context, - packageName: `@${packageName}/${name}`, + packageName: `@${packageName}/plugin-${name}`, packageVersion: packageVersion, pascalCaseName: capitalize(camelize(name)), }; diff --git a/packages/core/cli/templates/plugin/src/client/index.ts b/packages/core/cli/templates/plugin/src/client/index.ts deleted file mode 100644 index 0ffdd02fc..000000000 --- a/packages/core/cli/templates/plugin/src/client/index.ts +++ /dev/null @@ -1 +0,0 @@ -// TODO \ No newline at end of file diff --git a/packages/core/cli/templates/plugin/src/client/index.tsx b/packages/core/cli/templates/plugin/src/client/index.tsx new file mode 100644 index 000000000..db735f78d --- /dev/null +++ b/packages/core/cli/templates/plugin/src/client/index.tsx @@ -0,0 +1,5 @@ +import React from 'react'; + +export default React.memo((props) => { + return <>{props.children}; +}); diff --git a/packages/core/devtools/umiConfig.js b/packages/core/devtools/umiConfig.js index f194917e8..9cfbcb1d7 100644 --- a/packages/core/devtools/umiConfig.js +++ b/packages/core/devtools/umiConfig.js @@ -70,7 +70,7 @@ function resolveNocobasePackagesAlias(config) { const packageSrc = resolve(process.cwd(), './packages/samples/', package, 'src'); if (existsSync(packageSrc)) { config.module.rules.get('ts-in-node_modules').include.add(packageSrc); - config.resolve.alias.set(`@nocobase/plugin-${package}-sample`, packageSrc); + config.resolve.alias.set(`@nocobase/plugin-sample-${package}`, packageSrc); } } } diff --git a/packages/core/server/src/commands/pm.ts b/packages/core/server/src/commands/pm.ts index 5a0ff3543..82e5cb8f4 100644 --- a/packages/core/server/src/commands/pm.ts +++ b/packages/core/server/src/commands/pm.ts @@ -19,6 +19,7 @@ export default (app: Application) => { const pm = { async create() { const name = plugins[0]; + const { run } = require('@nocobase/cli/src/util'); const { PluginGenerator } = require('@nocobase/cli/src/plugin-generator'); const generator = new PluginGenerator({ cwd: resolve(process.cwd(), name), @@ -28,14 +29,33 @@ export default (app: Application) => { }, }); await generator.run(); + await run('yarn', ['install']); }, async add() { - if (started) { - const res = await axios.get(`${baseURL}pm:add/${plugins.join(',')}`); - console.log(res.data); - return; - } - await app.pm.add(plugins); + try { + if (started) { + const res = await axios.get(`${baseURL}pm:add/${plugins.join(',')}`); + console.log(res.data); + return; + } + await app.pm.add(plugins); + } catch (error) {} + const fs = require('fs/promises'); + await Promise.all( + plugins.map((plugin) => { + const file = resolve( + process.cwd(), + 'packages', + process.env.APP_PACKAGE_ROOT || 'app', + 'client/src/plugins', + `${plugin}.ts`, + ); + console.log(file); + return fs.writeFile(file, `export { default } from '@nocobase/plugin-${plugin}/client';`); + }), + ); + const { run } = require('@nocobase/cli/src/util'); + await run('yarn', ['nocobase', 'postinstall']); }, async enable() { if (started) { diff --git a/tsconfig.json b/tsconfig.json index 52ad39576..6458369b3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,7 @@ "@nocobase/app-*": [ "packages/app/*/src" ], - "@nocobase/plugin-*-sample": [ + "@nocobase/plugin-sample-*": [ "packages/samples/*/src" ], "@nocobase/plugin-*": [