feat: improve code
This commit is contained in:
parent
27f6bde775
commit
9d67ecaff0
@ -636,13 +636,6 @@ app.plugin(function pluginName1() {
|
||||
|
||||
```ts
|
||||
const plugin = app.plugin({
|
||||
async install() {},
|
||||
async upgrade() {},
|
||||
async activate() {},
|
||||
async bootstrap() {},
|
||||
async deactivate() {},
|
||||
async unstall() {},
|
||||
}, {
|
||||
enable: false, // 默认为 true,不需要启用时可以禁用。
|
||||
name: 'plugin-name1',
|
||||
displayName: '插件名称',
|
||||
@ -651,6 +644,12 @@ const plugin = app.plugin({
|
||||
pluginName2: '1.x',
|
||||
pluginName3: '1.x',
|
||||
},
|
||||
async install() {},
|
||||
async upgrade() {},
|
||||
async activate() {},
|
||||
async bootstrap() {},
|
||||
async deactivate() {},
|
||||
async unstall() {},
|
||||
});
|
||||
// 通过 api 激活插件
|
||||
plugin.activate();
|
||||
@ -668,7 +667,9 @@ class MyPlugin extends Plugin {
|
||||
async unstall() {}
|
||||
}
|
||||
|
||||
app.plugin(MyPlugin, {
|
||||
app.plugin(MyPlugin);
|
||||
// 或
|
||||
app.plugin({
|
||||
name: 'plugin-name1',
|
||||
displayName: '插件名称',
|
||||
version: '1.2.3',
|
||||
@ -676,6 +677,7 @@ app.plugin(MyPlugin, {
|
||||
pluginName2: '1.x',
|
||||
pluginName3: '1.x',
|
||||
},
|
||||
plugin: MyPlugin,
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
"bootstrap": "lerna bootstrap",
|
||||
"clean": "lerna clean",
|
||||
"examples": "ts-node-dev -r dotenv/config ./examples",
|
||||
"start": "cd packages/app && npm start",
|
||||
"start": "concurrently \"npm run start-server\" \"npm run start-client\"",
|
||||
"start-client": "cd packages/app && npm run start-client",
|
||||
"start-server": "ts-node-dev -r dotenv/config ./packages/api/src/index.ts",
|
||||
"start-docs": "dumi dev",
|
||||
@ -16,7 +16,6 @@
|
||||
"build2": "lerna run build",
|
||||
"build": "npm run build-father-build && node packages/father-build/bin/father-build.js",
|
||||
"build-father-build": "cd packages/father-build && npm run build",
|
||||
"db-migrate": "ts-node -r dotenv/config ./packages/api/src/migrate.ts",
|
||||
"lint": "eslint --ext .ts,.tsx,.js \"packages/*/src/**.@(ts|tsx|js)\" --fix",
|
||||
"test": "npm run lint && jest"
|
||||
},
|
||||
@ -39,6 +38,7 @@
|
||||
"@typescript-eslint/parser": "^4.8.2",
|
||||
"@umijs/plugin-antd": "^0.9.1",
|
||||
"antd": "^4.16.11",
|
||||
"concurrently": "^6.2.1",
|
||||
"dotenv": "^8.2.0",
|
||||
"dumi": "^1.1.25",
|
||||
"eslint": "^7.4.0",
|
||||
@ -63,6 +63,7 @@
|
||||
"supertest": "^6.1.3",
|
||||
"ts-jest": "^26.5.6",
|
||||
"ts-node": "^9.1.1",
|
||||
"ts-node-dev": "^1.1.8",
|
||||
"typescript": "4.1.5"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
import Server from '@nocobase/server';
|
||||
|
||||
const start = Date.now();
|
||||
|
||||
const api = new Server({
|
||||
database: {
|
||||
username: process.env.DB_USER,
|
||||
@ -49,17 +51,13 @@ for (const plugin of plugins) {
|
||||
api.plugin(require(`${plugin}/${__filename.endsWith('.ts') ? 'src' : 'lib'}/server`).default);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const start = Date.now();
|
||||
if (process.argv.length < 3) {
|
||||
// @ts-ignore
|
||||
process.argv.push('start', '--port', process.env.API_PORT);
|
||||
}
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
process.argv.push('start', '--port', process.env.API_PORT);
|
||||
}
|
||||
console.log(process.argv);
|
||||
|
||||
console.log(process.argv);
|
||||
|
||||
await api.parse(process.argv);
|
||||
console.log(api.db.getTables().map(t => t.getName()));
|
||||
api.parse(process.argv).then(() => {
|
||||
console.log(`Start-up time: ${(Date.now() - start) / 1000}s`);
|
||||
// console.log(`http://localhost:${process.env.API_PORT}/`);
|
||||
})();
|
||||
});
|
||||
|
@ -2,7 +2,7 @@
|
||||
"name": "@nocobase/app",
|
||||
"version": "0.4.0-alpha.7",
|
||||
"scripts": {
|
||||
"start": "concurrently \"cd ../../ && nodemon\" \"umi dev\"",
|
||||
"start": "concurrently \"cd ../../ && npm run start-server\" \"umi dev\"",
|
||||
"start-client": "umi dev",
|
||||
"start-server": "nodemon",
|
||||
"build": "npm run build-server && npm run build-client",
|
||||
|
@ -1,15 +1,6 @@
|
||||
import Server from '@nocobase/server';
|
||||
import { registerActions } from '@nocobase/actions';
|
||||
import dotenv from 'dotenv';
|
||||
import path from 'path';
|
||||
import mount from 'koa-mount';
|
||||
|
||||
const start = Date.now();
|
||||
console.log('starting... ', new Date().toUTCString());
|
||||
|
||||
dotenv.config({
|
||||
path: path.resolve(__dirname, '../../../../.env'),
|
||||
});
|
||||
|
||||
const api = new Server({
|
||||
database: {
|
||||
@ -41,24 +32,32 @@ const api = new Server({
|
||||
resourcer: {
|
||||
prefix: '/api',
|
||||
},
|
||||
dataWrapping: true,
|
||||
});
|
||||
|
||||
registerActions(api);
|
||||
const plugins = [
|
||||
'@nocobase/plugin-collections',
|
||||
'@nocobase/plugin-ui-router',
|
||||
'@nocobase/plugin-ui-schema',
|
||||
'@nocobase/plugin-users',
|
||||
'@nocobase/plugin-action-logs',
|
||||
'@nocobase/plugin-file-manager',
|
||||
'@nocobase/plugin-permissions',
|
||||
'@nocobase/plugin-export',
|
||||
'@nocobase/plugin-system-settings',
|
||||
'@nocobase/plugin-china-region',
|
||||
];
|
||||
|
||||
const file = `${__filename.endsWith('.ts') ? 'src' : 'lib'}/index`;
|
||||
|
||||
api.registerPlugin(
|
||||
'@nocobase/preset-nocobase',
|
||||
require(`@nocobase/preset-nocobase/${file}`).default,
|
||||
);
|
||||
for (const plugin of plugins) {
|
||||
api.plugin(require(`${plugin}/${__filename.endsWith('.ts') ? 'src' : 'lib'}/server`).default);
|
||||
}
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
process.argv.push('start', '--port', '2000');
|
||||
// @ts-ignore
|
||||
process.argv.push('start', '--port', process.env.API_PORT);
|
||||
}
|
||||
|
||||
console.log(process.argv);
|
||||
|
||||
api.start(process.argv).then(() => {
|
||||
api.parse(process.argv).then(() => {
|
||||
console.log(`Start-up time: ${(Date.now() - start) / 1000}s`);
|
||||
});
|
||||
|
@ -21,13 +21,13 @@ export default {
|
||||
type: 'string',
|
||||
name: 'collection_name',
|
||||
},
|
||||
// {
|
||||
// type: 'belongsTo',
|
||||
// name: 'collection',
|
||||
// target: 'collections',
|
||||
// targetKey: 'name',
|
||||
// constraints: false,
|
||||
// },
|
||||
{
|
||||
type: 'belongsTo',
|
||||
name: 'collection',
|
||||
target: 'collections',
|
||||
targetKey: 'name',
|
||||
constraints: false,
|
||||
},
|
||||
{
|
||||
type: 'string',
|
||||
name: 'type',
|
||||
|
4
packages/plugin-client/.gitignore
vendored
Normal file
4
packages/plugin-client/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
node_modules
|
||||
yarn-error.log
|
||||
.env
|
||||
src2
|
7
packages/plugin-client/.npmignore
Normal file
7
packages/plugin-client/.npmignore
Normal file
@ -0,0 +1,7 @@
|
||||
node_modules
|
||||
*.log
|
||||
docs
|
||||
__tests__
|
||||
tsconfig.json
|
||||
src
|
||||
.fatherrc.ts
|
17
packages/plugin-client/package.json
Normal file
17
packages/plugin-client/package.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@nocobase/plugin-client",
|
||||
"version": "0.4.0-alpha.7",
|
||||
"main": "lib/index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@nocobase/database": "^0.4.0-alpha.7",
|
||||
"@nocobase/resourcer": "^0.4.0-alpha.7",
|
||||
"@nocobase/server": "^0.4.0-alpha.7",
|
||||
"deepmerge": "^4.2.2",
|
||||
"flat-to-nested": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nocobase/actions": "^0.4.0-alpha.7"
|
||||
},
|
||||
"gitHead": "f0b335ac30f29f25c95d7d137655fa64d8d67f1e"
|
||||
}
|
0
packages/plugin-client/src/index.ts
Normal file
0
packages/plugin-client/src/index.ts
Normal file
0
packages/plugin-client/src/server.ts
Normal file
0
packages/plugin-client/src/server.ts
Normal file
@ -82,10 +82,6 @@ export default {
|
||||
// ui_schema_key: uiSchemaKey,
|
||||
});
|
||||
}
|
||||
// if (model.get('ui_schema_key')) {
|
||||
// collection.set('ui_schema_key', model.get('ui_schema_key'));
|
||||
// await collection.save({ hooks: false });
|
||||
// }
|
||||
await collection.migrate();
|
||||
} catch (error) {
|
||||
throw error;
|
||||
|
17
packages/plugin-saas/package.json
Normal file
17
packages/plugin-saas/package.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@nocobase/plugin-saas",
|
||||
"version": "0.4.0-alpha.7",
|
||||
"main": "lib/index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@nocobase/database": "^0.4.0-alpha.7",
|
||||
"@nocobase/resourcer": "^0.4.0-alpha.7",
|
||||
"@nocobase/server": "^0.4.0-alpha.7",
|
||||
"deepmerge": "^4.2.2",
|
||||
"flat-to-nested": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nocobase/actions": "^0.4.0-alpha.7"
|
||||
},
|
||||
"gitHead": "f0b335ac30f29f25c95d7d137655fa64d8d67f1e"
|
||||
}
|
0
packages/plugin-saas/src/index.ts
Normal file
0
packages/plugin-saas/src/index.ts
Normal file
69
yarn.lock
69
yarn.lock
@ -6374,6 +6374,15 @@ cliui@^6.0.0:
|
||||
strip-ansi "^6.0.0"
|
||||
wrap-ansi "^6.2.0"
|
||||
|
||||
cliui@^7.0.2:
|
||||
version "7.0.4"
|
||||
resolved "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f"
|
||||
integrity sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==
|
||||
dependencies:
|
||||
string-width "^4.2.0"
|
||||
strip-ansi "^6.0.0"
|
||||
wrap-ansi "^7.0.0"
|
||||
|
||||
clone-buffer@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.npmjs.org/clone-buffer/-/clone-buffer-1.0.0.tgz#e3e25b207ac4e701af721e2cb5a16792cac3dc58"
|
||||
@ -6651,6 +6660,21 @@ concurrently@^5.3.0:
|
||||
tree-kill "^1.2.2"
|
||||
yargs "^13.3.0"
|
||||
|
||||
concurrently@^6.2.1:
|
||||
version "6.2.1"
|
||||
resolved "https://registry.npmjs.org/concurrently/-/concurrently-6.2.1.tgz#d880fc1d77559084732fa514092a3d5109a0d5bf"
|
||||
integrity sha512-emgwhH+ezkuYKSHZQ+AkgEpoUZZlbpPVYCVv7YZx0r+T7fny1H03r2nYRebpi2DudHR4n1Rgbo2YTxKOxVJ4+g==
|
||||
dependencies:
|
||||
chalk "^4.1.0"
|
||||
date-fns "^2.16.1"
|
||||
lodash "^4.17.21"
|
||||
read-pkg "^5.2.0"
|
||||
rxjs "^6.6.3"
|
||||
spawn-command "^0.0.2-1"
|
||||
supports-color "^8.1.0"
|
||||
tree-kill "^1.2.2"
|
||||
yargs "^16.2.0"
|
||||
|
||||
config-chain@^1.1.11:
|
||||
version "1.1.13"
|
||||
resolved "https://registry.npmjs.org/config-chain/-/config-chain-1.1.13.tgz#fad0795aa6a6cdaff9ed1b68e9dff94372c232f4"
|
||||
@ -7405,6 +7429,11 @@ date-fns@2.x, date-fns@^2.0.1:
|
||||
resolved "https://registry.npmjs.org/date-fns/-/date-fns-2.23.0.tgz#4e886c941659af0cf7b30fafdd1eaa37e88788a9"
|
||||
integrity sha512-5ycpauovVyAk0kXNZz6ZoB9AYMZB4DObse7P3BPWmyEjXNORTI8EJ6X0uaSAq4sCHzM1uajzrkr6HnsLQpxGXA==
|
||||
|
||||
date-fns@^2.16.1:
|
||||
version "2.24.0"
|
||||
resolved "https://registry.npmjs.org/date-fns/-/date-fns-2.24.0.tgz#7d86dc0d93c87b76b63d213b4413337cfd1c105d"
|
||||
integrity sha512-6ujwvwgPID6zbI0o7UbURi2vlLDR9uP26+tW6Lg+Ji3w7dd0i3DOcjcClLjLPranT60SSEFBwdSyYwn/ZkPIuw==
|
||||
|
||||
dateformat@^2.0.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.npmjs.org/dateformat/-/dateformat-2.2.0.tgz#4065e2013cf9fb916ddfd82efb506ad4c6769062"
|
||||
@ -9248,7 +9277,7 @@ gensync@^1.0.0-beta.1, gensync@^1.0.0-beta.2:
|
||||
resolved "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0"
|
||||
integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==
|
||||
|
||||
get-caller-file@^2.0.1:
|
||||
get-caller-file@^2.0.1, get-caller-file@^2.0.5:
|
||||
version "2.0.5"
|
||||
resolved "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
|
||||
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==
|
||||
@ -17520,7 +17549,7 @@ run-queue@^1.0.0, run-queue@^1.0.3:
|
||||
dependencies:
|
||||
aproba "^1.1.1"
|
||||
|
||||
rxjs@^6.4.0, rxjs@^6.5.2:
|
||||
rxjs@^6.4.0, rxjs@^6.5.2, rxjs@^6.6.3:
|
||||
version "6.6.7"
|
||||
resolved "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz#90ac018acabf491bf65044235d5863c4dab804c9"
|
||||
integrity sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==
|
||||
@ -18581,6 +18610,13 @@ supports-color@^7.0.0, supports-color@^7.1.0:
|
||||
dependencies:
|
||||
has-flag "^4.0.0"
|
||||
|
||||
supports-color@^8.1.0:
|
||||
version "8.1.1"
|
||||
resolved "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c"
|
||||
integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==
|
||||
dependencies:
|
||||
has-flag "^4.0.0"
|
||||
|
||||
supports-hyperlinks@^2.0.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-2.2.0.tgz#4f77b42488765891774b70c79babd87f9bd594bb"
|
||||
@ -20197,6 +20233,15 @@ wrap-ansi@^6.2.0:
|
||||
string-width "^4.1.0"
|
||||
strip-ansi "^6.0.0"
|
||||
|
||||
wrap-ansi@^7.0.0:
|
||||
version "7.0.0"
|
||||
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
|
||||
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
|
||||
dependencies:
|
||||
ansi-styles "^4.0.0"
|
||||
string-width "^4.1.0"
|
||||
strip-ansi "^6.0.0"
|
||||
|
||||
wrappy@1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
|
||||
@ -20350,6 +20395,11 @@ y18n@^4.0.0:
|
||||
resolved "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz#b5f259c82cd6e336921efd7bfd8bf560de9eeedf"
|
||||
integrity sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==
|
||||
|
||||
y18n@^5.0.5:
|
||||
version "5.0.8"
|
||||
resolved "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
|
||||
integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==
|
||||
|
||||
yallist@^2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
|
||||
@ -20394,7 +20444,7 @@ yargs-parser@13.1.2, yargs-parser@^13.1.2:
|
||||
camelcase "^5.0.0"
|
||||
decamelize "^1.2.0"
|
||||
|
||||
yargs-parser@20.x, yargs-parser@^20.2.3:
|
||||
yargs-parser@20.x, yargs-parser@^20.2.2, yargs-parser@^20.2.3:
|
||||
version "20.2.9"
|
||||
resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee"
|
||||
integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==
|
||||
@ -20465,6 +20515,19 @@ yargs@^15.4.1:
|
||||
y18n "^4.0.0"
|
||||
yargs-parser "^18.1.2"
|
||||
|
||||
yargs@^16.2.0:
|
||||
version "16.2.0"
|
||||
resolved "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66"
|
||||
integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==
|
||||
dependencies:
|
||||
cliui "^7.0.2"
|
||||
escalade "^3.1.1"
|
||||
get-caller-file "^2.0.5"
|
||||
require-directory "^2.1.1"
|
||||
string-width "^4.2.0"
|
||||
y18n "^5.0.5"
|
||||
yargs-parser "^20.2.2"
|
||||
|
||||
yargs@~3.10.0:
|
||||
version "3.10.0"
|
||||
resolved "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1"
|
||||
|
Loading…
Reference in New Issue
Block a user