Skip to content

Commit

Permalink
feat: Add rollup middleware project
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Apr 5, 2023
1 parent daf10d4 commit a568ef1
Show file tree
Hide file tree
Showing 27 changed files with 1,171 additions and 427 deletions.
10 changes: 0 additions & 10 deletions .vercelignore

This file was deleted.

5 changes: 0 additions & 5 deletions jest.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@
}
}
},
"defaultProject": "zhi-static-blog-astro"
"defaultProject": "zhi"
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@
"@nrwl/node": "^15.8.9",
"@nrwl/nx-cloud": "latest",
"@nrwl/react": "^15.8.9",
"@nrwl/rollup": "15.8.9",
"@nrwl/vite": "15.8.9",
"@nrwl/web": "^15.8.9",
"@nrwl/workspace": "15.8.9",
"@nx-plus/docusaurus": "15.0.0-rc.0",
"@nxlv/python": "^15.7.0",
"@nxtensions/astro": "3.5.0",
"@swc/cli": "~0.1.55",
"@swc/core": "^1.2.173",
"@swc/jest": "0.2.20",
"@types/fs-extra": "^11.0.1",
"@types/git-clone": "^0.2.0",
"@types/jest": "^29.4.0",
Expand Down Expand Up @@ -80,6 +84,7 @@
"@docusaurus/core": "2.1.0",
"@docusaurus/preset-classic": "2.1.0",
"@mdx-js/react": "^1.6.22",
"@swc/helpers": "~0.4.11",
"callsites": "^4.0.0",
"clsx": "^1.2.1",
"commander": "^10.0.0",
Expand Down
18 changes: 18 additions & 0 deletions packages/zhi-blog-middleware-rollup/.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": {}
}
]
}
31 changes: 31 additions & 0 deletions packages/zhi-blog-middleware-rollup/.swcrc
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$"
]
}
11 changes: 11 additions & 0 deletions packages/zhi-blog-middleware-rollup/README.md
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).
22 changes: 22 additions & 0 deletions packages/zhi-blog-middleware-rollup/jest.config.ts
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",
}
5 changes: 5 additions & 0 deletions packages/zhi-blog-middleware-rollup/package.json
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"
}
52 changes: 52 additions & 0 deletions packages/zhi-blog-middleware-rollup/project.json
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": []
}
110 changes: 110 additions & 0 deletions packages/zhi-blog-middleware-rollup/src/ZhiUtil.ts
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
27 changes: 27 additions & 0 deletions packages/zhi-blog-middleware-rollup/src/index.ts
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
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")
})
})
Loading

0 comments on commit a568ef1

Please sign in to comment.