diff --git a/package.json b/package.json index 28bc184..f6652c0 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,13 @@ "scripts": { "dev": "concurrently --kill-others npm:dev:server npm:dev:web", "dev:web": "cd src/client && pnpm dev", - "dev:server": "cd src/server && pnpm dev", + "dev:server": "pnpm run dev --filer ./src/server", "start": "cross-env NODE_ENV=production node ./dist/src/server/main.js", "start:docker": "pnpm db:migrate:apply && pnpm db:generate && pnpm start", "test": "vitest", "build": "pnpm build:tracker && pnpm build:server && pnpm build:client && pnpm build:geo", "build:client": "cd src/client && pnpm build", - "build:server": "cd src/server && pnpm build", + "build:server": "pnpm run build --filer ./src/server", "build:tracker": "ts-node scripts/build-tracker.ts", "build:geo": "ts-node scripts/build-geo.ts", "build:openapi": "ts-node scripts/build-openapi-schema.ts", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c1bef50..44af3e9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + overrides: dayjs: 1.11.10 @@ -65,6 +69,9 @@ importers: '@tanstack/react-query': specifier: 4.33.0 version: 4.33.0(react-dom@18.2.0)(react@18.2.0) + '@tianji/shared': + specifier: workspace:^ + version: link:../shared '@trpc/client': specifier: ^10.45.0 version: 10.45.0(@trpc/server@10.45.0) @@ -195,6 +202,9 @@ importers: '@prisma/client': specifier: 5.4.2 version: 5.4.2(prisma@5.4.2) + '@tianji/shared': + specifier: workspace:^ + version: link:../shared '@trpc/server': specifier: ^10.45.0 version: 10.45.0 @@ -389,6 +399,12 @@ importers: specifier: ^1.2.1 version: 1.2.1(@types/node@18.17.12) + src/shared: + dependencies: + dayjs: + specifier: 1.11.10 + version: 1.11.10 + website: dependencies: '@docusaurus/core': @@ -16788,7 +16804,7 @@ packages: engines: {node: '>=8.x'} peerDependencies: date-fns: '>= 2.x' - dayjs: '>= 1.x' + dayjs: 1.11.10 luxon: '>= 3.x' moment: '>= 2.x' react: '>=16.9.0' @@ -16817,7 +16833,7 @@ packages: engines: {node: '>=8.x'} peerDependencies: date-fns: '>= 2.x' - dayjs: '>= 1.x' + dayjs: 1.11.10 luxon: '>= 3.x' moment: '>= 2.x' react: '>=16.9.0' diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 03a8519..a353506 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,4 +1,5 @@ packages: - 'src/client' - 'src/server' + - 'src/shared' - 'website' diff --git a/src/client/components/monitor/StatusPage/useAllowEdit.ts b/src/client/components/monitor/StatusPage/useAllowEdit.ts index 9ecc725..9d87294 100644 --- a/src/client/components/monitor/StatusPage/useAllowEdit.ts +++ b/src/client/components/monitor/StatusPage/useAllowEdit.ts @@ -1,4 +1,4 @@ -import { ROLES } from '../../../../shared'; +import { ROLES } from '@tianji/shared'; import { trpc } from '../../../api/trpc'; import { useUserInfo } from '../../../store/user'; diff --git a/src/client/hooks/useGlobalRangeDate.tsx b/src/client/hooks/useGlobalRangeDate.tsx index 5c0109d..bb1c195 100644 --- a/src/client/hooks/useGlobalRangeDate.tsx +++ b/src/client/hooks/useGlobalRangeDate.tsx @@ -1,7 +1,7 @@ import { CalendarOutlined } from '@ant-design/icons'; import dayjs, { Dayjs } from 'dayjs'; import { useMemo, useReducer } from 'react'; -import { getMinimumUnit } from '../../shared'; +import { getMinimumUnit } from '@tianji/shared'; import { DateRange, useGlobalStateStore } from '../store/global'; import { DateUnit } from '../utils/date'; diff --git a/src/client/package.json b/src/client/package.json index 1ebffaa..67107fd 100644 --- a/src/client/package.json +++ b/src/client/package.json @@ -17,6 +17,7 @@ "@loadable/component": "^5.16.3", "@monaco-editor/react": "^4.6.0", "@tanstack/react-query": "4.33.0", + "@tianji/shared": "workspace:^", "@trpc/client": "^10.45.0", "@trpc/react-query": "^10.45.0", "antd": "^5.13.1", diff --git a/src/client/pages/Layout.tsx b/src/client/pages/Layout.tsx index ad5dfdf..8f6634d 100644 --- a/src/client/pages/Layout.tsx +++ b/src/client/pages/Layout.tsx @@ -3,11 +3,11 @@ import { Outlet, useSearchParams } from 'react-router-dom'; import { NavItem } from '../components/NavItem'; import { MobileNavItem } from '../components/MobileNavItem'; import { UserOutlined } from '@ant-design/icons'; -import { Button, Divider, Drawer, Dropdown, Menu } from 'antd'; +import { Button, Divider, Drawer, Dropdown } from 'antd'; import { useUserStore } from '../store/user'; import { useLogout } from '../api/model/user'; import { ColorSchemeSwitcher } from '../components/ColorSchemeSwitcher'; -import { version } from '../../shared'; +import { version } from '@tianji/shared'; import { useIsMobile } from '../hooks/useIsMobile'; import { RiMenuUnfoldLine } from 'react-icons/ri'; diff --git a/src/client/pages/Servers.tsx b/src/client/pages/Servers.tsx index d0b0497..75ad35a 100644 --- a/src/client/pages/Servers.tsx +++ b/src/client/pages/Servers.tsx @@ -28,7 +28,7 @@ import { Loading } from '../components/Loading'; import { without } from 'lodash-es'; import { useIntervalUpdate } from '../hooks/useIntervalUpdate'; import clsx from 'clsx'; -import { isServerOnline } from '../../shared'; +import { isServerOnline } from '@tianji/shared'; import { defaultErrorHandler, trpc } from '../api/trpc'; import { useRequest } from '../hooks/useRequest'; diff --git a/src/client/utils/date.ts b/src/client/utils/date.ts index 66a5e97..a10777d 100644 --- a/src/client/utils/date.ts +++ b/src/client/utils/date.ts @@ -2,7 +2,7 @@ import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; import timezone from 'dayjs/plugin/timezone'; import advancedFormat from 'dayjs/plugin/advancedFormat'; -import type { DateUnit } from '../../shared'; +import type { DateUnit } from '@tianji/shared'; dayjs.extend(utc); dayjs.extend(timezone); diff --git a/src/client/utils/validator.ts b/src/client/utils/validator.ts index 895b034..e676f9c 100644 --- a/src/client/utils/validator.ts +++ b/src/client/utils/validator.ts @@ -1,6 +1,6 @@ import { RuleObject } from 'antd/es/form'; import { z } from 'zod'; -import { hostnameRegex, slugRegex } from '../../shared'; +import { hostnameRegex, slugRegex } from '@tianji/shared'; type Validator = ( rule: RuleObject, diff --git a/src/server/middleware/workspace.ts b/src/server/middleware/workspace.ts index 547ea85..a8b8a94 100644 --- a/src/server/middleware/workspace.ts +++ b/src/server/middleware/workspace.ts @@ -1,6 +1,6 @@ import { Handler } from 'express'; import { getWorkspaceUser } from '../model/workspace'; -import { ROLES } from '../../shared'; +import { ROLES } from '@tianji/shared'; export function workspacePermission(roles: ROLES[] = []): Handler { return async (req, res, next) => { diff --git a/src/server/model/serverStatus.ts b/src/server/model/serverStatus.ts index 02b0782..d63aa54 100644 --- a/src/server/model/serverStatus.ts +++ b/src/server/model/serverStatus.ts @@ -2,7 +2,7 @@ import dayjs from 'dayjs'; import { ServerStatusInfo } from '../../types'; import { createSubscribeInitializer, subscribeEventBus } from '../ws/shared'; import _ from 'lodash'; -import { isServerOnline } from '../../shared'; +import { isServerOnline } from '@tianji/shared'; const serverMap: Record< string, // workspaceId diff --git a/src/server/model/user.ts b/src/server/model/user.ts index 9b96c18..7bb0155 100644 --- a/src/server/model/user.ts +++ b/src/server/model/user.ts @@ -1,6 +1,6 @@ import { prisma } from './_client'; import bcryptjs from 'bcryptjs'; -import { ROLES, SYSTEM_ROLES } from '../../shared'; +import { ROLES, SYSTEM_ROLES } from '@tianji/shared'; import { jwtVerify } from '../middleware/auth'; import { TRPCError } from '@trpc/server'; import { Prisma } from '@prisma/client'; diff --git a/src/server/package.json b/src/server/package.json index 9bfb1a5..89b2bd0 100644 --- a/src/server/package.json +++ b/src/server/package.json @@ -1,6 +1,7 @@ { "name": "@tianji/server", "version": "1.0.0", + "private": true, "description": "", "main": "index.js", "scripts": { @@ -18,6 +19,7 @@ "dependencies": { "@paralleldrive/cuid2": "^2.2.2", "@prisma/client": "5.4.2", + "@tianji/shared": "workspace:^", "@trpc/server": "^10.45.0", "axios": "^1.5.0", "badge-maker": "^3.3.1", diff --git a/src/server/router/health.ts b/src/server/router/health.ts index efb6059..19f3053 100644 --- a/src/server/router/health.ts +++ b/src/server/router/health.ts @@ -1,5 +1,5 @@ import { Router } from 'express'; -import { version } from '../../shared'; +import { version } from '@tianji/shared'; export const healthRouter = Router(); diff --git a/src/server/router/website.ts b/src/server/router/website.ts index a8921e1..f2103a1 100644 --- a/src/server/router/website.ts +++ b/src/server/router/website.ts @@ -8,7 +8,7 @@ import { saveWebsiteSessionData, } from '../model/website'; import { createToken } from '../utils/common'; -import { hostnameRegex } from '../../shared'; +import { hostnameRegex } from '@tianji/shared'; export const websiteRouter = Router(); diff --git a/src/server/router/workspace.ts b/src/server/router/workspace.ts index 47d4a72..3a3727b 100644 --- a/src/server/router/workspace.ts +++ b/src/server/router/workspace.ts @@ -13,7 +13,7 @@ import { } from '../model/workspace'; import { parseDateRange } from '../utils/common'; import { QueryFilters } from '../utils/prisma'; -import { ROLES } from '../../shared'; +import { ROLES } from '@tianji/shared'; export const workspaceRouter = Router(); diff --git a/src/server/trpc/routers/website.ts b/src/server/trpc/routers/website.ts index d17acd0..e7e6f9b 100644 --- a/src/server/trpc/routers/website.ts +++ b/src/server/trpc/routers/website.ts @@ -17,7 +17,7 @@ import { parseDateRange } from '../../utils/common'; import { getSessionMetrics, getPageviewMetrics } from '../../model/website'; import { websiteInfoSchema } from '../../model/_schema'; import { OpenApiMeta } from 'trpc-openapi'; -import { hostnameRegex } from '../../../shared'; +import { hostnameRegex } from '@tianji/shared'; import { addWorkspaceWebsite } from '../../model/workspace'; const websiteNameSchema = z.string().max(100); diff --git a/src/server/trpc/trpc.ts b/src/server/trpc/trpc.ts index f009d60..5426b76 100644 --- a/src/server/trpc/trpc.ts +++ b/src/server/trpc/trpc.ts @@ -3,7 +3,7 @@ import _ from 'lodash'; import { z } from 'zod'; import { jwtVerify } from '../middleware/auth'; import { getWorkspaceUser } from '../model/workspace'; -import { ROLES, SYSTEM_ROLES } from '../../shared'; +import { ROLES, SYSTEM_ROLES } from '@tianji/shared'; import type { IncomingMessage } from 'http'; import { OpenApiMeta } from 'trpc-openapi'; diff --git a/src/server/tsconfig.server.json b/src/server/tsconfig.server.json index 6f4f868..09c6714 100644 --- a/src/server/tsconfig.server.json +++ b/src/server/tsconfig.server.json @@ -1,6 +1,6 @@ { "extends": "../../tsconfig.json", - "include": ["./**/*.ts", "../shared/**/*.ts", "../types/**/*.ts"], + "include": ["./**/*.ts", "../types/**/*.ts"], "exclude": ["node_modules/**/*", "dist"], "compilerOptions": { "rootDirs": ["./", "../"], diff --git a/src/server/utils/common.ts b/src/server/utils/common.ts index b800255..39c9bce 100644 --- a/src/server/utils/common.ts +++ b/src/server/utils/common.ts @@ -8,7 +8,7 @@ import jwt from 'jsonwebtoken'; import _ from 'lodash'; import { getWorkspaceWebsiteDateRange } from '../model/workspace'; import { isCuid } from '@paralleldrive/cuid2'; -import { getMinimumUnit } from '../../shared'; +import { getMinimumUnit } from '@tianji/shared'; export { isCuid }; diff --git a/src/server/utils/screenshot/website.ts b/src/server/utils/screenshot/website.ts index cddb102..0b4e7e3 100644 --- a/src/server/utils/screenshot/website.ts +++ b/src/server/utils/screenshot/website.ts @@ -1,6 +1,6 @@ import puppeteer from 'puppeteer'; import { jwtSign } from '../../middleware/auth'; -import { SYSTEM_ROLES } from '../../../shared'; +import { SYSTEM_ROLES } from '@tianji/shared'; import { env } from '../env'; /** diff --git a/src/shared/package.json b/src/shared/package.json new file mode 100644 index 0000000..0dd334e --- /dev/null +++ b/src/shared/package.json @@ -0,0 +1,13 @@ +{ + "name": "@tianji/shared", + "version": "1.0.0", + "private": true, + "description": "", + "main": "index.ts", + "scripts": {}, + "keywords": [], + "author": "moonrailgun ", + "dependencies": { + "dayjs": "^1.11.9" + } +}