diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..5a29e474 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +node_modules +.next +dist +lib \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..a041f951 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,12 @@ +{ + "singleQuote": true, + "quoteProps": "consistent", + "bracketSpacing": true, + "jsxBracketSameLine": false, + "arrowParens": "always", + "trailingComma": "es5", + "tabWidth": 2, + "semi": true, + "printWidth": 100, + "endOfLine": "lf" +} \ No newline at end of file diff --git a/README.md b/README.md index dd2d51d5..049a1a22 100644 --- a/README.md +++ b/README.md @@ -89,40 +89,40 @@ pnpm run dev ```yaml # 开发环境配置 server: - prefix: "/api" + prefix: '/api' port: 5001 collaborationPort: 5003 client: - assetPrefix: "/" - apiUrl: "http://localhost:5001/api" - collaborationUrl: "ws://localhost:5003" + assetPrefix: '/' + apiUrl: 'http://localhost:5001/api' + collaborationUrl: 'ws://localhost:5003' # 数据库配置 db: mysql: - host: "127.0.0.1" - username: "root" - password: "root" - database: "think" + host: '127.0.0.1' + username: 'root' + password: 'root' + database: 'think' port: 3306 - charset: "utf8mb4" - timezone: "+08:00" + charset: 'utf8mb4' + timezone: '+08:00' synchronize: true # oss 文件存储服务 oss: aliyun: - accessKeyId: "" - accessKeySecret: "" - bucket: "" + accessKeyId: '' + accessKeySecret: '' + bucket: '' https: true - region: "" + region: '' # jwt 配置 jwt: - secretkey: "zA_Think+KNOWLEDGE+WIKI+DOCUMENTS@2022" - expiresIn: "6h" + secretkey: 'zA_Think+KNOWLEDGE+WIKI+DOCUMENTS@2022' + expiresIn: '6h' ``` ### 项目部署 diff --git a/package.json b/package.json index a7ca5d20..cab38415 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,12 @@ "start:client": "pnpm run --dir packages/client start", "pm2": "concurrently \"pnpm:pm2:*\"", "pm2:server": "pnpm run --dir packages/server pm2", - "pm2:client": "pnpm run --dir packages/client pm2" + "pm2:client": "pnpm run --dir packages/client pm2", + "lint": "eslint . -c ./.eslintrc.js --fix --quiet 'packages/**/*.{ts,tsx,js,jsx}'", + "format": "npm run format:md && npm run format:json && npm run format:source", + "format:md": "prettier --parser markdown --write './**/*.md'", + "format:json": "prettier --parser json --write './**/*.json'", + "format:source": "prettier --write './**/*.{js,ts}'" }, "dependencies": { "concurrently": "^7.0.0", @@ -31,6 +36,7 @@ "node": ">=16.5.0" }, "devDependencies": { + "prettier": "^2.3.2", "typescript": "^4.5.5" } } diff --git a/packages/client/next.config.js b/packages/client/next.config.js index 7bd9cf8b..7d04e048 100644 --- a/packages/client/next.config.js +++ b/packages/client/next.config.js @@ -1,6 +1,6 @@ -const semi = require("@douyinfe/semi-next").default({}); -const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin"); -const { getConfig } = require("@think/config"); +const semi = require('@douyinfe/semi-next').default({}); +const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); +const { getConfig } = require('@think/config'); const config = getConfig().client; /** @type {import('next').NextConfig} */ diff --git a/packages/client/src/components/tiptap/menus/components/emoji/constants.ts b/packages/client/src/components/tiptap/menus/components/emoji/constants.ts index b1ec5305..f178b3e6 100644 --- a/packages/client/src/components/tiptap/menus/components/emoji/constants.ts +++ b/packages/client/src/components/tiptap/menus/components/emoji/constants.ts @@ -1,171 +1,171 @@ export const EXPRESSIONES = [ - "😀", - "😃", - "😄", - "😁", - "😆", - "😅", - "😂", - "🤣", - "🥲", - "😊", - "😇", - "🙂", - "🙃", - "😉", - "😌", - "😍", - "🥰", - "😘", - "😗", - "😙", - "😚", - "😋", - "😛", - "😝", - "😜", - "🤪", - "🤨", - "🧐", - "🤓", - "😎", - "🥸", - "🤩", - "🥳", - "😏", - "😒", - "😞", - "😔", - "😟", - "😕", - "🙁", - "😣", - "😖", - "😫", - "😩", - "🥺", - "😢", - "😭", - "😤", - "😠", - "😡", - "🤬", - "🤯", - "😳", - "🥵", - "🥶", - "😱", - "😨", - "😰", - "😥", - "😓", - "🤗", - "🤔", - "🤭", - "🤫", - "🤥", - "😶", - "😐", - "😑", - "😬", - "🙄", - "😯", - "😦", - "😧", - "😮", - "😲", - "🥱", - "😴", - "🤤", - "😪", - "😵", - "🤐", - "🥴", - "🤢", - "🤮", - "🤧", - "😷", - "🤒", - "🤕", - "🤑", - "🤠", - "😈", - "👿", - "👹", - "👺", - "🤡", - "💩", - "👻", - "💀", - "☠️", - "👽", - "👾", - "🤖", - "🎃", - "😺", - "😸", - "😹", - "😻", - "😼", - "😽", - "🙀", - "😿", - "😾", + '😀', + '😃', + '😄', + '😁', + '😆', + '😅', + '😂', + '🤣', + '🥲', + '😊', + '😇', + '🙂', + '🙃', + '😉', + '😌', + '😍', + '🥰', + '😘', + '😗', + '😙', + '😚', + '😋', + '😛', + '😝', + '😜', + '🤪', + '🤨', + '🧐', + '🤓', + '😎', + '🥸', + '🤩', + '🥳', + '😏', + '😒', + '😞', + '😔', + '😟', + '😕', + '🙁', + '😣', + '😖', + '😫', + '😩', + '🥺', + '😢', + '😭', + '😤', + '😠', + '😡', + '🤬', + '🤯', + '😳', + '🥵', + '🥶', + '😱', + '😨', + '😰', + '😥', + '😓', + '🤗', + '🤔', + '🤭', + '🤫', + '🤥', + '😶', + '😐', + '😑', + '😬', + '🙄', + '😯', + '😦', + '😧', + '😮', + '😲', + '🥱', + '😴', + '🤤', + '😪', + '😵', + '🤐', + '🥴', + '🤢', + '🤮', + '🤧', + '😷', + '🤒', + '🤕', + '🤑', + '🤠', + '😈', + '👿', + '👹', + '👺', + '🤡', + '💩', + '👻', + '💀', + '☠️', + '👽', + '👾', + '🤖', + '🎃', + '😺', + '😸', + '😹', + '😻', + '😼', + '😽', + '🙀', + '😿', + '😾', ]; export const GESTURES = [ - "👋", - "🤚", - "🖐", - "✋", - "🖖", - "👌", - "🤌", - "🤏", - "✌️", - "🤞", - "🤟", - "🤘", - "🤙", - "👈", - "👉", - "👆", - "🖕", - "👇", - "☝️", - "👍", - "👎", - "✊", - "👊", - "🤛", - "🤜", - "👏", - "🙌", - "👐", - "🤲", - "🤝", - "🙏", - "✍️", - "💅", - "🤳", - "💪", - "🦾", - "🦵", - "🦿", - "🦶", - "👣", - "👂", - "🦻", - "👃", - "🫀", - "🫁", - "🧠", - "🦷", - "🦴", - "👀", - "👁", - "👅", - "👄", - "💋", - "🩸", + '👋', + '🤚', + '🖐', + '✋', + '🖖', + '👌', + '🤌', + '🤏', + '✌️', + '🤞', + '🤟', + '🤘', + '🤙', + '👈', + '👉', + '👆', + '🖕', + '👇', + '☝️', + '👍', + '👎', + '✊', + '👊', + '🤛', + '🤜', + '👏', + '🙌', + '👐', + '🤲', + '🤝', + '🙏', + '✍️', + '💅', + '🤳', + '💪', + '🦾', + '🦵', + '🦿', + '🦶', + '👣', + '👂', + '🦻', + '👃', + '🫀', + '🫁', + '🧠', + '🦷', + '🦴', + '👀', + '👁', + '👅', + '👄', + '💋', + '🩸', ]; diff --git a/packages/client/src/components/tiptap/provider.ts b/packages/client/src/components/tiptap/provider.ts index afaf5042..1af01843 100644 --- a/packages/client/src/components/tiptap/provider.ts +++ b/packages/client/src/components/tiptap/provider.ts @@ -1,5 +1,5 @@ -import { HocuspocusProvider } from "@hocuspocus/provider"; -import { IUser } from "@think/domains"; +import { HocuspocusProvider } from '@hocuspocus/provider'; +import { IUser } from '@think/domains'; const PROVIDER_POOL_READER = new Map(); const PROVIDER_POOL_EDITOR = new Map(); @@ -7,22 +7,21 @@ const PROVIDER_POOL_EDITOR = new Map(); export const getProvider = ({ targetId, token, - cacheType = "READER", + cacheType = 'READER', user, - docType = "document", + docType = 'document', events = {}, }: { targetId: string; token: string; - cacheType: "READER" | "EDITOR"; + cacheType: 'READER' | 'EDITOR'; user: IUser; - docType: "document" | "template"; + docType: 'document' | 'template'; events?: { onAwarenessUpdate?: (states: any) => void; }; }) => { - const pool = - cacheType === "READER" ? PROVIDER_POOL_READER : PROVIDER_POOL_EDITOR; + const pool = cacheType === 'READER' ? PROVIDER_POOL_READER : PROVIDER_POOL_EDITOR; if (!pool.has(targetId)) { const provider = new HocuspocusProvider({ @@ -43,12 +42,8 @@ export const getProvider = ({ return pool.get(targetId); }; -export const destoryProvider = ( - provider, - cacheType: "READER" | "EDITOR" = "READER" -) => { - const pool = - cacheType === "READER" ? PROVIDER_POOL_READER : PROVIDER_POOL_EDITOR; +export const destoryProvider = (provider, cacheType: 'READER' | 'EDITOR' = 'READER') => { + const pool = cacheType === 'READER' ? PROVIDER_POOL_READER : PROVIDER_POOL_EDITOR; pool.delete(provider.configuration.name); provider.document.destroy(); diff --git a/packages/client/src/components/tiptap/utils/active.ts b/packages/client/src/components/tiptap/utils/active.ts index e4e2da58..23c1a311 100644 --- a/packages/client/src/components/tiptap/utils/active.ts +++ b/packages/client/src/components/tiptap/utils/active.ts @@ -1,9 +1,7 @@ export const isListActive = (editor) => { return ( - editor.isActive("bulletList") || - editor.isActive("orderedList") || - editor.isActive("taskList") + editor.isActive('bulletList') || editor.isActive('orderedList') || editor.isActive('taskList') ); }; -export const isTitleActive = (editor) => editor.isActive("title"); +export const isTitleActive = (editor) => editor.isActive('title'); diff --git a/packages/client/src/components/tiptap/utils/download.ts b/packages/client/src/components/tiptap/utils/download.ts index 6d117377..a64eec4d 100644 --- a/packages/client/src/components/tiptap/utils/download.ts +++ b/packages/client/src/components/tiptap/utils/download.ts @@ -1,5 +1,5 @@ export function download(url, name) { - const link = document.createElement("a"); + const link = document.createElement('a'); link.download = name; link.href = url; document.body.appendChild(link); diff --git a/packages/client/src/components/tiptap/utils/node.ts b/packages/client/src/components/tiptap/utils/node.ts index 050aacdd..2d866acb 100644 --- a/packages/client/src/components/tiptap/utils/node.ts +++ b/packages/client/src/components/tiptap/utils/node.ts @@ -1,19 +1,17 @@ -import { Node } from "prosemirror-model"; +import { Node } from 'prosemirror-model'; export function isBulletListNode(node: Node): boolean { - return node.type.name === "bulletList"; + return node.type.name === 'bulletList'; } export function isOrderedListNode(node: Node): boolean { - return node.type.name === "orderedList"; + return node.type.name === 'orderedList'; } export function isTodoListNode(node: Node): boolean { - return node.type.name === "taskList"; + return node.type.name === 'taskList'; } export function isListNode(node: Node): boolean { - return ( - isBulletListNode(node) || isOrderedListNode(node) || isTodoListNode(node) - ); + return isBulletListNode(node) || isOrderedListNode(node) || isTodoListNode(node); } diff --git a/packages/client/src/components/tiptap/utils/type.ts b/packages/client/src/components/tiptap/utils/type.ts index 6ca2e8d7..a1a6be94 100644 --- a/packages/client/src/components/tiptap/utils/type.ts +++ b/packages/client/src/components/tiptap/utils/type.ts @@ -1,10 +1,7 @@ -import { NodeType, Schema } from "prosemirror-model"; +import { NodeType, Schema } from 'prosemirror-model'; -export function getNodeType( - nameOrType: string | NodeType, - schema: Schema -): NodeType { - if (typeof nameOrType === "string") { +export function getNodeType(nameOrType: string | NodeType, schema: Schema): NodeType { + if (typeof nameOrType === 'string') { if (!schema.nodes[nameOrType]) { throw Error( `There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?` diff --git a/packages/client/src/data/comment.ts b/packages/client/src/data/comment.ts index baac5248..a5209872 100644 --- a/packages/client/src/data/comment.ts +++ b/packages/client/src/data/comment.ts @@ -1,14 +1,11 @@ -import type { IComment } from "@think/domains"; -import { useState } from "react"; -import useSWR from "swr"; -import { HttpClient } from "services/HttpClient"; +import type { IComment } from '@think/domains'; +import { useState } from 'react'; +import useSWR from 'swr'; +import { HttpClient } from 'services/HttpClient'; -export type CreateCommentDto = Pick< - IComment, - "parentCommentId" | "html" | "replyUserId" ->; +export type CreateCommentDto = Pick; -export type UpdateCommentDto = Pick; +export type UpdateCommentDto = Pick; /** * 文档评论 @@ -20,9 +17,7 @@ export const useComments = (documentId) => { const { data, error, mutate } = useSWR<{ data: Array; total: number; - }>(`/comment/document/${documentId}?page=${page}`, (url) => - HttpClient.get(url) - ); + }>(`/comment/document/${documentId}?page=${page}`, (url) => HttpClient.get(url)); const loading = !data && !error; const addComment = async (data: CreateCommentDto) => { diff --git a/packages/client/src/data/document.ts b/packages/client/src/data/document.ts index 73bc3447..9fcc6b46 100644 --- a/packages/client/src/data/document.ts +++ b/packages/client/src/data/document.ts @@ -1,9 +1,9 @@ -import type { IUser, IDocument } from "@think/domains"; -import useSWR from "swr"; -import { useState, useCallback, useEffect } from "react"; -import { useAsyncLoading } from "hooks/useAsyncLoading"; -import { HttpClient } from "services/HttpClient"; -import { getPublicDocumentDetail } from "services/document"; +import type { IUser, IDocument } from '@think/domains'; +import useSWR from 'swr'; +import { useState, useCallback, useEffect } from 'react'; +import { useAsyncLoading } from 'hooks/useAsyncLoading'; +import { HttpClient } from 'services/HttpClient'; +import { getPublicDocumentDetail } from 'services/document'; interface IAuthority { id: string; @@ -13,20 +13,18 @@ interface IAuthority { editable: boolean; } -type ICreateDocument = Partial>; +type ICreateDocument = Partial>; type IDocumentWithAuth = { document: IDocument; authority: IAuthority }; -type IUpdateDocument = Partial>; +type IUpdateDocument = Partial>; /** * 创建文档 * @returns */ export const useCreateDocument = () => { - const [create, loading] = useAsyncLoading( - (data: ICreateDocument): Promise => { - return HttpClient.post("/document/create", data); - } - ); + const [create, loading] = useAsyncLoading((data: ICreateDocument): Promise => { + return HttpClient.post('/document/create', data); + }); return { create, loading }; }; @@ -36,7 +34,7 @@ export const useCreateDocument = () => { * @returns */ export const updateDocumentViews = (id: string) => { - return HttpClient.get("/document/views/" + id); + return HttpClient.get('/document/views/' + id); }; /** @@ -46,7 +44,7 @@ export const updateDocumentViews = (id: string) => { */ export const useDeleteDocument = (id) => { const [deleteDocument, loading] = useAsyncLoading((): Promise => { - return HttpClient.delete("/document/delete/" + id); + return HttpClient.delete('/document/delete/' + id); }); return { deleteDocument, loading }; }; @@ -64,15 +62,13 @@ export const useDocumentDetail = (documentId, options = null) => { ); const loading = !data && !error; const update = async (data: IUpdateDocument) => { - const res = await HttpClient.post("/document/update/" + documentId, data); + const res = await HttpClient.post('/document/update/' + documentId, data); mutate(); return res; }; - const toggleStatus = async ( - data: Partial> - ) => { - const ret = await HttpClient.post("/document/share/" + documentId, data); + const toggleStatus = async (data: Partial>) => { + const ret = await HttpClient.post('/document/share/' + documentId, data); mutate(); return ret; }; @@ -85,9 +81,8 @@ export const useDocumentDetail = (documentId, options = null) => { * @returns */ export const useRecentDocuments = () => { - const { data, error, mutate } = useSWR( - "/document/recent", - (url) => HttpClient.get(url) + const { data, error, mutate } = useSWR('/document/recent', (url) => + HttpClient.get(url) ); const loading = !data && !error; return { data, error, loading, refresh: mutate }; @@ -99,18 +94,16 @@ export const useRecentDocuments = () => { * @returns */ export const useDocumentStar = (documentId) => { - const { data, error, mutate } = useSWR( - `/collector/check/${documentId}`, - () => - HttpClient.post(`/collector/check`, { - type: "document", - targetId: documentId, - }) + const { data, error, mutate } = useSWR(`/collector/check/${documentId}`, () => + HttpClient.post(`/collector/check`, { + type: 'document', + targetId: documentId, + }) ); const toggleStar = async () => { - await HttpClient.post("/collector/toggle/", { - type: "document", + await HttpClient.post('/collector/toggle/', { + type: 'document', targetId: documentId, }); mutate(); @@ -124,9 +117,8 @@ export const useDocumentStar = (documentId) => { * @returns */ export const useStaredDocuments = () => { - const { data, error, mutate } = useSWR( - "/collector/documents", - (url) => HttpClient.post(url) + const { data, error, mutate } = useSWR('/collector/documents', (url) => + HttpClient.post(url) ); const loading = !data && !error; @@ -141,13 +133,11 @@ export const useStaredDocuments = () => { export const usePublicDocument = (documentId: string) => { const [fetch] = useAsyncLoading(getPublicDocumentDetail); const [document, setDocument] = useState(null); - const [error, setError] = useState<(Error & { statusCode?: number }) | null>( - null - ); + const [error, setError] = useState<(Error & { statusCode?: number }) | null>(null); const loading = !document && !error; const queryData = useCallback( - (sharePassword = "") => { + (sharePassword = '') => { fetch(documentId, { sharePassword }) .then((doc) => { setDocument(doc); @@ -221,16 +211,10 @@ export const useCollaborationDocument = (documentId) => { * @param isShare 访问路径 * @returns */ -export const useChildrenDocument = ({ - wikiId, - documentId, - isShare = false, -}) => { +export const useChildrenDocument = ({ wikiId, documentId, isShare = false }) => { const { data, error, mutate } = useSWR>( - isShare ? "/document/public/children" : `/document/children`, - wikiId || documentId - ? (url) => HttpClient.post(url, { wikiId, documentId, isShare }) - : null, + isShare ? '/document/public/children' : `/document/children`, + wikiId || documentId ? (url) => HttpClient.post(url, { wikiId, documentId, isShare }) : null, { shouldRetryOnError: false } ); const loading = !data && !error; diff --git a/packages/client/src/data/message.ts b/packages/client/src/data/message.ts index 4d102647..b67ae007 100644 --- a/packages/client/src/data/message.ts +++ b/packages/client/src/data/message.ts @@ -1,7 +1,7 @@ -import type { IMessage } from "@think/domains"; -import { useState } from "react"; -import useSWR from "swr"; -import { HttpClient } from "services/HttpClient"; +import type { IMessage } from '@think/domains'; +import { useState } from 'react'; +import useSWR from 'swr'; +import { HttpClient } from 'services/HttpClient'; /** * 所有消息 diff --git a/packages/client/src/data/template.ts b/packages/client/src/data/template.ts index 84f6b44d..81758ca4 100644 --- a/packages/client/src/data/template.ts +++ b/packages/client/src/data/template.ts @@ -1,7 +1,7 @@ -import type { ITemplate } from "@think/domains"; -import { useState } from "react"; -import useSWR from "swr"; -import { HttpClient } from "services/HttpClient"; +import type { ITemplate } from '@think/domains'; +import { useState } from 'react'; +import useSWR from 'swr'; +import { HttpClient } from 'services/HttpClient'; export const usePublicTemplates = () => { const [page, setPage] = useState(1); diff --git a/packages/client/src/hooks/useDocumentStyle.ts b/packages/client/src/hooks/useDocumentStyle.ts index 83c429f2..9be4d6f1 100644 --- a/packages/client/src/hooks/useDocumentStyle.ts +++ b/packages/client/src/hooks/useDocumentStyle.ts @@ -1,35 +1,31 @@ -import { useEffect } from "react"; -import useSWR from "swr"; -import { setStorage, getStorage } from "helpers/storage"; +import { useEffect } from 'react'; +import useSWR from 'swr'; +import { setStorage, getStorage } from 'helpers/storage'; export enum Width { - "standardWidth" = "standardWidth", - "fullWidth" = "fullWidth", + 'standardWidth' = 'standardWidth', + 'fullWidth' = 'fullWidth', } -const WIDTH_KEY = "document-style-width"; -const FONT_SIZE_KEY = "document-style-font-size"; +const WIDTH_KEY = 'document-style-width'; +const FONT_SIZE_KEY = 'document-style-font-size'; const DEFAULT_WIDTH = Width.standardWidth; const DEFAULT_FONT_SIZE = 16; export const useDocumentStyle = () => { - const { data, mutate } = useSWR( - `/fe/mock/${WIDTH_KEY}/${FONT_SIZE_KEY}`, - () => { - if (typeof window !== "undefined") { - return { - width: getStorage(WIDTH_KEY) || DEFAULT_WIDTH, - fontSize: - parseInt(getStorage(FONT_SIZE_KEY), 10) || DEFAULT_FONT_SIZE, - }; - } - + const { data, mutate } = useSWR(`/fe/mock/${WIDTH_KEY}/${FONT_SIZE_KEY}`, () => { + if (typeof window !== 'undefined') { return { - width: DEFAULT_WIDTH, - fontSize: DEFAULT_FONT_SIZE, + width: getStorage(WIDTH_KEY) || DEFAULT_WIDTH, + fontSize: parseInt(getStorage(FONT_SIZE_KEY), 10) || DEFAULT_FONT_SIZE, }; } - ); + + return { + width: DEFAULT_WIDTH, + fontSize: DEFAULT_FONT_SIZE, + }; + }); const setWidth = (width: Width) => { setStorage(WIDTH_KEY, width); diff --git a/packages/client/src/hooks/useDragableWidth.ts b/packages/client/src/hooks/useDragableWidth.ts index fa046fb3..6b6c98c3 100644 --- a/packages/client/src/hooks/useDragableWidth.ts +++ b/packages/client/src/hooks/useDragableWidth.ts @@ -1,9 +1,9 @@ -import { useEffect, useRef } from "react"; -import useSWR from "swr"; -import { useWindowSize } from "hooks/useWindowSize"; -import { setStorage, getStorage } from "helpers/storage"; +import { useEffect, useRef } from 'react'; +import useSWR from 'swr'; +import { useWindowSize } from 'hooks/useWindowSize'; +import { setStorage, getStorage } from 'helpers/storage'; -const key = "dragable-menu-width"; +const key = 'dragable-menu-width'; export const MIN_WIDTH = 240; export const MAX_WIDTH = 600; @@ -22,7 +22,7 @@ export const useDragableWidth = () => { }; const toggleCollapsed = (collapsed = null) => { - const isBool = typeof collapsed === "boolean"; + const isBool = typeof collapsed === 'boolean'; const nextCollapsed = isBool ? collapsed : !isCollapsed; let nextWidth = nextCollapsed ? COLLAPSED_WIDTH : MIN_WIDTH; setStorage(key, nextWidth); diff --git a/packages/client/src/services/document.ts b/packages/client/src/services/document.ts index a31a4253..6d2c5c4c 100644 --- a/packages/client/src/services/document.ts +++ b/packages/client/src/services/document.ts @@ -1,5 +1,5 @@ -import { IDocument } from "@think/domains"; -import { HttpClient } from "./HttpClient"; +import { IDocument } from '@think/domains'; +import { HttpClient } from './HttpClient'; /** * 更新文档阅读量 @@ -7,7 +7,7 @@ import { HttpClient } from "./HttpClient"; * @returns */ export const updateDocumentViews = (id: string) => { - return HttpClient.get("/document/views/" + id); + return HttpClient.get('/document/views/' + id); }; /** @@ -18,9 +18,9 @@ export const updateDocumentViews = (id: string) => { */ export const getPublicDocumentDetail = ( id: string, - data: Partial> + data: Partial> ): Promise => { - return HttpClient.post("/document/public/detail/" + id, data); + return HttpClient.post('/document/public/detail/' + id, data); }; /** @@ -29,5 +29,5 @@ export const getPublicDocumentDetail = ( * @returns */ export const searchDocument = (keyword: string): Promise => { - return HttpClient.get("/document/search", { params: { keyword } }); + return HttpClient.get('/document/search', { params: { keyword } }); }; diff --git a/packages/client/src/services/file.ts b/packages/client/src/services/file.ts index 335e5de1..4ec1c17d 100644 --- a/packages/client/src/services/file.ts +++ b/packages/client/src/services/file.ts @@ -1,18 +1,16 @@ -import { HttpClient } from "./HttpClient"; +import { HttpClient } from './HttpClient'; export const uploadFile = async (file: Blob): Promise => { if (process.env.ENABLE_ALIYUN_OSS) { - return Promise.reject( - new Error("阿里云OSS配置不完善,请自行实现上传文件!") - ); + return Promise.reject(new Error('阿里云OSS配置不完善,请自行实现上传文件!')); } const formData = new FormData(); - formData.append("file", file); + formData.append('file', file); - return HttpClient.post("/file/upload", formData, { + return HttpClient.post('/file/upload', formData, { headers: { - "Content-Type": "multipart/form-data", + 'Content-Type': 'multipart/form-data', }, }); }; diff --git a/packages/client/src/services/user.ts b/packages/client/src/services/user.ts index 4d77f801..d2bf7a0c 100644 --- a/packages/client/src/services/user.ts +++ b/packages/client/src/services/user.ts @@ -1,6 +1,6 @@ -import type { IUser } from "@think/domains"; -import { HttpClient } from "./HttpClient"; +import type { IUser } from '@think/domains'; +import { HttpClient } from './HttpClient'; export const register = (data: Partial): Promise => { - return HttpClient.post("/user/register", data); + return HttpClient.post('/user/register', data); }; diff --git a/packages/config/package.json b/packages/config/package.json index bd0e1178..d804243a 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -14,11 +14,7 @@ "scripts": { "build": "tsc --declaration" }, - "files": [ - "lib", - "src", - "yaml" - ], + "files": ["lib", "src", "yaml"], "dependencies": { "js-yaml": "^4.1.0" } diff --git a/packages/constants/package.json b/packages/constants/package.json index 02b71443..14deaaac 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -14,10 +14,7 @@ "scripts": { "build": "tsc --declaration" }, - "files": [ - "lib", - "src" - ], + "files": ["lib", "src"], "devDependencies": { "typescript": "^4.5.5" } diff --git a/packages/constants/src/index.ts b/packages/constants/src/index.ts index a5e8fbc0..2c70dd74 100644 --- a/packages/constants/src/index.ts +++ b/packages/constants/src/index.ts @@ -1,17 +1,17 @@ export const DEFAULT_WIKI_AVATAR = - "https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default0-96.png"; + 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default0-96.png'; export const WIKI_AVATARS = [ DEFAULT_WIKI_AVATAR, - "https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default2-96.png", - "https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default7-96.png", - "https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default8-96.png", - "https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default14-96.png", - "https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default21-96.png", - "https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default23-96.png", - "https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default1-96%20(1).png", - "https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default4-96.png", - "https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default12-96.png", - "https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default17-96.png", - "https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default18-96.png", + 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default2-96.png', + 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default7-96.png', + 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default8-96.png', + 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default14-96.png', + 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default21-96.png', + 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default23-96.png', + 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default1-96%20(1).png', + 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default4-96.png', + 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default12-96.png', + 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default17-96.png', + 'https://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-01/default18-96.png', ]; diff --git a/packages/domains/package.json b/packages/domains/package.json index 2b2c6e1b..abba4a0d 100644 --- a/packages/domains/package.json +++ b/packages/domains/package.json @@ -14,10 +14,7 @@ "scripts": { "build": "tsc --declaration" }, - "files": [ - "lib", - "src" - ], + "files": ["lib", "src"], "devDependencies": { "typescript": "^4.5.5" } diff --git a/packages/domains/src/index.ts b/packages/domains/src/index.ts index 93fa0482..beca895c 100644 --- a/packages/domains/src/index.ts +++ b/packages/domains/src/index.ts @@ -1,2 +1,2 @@ -export * from "./models"; -export * from "./util"; +export * from './models'; +export * from './util'; diff --git a/packages/domains/src/models/collector.ts b/packages/domains/src/models/collector.ts index 1b944072..4524d597 100644 --- a/packages/domains/src/models/collector.ts +++ b/packages/domains/src/models/collector.ts @@ -1,4 +1,4 @@ export enum CollectType { - document = "document", - wiki = "wiki", + document = 'document', + wiki = 'wiki', } diff --git a/packages/domains/src/models/comment.ts b/packages/domains/src/models/comment.ts index 87c39004..8af79bef 100644 --- a/packages/domains/src/models/comment.ts +++ b/packages/domains/src/models/comment.ts @@ -1,16 +1,16 @@ -import { IUser } from "./user"; -import { IDocument } from "./document"; +import { IUser } from './user'; +import { IDocument } from './document'; /** * 评论 */ export interface IComment { id: string; - parentCommentId?: IComment["id"]; - documentId: IDocument["id"]; - createUserId: IUser["id"]; + parentCommentId?: IComment['id']; + documentId: IDocument['id']; + createUserId: IUser['id']; createUser: IUser; - replyUserId?: IUser["id"]; + replyUserId?: IUser['id']; replyUser?: IUser; html: string; userAgent: string; diff --git a/packages/domains/src/models/document.ts b/packages/domains/src/models/document.ts index 35340acc..b4672115 100644 --- a/packages/domains/src/models/document.ts +++ b/packages/domains/src/models/document.ts @@ -1,12 +1,12 @@ -import { IUser } from "./user"; -import { IWiki } from "./wiki"; +import { IUser } from './user'; +import { IWiki } from './wiki'; /** * 文档状态枚举 */ export enum DocumentStatus { - private = "private", - public = "public", + private = 'private', + public = 'public', } /** @@ -14,11 +14,11 @@ export enum DocumentStatus { */ export interface IDocument { id: string; - wikiId: IWiki["id"]; + wikiId: IWiki['id']; isWikiHome: boolean; - createUserId: IUser["id"]; + createUserId: IUser['id']; createUser: IUser; - parentDocumentId?: IDocument["id"]; + parentDocumentId?: IDocument['id']; title: string; content: string; status: DocumentStatus; @@ -34,8 +34,8 @@ export interface IDocument { */ export interface IAuthority { id: string; - documentId: IDocument["id"]; - userId: IUser["id"]; + documentId: IDocument['id']; + userId: IUser['id']; readable: boolean; editable: boolean; } diff --git a/packages/domains/src/models/index.ts b/packages/domains/src/models/index.ts index 3a069d65..7f718fc3 100644 --- a/packages/domains/src/models/index.ts +++ b/packages/domains/src/models/index.ts @@ -1,8 +1,8 @@ -export * from "./user"; -export * from "./wiki"; -export * from "./document"; -export * from "./message"; -export * from "./template"; -export * from "./comment"; -export * from "./collector"; -export * from "./pagination"; +export * from './user'; +export * from './wiki'; +export * from './document'; +export * from './message'; +export * from './template'; +export * from './comment'; +export * from './collector'; +export * from './pagination'; diff --git a/packages/domains/src/models/message.ts b/packages/domains/src/models/message.ts index c9b012c8..ebcc1d77 100644 --- a/packages/domains/src/models/message.ts +++ b/packages/domains/src/models/message.ts @@ -1,11 +1,11 @@ -import { IUser } from "./user"; +import { IUser } from './user'; /** * 消息数据定义 */ export interface IMessage { id: string; - userId: IUser["id"]; + userId: IUser['id']; title: string; message: string; url: string; diff --git a/packages/domains/src/models/template.ts b/packages/domains/src/models/template.ts index 091f144b..0f812acf 100644 --- a/packages/domains/src/models/template.ts +++ b/packages/domains/src/models/template.ts @@ -1,11 +1,11 @@ -import { IUser } from "./user"; +import { IUser } from './user'; /** * 文档模板数据定义 */ export interface ITemplate { id: string; - createUserId: IUser["id"]; + createUserId: IUser['id']; createUser: IUser; title: string; content: string; diff --git a/packages/domains/src/models/user.ts b/packages/domains/src/models/user.ts index 4c128387..30c4995f 100644 --- a/packages/domains/src/models/user.ts +++ b/packages/domains/src/models/user.ts @@ -2,17 +2,17 @@ * 用户角色枚举 */ export enum UserRole { - normal = "normal", - admin = "admin", - superadmin = "superadmin", + normal = 'normal', + admin = 'admin', + superadmin = 'superadmin', } /** * 用户状态枚举 */ export enum UserStatus { - normal = "normal", - locked = "locked", + normal = 'normal', + locked = 'locked', } /** diff --git a/packages/domains/src/models/wiki.ts b/packages/domains/src/models/wiki.ts index d380fad1..13819cf2 100644 --- a/packages/domains/src/models/wiki.ts +++ b/packages/domains/src/models/wiki.ts @@ -1,28 +1,28 @@ -import { IUser } from "./user"; +import { IUser } from './user'; /** * 知识库状态枚举 */ export enum WikiStatus { - private = "private", - public = "public", + private = 'private', + public = 'public', } /** * 知识库成员状态枚举 */ export enum WikiUserStatus { - applying = "applying", - inviting = "inviting", - normal = "normal", + applying = 'applying', + inviting = 'inviting', + normal = 'normal', } /** * 知识库成员角色枚举 */ export enum WikiUserRole { - normal = "normal", - admin = "admin", + normal = 'normal', + admin = 'admin', } /** @@ -33,7 +33,7 @@ export interface IWiki { name: string; avatar: string; description: string; - createUserId: IUser["id"]; + createUserId: IUser['id']; createUser: IUser; status: WikiStatus; createdAt: Date; diff --git a/packages/domains/src/util.ts b/packages/domains/src/util.ts index ca2875e1..2b51d414 100644 --- a/packages/domains/src/util.ts +++ b/packages/domains/src/util.ts @@ -1,10 +1,4 @@ -import { - WikiStatus, - WikiUserRole, - DocumentStatus, - IWiki, - IDocument, -} from "./models"; +import { WikiStatus, WikiUserRole, DocumentStatus, IWiki, IDocument } from './models'; /** * 知识库状态列表数据 @@ -12,11 +6,11 @@ import { export const WIKI_STATUS_LIST = [ { value: WikiStatus.private, - label: "私有", + label: '私有', }, { value: WikiStatus.public, - label: "公开", + label: '公开', }, ]; @@ -25,12 +19,12 @@ export const WIKI_STATUS_LIST = [ */ export const WIKI_USER_ROLES = [ { - value: "admin", - label: "管理员", + value: 'admin', + label: '管理员', }, { - value: "normal", - label: "成员", + value: 'normal', + label: '成员', }, ]; @@ -40,11 +34,11 @@ export const WIKI_USER_ROLES = [ export const DOCUMENT_STATUS = [ { value: DocumentStatus.private, - label: "私有", + label: '私有', }, { value: DocumentStatus.public, - label: "公开", + label: '公开', }, ]; @@ -62,8 +56,7 @@ export const getWikiStatusText = (wiki: IWiki): string => { * @param currentStatus wiki 实例数据的 status 字段 * @returns */ -export const isPublicWiki = (currentStatus: IWiki["status"]) => - currentStatus === WikiStatus.public; +export const isPublicWiki = (currentStatus: IWiki['status']) => currentStatus === WikiStatus.public; /** * 获取知识库成员角色对应文本 @@ -79,5 +72,5 @@ export const getWikiUserRoleText = (role: WikiUserRole) => { * @param currentStatus document 实例数据的 status 字段 * @returns */ -export const isPublicDocument = (currentStatus: IDocument["status"]) => +export const isPublicDocument = (currentStatus: IDocument['status']) => currentStatus === DocumentStatus.public; diff --git a/packages/server/package.json b/packages/server/package.json index 86e26f98..c64bc57d 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -76,19 +76,13 @@ "typescript": "^4.3.5" }, "jest": { - "moduleFileExtensions": [ - "js", - "json", - "ts" - ], + "moduleFileExtensions": ["js", "json", "ts"], "rootDir": "src", "testRegex": ".*\\.spec\\.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" }, - "collectCoverageFrom": [ - "**/*.(t|j)s" - ], + "collectCoverageFrom": ["**/*.(t|j)s"], "coverageDirectory": "../coverage", "testEnvironment": "node" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ca55ecb6..4680092b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,7 @@ importers: concurrently: ^7.0.0 cross-env: ^7.0.3 fs-extra: ^10.0.0 + prettier: ^2.3.2 rimraf: ^3.0.2 typescript: ^4.5.5 dependencies: @@ -15,6 +16,7 @@ importers: fs-extra: 10.0.0 rimraf: 3.0.2 devDependencies: + prettier: 2.5.1 typescript: 4.5.5 packages/client: