diff --git a/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/package.json b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/package.json new file mode 100644 index 00000000..6d671326 --- /dev/null +++ b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/package.json @@ -0,0 +1,7 @@ +{ + "name": "@siyuan-community/zhi-core", + "version": "0.0.1", + "type": "commonjs", + "main": "./src/index.js", + "types": "./src/index.d.ts" +} diff --git a/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/index.d.ts b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/index.d.ts new file mode 100644 index 00000000..af80bdce --- /dev/null +++ b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/index.d.ts @@ -0,0 +1 @@ +export * from "./lib/zhi-core"; diff --git a/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/index.js b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/index.js new file mode 100644 index 00000000..b21b1af8 --- /dev/null +++ b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/index.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const tslib_1 = require("tslib"); +tslib_1.__exportStar(require("./lib/zhi-core"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/index.js.map b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/index.js.map new file mode 100644 index 00000000..412c00b2 --- /dev/null +++ b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../../../../../packages/zhi-core/src/index.ts"],"names":[],"mappings":";;;AAAA,yDAA8B"} \ No newline at end of file diff --git a/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/core/zhi.d.ts b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/core/zhi.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/core/zhi.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/core/zhi.js b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/core/zhi.js new file mode 100644 index 00000000..9f6e845e --- /dev/null +++ b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/core/zhi.js @@ -0,0 +1,73 @@ +"use strict"; +/* + * 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. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +const tslib_1 = require("tslib"); +/** + * 主题通用类(由theme.js动态调用,除了单元测试之外请勿主动调用) + * + * @public + * @author terwer + * @since 0.1.0 + */ +class Zhi { +} +// +// const importMap = { +// imports: { +// react: "https://esm.sh/react@18.2.0?dev", +// "react-dom": "https://esm.sh/react-dom@18.2.0?dev", +// "react-dom/client": "https://esm.sh/react-dom@18.2.0/client?dev", +// "prop-types": "https://esm.sh/prop-types@15.8.1?dev", +// "react-feather": "https://unpkg.com/react-feather@2.0.10/dist/index.js", +// }, +// } +// +// const React = await importWithMap("react", importMap) +// const { createRoot } = await importWithMap("react-dom/client", importMap) +// +// // react-feather is a React icon library +// // which contains bare import specifiers for "react" and "prop-types" +// const { Smile } = await importWithMap("react-feather", importMap) +// +// function MyApp(props) { +// return React.createElement( +// React.Suspense, +// { fallback: React.createElement("div", {}, "Loading...") }, +// React.createElement(Smile) +// ) +// } +// +// const domContainer = document.getElementById("root") +// const root = createRoot(domContainer) +// root.render(React.createElement(MyApp)) +console.log("hello from dynamic importmap2, see https://github.com/keller-mark/dynamic-importmap#react-example for more details"); +// @ts-ignore +const zhi_log_1_9_1_1 = tslib_1.__importDefault(require("https://esm.sh/zhi-log@1.9.1")); +// const env = new Env({}) +// console.log(Env) +// console.log(env.isNodeDev()) +console.log(zhi_log_1_9_1_1.default); +//# sourceMappingURL=zhi.js.map \ No newline at end of file diff --git a/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/core/zhi.js.map b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/core/zhi.js.map new file mode 100644 index 00000000..5129d5d1 --- /dev/null +++ b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/core/zhi.js.map @@ -0,0 +1 @@ +{"version":3,"file":"zhi.js","sourceRoot":"","sources":["../../../../../../../../../../../../../../packages/zhi-core/src/lib/core/zhi.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AAEH;;;;;;GAMG;AACH,MAAM,GAAG;CAIR;AAED,EAAE;AACF,sBAAsB;AACtB,eAAe;AACf,gDAAgD;AAChD,0DAA0D;AAC1D,wEAAwE;AACxE,4DAA4D;AAC5D,+EAA+E;AAC/E,OAAO;AACP,IAAI;AACJ,EAAE;AACF,wDAAwD;AACxD,4EAA4E;AAC5E,EAAE;AACF,2CAA2C;AAC3C,wEAAwE;AACxE,oEAAoE;AACpE,EAAE;AACF,0BAA0B;AAC1B,gCAAgC;AAChC,sBAAsB;AACtB,kEAAkE;AAClE,iCAAiC;AACjC,MAAM;AACN,IAAI;AACJ,EAAE;AACF,uDAAuD;AACvD,wCAAwC;AACxC,0CAA0C;AAC1C,OAAO,CAAC,GAAG,CAAC,oHAAoH,CAAC,CAAA;AAqBjI,aAAa;AACb,yFAAiD;AAEjD,0BAA0B;AAC1B,mBAAmB;AACnB,+BAA+B;AAG/B,OAAO,CAAC,GAAG,CAAC,uBAAM,CAAC,CAAA"} \ No newline at end of file diff --git a/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/zhi-core.d.ts b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/zhi-core.d.ts new file mode 100644 index 00000000..84102dc7 --- /dev/null +++ b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/zhi-core.d.ts @@ -0,0 +1 @@ +export declare function zhiCore(): string; diff --git a/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/zhi-core.js b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/zhi-core.js new file mode 100644 index 00000000..e56fda2a --- /dev/null +++ b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/zhi-core.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.zhiCore = void 0; +function zhiCore() { + return "zhi-core"; +} +exports.zhiCore = zhiCore; +//# sourceMappingURL=zhi-core.js.map \ No newline at end of file diff --git a/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/zhi-core.js.map b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/zhi-core.js.map new file mode 100644 index 00000000..7d2aef15 --- /dev/null +++ b/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core/src/lib/zhi-core.js.map @@ -0,0 +1 @@ +{"version":3,"file":"zhi-core.js","sourceRoot":"","sources":["../../../../../../../../../../../../../packages/zhi-core/src/lib/zhi-core.ts"],"names":[],"mappings":";;;AAAA,SAAgB,OAAO;IACrB,OAAO,UAAU,CAAA;AACnB,CAAC;AAFD,0BAEC"} \ No newline at end of file diff --git a/package.json b/package.json index 9c8b9908..802c3ff0 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "prettier": "^2.6.2", "rollup-plugin-livereload": "^2.0.5", "stylus": "^0.59.0", + "tslib": "^2.5.0", "typescript": "~5.0.4", "vite": "^4.0.1", "vite-plugin-dts": "~2.3.0", diff --git a/packages/zhi-core/README.md b/packages/zhi-core/README.md index d39783d8..e11ed4a3 100644 --- a/packages/zhi-core/README.md +++ b/packages/zhi-core/README.md @@ -1,10 +1,6 @@ # zhi-core -core module for zhi - -## Dev - -Run `nx dev zhi-core` for development in siyuan-note. +This library was generated with [Nx](https://nx.dev). ## Building @@ -12,4 +8,4 @@ Run `nx build zhi-core` to build the library. ## Running unit tests -Run `nx test zhi-core` to execute the unit tests via [Vitest](https://vitest.dev). +Run `nx test zhi-core` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/packages/zhi-core/package.json b/packages/zhi-core/package.json index 87c5484b..6f8ef0ee 100644 --- a/packages/zhi-core/package.json +++ b/packages/zhi-core/package.json @@ -1,5 +1,5 @@ { - "name": "@zhi/zhi-core", - "version": "0.0.1", + "name": "@siyuan-community/zhi-core", + "version": "0.1.0", "type": "module" } diff --git a/packages/zhi-core/project.json b/packages/zhi-core/project.json index 677b7354..dcc8cc64 100644 --- a/packages/zhi-core/project.json +++ b/packages/zhi-core/project.json @@ -5,29 +5,26 @@ "projectType": "library", "targets": { "dev": { - "executor": "@nx/vite:build", - "outputs": ["{options.outputPath}"], + "executor": "nx:run-commands", "options": { - "outputPath": "/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi", - "emptyOutDir": false, - "watch": true - } + "commands": ["cp -r dist/packages/zhi/core/**/* /Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi/core"], + "parallel": false + }, + "dependsOn": [{ "projects": "self", "target": "build" }] }, "build": { - "executor": "@nx/vite:build", + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { - "outputPath": "dist/packages/zhi", - "emptyOutDir": false + "outputPath": "dist/packages/zhi/core", + "main": "packages/zhi-core/src/index.ts", + "tsConfig": "packages/zhi-core/tsconfig.lib.json", + "assets": ["packages/zhi-core/*.md"] } }, - "test": { - "executor": "@nx/vite:test", - "outputs": ["coverage/packages/zhi-core"], - "options": { - "passWithNoTests": true, - "reportsDirectory": "../../coverage/packages/zhi-core" - } + "publish": { + "command": "node tools/scripts/publish.mjs zhi-core {args.ver} {args.tag}", + "dependsOn": ["build"] }, "lint": { "executor": "@nx/linter:eslint", @@ -35,6 +32,14 @@ "options": { "lintFilePatterns": ["packages/zhi-core/**/*.ts"] } + }, + "test": { + "executor": "@nx/vite:test", + "outputs": ["coverage/packages/zhi-core"], + "options": { + "passWithNoTests": true, + "reportsDirectory": "../../coverage/packages/zhi-core" + } } }, "tags": [] diff --git a/packages/zhi-core/src/index.ts b/packages/zhi-core/src/index.ts index 038db653..4c8d921e 100644 --- a/packages/zhi-core/src/index.ts +++ b/packages/zhi-core/src/index.ts @@ -23,19 +23,4 @@ * questions. */ -/** - * @packageDocumentation - * zhi-core 主题核心模块 - */ - -import { zhiCore } from "./lib/zhi-core" - -// 主题样式注入入口 -import "./style/theme.styl" - -/** - * 主题入口,由思源笔记自动触发,请勿主动调用 - */ -;(async () => { - await zhiCore() -})() +export * from "./lib/zhi-core.js" diff --git a/packages/zhi-core/src/lib/core/ZhiCoreUtil.ts b/packages/zhi-core/src/lib/core/ZhiCoreUtil.ts new file mode 100644 index 00000000..38c1bf53 --- /dev/null +++ b/packages/zhi-core/src/lib/core/ZhiCoreUtil.ts @@ -0,0 +1,59 @@ +/* + * 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. + */ + +// @ts-ignore +import { importWithMap } from "https://esm.sh/dynamic-importmap" +// @ts-ignore +// import ZhiUtil from "https://esm.sh/@siyuan-community/zhi-common@1.5.5" +// @ts-ignore +import Env from "https://esm.sh/zhi-env" +// @ts-ignore +import ZhiLog from "https://esm.sh/zhi-log" + +console.log("Env=>", Env) +console.log("ZhiLog=>", ZhiLog) + +/** + * 工具类统一入口,每个应用自己实现 + * + * @public + * @author terwer + * @since 1.0.0 + */ +class ZhiCoreUtil{ + // extends ZhiUtil { +// // @ts-ignore +// public static override zhiEnv(): Env { +// // @ts-ignore +// if (!this.env) { +// // @ts-ignore +// this.env = new Env(import.meta.env) +// } +// // @ts-ignore +// return this.env +// } +} + +export default ZhiCoreUtil diff --git a/packages/zhi-core/src/lib/core/zhi.ts b/packages/zhi-core/src/lib/core/zhi.ts index e2f0c0f2..6296654f 100644 --- a/packages/zhi-core/src/lib/core/zhi.ts +++ b/packages/zhi-core/src/lib/core/zhi.ts @@ -23,6 +23,9 @@ * questions. */ +// @ts-ignore +import ZhiCoreUtil from "./ZhiCoreUtil.js" + /** * 主题通用类(由theme.js动态调用,除了单元测试之外请勿主动调用) * @@ -31,5 +34,92 @@ * @since 0.1.0 */ class Zhi { + // private readonly logger + // private readonly common + // private readonly kernelApi + + /** + * 主题初始化 + */ + constructor() { + // const env = ZhiCoreUtil.zhiEnv() + // // @ts-ignore + // this.logger = ZhiCoreUtil.zhiLog("zhi-core") + // // @ts-ignore + // this.common = ZhiCoreUtil.zhiCommon() + // this.kernelApi = new SiyuanKernelApi(env) + // + // this.runAs = runAs ?? DeviceTypeEnum.DeviceType_Node + } + + /** + * 初始化 + */ + public async init(): Promise { + // + // const importMap = { + // imports: { + // react: "https://esm.sh/react@18.2.0?dev", + // "react-dom": "https://esm.sh/react-dom@18.2.0?dev", + // "react-dom/client": "https://esm.sh/react-dom@18.2.0/client?dev", + // "prop-types": "https://esm.sh/prop-types@15.8.1?dev", + // "react-feather": "https://unpkg.com/react-feather@2.0.10/dist/index.js", + // }, + // } + // + // const React = await importWithMap("react", importMap) + // const { createRoot } = await importWithMap("react-dom/client", importMap) + // + // // react-feather is a React icon library + // // which contains bare import specifiers for "react" and "prop-types" + // const { Smile } = await importWithMap("react-feather", importMap) + // + // function MyApp(props) { + // return React.createElement( + // React.Suspense, + // { fallback: React.createElement("div", {}, "Loading...") }, + // React.createElement(Smile) + // ) + // } + // + // const domContainer = document.getElementById("root") + // const root = createRoot(domContainer) + // root.render(React.createElement(MyApp)) + console.log( + "hello from dynamic import, see https://github.com/keller-mark/dynamic-importmap#react-example for more details" + ) + // + // const importMap = { + // imports: { + // react: "https://esm.sh/react@18.2.0?dev", + // "react-dom": "https://esm.sh/react-dom@18.2.0?dev", + // "react-dom/client": "https://esm.sh/react-dom@18.2.0/client?dev", + // "prop-types": "https://esm.sh/prop-types@15.8.1?dev", + // "react-feather": "https://unpkg.com/react-feather@2.0.10/dist/index.js", + // }, + // } + // + // const React = await importWithMap("react", importMap) + // + // console.log("React=>", React) + // const env = new Env({}) + // console.log(Env) + // console.log(env.isNodeDev()) + + console.log(ZhiCoreUtil) + } + + /** + * 主流程加载 + */ + public async start(): Promise { + try { + console.info("Zhi Theme inited") + } catch (e) { + console.error("Zhi Theme load error=>", e) + } + } } + +export default Zhi diff --git a/packages/zhi-core/src/lib/zhi-core.spec.ts b/packages/zhi-core/src/lib/zhi-core.spec.ts index 1abecab8..c813d748 100644 --- a/packages/zhi-core/src/lib/zhi-core.spec.ts +++ b/packages/zhi-core/src/lib/zhi-core.spec.ts @@ -23,7 +23,7 @@ * questions. */ -import { zhiCore } from "./zhi-core" +import { zhiCore } from "./zhi-core.js" describe("zhiCore", () => { it("zhiCore should work", () => { diff --git a/packages/zhi-core/src/lib/zhi-core.ts b/packages/zhi-core/src/lib/zhi-core.ts index 5292c3f3..a25a4304 100644 --- a/packages/zhi-core/src/lib/zhi-core.ts +++ b/packages/zhi-core/src/lib/zhi-core.ts @@ -23,8 +23,17 @@ * questions. */ +import Zhi from "./core/zhi.js" + +/** + * 主题实际上的最终执行入口 + * + * @author terwer + * @version 0.1.0 + * @since 0.1.0 + */ export async function zhiCore(): Promise { - // const zhi = new Zhi(DeviceDetection.getDevice()) - // await zhi.init() - console.log("hello, zhi theme5") + const zhi = new Zhi() + await zhi.init() + await zhi.start() } diff --git a/packages/zhi-core/tsconfig.json b/packages/zhi-core/tsconfig.json index bdf594cd..09231f13 100644 --- a/packages/zhi-core/tsconfig.json +++ b/packages/zhi-core/tsconfig.json @@ -1,13 +1,14 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "module": "commonjs", + "module": "esnext", "forceConsistentCasingInFileNames": true, "strict": true, "noImplicitOverride": true, "noPropertyAccessFromIndexSignature": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, + "importHelpers": false, "types": ["vitest"] }, "files": [], diff --git a/packages/zhi-core/vite.config.ts b/packages/zhi-core/vite.config.ts index 546a2d07..bb3f269f 100644 --- a/packages/zhi-core/vite.config.ts +++ b/packages/zhi-core/vite.config.ts @@ -2,47 +2,24 @@ import { defineConfig } from "vite" import viteTsConfigPaths from "vite-tsconfig-paths" -import livereload from "rollup-plugin-livereload" -import { argv } from "process" - -// 处理参数 -const devOutDir = "/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi" -const args: any = argv[2].startsWith("{") ? JSON.parse(argv[2]) : undefined -const isWatch = args?.targetDescription?.target === "dev" ?? false -const isProduction = !isWatch -const isTest = process.env["npm_command"] === "test" -console.log("isTest=>", isTest) -console.log("isWatch=>", isWatch) -console.log("isProduction=>", isProduction) export default defineConfig({ cacheDir: "../../node_modules/.vite/zhi-core", plugins: [ - !isTest && - viteTsConfigPaths({ - root: "../../", - }), + viteTsConfigPaths({ + root: "../../", + }), ], - // Configuration for building your library. - // See: https://vitejs.dev/guide/build.html#library-mode - build: { - lib: { - entry: ["src/index.ts"], - formats: ["es"], - }, - - rollupOptions: { - plugins: [...(isWatch ? [livereload(devOutDir)] : [])] as Plugin[], - // External packages that should not be bundled into your library. - external: [], - output: { - entryFileNames: "theme.js", - assetFileNames: "theme.css", - }, - }, - }, + // Uncomment this if you are using workers. + // worker: { + // plugins: [ + // viteTsConfigPaths({ + // root: '../../', + // }), + // ], + // }, test: { globals: true, diff --git a/packages/zhi-loader/.eslintrc.json b/packages/zhi-loader/.eslintrc.json new file mode 100644 index 00000000..9d9c0db5 --- /dev/null +++ b/packages/zhi-loader/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/packages/zhi-loader/README.md b/packages/zhi-loader/README.md new file mode 100644 index 00000000..cdf1d647 --- /dev/null +++ b/packages/zhi-loader/README.md @@ -0,0 +1,15 @@ +# zhi-loader + +loader for zhi + +## Dev + +Run `nx dev zhi-loader` for development in siyuan-note. + +## Building + +Run `nx build zhi-loader` to build the library. + +## Running unit tests + +Run `nx test zhi-loader` to execute the unit tests via [Vitest](https://vitest.dev). diff --git a/packages/zhi-loader/package.json b/packages/zhi-loader/package.json new file mode 100644 index 00000000..846dd67c --- /dev/null +++ b/packages/zhi-loader/package.json @@ -0,0 +1,5 @@ +{ + "name": "@zhi/zhi-loager", + "version": "0.1.0", + "type": "module" +} diff --git a/packages/zhi-loader/project.json b/packages/zhi-loader/project.json new file mode 100644 index 00000000..99eb988e --- /dev/null +++ b/packages/zhi-loader/project.json @@ -0,0 +1,41 @@ +{ + "name": "zhi-loader", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "packages/zhi-loader/src", + "projectType": "library", + "targets": { + "dev": { + "executor": "@nx/vite:build", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi", + "emptyOutDir": false, + "watch": true + } + }, + "build": { + "executor": "@nx/vite:build", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/packages/zhi", + "emptyOutDir": false + } + }, + "test": { + "executor": "@nx/vite:test", + "outputs": ["coverage/packages/zhi-loader"], + "options": { + "passWithNoTests": true, + "reportsDirectory": "../../coverage/packages/zhi-loader" + } + }, + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["packages/zhi-loader/**/*.ts"] + } + } + }, + "tags": [] +} diff --git a/packages/zhi-core/public/favicon.ico b/packages/zhi-loader/public/favicon.ico similarity index 100% rename from packages/zhi-core/public/favicon.ico rename to packages/zhi-loader/public/favicon.ico diff --git a/packages/zhi-core/public/theme.json b/packages/zhi-loader/public/theme.json similarity index 100% rename from packages/zhi-core/public/theme.json rename to packages/zhi-loader/public/theme.json diff --git a/packages/zhi-loader/src/index.ts b/packages/zhi-loader/src/index.ts new file mode 100644 index 00000000..6a8bbd9e --- /dev/null +++ b/packages/zhi-loader/src/index.ts @@ -0,0 +1,41 @@ +/* + * 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. + */ + +/** + * @packageDocumentation + * zhi-loader 主题引导器 + */ + +import { zhiLoader } from "./lib/zhi-loader" + +// 主题样式注入入口 +import "./style/theme.styl" + +/** + * 主题入口,由思源笔记自动触发,请勿主动调用 + */ +;(async () => { + await zhiLoader() +})() diff --git a/packages/zhi-loader/src/lib/zhi-loader.spec.ts b/packages/zhi-loader/src/lib/zhi-loader.spec.ts new file mode 100644 index 00000000..5f36a3fc --- /dev/null +++ b/packages/zhi-loader/src/lib/zhi-loader.spec.ts @@ -0,0 +1,32 @@ +/* + * 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 { zhiLoader } from "./zhi-loader" + +describe("zhiLoader", () => { + it("zhiLoader should work", () => { + console.log("hello") + }) +}) diff --git a/packages/zhi-loader/src/lib/zhi-loader.ts b/packages/zhi-loader/src/lib/zhi-loader.ts new file mode 100644 index 00000000..4c6e3216 --- /dev/null +++ b/packages/zhi-loader/src/lib/zhi-loader.ts @@ -0,0 +1,29 @@ +/* + * 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. + */ + +export async function zhiLoader(): Promise { + const zhiCore = await import("/appearance/themes/zhi/core/index.js" as any) + await zhiCore.zhiCore() +} diff --git a/packages/zhi-core/src/style/common/basic/basic-dark.styl b/packages/zhi-loader/src/style/common/basic/basic-dark.styl similarity index 100% rename from packages/zhi-core/src/style/common/basic/basic-dark.styl rename to packages/zhi-loader/src/style/common/basic/basic-dark.styl diff --git a/packages/zhi-core/src/style/common/basic/basic-green.styl b/packages/zhi-loader/src/style/common/basic/basic-green.styl similarity index 100% rename from packages/zhi-core/src/style/common/basic/basic-green.styl rename to packages/zhi-loader/src/style/common/basic/basic-green.styl diff --git a/packages/zhi-core/src/style/common/basic/basic-light.styl b/packages/zhi-loader/src/style/common/basic/basic-light.styl similarity index 100% rename from packages/zhi-core/src/style/common/basic/basic-light.styl rename to packages/zhi-loader/src/style/common/basic/basic-light.styl diff --git a/packages/zhi-core/src/style/common/basic/index.styl b/packages/zhi-loader/src/style/common/basic/index.styl similarity index 100% rename from packages/zhi-core/src/style/common/basic/index.styl rename to packages/zhi-loader/src/style/common/basic/index.styl diff --git a/packages/zhi-core/src/style/common/fonts/README.md b/packages/zhi-loader/src/style/common/fonts/README.md similarity index 100% rename from packages/zhi-core/src/style/common/fonts/README.md rename to packages/zhi-loader/src/style/common/fonts/README.md diff --git a/packages/zhi-core/src/style/common/fonts/font.styl b/packages/zhi-loader/src/style/common/fonts/font.styl similarity index 100% rename from packages/zhi-core/src/style/common/fonts/font.styl rename to packages/zhi-loader/src/style/common/fonts/font.styl diff --git a/packages/zhi-core/src/style/common/fonts/index.styl b/packages/zhi-loader/src/style/common/fonts/index.styl similarity index 100% rename from packages/zhi-core/src/style/common/fonts/index.styl rename to packages/zhi-loader/src/style/common/fonts/index.styl diff --git a/packages/zhi-core/src/style/common/fonts/webfont.css b/packages/zhi-loader/src/style/common/fonts/webfont.css similarity index 100% rename from packages/zhi-core/src/style/common/fonts/webfont.css rename to packages/zhi-loader/src/style/common/fonts/webfont.css diff --git a/packages/zhi-core/src/style/common/global/index.styl b/packages/zhi-loader/src/style/common/global/index.styl similarity index 100% rename from packages/zhi-core/src/style/common/global/index.styl rename to packages/zhi-loader/src/style/common/global/index.styl diff --git a/packages/zhi-core/src/style/common/vars/index.styl b/packages/zhi-loader/src/style/common/vars/index.styl similarity index 100% rename from packages/zhi-core/src/style/common/vars/index.styl rename to packages/zhi-loader/src/style/common/vars/index.styl diff --git a/packages/zhi-core/src/style/common/vars/vars-blog.styl b/packages/zhi-loader/src/style/common/vars/vars-blog.styl similarity index 100% rename from packages/zhi-core/src/style/common/vars/vars-blog.styl rename to packages/zhi-loader/src/style/common/vars/vars-blog.styl diff --git a/packages/zhi-core/src/style/common/vars/vars-common.styl b/packages/zhi-loader/src/style/common/vars/vars-common.styl similarity index 100% rename from packages/zhi-core/src/style/common/vars/vars-common.styl rename to packages/zhi-loader/src/style/common/vars/vars-common.styl diff --git a/packages/zhi-core/src/style/common/vars/vars-zhi.styl b/packages/zhi-loader/src/style/common/vars/vars-zhi.styl similarity index 100% rename from packages/zhi-core/src/style/common/vars/vars-zhi.styl rename to packages/zhi-loader/src/style/common/vars/vars-zhi.styl diff --git a/packages/zhi-core/src/style/theme.styl b/packages/zhi-loader/src/style/theme.styl similarity index 100% rename from packages/zhi-core/src/style/theme.styl rename to packages/zhi-loader/src/style/theme.styl diff --git a/packages/zhi-core/src/style/theme/widgets/code-block/code-block-dark-plus-plus.styl b/packages/zhi-loader/src/style/theme/widgets/code-block/code-block-dark-plus-plus.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/code-block/code-block-dark-plus-plus.styl rename to packages/zhi-loader/src/style/theme/widgets/code-block/code-block-dark-plus-plus.styl diff --git a/packages/zhi-core/src/style/theme/widgets/code-block/code-block-dark.styl b/packages/zhi-loader/src/style/theme/widgets/code-block/code-block-dark.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/code-block/code-block-dark.styl rename to packages/zhi-loader/src/style/theme/widgets/code-block/code-block-dark.styl diff --git a/packages/zhi-core/src/style/theme/widgets/code-block/code-block-green.styl b/packages/zhi-loader/src/style/theme/widgets/code-block/code-block-green.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/code-block/code-block-green.styl rename to packages/zhi-loader/src/style/theme/widgets/code-block/code-block-green.styl diff --git a/packages/zhi-core/src/style/theme/widgets/code-block/code-block-hbuildx-light.styl b/packages/zhi-loader/src/style/theme/widgets/code-block/code-block-hbuildx-light.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/code-block/code-block-hbuildx-light.styl rename to packages/zhi-loader/src/style/theme/widgets/code-block/code-block-hbuildx-light.styl diff --git a/packages/zhi-core/src/style/theme/widgets/code-block/code-block-light.styl b/packages/zhi-loader/src/style/theme/widgets/code-block/code-block-light.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/code-block/code-block-light.styl rename to packages/zhi-loader/src/style/theme/widgets/code-block/code-block-light.styl diff --git a/packages/zhi-core/src/style/theme/widgets/code-block/code-block-print.styl b/packages/zhi-loader/src/style/theme/widgets/code-block/code-block-print.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/code-block/code-block-print.styl rename to packages/zhi-loader/src/style/theme/widgets/code-block/code-block-print.styl diff --git a/packages/zhi-core/src/style/theme/widgets/code-block/code-block-rem-craft.styl b/packages/zhi-loader/src/style/theme/widgets/code-block/code-block-rem-craft.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/code-block/code-block-rem-craft.styl rename to packages/zhi-loader/src/style/theme/widgets/code-block/code-block-rem-craft.styl diff --git a/packages/zhi-core/src/style/theme/widgets/code-block/code-block-savor.styl b/packages/zhi-loader/src/style/theme/widgets/code-block/code-block-savor.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/code-block/code-block-savor.styl rename to packages/zhi-loader/src/style/theme/widgets/code-block/code-block-savor.styl diff --git a/packages/zhi-core/src/style/theme/widgets/code-block/code-block-sofill.styl b/packages/zhi-loader/src/style/theme/widgets/code-block/code-block-sofill.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/code-block/code-block-sofill.styl rename to packages/zhi-loader/src/style/theme/widgets/code-block/code-block-sofill.styl diff --git a/packages/zhi-core/src/style/theme/widgets/code-block/index.styl b/packages/zhi-loader/src/style/theme/widgets/code-block/index.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/code-block/index.styl rename to packages/zhi-loader/src/style/theme/widgets/code-block/index.styl diff --git a/packages/zhi-core/src/style/theme/widgets/deck/index.styl b/packages/zhi-loader/src/style/theme/widgets/deck/index.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/deck/index.styl rename to packages/zhi-loader/src/style/theme/widgets/deck/index.styl diff --git a/packages/zhi-core/src/style/theme/widgets/editor/index.styl b/packages/zhi-loader/src/style/theme/widgets/editor/index.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/editor/index.styl rename to packages/zhi-loader/src/style/theme/widgets/editor/index.styl diff --git a/packages/zhi-core/src/style/theme/widgets/mobile/index.styl b/packages/zhi-loader/src/style/theme/widgets/mobile/index.styl similarity index 100% rename from packages/zhi-core/src/style/theme/widgets/mobile/index.styl rename to packages/zhi-loader/src/style/theme/widgets/mobile/index.styl diff --git a/packages/zhi-core/src/style/theme/zhi.styl b/packages/zhi-loader/src/style/theme/zhi.styl similarity index 100% rename from packages/zhi-core/src/style/theme/zhi.styl rename to packages/zhi-loader/src/style/theme/zhi.styl diff --git a/packages/zhi-loader/tsconfig.json b/packages/zhi-loader/tsconfig.json new file mode 100644 index 00000000..2eed2799 --- /dev/null +++ b/packages/zhi-loader/tsconfig.json @@ -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" + } + ] +} diff --git a/packages/zhi-loader/tsconfig.lib.json b/packages/zhi-loader/tsconfig.lib.json new file mode 100644 index 00000000..33eca2c2 --- /dev/null +++ b/packages/zhi-loader/tsconfig.lib.json @@ -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"] +} diff --git a/packages/zhi-loader/tsconfig.spec.json b/packages/zhi-loader/tsconfig.spec.json new file mode 100644 index 00000000..6d3be742 --- /dev/null +++ b/packages/zhi-loader/tsconfig.spec.json @@ -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" + ] +} diff --git a/packages/zhi-loader/vite.config.ts b/packages/zhi-loader/vite.config.ts new file mode 100644 index 00000000..760c7631 --- /dev/null +++ b/packages/zhi-loader/vite.config.ts @@ -0,0 +1,55 @@ +/// +import { defineConfig } from "vite" + +import viteTsConfigPaths from "vite-tsconfig-paths" +import livereload from "rollup-plugin-livereload" +import { argv } from "process" + +// 处理参数 +const devOutDir = "/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi" +const args: any = argv[2].startsWith("{") ? JSON.parse(argv[2]) : undefined +const isWatch = args?.targetDescription?.target === "dev" ?? false +const isProduction = !isWatch +const isTest = process.env["npm_command"] === "test" +console.log("isTest=>", isTest) +console.log("isWatch=>", isWatch) +console.log("isProduction=>", isProduction) + +export default defineConfig({ + cacheDir: "../../node_modules/.vite/zhi-loader", + + plugins: [ + !isTest && + viteTsConfigPaths({ + root: "../../", + }), + ], + + // Configuration for building your library. + // See: https://vitejs.dev/guide/build.html#library-mode + build: { + lib: { + entry: ["src/index.ts"], + formats: ["es"], + }, + + rollupOptions: { + plugins: [...(isWatch ? [livereload(devOutDir)] : [])] as Plugin[], + // External packages that should not be bundled into your library. + external: ["/appearance/themes/zhi/core/index.js"], + output: { + entryFileNames: "theme.js", + assetFileNames: "theme.css", + }, + }, + }, + + test: { + globals: true, + cache: { + dir: "../../node_modules/.vitest", + }, + environment: "jsdom", + include: ["src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"], + }, +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1e587b15..23a0d7f9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -70,6 +70,9 @@ devDependencies: stylus: specifier: ^0.59.0 version: 0.59.0 + tslib: + specifier: ^2.5.0 + version: 2.5.0 typescript: specifier: ~5.0.4 version: 5.0.4 diff --git a/tools/scripts/publish.mjs b/tools/scripts/publish.mjs new file mode 100644 index 00000000..48bc4a9d --- /dev/null +++ b/tools/scripts/publish.mjs @@ -0,0 +1,58 @@ +/** + * This is a minimal script to publish your package to "npm". + * This is meant to be used as-is or customize as you see fit. + * + * This script is executed on "dist/path/to/library" as "cwd" by default. + * + * You might need to authenticate with NPM before running this script. + */ + +import { execSync } from "child_process" +import { readFileSync, writeFileSync } from "fs" +import chalk from "chalk" + +import devkit from "@nx/devkit" +const { readCachedProjectGraph } = devkit + +function invariant(condition, message) { + if (!condition) { + console.error(chalk.bold.red(message)) + process.exit(1) + } +} + +// Executing publish script: node path/to/publish.mjs {name} --version {version} --tag {tag} +// Default "tag" to "next" so we won't publish the "latest" tag by accident. +const [, , name, version, tag = "next"] = process.argv + +// A simple SemVer validation to validate the version +const validVersion = /^\d+\.\d+\.\d+(-\w+\.\d+)?/ +invariant( + version && validVersion.test(version), + `No version provided or version did not match Semantic Versioning, expected: #.#.#-tag.# or #.#.#, got ${version}.` +) + +const graph = readCachedProjectGraph() +const project = graph.nodes[name] + +invariant(project, `Could not find project "${name}" in the workspace. Is the project.json configured correctly?`) + +const outputPath = project.data?.targets?.build?.options?.outputPath +invariant( + outputPath, + `Could not find "build.options.outputPath" of project "${name}". Is project.json configured correctly?` +) + +process.chdir(outputPath) + +// Updating the version in "package.json" before publishing +try { + const json = JSON.parse(readFileSync(`package.json`).toString()) + json.version = version + writeFileSync(`package.json`, JSON.stringify(json, null, 2)) +} catch (e) { + console.error(chalk.bold.red(`Error reading package.json file from library build output.`)) +} + +// Execute "npm publish" to publish +execSync(`npm publish --access public --tag ${tag}`) diff --git a/tsconfig.base.json b/tsconfig.base.json index 08d497f8..099f1b3c 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -16,7 +16,8 @@ "skipDefaultLibCheck": true, "baseUrl": ".", "paths": { - "@zhi/zhi-core": ["packages/zhi-core/src/index.ts"] + "@siyuan-community/zhi-core": ["packages/zhi-core/src/index.ts"], + "@zhi/zhi-loader": ["packages/zhi-loader/src/index.ts"] } }, "exclude": ["node_modules", "tmp"]