From 96bf7cee77cd5987e3c94a836b6d5c291743022a Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Wed, 11 Aug 2021 22:37:21 +0800 Subject: [PATCH 1/2] refactor(core): re-org files --- packages/core/src/{init/app.ts => app/init.ts} | 6 +++--- packages/core/src/{ => env}/consts.ts | 10 +--------- packages/core/src/{init/i18n.ts => i18n/init.ts} | 0 packages/core/src/index.ts | 4 ++-- packages/core/src/middleware/koa-ui-proxy.ts | 2 +- packages/core/src/{init/oidc.ts => oidc/init.ts} | 3 ++- packages/core/src/routes/consts.ts | 8 ++++++++ packages/core/src/{init/apis.ts => routes/init.ts} | 0 8 files changed, 17 insertions(+), 16 deletions(-) rename packages/core/src/{init/app.ts => app/init.ts} (88%) rename packages/core/src/{ => env}/consts.ts (64%) rename packages/core/src/{init/i18n.ts => i18n/init.ts} (100%) rename packages/core/src/{init/oidc.ts => oidc/init.ts} (96%) create mode 100644 packages/core/src/routes/consts.ts rename packages/core/src/{init/apis.ts => routes/init.ts} (100%) diff --git a/packages/core/src/init/app.ts b/packages/core/src/app/init.ts similarity index 88% rename from packages/core/src/init/app.ts rename to packages/core/src/app/init.ts index 7b7052aec..bf97415fb 100644 --- a/packages/core/src/init/app.ts +++ b/packages/core/src/app/init.ts @@ -4,10 +4,10 @@ import Koa from 'koa'; import koaLogger from 'koa-logger'; import koaErrorHandler from '@/middleware/koa-error-handler'; -import { port } from '@/consts'; +import { port } from '@/env/consts'; import koaUIProxy from '@/middleware/koa-ui-proxy'; -import initOidc from './oidc'; -import initRouter from './apis'; +import initOidc from '@/oidc/init'; +import initRouter from '@/routes/init'; export default async function initApp(app: Koa): Promise { app.use(koaErrorHandler()); diff --git a/packages/core/src/consts.ts b/packages/core/src/env/consts.ts similarity index 64% rename from packages/core/src/consts.ts rename to packages/core/src/env/consts.ts index cf1832a0a..bcb91a874 100644 --- a/packages/core/src/consts.ts +++ b/packages/core/src/env/consts.ts @@ -1,14 +1,6 @@ import { assertEnv, getEnv } from '@/utils/env'; -const signIn = assertEnv('UI_SIGN_IN_ROUTE'); - -export const routes = Object.freeze({ - signIn: { - credentials: signIn, - consent: signIn + '/consent', - }, -}); - +export const signIn = assertEnv('UI_SIGN_IN_ROUTE'); export const isProduction = getEnv('NODE_ENV') === 'production'; export const port = Number(getEnv('PORT', '3001')); export const oidcIssuer = getEnv('OIDC_ISSUER', `http://localhost:${port}/oidc`); diff --git a/packages/core/src/init/i18n.ts b/packages/core/src/i18n/init.ts similarity index 100% rename from packages/core/src/init/i18n.ts rename to packages/core/src/i18n/init.ts diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index c258d1f43..671d33c6d 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -6,8 +6,8 @@ import dotenv from 'dotenv'; dotenv.config(); import Koa from 'koa'; -import initI18n from './init/i18n'; -import initApp from './init/app'; +import initI18n from './i18n/init'; +import initApp from './app/init'; const app = new Koa(); diff --git a/packages/core/src/middleware/koa-ui-proxy.ts b/packages/core/src/middleware/koa-ui-proxy.ts index 2af444317..c5f971b24 100644 --- a/packages/core/src/middleware/koa-ui-proxy.ts +++ b/packages/core/src/middleware/koa-ui-proxy.ts @@ -3,7 +3,7 @@ import { MiddlewareType } from 'koa'; import proxy from 'koa-proxies'; import serveStatic from 'koa-static'; import { IRouterParamContext } from 'koa-router'; -import { isProduction, mountedApps } from '@/consts'; +import { isProduction, mountedApps } from '@/env/consts'; const PATH_TO_UI_DIST = '../ui/build/public'; const uiDistFiles = fs.readdirSync(PATH_TO_UI_DIST); diff --git a/packages/core/src/init/oidc.ts b/packages/core/src/oidc/init.ts similarity index 96% rename from packages/core/src/init/oidc.ts rename to packages/core/src/oidc/init.ts index 8d966cbd4..e8b680945 100644 --- a/packages/core/src/init/oidc.ts +++ b/packages/core/src/oidc/init.ts @@ -7,7 +7,8 @@ import postgresAdapter from '@/oidc/adapter'; import { fromKeyLike } from 'jose/jwk/from_key_like'; import { getEnv } from '@/utils/env'; import { findUserById } from '@/queries/user'; -import { oidcIssuer, routes } from '@/consts'; +import { oidcIssuer } from '@/env/consts'; +import { routes } from '@/routes/consts'; export default async function initOidc(app: Koa): Promise { const privateKey = crypto.createPrivateKey( diff --git a/packages/core/src/routes/consts.ts b/packages/core/src/routes/consts.ts new file mode 100644 index 000000000..6b484dff9 --- /dev/null +++ b/packages/core/src/routes/consts.ts @@ -0,0 +1,8 @@ +import { signIn } from '@/env/consts'; + +export const routes = Object.freeze({ + signIn: { + credentials: signIn, + consent: signIn + '/consent', + }, +}); diff --git a/packages/core/src/init/apis.ts b/packages/core/src/routes/init.ts similarity index 100% rename from packages/core/src/init/apis.ts rename to packages/core/src/routes/init.ts From b6900a6551dc2cd2506027fb31bb6ea419684e17 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Thu, 12 Aug 2021 19:39:57 +0800 Subject: [PATCH 2/2] chore: remove concurrency in `prepare` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f2ed921e5..f36ae3efc 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "preinstall": "npx only-allow pnpm", "lerna": "lerna", "bootstrap": "lerna bootstrap", - "prepare": "if test \"$NODE_ENV\" != \"production\" ; then husky install && lerna run --concurrency 1 --stream prepack ; fi", + "prepare": "if test \"$NODE_ENV\" != \"production\" ; then husky install && lerna run --stream prepack ; fi", "dev": "lerna run --parallel dev" }, "devDependencies": { @@ -28,4 +28,4 @@ "node": ">=14.15.0", "pnpm": ">=6" } -} \ No newline at end of file +}