Skip to content

Commit

Permalink
feat: Init zhi-blog and zhi-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Mar 31, 2023
1 parent 09cae99 commit 6889d48
Show file tree
Hide file tree
Showing 26 changed files with 500 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[![](https://img.shields.io/badge/dynamic-blog-blue)](https://github.com/terwer/zhi/tree/dev/packages/zhi-blog)
[![](https://img.shields.io/badge/static-blog-purple)](https://github.com/terwer/zhi/tree/dev/packages/zhi-blog-astro)

> ⚠️ WARNING 1: Attention: The `zhi` theme only supports the `2.7.6+` version of [siyuan-note](https://github.com/siyuan-note/siyuan) , and the plugin function only supports `2.8.1+`. Otherwise, you need to upgrade [siyuan-note](https://github.com/siyuan-note/siyuan) to a new version.
> ⚠️ WARNING 1: Attention: The `zhi` theme only supports the `2.7.6+` version of [siyuan-note](https://github.com/siyuan-note/siyuan) , and the plugin system only supports `2.8.1+`. Otherwise, you need to upgrade [siyuan-note](https://github.com/siyuan-note/siyuan) to a new version.
> ⚠️ WARNING 2: `1.0.0` is an available version in the early stage, and the function is not comprehensive yet. It is only used for testing and welcomes valuable opinions through issuing. Please refer to [core features](#core-features) for this version's characteristics.
Expand Down
18 changes: 18 additions & 0 deletions packages/zhi-blog-api/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
13 changes: 13 additions & 0 deletions packages/zhi-blog-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# zhi-blog-api

a common blog interface

## Building

This library was generated with [Nx](https://nx.dev).

Run `nx build zhi-blog-api` to build the library.

## Running unit tests

Run `nx test zhi-blog-api` to execute the unit tests via [Jest](https://jestjs.io).
17 changes: 17 additions & 0 deletions packages/zhi-blog-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "zhi-blog-api",
"version": "1.0.0",
"type": "module",
"description": "a common blog interface",
"repository": "terwer/zhi",
"homepage": "https://terwer.space",
"author": "terwer",
"license": "GPL",
"keywords": [
"zhi-blog-api",
"zhi",
"blog",
"api",
"blog-api"
]
}
38 changes: 38 additions & 0 deletions packages/zhi-blog-api/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "zhi-blog-api",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/zhi-blog-api/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/vite:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/zhi-blog-api"
}
},
"publish": {
"executor": "nx:run-commands",
"options": {
"command": "node tools/scripts/publish.mjs zhi-blog-api {args.ver} {args.tag}"
},
"dependsOn": ["build"]
},
"test": {
"executor": "@nrwl/vite:test",
"outputs": ["coverage/packages/zhi-blog-api"],
"options": {
"passWithNoTests": true,
"reportsDirectory": "../../coverage/packages/zhi-blog-api"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/zhi-blog-api/**/*.ts"]
}
}
},
"tags": []
}
1 change: 1 addition & 0 deletions packages/zhi-blog-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./lib/zhi-blog-api"
7 changes: 7 additions & 0 deletions packages/zhi-blog-api/src/lib/zhi-blog-api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { zhiBlogApi } from "./zhi-blog-api"

describe("zhiBlogApi", () => {
it("should work", () => {
expect(zhiBlogApi()).toEqual("zhi-blog-api")
})
})
3 changes: 3 additions & 0 deletions packages/zhi-blog-api/src/lib/zhi-blog-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function zhiBlogApi(): string {
return "zhi-blog-api"
}
23 changes: 23 additions & 0 deletions packages/zhi-blog-api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "esnext",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"types": ["vitest"]
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions packages/zhi-blog-api/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
19 changes: 19 additions & 0 deletions packages/zhi-blog-api/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"]
},
"include": [
"vite.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
58 changes: 58 additions & 0 deletions packages/zhi-blog-api/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/// <reference types="vitest" />
import { defineConfig } from "vite"

import viteTsConfigPaths from "vite-tsconfig-paths"
import dts from "vite-plugin-dts"
import { join } from "path"

export default defineConfig({
cacheDir: "../../node_modules/.vite/zhi-blog-api",

plugins: [
dts({
entryRoot: "src",
tsConfigFilePath: join(__dirname, "tsconfig.lib.json"),
skipDiagnostics: true,
}),

viteTsConfigPaths({
root: "../../",
}),
],

// Uncomment this if you are using workers.
// worker: {
// plugins: [
// viteTsConfigPaths({
// root: '../../',
// }),
// ],
// },

// Configuration for building your library.
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
lib: {
// Could also be a dictionary or array of multiple entry points.
entry: "src/index.ts",
name: "zhi-blog-api",
fileName: "index",
// Change this to the formats you want to support.
// Don't forgot to update your package.json as well.
formats: ["es", "cjs"],
},
rollupOptions: {
// External packages that should not be bundled into your library.
external: [],
},
},

test: {
globals: true,
cache: {
dir: "../../node_modules/.vitest",
},
environment: "jsdom",
include: ["src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
},
})
18 changes: 18 additions & 0 deletions packages/zhi-sdk/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
85 changes: 85 additions & 0 deletions packages/zhi-sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# zhi-sdk

a simple sdk for siyuan-note, blog, and more

## Usage

```bash
pnpm add zhi-sdk
```

```ts
import ZhiSdk from "zhi-sdk"
import Env from "zhi-env"

// init zhiSdk
const zhiSdk = new ZhiSdk()

// init zhiSdk with env
const env = new Env(import.meta.env)
const zhiSdk = new ZhiSdk(env)

// siyuanAPI
const siyuanApi = zhiSdk.siyuanApi
console.log(siyuanApi.serverApi.VERSION)
console.log(siyuanApi.clientApi.VERSION)

// blogApi
const blogApi = zhiSdk.blogApi
console.log(blogApi.VERSION)

// common
const msg = "message"
const fmsg = zhiSdk.common.strUtil.f("This a {0}", msg)
console.log(fmsg)
```

## Deps

```
├── zhi-log
├── zhi-common
├── zhi-blog-api
├── zhi-siyuan-api
```

## Architecture

`zhi-sdk` consist a set of component apis, each component will have their own dependency trees

- zhi-sdk
- zhi-env
- zhi-log
- zhi-common
- browserUtil
- dateUtil
- deviceUtil
- electronUtil
- strUtil
- versionUtil
- zhi-core
- zhi-ui
- zhi-middleware
- zhi-siyuan-api
- zhi-siyuan-server-api
- zhi-siyuan-client-api
- zhi-siyuan-util
- zhi-blog-api
- zhi-metaweblog-api
- zhi-wordpress
- zhi-cnblogs
- zhi-common-blog-api
- zhi-yuque
- zhi-http-custom-api
- zhi-blog-zhihu
- zhi-blog-csdn

## Building

This library was generated with [Nx](https://nx.dev).

Run `nx build zhi-sdk` to build the library.

## Running unit tests

Run `nx test zhi-sdk` to execute the unit tests via [Jest](https://jestjs.io).
17 changes: 17 additions & 0 deletions packages/zhi-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "zhi-sdk",
"version": "1.3.0",
"type": "module",
"description": "a simple sdk for siyuan-note, blog, and more",
"repository": "terwer/zhi",
"homepage": "https://terwer.space",
"author": "terwer",
"license": "GPL",
"keywords": [
"zhi-sdk",
"zhi",
"sdk",
"siyuan-note",
"blog"
]
}
38 changes: 38 additions & 0 deletions packages/zhi-sdk/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "zhi-sdk",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/zhi-sdk/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/vite:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/zhi-sdk"
}
},
"publish": {
"executor": "nx:run-commands",
"options": {
"command": "node tools/scripts/publish.mjs zhi-sdk {args.ver} {args.tag}"
},
"dependsOn": ["build"]
},
"test": {
"executor": "@nrwl/vite:test",
"outputs": ["coverage/packages/zhi-sdk"],
"options": {
"passWithNoTests": true,
"reportsDirectory": "../../coverage/packages/zhi-sdk"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/zhi-sdk/**/*.ts"]
}
}
},
"tags": []
}
1 change: 1 addition & 0 deletions packages/zhi-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./lib/zhi-sdk"
7 changes: 7 additions & 0 deletions packages/zhi-sdk/src/lib/zhi-sdk.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { zhiSdk } from "./zhi-sdk"

describe("zhiSdk", () => {
it("should work", () => {
expect(zhiSdk()).toEqual("zhi-sdk")
})
})
Loading

0 comments on commit 6889d48

Please sign in to comment.