Skip to content

Commit

Permalink
feat: 新增发布 SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 15, 2023
1 parent 9bb152c commit b818b47
Show file tree
Hide file tree
Showing 16 changed files with 306 additions and 11 deletions.
1 change: 1 addition & 0 deletions libs/publisher-sdk/.env.development.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_DEBUG_MODE=true
4 changes: 4 additions & 0 deletions libs/publisher-sdk/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["./node_modules/@terwer/eslint-config-custom/typescript/index.cjs"],
}
2 changes: 2 additions & 0 deletions libs/publisher-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
.DS_Store
11 changes: 11 additions & 0 deletions libs/publisher-sdk/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# platform

# Ignore artifacts:
dist
node_modules

# Ignore all dts files:
*.d.ts

# lib
/pnpm-lock.yaml
30 changes: 30 additions & 0 deletions libs/publisher-sdk/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -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
}
41 changes: 41 additions & 0 deletions libs/publisher-sdk/README.md
Original file line number Diff line number Diff line change
@@ -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
```
12 changes: 12 additions & 0 deletions libs/publisher-sdk/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue + TS</title>
</head>
<body>
This file is for lib hot-load test only, see <a href="/src/index.ts">/src/index.ts</a>
<script type="module" src="/src/index.ts"></script>
</body>
</html>
34 changes: 34 additions & 0 deletions libs/publisher-sdk/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
7 changes: 7 additions & 0 deletions libs/publisher-sdk/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, it } from "vitest"

describe("index", () => {
it("test index", () => {
console.log("hello")
})
})
5 changes: 5 additions & 0 deletions libs/publisher-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const init = () => {
return "ok"
}

export default init
42 changes: 42 additions & 0 deletions libs/publisher-sdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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": "."
}
10 changes: 10 additions & 0 deletions libs/publisher-sdk/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
33 changes: 33 additions & 0 deletions libs/publisher-sdk/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/// <reference types="vitest" />

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}"],
},
})
3 changes: 1 addition & 2 deletions plugins/publisher-main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"svelte-routing": "^1.8.8"
},
"dependencies": {
"zhi-device": "^0.5.0",
"zhi-log": "^1.13.0"
"@terwer/publisher-sdk": "workspace:*"
}
}
9 changes: 8 additions & 1 deletion plugins/publisher-main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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()
Expand Down Expand Up @@ -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)
},
})

Expand Down
Loading

0 comments on commit b818b47

Please sign in to comment.