-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,171 additions
and
427 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,5 +43,5 @@ | |
} | ||
} | ||
}, | ||
"defaultProject": "zhi-static-blog-astro" | ||
"defaultProject": "zhi" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"jsc": { | ||
"target": "es2017", | ||
"parser": { | ||
"syntax": "typescript", | ||
"decorators": true, | ||
"dynamicImport": true | ||
}, | ||
"transform": { | ||
"decoratorMetadata": true, | ||
"legacyDecorator": true | ||
}, | ||
"keepClassNames": true, | ||
"externalHelpers": true, | ||
"loose": true | ||
}, | ||
"module": { | ||
"type": "es6", | ||
"strict": true, | ||
"noInterop": true | ||
}, | ||
"sourceMaps": true, | ||
"exclude": [ | ||
"jest.config.ts", | ||
".*\\.spec.tsx?$", | ||
".*\\.test.tsx?$", | ||
"./src/jest-setup.ts$", | ||
"./**/jest-setup.ts$", | ||
".*.js$" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# zhi-blog-middleware-rollup | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build zhi-blog-middleware-rollup` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test zhi-blog-middleware-rollup` to execute the unit tests via [Jest](https://jestjs.io). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-disable */ | ||
import { readFileSync } from "fs" | ||
|
||
// Reading the SWC compilation config and remove the "exclude" | ||
// for the test files to be compiled by SWC | ||
const { exclude: _, ...swcJestConfig } = JSON.parse(readFileSync(`${__dirname}/.swcrc`, "utf-8")) | ||
|
||
// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves. | ||
// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude" | ||
if (swcJestConfig.swcrc === undefined) { | ||
swcJestConfig.swcrc = false | ||
} | ||
|
||
export default { | ||
displayName: "zhi-blog-middleware-rollup", | ||
preset: "../../jest.preset.js", | ||
transform: { | ||
"^.+\\.[tj]s$": ["@swc/jest", swcJestConfig], | ||
}, | ||
moduleFileExtensions: ["ts", "js", "html"], | ||
coverageDirectory: "../../coverage/packages/zhi-blog-middleware-rollup", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "zhi-blog-middleware-rollup", | ||
"version": "1.0.0", | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "zhi-blog-middleware-rollup", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/zhi-blog-middleware-rollup/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nrwl/rollup:rollup", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
// https://nx.dev/packages/web/executors/rollup#options-playground | ||
// "outputPath": "dist/packages/zhi-blog-middleware-rollup", | ||
"outputPath": "../SiYuanWorkspace/public/conf/appearance/themes/zhi/modules/blog-middleware-esbuild", | ||
"main": "packages/zhi-blog-middleware-rollup/src/index.ts", | ||
"tsConfig": "packages/zhi-blog-middleware-rollup/tsconfig.lib.json", | ||
"assets": [], | ||
"project": "packages/zhi-blog-middleware-rollup/package.json", | ||
"compiler": "swc", | ||
"format": ["cjs"] | ||
}, | ||
}, | ||
"publish": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "node tools/scripts/publish.mjs zhi-blog-middleware-rollup {args.ver} {args.tag}" | ||
}, | ||
"dependsOn": ["build"] | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/zhi-blog-middleware-rollup/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "packages/zhi-blog-middleware-rollup/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import LogFactory from "zhi-log" | ||
import ZhiCommon from "zhi-common" | ||
import Env from "zhi-env" | ||
import { SiyuanKernelApi } from "zhi-siyuan-api" | ||
|
||
/** | ||
* 工具类统一入口,每个应用自己实现 | ||
* | ||
* @public | ||
* @author terwer | ||
* @since 1.0.0 | ||
*/ | ||
class ZhiUtil { | ||
/** | ||
* 按照logger缓存 | ||
* @private | ||
*/ | ||
private static loggerMap: any | ||
private static common: ZhiCommon | ||
private static env: Env | ||
private static kernelApi: SiyuanKernelApi | ||
|
||
/** | ||
* 获取 zhi-env 实例 | ||
*/ | ||
public static zhiEnv() { | ||
if (!ZhiUtil.env) { | ||
// https://github.com/vitejs/vite/issues/9539#issuecomment-1206301266 | ||
// add vite/client to tsconfig.lib.json | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
ZhiUtil.env = new Env(import.meta.env) | ||
} | ||
return ZhiUtil.env | ||
} | ||
|
||
/** | ||
* 获取 zhi-common 实例 | ||
*/ | ||
public static zhiCommon() { | ||
if (!ZhiUtil.common) { | ||
ZhiUtil.common = new ZhiCommon() | ||
} | ||
return ZhiUtil.common | ||
} | ||
|
||
/** | ||
* 获取 zhi-log 实例 | ||
*/ | ||
public static zhiLog(loggerName: string) { | ||
// 先检测日志Map | ||
if (ZhiUtil.loggerMap) { | ||
// 日志不存在,生成一个新的缓存到Map | ||
if (ZhiUtil.loggerMap[loggerName]) { | ||
ZhiUtil.loggerMap[loggerName].debug("Zhi-log use cache.") | ||
} else { | ||
const env = ZhiUtil.zhiEnv() | ||
ZhiUtil.loggerMap[loggerName] = LogFactory.customSignLogFactory("zhi", env).getLogger(loggerName) | ||
ZhiUtil.loggerMap[loggerName].debug("Zhi-log add new logger.") | ||
} | ||
} else { | ||
// 生成新的日志器 | ||
const env = ZhiUtil.zhiEnv() | ||
ZhiUtil.loggerMap = {} | ||
ZhiUtil.loggerMap[loggerName] = LogFactory.customSignLogFactory("zhi", env).getLogger(loggerName) | ||
ZhiUtil.loggerMap[loggerName].debug("Zhi-log inited.") | ||
} | ||
|
||
// 从Map缓存获取日志器 | ||
return ZhiUtil.loggerMap[loggerName] | ||
} | ||
|
||
/** | ||
* 获取 siyuan-kernel-api 实例 | ||
*/ | ||
public static siyuanKernelApi() { | ||
if (!ZhiUtil.kernelApi) { | ||
const env = ZhiUtil.zhiEnv() | ||
ZhiUtil.kernelApi = new SiyuanKernelApi(env) | ||
} | ||
return ZhiUtil.kernelApi | ||
} | ||
} | ||
|
||
export default ZhiUtil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import ZhiBlogMiddlewareRollup from "./lib/zhi-blog-middleware-rollup" | ||
export default ZhiBlogMiddlewareRollup |
30 changes: 30 additions & 0 deletions
30
packages/zhi-blog-middleware-rollup/src/lib/zhi-blog-middleware-rollup.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
||
describe("zhiBlogMiddlewareRollup", () => { | ||
it("should work", () => { | ||
console.log("hello") | ||
}) | ||
}) |
Oops, something went wrong.