fix: some bugs

This commit is contained in:
chenos 2022-09-26 14:52:10 +08:00
parent 47b857d80a
commit 50286e2c3c
6 changed files with 34 additions and 10 deletions

View File

@ -37,7 +37,7 @@ class PluginGenerator extends Generator {
const packageVersion = await getProjectVersion(); const packageVersion = await getProjectVersion();
return { return {
...this.context, ...this.context,
packageName: `@${packageName}/${name}`, packageName: `@${packageName}/plugin-${name}`,
packageVersion: packageVersion, packageVersion: packageVersion,
pascalCaseName: capitalize(camelize(name)), pascalCaseName: capitalize(camelize(name)),
}; };

View File

@ -1 +0,0 @@
// TODO

View File

@ -0,0 +1,5 @@
import React from 'react';
export default React.memo((props) => {
return <>{props.children}</>;
});

View File

@ -70,7 +70,7 @@ function resolveNocobasePackagesAlias(config) {
const packageSrc = resolve(process.cwd(), './packages/samples/', package, 'src'); const packageSrc = resolve(process.cwd(), './packages/samples/', package, 'src');
if (existsSync(packageSrc)) { if (existsSync(packageSrc)) {
config.module.rules.get('ts-in-node_modules').include.add(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);
} }
} }
} }

View File

@ -19,6 +19,7 @@ export default (app: Application) => {
const pm = { const pm = {
async create() { async create() {
const name = plugins[0]; const name = plugins[0];
const { run } = require('@nocobase/cli/src/util');
const { PluginGenerator } = require('@nocobase/cli/src/plugin-generator'); const { PluginGenerator } = require('@nocobase/cli/src/plugin-generator');
const generator = new PluginGenerator({ const generator = new PluginGenerator({
cwd: resolve(process.cwd(), name), cwd: resolve(process.cwd(), name),
@ -28,14 +29,33 @@ export default (app: Application) => {
}, },
}); });
await generator.run(); await generator.run();
await run('yarn', ['install']);
}, },
async add() { async add() {
if (started) { try {
const res = await axios.get(`${baseURL}pm:add/${plugins.join(',')}`); if (started) {
console.log(res.data); const res = await axios.get(`${baseURL}pm:add/${plugins.join(',')}`);
return; console.log(res.data);
} return;
await app.pm.add(plugins); }
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() { async enable() {
if (started) { if (started) {

View File

@ -20,7 +20,7 @@
"@nocobase/app-*": [ "@nocobase/app-*": [
"packages/app/*/src" "packages/app/*/src"
], ],
"@nocobase/plugin-*-sample": [ "@nocobase/plugin-sample-*": [
"packages/samples/*/src" "packages/samples/*/src"
], ],
"@nocobase/plugin-*": [ "@nocobase/plugin-*": [