Skip to content

Commit

Permalink
feat(zhi-core): test new import map solution
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 4, 2023
1 parent 32fd3e4 commit 806ac59
Show file tree
Hide file tree
Showing 65 changed files with 652 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@siyuan-community/zhi-core",
"version": "0.0.1",
"type": "commonjs",
"main": "./src/index.js",
"types": "./src/index.d.ts"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./lib/zhi-core";

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function zhiCore(): string;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 2 additions & 6 deletions packages/zhi-core/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# 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

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).
4 changes: 2 additions & 2 deletions packages/zhi-core/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@zhi/zhi-core",
"version": "0.0.1",
"name": "@siyuan-community/zhi-core",
"version": "0.1.0",
"type": "module"
}
37 changes: 21 additions & 16 deletions packages/zhi-core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,41 @@
"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",
"outputs": ["{options.outputFile}"],
"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": []
Expand Down
17 changes: 1 addition & 16 deletions packages/zhi-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
59 changes: 59 additions & 0 deletions packages/zhi-core/src/lib/core/ZhiCoreUtil.ts
Original file line number Diff line number Diff line change
@@ -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
90 changes: 90 additions & 0 deletions packages/zhi-core/src/lib/core/zhi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
* questions.
*/

// @ts-ignore
import ZhiCoreUtil from "./ZhiCoreUtil.js"

/**
* 主题通用类(由theme.js动态调用,除了单元测试之外请勿主动调用)
*
Expand All @@ -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<void> {
//
// 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<void> {
try {
console.info("Zhi Theme inited")
} catch (e) {
console.error("Zhi Theme load error=>", e)
}
}
}

export default Zhi
2 changes: 1 addition & 1 deletion packages/zhi-core/src/lib/zhi-core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* questions.
*/

import { zhiCore } from "./zhi-core"
import { zhiCore } from "./zhi-core.js"

describe("zhiCore", () => {
it("zhiCore should work", () => {
Expand Down
Loading

0 comments on commit 806ac59

Please sign in to comment.