Skip to content

Commit

Permalink
feat(zhi-electron): add electron lib
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 8, 2023
1 parent 494aea1 commit f31b90f
Show file tree
Hide file tree
Showing 20 changed files with 581 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
- [zhi-device](https://github.com/terwer/zhi/tree/main/libs/zhi-device)
- [zhi-env](https://github.com/terwer/zhi/tree/main/libs/zhi-env)
- [zhi-log](https://github.com/terwer/zhi/tree/main/libs/zhi-log)
- [zhi-cli](https://github.com/terwer/zhi/tree/main/apps/zhi-cli)
- [zhi-common](https://github.com/terwer/zhi/tree/main/apps/zhi-common)
- [zhi-blog-api](https://github.com/terwer/zhi/tree/main/apps/zhi-blog-api)
- [zhi-siyuan-api](https://github.com/terwer/zhi/tree/main/apps/zhi-siyuan-api)
- [zhi-common](https://github.com/terwer/zhi/tree/main/libs/zhi-common)
- [zhi-blog-api](https://github.com/terwer/zhi/tree/main/libs/zhi-blog-api)
- [zhi-siyuan-api](https://github.com/terwer/zhi/tree/main/libs/zhi-siyuan-api)
- [zhi-electron](https://github.com/terwer/zhi/tree/main/libs/zhi-electron)

### themes
- [zhi-theme](https://github.com/terwer/zhi-theme) - Style-based theme <sup> in progress </sup>
Expand Down
8 changes: 4 additions & 4 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
- [zhi-device](https://github.com/terwer/zhi/tree/main/libs/zhi-device)
- [zhi-env](https://github.com/terwer/zhi/tree/main/libs/zhi-env)
- [zhi-log](https://github.com/terwer/zhi/tree/main/libs/zhi-log)
- [zhi-cli](https://github.com/terwer/zhi/tree/main/apps/zhi-cli)
- [zhi-common](https://github.com/terwer/zhi/tree/main/apps/zhi-common)
- [zhi-blog-api](https://github.com/terwer/zhi/tree/main/apps/zhi-blog-api)
- [zhi-siyuan-api](https://github.com/terwer/zhi/tree/main/apps/zhi-siyuan-api)
- [zhi-common](https://github.com/terwer/zhi/tree/main/libs/zhi-common)
- [zhi-blog-api](https://github.com/terwer/zhi/tree/main/libs/zhi-blog-api)
- [zhi-siyuan-api](https://github.com/terwer/zhi/tree/main/libs/zhi-siyuan-api)
- [zhi-electron](https://github.com/terwer/zhi/tree/main/libs/zhi-electron)

### 主题
- [zhi-theme](https://github.com/terwer/zhi-theme) - 基于样式的主题 <sup>进行中</sup>
Expand Down
59 changes: 59 additions & 0 deletions libs/zhi-blog-api/vite.config.ts.timestamp-1683561924635.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// vite.config.ts
import { defineConfig } from "file:///Users/terwer/Documents/mydocs/zhi-framework/zhi/node_modules/.pnpm/registry.npmjs.org+vite@4.2.2_@types+node@18.15.11/node_modules/vite/dist/node/index.js";
import { join } from "path";
import { viteStaticCopy } from "file:///Users/terwer/Documents/mydocs/zhi-framework/zhi/node_modules/.pnpm/registry.npmjs.org+vite-plugin-static-copy@0.14.0_vite@4.2.2/node_modules/vite-plugin-static-copy/dist/index.js";
import dts from "file:///Users/terwer/Documents/mydocs/zhi-framework/zhi/node_modules/.pnpm/registry.npmjs.org+vite-plugin-dts@2.3.0_vite@4.2.2/node_modules/vite-plugin-dts/dist/index.mjs";
var __vite_injected_original_dirname = "/Users/terwer/Documents/mydocs/zhi-framework/zhi/libs/zhi-blog-api";
var vite_config_default = defineConfig({
plugins: [
dts({
entryRoot: "src",
tsConfigFilePath: join(__vite_injected_original_dirname, "tsconfig.json"),
skipDiagnostics: true
}),
// viteTsConfigPaths({
// root: "../../",
// }),
viteStaticCopy({
targets: [
{
src: "README.md",
dest: "./"
}
]
})
],
// 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",
fileName: "index",
// Change this to the formats you want to support.
// Don't forgot to update your package.json as well.
formats: ["es"]
},
rollupOptions: {
// External packages that should not be bundled into your library.
external: []
}
},
test: {
globals: true,
environment: "jsdom",
include: ["src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"]
}
});
export {
vite_config_default as default
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCIvVXNlcnMvdGVyd2VyL0RvY3VtZW50cy9teWRvY3MvemhpLWZyYW1ld29yay96aGkvbGlicy96aGktYmxvZy1hcGlcIjtjb25zdCBfX3ZpdGVfaW5qZWN0ZWRfb3JpZ2luYWxfZmlsZW5hbWUgPSBcIi9Vc2Vycy90ZXJ3ZXIvRG9jdW1lbnRzL215ZG9jcy96aGktZnJhbWV3b3JrL3poaS9saWJzL3poaS1ibG9nLWFwaS92aXRlLmNvbmZpZy50c1wiO2NvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9pbXBvcnRfbWV0YV91cmwgPSBcImZpbGU6Ly8vVXNlcnMvdGVyd2VyL0RvY3VtZW50cy9teWRvY3MvemhpLWZyYW1ld29yay96aGkvbGlicy96aGktYmxvZy1hcGkvdml0ZS5jb25maWcudHNcIjsvLy8gPHJlZmVyZW5jZSB0eXBlcz1cInZpdGVzdFwiIC8+XG5cbmltcG9ydCB7IGRlZmluZUNvbmZpZyB9IGZyb20gXCJ2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SUFDUCxJQUFJO0FBQUEsTUFDRixXQUFXO0FBQUEsTUFDWCxrQkFBa0IsS0FBSyxrQ0FBVyxlQUFlO0FBQUEsTUFDakQsaUJBQWlCO0FBQUEsSUFDbkIsQ0FBQztBQUFBO0FBQUE7QUFBQTtBQUFBLElBTUQsZUFBZTtBQUFBLE1BQ2IsU0FBUztBQUFBLFFBQ1A7QUFBQSxVQUNFLEtBQUs7QUFBQSxVQUNMLE1BQU07QUFBQSxRQUNSO0FBQUEsTUFDRjtBQUFBLElBQ0YsQ0FBQztBQUFBLEVBQ0g7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBLEVBYUEsT0FBTztBQUFBLElBQ0wsS0FBSztBQUFBO0FBQUEsTUFFSCxPQUFPO0FBQUEsTUFDUCxVQUFVO0FBQUE7QUFBQTtBQUFBLE1BR1YsU0FBUyxDQUFDLElBQUk7QUFBQSxJQUNoQjtBQUFBLElBQ0EsZUFBZTtBQUFBO0FBQUEsTUFFYixVQUFVLENBQUM7QUFBQSxJQUNiO0FBQUEsRUFDRjtBQUFBLEVBRUEsTUFBTTtBQUFBLElBQ0osU0FBUztBQUFBLElBQ1QsYUFBYTtBQUFBLElBQ2IsU0FBUyxDQUFDLHNEQUFzRDtBQUFBLEVBQ2xFO0FBQ0YsQ0FBQzsiLAogICJuYW1lcyI6IFtdCn0K
1 change: 1 addition & 0 deletions libs/zhi-electron/.env.development.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_DEBUG_MODE=true
1 change: 1 addition & 0 deletions libs/zhi-electron/.env.production.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_DEBUG_MODE=false
1 change: 1 addition & 0 deletions libs/zhi-electron/.env.test.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_DEBUG_MODE=true
5 changes: 5 additions & 0 deletions libs/zhi-electron/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
root: true,
extends: ["./node_modules/@terwer/eslint-config-custom/index.cjs"],
ignorePatterns: ["node_modules/"],
}
18 changes: 18 additions & 0 deletions libs/zhi-electron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# idea
.idea

# build
dist
lib
!src/lib
node_modules

# api-extractor
etc
temp
tsdoc-metadata.json

# env
.env.development
.env.production
.env.test
9 changes: 9 additions & 0 deletions libs/zhi-electron/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# zhi-electron
a simple api for electron

## Usage

```js
// siyuan condole
zhiWindow.openBrowserWindow("https://www.baidu.com")
```
30 changes: 30 additions & 0 deletions libs/zhi-electron/babel.config.cjs
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.
*/

const sharedConfig = require("jest-config-custom/babel.config.cjs")

module.exports = {
...sharedConfig,
}
28 changes: 28 additions & 0 deletions libs/zhi-electron/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.
*/

interface ImportMeta {
readonly env: ImportMetaEnv
}
68 changes: 68 additions & 0 deletions libs/zhi-electron/esbuild.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.
*/

const path = require("path")
const minimist = require("minimist")
const { dtsPlugin } = require("esbuild-plugin-d.ts")
const { copy } = require("esbuild-plugin-copy")

const args = minimist(process.argv.slice(2))
const isWatch = args.watch || args.w

// for outer custom output for dev
const baseDir = "./"
const distDir = isWatch ? baseDir : path.join(baseDir, "dist")

/**
* 构建配置
*/
module.exports = {
esbuildConfig: {
entryPoints: ["src/index.ts"],
outfile: path.join(distDir, "index.js"),
format: "esm",
plugins: [
dtsPlugin(),
copy({
// this is equal to process.cwd(), which means we use cwd path as base path to resolve `to` path
// if not specified, this plugin uses ESBuild.build outdir/outfile options as base path.
resolveFrom: "cwd",
assets: [
// copy folder
{
from: "./public/**/*",
to: [distDir],
},
// copy one file
{
from: ["./README.md"],
to: [path.join(distDir, "/README.md")],
},
],
watch: true,
}),
],
},
}
33 changes: 33 additions & 0 deletions libs/zhi-electron/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "zhi-electron",
"version": "0.1.0",
"type": "module",
"description": "a simple api for electron",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"repository": "terwer/zhi",
"homepage": "https://github.com/terwer/zhi/tree/main/libs/zhi-electron",
"author": "terwer",
"license": "GPL",
"keywords": [
"zhi",
"server",
"electron"
],
"scripts": {
"dev": "zhi-build --watch",
"build": "zhi-build --production"
},
"devDependencies": {
"@terwer/esbuild-config-custom": "workspace:*",
"@terwer/eslint-config-custom": "workspace:*",
"@terwer/vitest-config-custom": "workspace:*",
"@terwer/tsconfig": "workspace:*"
},
"dependencies": {
"zhi-env": "workspace:*",
"zhi-log": "workspace:*",
"zhi-device": "workspace:*",
"zhi-common": "workspace:*"
}
}
32 changes: 32 additions & 0 deletions libs/zhi-electron/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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 { describe, it } from "vitest"

describe("zhi-server-electron", () => {
it("index", () => {
console.log("hello world")
})
})
12 changes: 12 additions & 0 deletions libs/zhi-electron/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ZhiBrowserWindow from "./lib/browser-window"

/**
* zhi-server-electron 入口
*/
const init = () => {
const zhiBrowserWindow = new ZhiBrowserWindow()
zhiBrowserWindow.initBrowserWindow()
return "ok"
}

export default init
Loading

0 comments on commit f31b90f

Please sign in to comment.