From b818b4726a9000f81fce98ba3e3a9dd21c079bfc Mon Sep 17 00:00:00 2001 From: terwer Date: Tue, 16 May 2023 01:40:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=8F=91=E5=B8=83=20?= =?UTF-8?q?SDK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.env.development.local.example | 1 + libs/publisher-sdk/.eslintrc.cjs | 4 + libs/publisher-sdk/.gitignore | 2 + libs/publisher-sdk/.prettierignore | 11 +++ libs/publisher-sdk/.prettierrc.cjs | 30 ++++++++ libs/publisher-sdk/README.md | 41 +++++++++++ libs/publisher-sdk/index.html | 12 +++ libs/publisher-sdk/package.json | 34 +++++++++ libs/publisher-sdk/src/index.spec.ts | 7 ++ libs/publisher-sdk/src/index.ts | 5 ++ libs/publisher-sdk/tsconfig.json | 42 +++++++++++ libs/publisher-sdk/tsconfig.node.json | 10 +++ libs/publisher-sdk/vite.config.ts | 33 +++++++++ plugins/publisher-main/package.json | 3 +- plugins/publisher-main/src/index.ts | 9 ++- pnpm-lock.yaml | 73 +++++++++++++++++-- 16 files changed, 306 insertions(+), 11 deletions(-) create mode 100644 libs/publisher-sdk/.env.development.local.example create mode 100644 libs/publisher-sdk/.eslintrc.cjs create mode 100644 libs/publisher-sdk/.gitignore create mode 100644 libs/publisher-sdk/.prettierignore create mode 100644 libs/publisher-sdk/.prettierrc.cjs create mode 100644 libs/publisher-sdk/README.md create mode 100644 libs/publisher-sdk/index.html create mode 100644 libs/publisher-sdk/package.json create mode 100644 libs/publisher-sdk/src/index.spec.ts create mode 100644 libs/publisher-sdk/src/index.ts create mode 100644 libs/publisher-sdk/tsconfig.json create mode 100644 libs/publisher-sdk/tsconfig.node.json create mode 100644 libs/publisher-sdk/vite.config.ts diff --git a/libs/publisher-sdk/.env.development.local.example b/libs/publisher-sdk/.env.development.local.example new file mode 100644 index 00000000..04f0ca42 --- /dev/null +++ b/libs/publisher-sdk/.env.development.local.example @@ -0,0 +1 @@ +VITE_DEBUG_MODE=true diff --git a/libs/publisher-sdk/.eslintrc.cjs b/libs/publisher-sdk/.eslintrc.cjs new file mode 100644 index 00000000..a1993b7b --- /dev/null +++ b/libs/publisher-sdk/.eslintrc.cjs @@ -0,0 +1,4 @@ +module.exports = { + root: true, + extends: ["./node_modules/@terwer/eslint-config-custom/typescript/index.cjs"], +} diff --git a/libs/publisher-sdk/.gitignore b/libs/publisher-sdk/.gitignore new file mode 100644 index 00000000..1f1025f2 --- /dev/null +++ b/libs/publisher-sdk/.gitignore @@ -0,0 +1,2 @@ +.idea +.DS_Store \ No newline at end of file diff --git a/libs/publisher-sdk/.prettierignore b/libs/publisher-sdk/.prettierignore new file mode 100644 index 00000000..8f9d2dfa --- /dev/null +++ b/libs/publisher-sdk/.prettierignore @@ -0,0 +1,11 @@ +# platform + +# Ignore artifacts: +dist +node_modules + +# Ignore all dts files: +*.d.ts + +# lib +/pnpm-lock.yaml diff --git a/libs/publisher-sdk/.prettierrc.cjs b/libs/publisher-sdk/.prettierrc.cjs new file mode 100644 index 00000000..eec8622f --- /dev/null +++ b/libs/publisher-sdk/.prettierrc.cjs @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023, Terwer . All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Terwer designates this + * particular file as subject to the "Classpath" exception as provided + * by Terwer in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com + * or visit www.terwer.space if you need additional information or have any + * questions. + */ + +module.exports = { + semi: false, + singleQuote: false, + printWidth: 120 +} diff --git a/libs/publisher-sdk/README.md b/libs/publisher-sdk/README.md new file mode 100644 index 00000000..e25f1f17 --- /dev/null +++ b/libs/publisher-sdk/README.md @@ -0,0 +1,41 @@ +# publisher-sdk + +a common sdk for publishing post to every platform + +## Usage + +```js +// usage +``` + +## Deps + +``` +## Congregations! publisher-sdk need no deps, it is just pure js code 🎉 +``` + +## Dev + +```bash +pnpm dev -F publisher-sdk +``` + +## Build + +```bash +pnpm build -F publisher-sdk +``` + +## Test + +Execute the unit tests via [vitest](https://vitest.dev) + +```bash +pnpm test -F publisher-sdk +``` + +## Publish + +```bash +pnpm publish -F publisher-sdk --tag latest +``` \ No newline at end of file diff --git a/libs/publisher-sdk/index.html b/libs/publisher-sdk/index.html new file mode 100644 index 00000000..9ecb5ed8 --- /dev/null +++ b/libs/publisher-sdk/index.html @@ -0,0 +1,12 @@ + + + + + + Vite + Vue + TS + + + This file is for lib hot-load test only, see /src/index.ts + + + diff --git a/libs/publisher-sdk/package.json b/libs/publisher-sdk/package.json new file mode 100644 index 00000000..c8316a5d --- /dev/null +++ b/libs/publisher-sdk/package.json @@ -0,0 +1,34 @@ +{ + "name": "@terwer/publisher-sdk", + "version": "0.0.1", + "type": "module", + "description": "a common sdk for publishing post to every platform", + "main": "./dist/index.js", + "typings": "./dist/index.d.ts", + "repository": "terwer/siyuan-plugin-publisher", + "homepage": "https://github.com/terwer/siyuan-plugin-publisher/tree/main/libs/publisher-sdk", + "author": "terwer", + "license": "GPL", + "files": [ + "dist", + "README.md" + ], + "keywords": [ + "zhi", + "lib" + ], + "scripts": { + "serve": "vite", + "dev": "vite build --watch", + "build": "vite build", + "start": "vite preview", + "test": "vitest --watch" + }, + "devDependencies": { + "@terwer/eslint-config-custom": "^1.2.0", + "@terwer/vite-config-custom": "^0.2.0" + }, + "dependencies": { + "zhi-siyuan-api": "^1.1.1" + } +} diff --git a/libs/publisher-sdk/src/index.spec.ts b/libs/publisher-sdk/src/index.spec.ts new file mode 100644 index 00000000..ec837a46 --- /dev/null +++ b/libs/publisher-sdk/src/index.spec.ts @@ -0,0 +1,7 @@ +import { describe, it } from "vitest" + +describe("index", () => { + it("test index", () => { + console.log("hello") + }) +}) diff --git a/libs/publisher-sdk/src/index.ts b/libs/publisher-sdk/src/index.ts new file mode 100644 index 00000000..a8d0db98 --- /dev/null +++ b/libs/publisher-sdk/src/index.ts @@ -0,0 +1,5 @@ +const init = () => { + return "ok" +} + +export default init diff --git a/libs/publisher-sdk/tsconfig.json b/libs/publisher-sdk/tsconfig.json new file mode 100644 index 00000000..08cfe0c6 --- /dev/null +++ b/libs/publisher-sdk/tsconfig.json @@ -0,0 +1,42 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": [ + "ES2020", + "DOM", + "DOM.Iterable" + ], + "skipLibCheck": true, + /* Bundler mode */ + "moduleResolution": "Node", + // "allowImportingTsExtensions": true, + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "preserve", + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "types": [ + "node", + "vite/client" + ] + }, + "include": [ + "src/**/*.ts", + "src/**/*.d.ts", + "src/**/*.tsx", + "src/**/*.vue" + ], + "references": [ + { + "path": "./tsconfig.node.json" + } + ], + "root": "." +} diff --git a/libs/publisher-sdk/tsconfig.node.json b/libs/publisher-sdk/tsconfig.node.json new file mode 100644 index 00000000..7065ca9a --- /dev/null +++ b/libs/publisher-sdk/tsconfig.node.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "Node", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/libs/publisher-sdk/vite.config.ts b/libs/publisher-sdk/vite.config.ts new file mode 100644 index 00000000..5b50f096 --- /dev/null +++ b/libs/publisher-sdk/vite.config.ts @@ -0,0 +1,33 @@ +/// + +import { resolve } from "path" +import { defineConfig } from "vite" +import dts from "vite-plugin-dts" + +export default defineConfig({ + plugins: [dts()], + + build: { + lib: { + // Could also be a dictionary or array of multiple entry points + entry: resolve(__dirname, "src/index.ts"), + // the proper extensions will be added + fileName: "index", + formats: ["es"], + }, + rollupOptions: { + // make sure to externalize deps that shouldn't be bundled + // into your library + external: [], + output: { + entryFileNames: "[name].js", + }, + }, + }, + + test: { + globals: true, + environment: "jsdom", + include: ["src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"], + }, +}) diff --git a/plugins/publisher-main/package.json b/plugins/publisher-main/package.json index 603c482e..e7250672 100644 --- a/plugins/publisher-main/package.json +++ b/plugins/publisher-main/package.json @@ -21,7 +21,6 @@ "svelte-routing": "^1.8.8" }, "dependencies": { - "zhi-device": "^0.5.0", - "zhi-log": "^1.13.0" + "@terwer/publisher-sdk": "workspace:*" } } \ No newline at end of file diff --git a/plugins/publisher-main/src/index.ts b/plugins/publisher-main/src/index.ts index da8aa15f..0e09f1b5 100644 --- a/plugins/publisher-main/src/index.ts +++ b/plugins/publisher-main/src/index.ts @@ -7,6 +7,7 @@ import PageUtil from "./utils/pageUtil" import Constants from "./utils/constants" import iconPublish from "./utils/svg" import HtmlUtils from "./utils/htmlUtils" +import { SiyuanKernelApi } from "zhi-siyuan-api" const STORAGE_NAME = "menu-config" @@ -17,6 +18,8 @@ export default class PublishTool extends Plugin { private env: Env = new Env(process.env) private logger: DefaultLogger = new CustomLogFactory(undefined, "publish-tool", this.env).getLogger("main") + private kernelApi: SiyuanKernelApi = new SiyuanKernelApi(this.env) + // lifecycle public onload() { this._addTopBar() @@ -170,7 +173,11 @@ export default class PublishTool extends Plugin { label: this.i18n.copyPageId, click: async () => { await HtmlUtils.copyToClipboard(pageId) - this.logger.info("当前文档ID已复制", pageId) + this.kernelApi.pushMsg({ + msg: `当前文档ID已复制=>${pageId}`, + timeout: 3000, + }) + // this.logger.info("当前文档ID已复制", pageId) }, }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 359d2c22..721303ac 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -98,6 +98,19 @@ importers: specifier: ^0.2.0 version: registry.npmjs.org/@terwer/vite-config-custom@0.2.0(jsdom@22.0.0)(tslib@2.5.0)(typescript@5.0.4)(vite-plugin-css-injected-by-js@3.1.1)(vite-plugin-dts@2.3.0)(vite-plugin-static-copy@0.15.0)(vite-tsconfig-paths@4.2.0)(vite@4.3.5)(vitest@0.31.0) + libs/publisher-sdk: + dependencies: + zhi-siyuan-api: + specifier: ^1.1.1 + version: registry.npmjs.org/zhi-siyuan-api@1.1.1 + devDependencies: + '@terwer/eslint-config-custom': + specifier: ^1.2.0 + version: registry.npmjs.org/@terwer/eslint-config-custom@1.2.0(@nuxt/eslint-config@0.1.1)(@typescript-eslint/eslint-plugin@5.59.5)(astro-eslint-parser@0.13.3)(eslint-config-prettier@8.8.0)(eslint-config-turbo@1.9.4)(eslint-plugin-prettier@4.2.1)(eslint-plugin-svelte@2.28.0)(eslint-plugin-vue@9.12.0)(eslint@8.40.0)(prettier-plugin-svelte@2.10.0)(prettier@2.8.8)(typescript@5.0.4) + '@terwer/vite-config-custom': + specifier: ^0.2.0 + version: registry.npmjs.org/@terwer/vite-config-custom@0.2.0(jsdom@22.0.0)(tslib@2.5.0)(typescript@5.0.4)(vite-plugin-css-injected-by-js@3.1.1)(vite-plugin-dts@2.3.0)(vite-plugin-static-copy@0.15.0)(vite-tsconfig-paths@4.2.0)(vite@4.3.5)(vitest@0.31.0) + libs/siyuan-hook: dependencies: '@terwer/publisher-hook': @@ -113,12 +126,9 @@ importers: plugins/publisher-main: dependencies: - zhi-device: - specifier: ^0.5.0 - version: registry.npmjs.org/zhi-device@0.5.0 - zhi-log: - specifier: ^1.13.0 - version: registry.npmjs.org/zhi-log@1.13.0 + '@terwer/publisher-sdk': + specifier: workspace:* + version: link:../../libs/publisher-sdk devDependencies: '@sveltejs/vite-plugin-svelte': specifier: ^2.0.3 @@ -6287,8 +6297,6 @@ packages: version: 9.5.0 engines: {node: ^12.20.0 || >=14} requiresBuild: true - dev: true - optional: true registry.npmjs.org/commitizen@4.3.0: resolution: {integrity: sha512-H0iNtClNEhT0fotHvGV3E9tDejDeS04sN1veIebsKYGMuGscFaswRoYJKmT3eW85eIJAs0F28bG2+a/9wCOfPw==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/commitizen/-/commitizen-4.3.0.tgz} @@ -6331,6 +6339,12 @@ packages: dot-prop: registry.npmjs.org/dot-prop@5.3.0 dev: true + registry.npmjs.org/compare-versions@5.0.3: + resolution: {integrity: sha512-4UZlZP8Z99MGEY+Ovg/uJxJuvoXuN4M6B3hKaiackiHrgzQFEe3diJi1mf1PNHbFujM7FvLrK2bpgIaImbtZ1A==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/compare-versions/-/compare-versions-5.0.3.tgz} + name: compare-versions + version: 5.0.3 + dev: false + registry.npmjs.org/compress-commons@4.1.1: resolution: {integrity: sha512-QLdDLCKNV2dtoTorqgxngQCMA+gWXkM/Nwu7FpeBhk/RdkzimqC3jueb/FDmaZeXh+uby1jkBqE3xArsLBE5wQ==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/compress-commons/-/compress-commons-4.1.1.tgz} name: compress-commons @@ -12991,6 +13005,15 @@ packages: vscode-textmate: registry.npmjs.org/vscode-textmate@8.0.0 dev: true + registry.npmjs.org/showdown@2.1.0: + resolution: {integrity: sha512-/6NVYu4U819R2pUIk79n67SYgJHWCce0a5xTP979WbNp0FL9MN1I1QK662IDU1b6JzKTvmhgI7T7JYIxBi3kMQ==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/showdown/-/showdown-2.1.0.tgz} + name: showdown + version: 2.1.0 + hasBin: true + dependencies: + commander: registry.npmjs.org/commander@9.5.0 + dev: false + registry.npmjs.org/side-channel@1.0.4: resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz} name: side-channel @@ -15308,6 +15331,29 @@ packages: commander: registry.npmjs.org/commander@9.5.0 dev: true + registry.npmjs.org/zhi-blog-api@1.1.0: + resolution: {integrity: sha512-n66lw94Fx/DHzdfX8FYz3uk++PFfTm65lnf9JpP3nkDU/UNpPZImteClREtsdg9fq2yRK/wnBUYERrkLfwAu2g==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/zhi-blog-api/-/zhi-blog-api-1.1.0.tgz} + name: zhi-blog-api + version: 1.1.0 + dependencies: + zhi-common: registry.npmjs.org/zhi-common@1.5.2 + zhi-env: registry.npmjs.org/zhi-env@1.17.0 + zhi-log: registry.npmjs.org/zhi-log@1.13.0 + dev: false + + registry.npmjs.org/zhi-common@1.5.2: + resolution: {integrity: sha512-AbypXF7USpGGYl3zIjqm4W50gRlbkx3VV4UB5d72pvl+uFZQLWbAct/M9v8btTxEtndwDpBnAsyvIWhnvIrScA==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/zhi-common/-/zhi-common-1.5.2.tgz} + name: zhi-common + version: 1.5.2 + dependencies: + ajv: registry.npmjs.org/ajv@8.12.0 + compare-versions: registry.npmjs.org/compare-versions@5.0.3 + showdown: registry.npmjs.org/showdown@2.1.0 + zhi-device: registry.npmjs.org/zhi-device@0.5.0 + zhi-env: registry.npmjs.org/zhi-env@1.17.0 + zhi-log: registry.npmjs.org/zhi-log@1.13.0 + dev: false + registry.npmjs.org/zhi-device@0.5.0: resolution: {integrity: sha512-fa3oPl7zA76ecSHTkPG4v3t66fd8uvPxIGgoddI17ORx/TuyYW8LaKP0ULy7y2O+ZpUQc2+Hr+Qb76kf35Gf9w==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/zhi-device/-/zhi-device-0.5.0.tgz} name: zhi-device @@ -15334,6 +15380,17 @@ packages: zhi-env: registry.npmjs.org/zhi-env@1.17.0 dev: false + registry.npmjs.org/zhi-siyuan-api@1.1.1: + resolution: {integrity: sha512-DFCVAEPJ0JhW6Rz/jUYXVoG+G6gqgP/CYlQC3f+YwDWBiACVRaf2Geu+pHDE9nXbBhhuexqk370Ac5qsGHRRYw==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/zhi-siyuan-api/-/zhi-siyuan-api-1.1.1.tgz} + name: zhi-siyuan-api + version: 1.1.1 + dependencies: + zhi-blog-api: registry.npmjs.org/zhi-blog-api@1.1.0 + zhi-common: registry.npmjs.org/zhi-common@1.5.2 + zhi-env: registry.npmjs.org/zhi-env@1.17.0 + zhi-log: registry.npmjs.org/zhi-log@1.13.0 + dev: false + registry.npmjs.org/zip-stream@4.1.0: resolution: {integrity: sha512-zshzwQW7gG7hjpBlgeQP9RuyPGNxvJdzR8SUM3QhxCnLjWN2E7j3dOvpeDcQoETfHx0urRS7EtmVToql7YpU4A==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/zip-stream/-/zip-stream-4.1.0.tgz} name: zip-stream