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();
return {
...this.context,
packageName: `@${packageName}/${name}`,
packageName: `@${packageName}/plugin-${name}`,
packageVersion: packageVersion,
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');
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);
}
}
}

View File

@ -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) {

View File

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