feat: add api package

This commit is contained in:
chenos 2021-03-23 10:53:11 +08:00
parent e4840f9b76
commit d3fa4d3d1a
15 changed files with 64 additions and 45 deletions

View File

@ -3,11 +3,12 @@
"private": true, "private": true,
"scripts": { "scripts": {
"start": "cd packages/app && npm start", "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", "bootstrap": "lerna bootstrap --no-ci",
"build": "father-build", "build": "father-build",
"clean": "lerna clean", "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", "db:start": "docker-compose up -d",
"lint": "eslint --ext .ts,.tsx,.js \"packages/*/src/**.@(ts|tsx|js)\" --fix", "lint": "eslint --ext .ts,.tsx,.js \"packages/*/src/**.@(ts|tsx|js)\" --fix",
"test": "npm run lint && jest", "test": "npm run lint && jest",

View File

@ -0,0 +1,6 @@
{
"watch": ["src", "../"],
"ignore": ["../app"],
"ext": "ts",
"exec": "ts-node ./src/index.ts"
}

22
packages/api/package.json Normal file
View File

@ -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"
}
}

View File

@ -1,8 +1,8 @@
import Api from '../../../server/src';
import dotenv from 'dotenv';
import path from 'path'; import path from 'path';
import actions from '../../../actions/src'; import dotenv from 'dotenv';
import associated from '../../../actions/src/middlewares/associated'; import Api from '../../server/src';
import actions from '../../actions/src';
import associated from '../../actions/src/middlewares/associated';
// @ts-ignore // @ts-ignore
const sync = global.sync || { const sync = global.sync || {
@ -61,13 +61,13 @@ api.resourcer.registerActionHandlers({...actions.common, ...actions.associate});
// await next(); // await next();
// }); // });
api.registerPlugin('plugin-collections', [path.resolve(__dirname, '../../../plugin-collections'), {}]); api.registerPlugin('plugin-collections', [path.resolve(__dirname, '../../plugin-collections'), {}]);
api.registerPlugin('plugin-action-logs', [path.resolve(__dirname, '../../../plugin-action-logs'), {}]); api.registerPlugin('plugin-action-logs', [path.resolve(__dirname, '../../plugin-action-logs'), {}]);
api.registerPlugin('plugin-pages', [path.resolve(__dirname, '../../../plugin-pages'), {}]); api.registerPlugin('plugin-pages', [path.resolve(__dirname, '../../plugin-pages'), {}]);
api.registerPlugin('plugin-users', [path.resolve(__dirname, '../../../plugin-users'), {}]); api.registerPlugin('plugin-users', [path.resolve(__dirname, '../../plugin-users'), {}]);
api.registerPlugin('plugin-file-manager', [path.resolve(__dirname, '../../../plugin-file-manager'), {}]); api.registerPlugin('plugin-file-manager', [path.resolve(__dirname, '../../plugin-file-manager'), {}]);
api.registerPlugin('plugin-permissions', [path.resolve(__dirname, '../../../plugin-permissions'), {}]); api.registerPlugin('plugin-permissions', [path.resolve(__dirname, '../../plugin-permissions'), {}]);
api.registerPlugin('plugin-automations', [path.resolve(__dirname, '../../../plugin-automations'), {}]); api.registerPlugin('plugin-automations', [path.resolve(__dirname, '../../plugin-automations'), {}]);
api.registerPlugin('plugin-china-region', [path.resolve(__dirname, '../../../plugin-china-region'), {}]); api.registerPlugin('plugin-china-region', [path.resolve(__dirname, '../../plugin-china-region'), {}]);
export default api; export default api;

View File

@ -1,5 +1,5 @@
import api from './app'; import api from './app';
import actions from '../../../actions/src'; import actions from '../../actions/src';
api.resourcer.use(async (ctx: actions.Context, next) => { api.resourcer.use(async (ctx: actions.Context, next) => {
const { actionName, resourceField, resourceName, fields = {} } = ctx.action.params; const { actionName, resourceField, resourceName, fields = {} } = ctx.action.params;

View File

@ -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}`);

View File

@ -1,5 +1,6 @@
{ {
"watch": ["src/api", ".env", "../"], "watch": ["../"],
"ignore": ["../app"],
"ext": "ts", "ext": "ts",
"exec": "ts-node ./src/api/index.ts" "exec": "ts-node ../api/src/index.ts"
} }

View File

@ -1,11 +1,8 @@
{ {
"name": "@nocobase/app", "name": "@nocobase/app",
"version": "0.4.0-alpha.0", "version": "0.4.0-alpha.0",
"private": true,
"scripts": { "scripts": {
"start": "concurrently \"nodemon\" \"umi dev\"", "start": "concurrently \"nodemon\" \"umi dev\"",
"start-api": "nodemon",
"db-migrate": "ts-node ./src/api/migrate.ts",
"build": "umi build", "build": "umi build",
"postinstall": "umi generate tmp", "postinstall": "umi generate tmp",
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'", "prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
@ -26,13 +23,6 @@
"dependencies": { "dependencies": {
"@ant-design/pro-layout": "^5.0.12", "@ant-design/pro-layout": "^5.0.12",
"@formily/antd-components": "^1.3.6", "@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", "@types/react-big-calendar": "^0.24.8",
"@umijs/preset-react": "1.x", "@umijs/preset-react": "1.x",
"@umijs/test": "^3.2.23", "@umijs/test": "^3.2.23",

View File

@ -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}`);

View File

@ -45,10 +45,7 @@ export async function getInitialState() {
const { data: systemSettings = {} } = await umiRequest('/system_settings:get?fields[appends]=logo,logo.storage', { const { data: systemSettings = {} } = await umiRequest('/system_settings:get?fields[appends]=logo,logo.storage', {
method: 'get', method: 'get',
}); });
let redirect = ''; let redirect = `?redirect=${pathname}${search}`;
// if (href.includes('?')) {
redirect = `?redirect=${pathname}${search}`;
// }
if (!pathnames.includes(pathname)) { if (!pathnames.includes(pathname)) {
try { try {