refactor: add shared packacage
This commit is contained in:
parent
d2171ce2b3
commit
39550ece83
@ -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",
|
||||
|
@ -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'
|
||||
|
@ -1,4 +1,5 @@
|
||||
packages:
|
||||
- 'src/client'
|
||||
- 'src/server'
|
||||
- 'src/shared'
|
||||
- 'website'
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { ROLES } from '../../../../shared';
|
||||
import { ROLES } from '@tianji/shared';
|
||||
import { trpc } from '../../../api/trpc';
|
||||
import { useUserInfo } from '../../../store/user';
|
||||
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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) => {
|
||||
|
@ -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
|
||||
|
@ -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';
|
||||
|
@ -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",
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Router } from 'express';
|
||||
import { version } from '../../shared';
|
||||
import { version } from '@tianji/shared';
|
||||
|
||||
export const healthRouter = Router();
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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';
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["./**/*.ts", "../shared/**/*.ts", "../types/**/*.ts"],
|
||||
"include": ["./**/*.ts", "../types/**/*.ts"],
|
||||
"exclude": ["node_modules/**/*", "dist"],
|
||||
"compilerOptions": {
|
||||
"rootDirs": ["./", "../"],
|
||||
|
@ -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 };
|
||||
|
||||
|
@ -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';
|
||||
|
||||
/**
|
||||
|
13
src/shared/package.json
Normal file
13
src/shared/package.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "@tianji/shared",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "",
|
||||
"main": "index.ts",
|
||||
"scripts": {},
|
||||
"keywords": [],
|
||||
"author": "moonrailgun <moonrailgun@gmail.com>",
|
||||
"dependencies": {
|
||||
"dayjs": "^1.11.9"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user