From d3fa4d3d1a41ef83d13c618e63b4fc3947c97d66 Mon Sep 17 00:00:00 2001 From: chenos Date: Tue, 23 Mar 2021 10:53:11 +0800 Subject: [PATCH] feat: add api package --- package.json | 5 ++-- packages/api/nodemon.json | 6 +++++ packages/api/package.json | 22 +++++++++++++++++ packages/{app/src/api => api/src}/app.ts | 24 +++++++++---------- packages/{app/src/api => api/src}/index.ts | 2 +- packages/api/src/migrate.ts | 16 +++++++++++++ .../src}/migrations/collections/authors.ts | 0 .../src}/migrations/collections/books.ts | 0 .../src}/migrations/collections/example.ts | 0 .../src/api => api/src}/migrations/init.ts | 0 .../src/api => api/src}/migrations/sync.ts | 0 packages/app/nodemon.json | 5 ++-- packages/app/package.json | 10 -------- packages/app/src/api/migrate.ts | 14 ----------- packages/app/src/app.ts | 5 +--- 15 files changed, 64 insertions(+), 45 deletions(-) create mode 100644 packages/api/nodemon.json create mode 100644 packages/api/package.json rename packages/{app/src/api => api/src}/app.ts (81%) rename packages/{app/src/api => api/src}/index.ts (98%) create mode 100644 packages/api/src/migrate.ts rename packages/{app/src/api => api/src}/migrations/collections/authors.ts (100%) rename packages/{app/src/api => api/src}/migrations/collections/books.ts (100%) rename packages/{app/src/api => api/src}/migrations/collections/example.ts (100%) rename packages/{app/src/api => api/src}/migrations/init.ts (100%) rename packages/{app/src/api => api/src}/migrations/sync.ts (100%) delete mode 100644 packages/app/src/api/migrate.ts diff --git a/package.json b/package.json index 633548794..24b35ff76 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,12 @@ "private": true, "scripts": { "start": "cd packages/app && npm start", - "start-server": "cd packages/app && nodemon", + "start-server": "cd packages/api && nodemon", + "start-client": "cd packages/app && umi dev", "bootstrap": "lerna bootstrap --no-ci", "build": "father-build", "clean": "lerna clean", - "db-migrate": "cd packages/app && npm run db-migrate", + "db-migrate": "cd packages/api && npm run db-migrate", "db:start": "docker-compose up -d", "lint": "eslint --ext .ts,.tsx,.js \"packages/*/src/**.@(ts|tsx|js)\" --fix", "test": "npm run lint && jest", diff --git a/packages/api/nodemon.json b/packages/api/nodemon.json new file mode 100644 index 000000000..afc01b317 --- /dev/null +++ b/packages/api/nodemon.json @@ -0,0 +1,6 @@ +{ + "watch": ["src", "../"], + "ignore": ["../app"], + "ext": "ts", + "exec": "ts-node ./src/index.ts" +} \ No newline at end of file diff --git a/packages/api/package.json b/packages/api/package.json new file mode 100644 index 000000000..f911560e0 --- /dev/null +++ b/packages/api/package.json @@ -0,0 +1,22 @@ +{ + "name": "@nocobase/api", + "version": "0.4.0-alpha.0", + "scripts": { + "start": "nodemon", + "db-migrate": "ts-node ./src/migrate.ts" + }, + "dependencies": { + "@nocobase/actions": "^0.4.0-alpha.0", + "@nocobase/client": "^0.4.0-alpha.0", + "@nocobase/database": "^0.4.0-alpha.0", + "@nocobase/plugin-action-logs": "^0.4.0-alpha.0", + "@nocobase/plugin-china-region": "^0.4.0-alpha.0", + "@nocobase/plugin-collections": "^0.4.0-alpha.0", + "@nocobase/plugin-pages": "^0.4.0-alpha.0", + "@nocobase/server": "^0.4.0-alpha.0" + }, + "devDependencies": { + "nodemon": "^2.0.6", + "typescript": "^3.9.6" + } +} diff --git a/packages/app/src/api/app.ts b/packages/api/src/app.ts similarity index 81% rename from packages/app/src/api/app.ts rename to packages/api/src/app.ts index 129e09954..e6885764b 100644 --- a/packages/app/src/api/app.ts +++ b/packages/api/src/app.ts @@ -1,8 +1,8 @@ -import Api from '../../../server/src'; -import dotenv from 'dotenv'; import path from 'path'; -import actions from '../../../actions/src'; -import associated from '../../../actions/src/middlewares/associated'; +import dotenv from 'dotenv'; +import Api from '../../server/src'; +import actions from '../../actions/src'; +import associated from '../../actions/src/middlewares/associated'; // @ts-ignore const sync = global.sync || { @@ -61,13 +61,13 @@ api.resourcer.registerActionHandlers({...actions.common, ...actions.associate}); // await next(); // }); -api.registerPlugin('plugin-collections', [path.resolve(__dirname, '../../../plugin-collections'), {}]); -api.registerPlugin('plugin-action-logs', [path.resolve(__dirname, '../../../plugin-action-logs'), {}]); -api.registerPlugin('plugin-pages', [path.resolve(__dirname, '../../../plugin-pages'), {}]); -api.registerPlugin('plugin-users', [path.resolve(__dirname, '../../../plugin-users'), {}]); -api.registerPlugin('plugin-file-manager', [path.resolve(__dirname, '../../../plugin-file-manager'), {}]); -api.registerPlugin('plugin-permissions', [path.resolve(__dirname, '../../../plugin-permissions'), {}]); -api.registerPlugin('plugin-automations', [path.resolve(__dirname, '../../../plugin-automations'), {}]); -api.registerPlugin('plugin-china-region', [path.resolve(__dirname, '../../../plugin-china-region'), {}]); +api.registerPlugin('plugin-collections', [path.resolve(__dirname, '../../plugin-collections'), {}]); +api.registerPlugin('plugin-action-logs', [path.resolve(__dirname, '../../plugin-action-logs'), {}]); +api.registerPlugin('plugin-pages', [path.resolve(__dirname, '../../plugin-pages'), {}]); +api.registerPlugin('plugin-users', [path.resolve(__dirname, '../../plugin-users'), {}]); +api.registerPlugin('plugin-file-manager', [path.resolve(__dirname, '../../plugin-file-manager'), {}]); +api.registerPlugin('plugin-permissions', [path.resolve(__dirname, '../../plugin-permissions'), {}]); +api.registerPlugin('plugin-automations', [path.resolve(__dirname, '../../plugin-automations'), {}]); +api.registerPlugin('plugin-china-region', [path.resolve(__dirname, '../../plugin-china-region'), {}]); export default api; diff --git a/packages/app/src/api/index.ts b/packages/api/src/index.ts similarity index 98% rename from packages/app/src/api/index.ts rename to packages/api/src/index.ts index 8a65e1e94..d5eeba46b 100644 --- a/packages/app/src/api/index.ts +++ b/packages/api/src/index.ts @@ -1,5 +1,5 @@ import api from './app'; -import actions from '../../../actions/src'; +import actions from '../../actions/src'; api.resourcer.use(async (ctx: actions.Context, next) => { const { actionName, resourceField, resourceName, fields = {} } = ctx.action.params; diff --git a/packages/api/src/migrate.ts b/packages/api/src/migrate.ts new file mode 100644 index 000000000..5711e6c0d --- /dev/null +++ b/packages/api/src/migrate.ts @@ -0,0 +1,16 @@ + +// @ts-ignore +const keys = process.argv; + +// @ts-ignore +global.sync = { + force: false, + alter: { + drop: false, + }, +}; + +// @ts-ignore +const filename: string = keys.pop(); + +require(`./migrations/${filename}`); diff --git a/packages/app/src/api/migrations/collections/authors.ts b/packages/api/src/migrations/collections/authors.ts similarity index 100% rename from packages/app/src/api/migrations/collections/authors.ts rename to packages/api/src/migrations/collections/authors.ts diff --git a/packages/app/src/api/migrations/collections/books.ts b/packages/api/src/migrations/collections/books.ts similarity index 100% rename from packages/app/src/api/migrations/collections/books.ts rename to packages/api/src/migrations/collections/books.ts diff --git a/packages/app/src/api/migrations/collections/example.ts b/packages/api/src/migrations/collections/example.ts similarity index 100% rename from packages/app/src/api/migrations/collections/example.ts rename to packages/api/src/migrations/collections/example.ts diff --git a/packages/app/src/api/migrations/init.ts b/packages/api/src/migrations/init.ts similarity index 100% rename from packages/app/src/api/migrations/init.ts rename to packages/api/src/migrations/init.ts diff --git a/packages/app/src/api/migrations/sync.ts b/packages/api/src/migrations/sync.ts similarity index 100% rename from packages/app/src/api/migrations/sync.ts rename to packages/api/src/migrations/sync.ts diff --git a/packages/app/nodemon.json b/packages/app/nodemon.json index 67624595a..2c0d27e2a 100644 --- a/packages/app/nodemon.json +++ b/packages/app/nodemon.json @@ -1,5 +1,6 @@ { - "watch": ["src/api", ".env", "../"], + "watch": ["../"], + "ignore": ["../app"], "ext": "ts", - "exec": "ts-node ./src/api/index.ts" + "exec": "ts-node ../api/src/index.ts" } \ No newline at end of file diff --git a/packages/app/package.json b/packages/app/package.json index b9dec4ed6..8f65f9697 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -1,11 +1,8 @@ { "name": "@nocobase/app", "version": "0.4.0-alpha.0", - "private": true, "scripts": { "start": "concurrently \"nodemon\" \"umi dev\"", - "start-api": "nodemon", - "db-migrate": "ts-node ./src/api/migrate.ts", "build": "umi build", "postinstall": "umi generate tmp", "prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'", @@ -26,13 +23,6 @@ "dependencies": { "@ant-design/pro-layout": "^5.0.12", "@formily/antd-components": "^1.3.6", - "@nocobase/client": "^0.4.0-alpha.0", - "@nocobase/database": "^0.4.0-alpha.0", - "@nocobase/plugin-action-logs": "^0.4.0-alpha.0", - "@nocobase/plugin-china-region": "^0.4.0-alpha.0", - "@nocobase/plugin-collections": "^0.4.0-alpha.0", - "@nocobase/plugin-pages": "^0.4.0-alpha.0", - "@nocobase/server": "^0.4.0-alpha.0", "@types/react-big-calendar": "^0.24.8", "@umijs/preset-react": "1.x", "@umijs/test": "^3.2.23", diff --git a/packages/app/src/api/migrate.ts b/packages/app/src/api/migrate.ts deleted file mode 100644 index 0d63500ad..000000000 --- a/packages/app/src/api/migrate.ts +++ /dev/null @@ -1,14 +0,0 @@ - -const args = process.argv; - -// @ts-ignore -global.sync = { - force: false, - alter: { - drop: false, - }, -}; - -const fileName: string = args.pop(); - -require(`./migrations/${fileName}`); diff --git a/packages/app/src/app.ts b/packages/app/src/app.ts index b74656eba..cacd2ef1b 100644 --- a/packages/app/src/app.ts +++ b/packages/app/src/app.ts @@ -45,10 +45,7 @@ export async function getInitialState() { const { data: systemSettings = {} } = await umiRequest('/system_settings:get?fields[appends]=logo,logo.storage', { method: 'get', }); - let redirect = ''; - // if (href.includes('?')) { - redirect = `?redirect=${pathname}${search}`; - // } + let redirect = `?redirect=${pathname}${search}`; if (!pathnames.includes(pathname)) { try {