sys-shim 0.0.1-18 → 0.0.1-20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "sys-shim",
3
3
  "private": false,
4
4
  "type": "module",
5
- "version": "0.0.1-18",
5
+ "version": "0.0.1-20",
6
6
  "main": "./script/npm-pkg/node/main.min.cjs",
7
7
  "module": "./script/npm-pkg/node/main.min.mjs",
8
8
  "browser": {
@@ -55,23 +55,6 @@
55
55
  "after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
56
56
  }
57
57
  },
58
- "scripts": {
59
- "release": "release-it prerelease -V --ci",
60
- "sys-shim": "node ./script/npm-pkg/bin/index.mjs",
61
- "lint": "eslint ./ --format unix",
62
- "lint-fix": "eslint ./ --fix --format unix",
63
- "dev": "run-p vite run.shim",
64
- "main:build": "npx download-cli https://github.com/wll8/sys-shim/releases/download/example/main.exe -o win-api/",
65
- "vite": "vite",
66
- "test": "vitest",
67
- "test:basic": "vitest --reporter=basic",
68
- "preview": "vite preview",
69
- "gen.npm": "node script/gen.npm.mjs",
70
- "gen.npm.push": "cross-env push=yes node script/gen.npm.mjs",
71
- "gen.res": "node script/gen.res.mjs",
72
- "run.shim": "node script/run.shim.mjs",
73
- "prepare": "husky"
74
- },
75
58
  "devDependencies": {
76
59
  "@guolao/vue-monaco-editor": "^1.5.1",
77
60
  "@release-it/conventional-changelog": "^8.0.1",
@@ -92,7 +75,6 @@
92
75
  "release-it": "^17.2.1",
93
76
  "rollup": "^4.17.2",
94
77
  "rpc-websockets": "^7.6.0",
95
- "sys-shim": "link:",
96
78
  "vite": "^5.0.0",
97
79
  "vitest": "^1.6.0",
98
80
  "vue": "^3.3.8"
@@ -101,8 +83,26 @@
101
83
  "dayjs": "^1.11.11",
102
84
  "download": "^8.0.0",
103
85
  "filenamify": "^6.0.0",
86
+ "iconv-lite": "^0.6.3",
104
87
  "minimist": "^1.2.8",
105
88
  "shelljs": "^0.8.5",
106
- "shx": "^0.3.4"
89
+ "shx": "^0.3.4",
90
+ "sys-shim-bin": "0.0.2-2"
91
+ },
92
+ "scripts": {
93
+ "release": "release-it prerelease -V --ci",
94
+ "sys-shim": "node ./script/npm-pkg/bin/index.mjs",
95
+ "lint": "eslint ./ --format unix",
96
+ "lint-fix": "eslint ./ --fix --format unix",
97
+ "dev": "run-p vite run.shim",
98
+ "main:build": "npx download-cli https://github.com/wll8/sys-shim/releases/download/example/main.exe -o win-api/",
99
+ "vite": "vite",
100
+ "test": "vitest",
101
+ "test:basic": "vitest --reporter=basic",
102
+ "preview": "vite preview",
103
+ "gen.npm": "node script/gen.npm.mjs",
104
+ "gen.npm.pack": "cross-env pack=yes node script/gen.npm.mjs",
105
+ "gen.res": "node script/gen.res.mjs",
106
+ "run.shim": "node script/run.shim.mjs"
107
107
  }
108
- }
108
+ }
package/readme.md CHANGED
@@ -1,110 +1,38 @@
1
- <div align="center">
2
- <a href="https://github.com/wll8/sys-shim/blob/pre/doc.md">
3
- 文档
4
- </a>
5
- &nbsp;|&nbsp;
6
- <a href="https://github.com/wll8/sys-shim/releases/tag/example">
7
- 示例
8
- </a>
9
- </div>
1
+ # sys-shim-sdk
10
2
 
11
- <br />
3
+ ## 开发
12
4
 
13
- 简单的使用前端语言即可快速开发桌面程序,程序体积小于 1M。
5
+ ```bat
6
+ :: 启动服务端
7
+ npm run sys-shim
14
8
 
15
- ## 为什么
9
+ :: 启动前端
10
+ npx vite
16
11
 
17
- 想开发一个简单的桌面程序,只使用前端语言开发,暂只考虑在 windows 上运行,希望开发体验像在浏览器中一样,然后程序的样子像是本地应用一样,调用本地文件、系统命令、后台运行、托盘菜单这些都没有问题。
18
-
19
- [调研了一些常见的方案](#方案对比),发现他们都不适合,所以就开发了此项目 。
20
-
21
- ## 如何使用
22
-
23
- ### 方式一:直接开发
24
-
25
- 这个方式适用于体验,无需任何开发环境。
26
-
27
- - 第一步:下载 [main](https://github.com/wll8/sys-shim/releases/download/example/main.exe) 文件打开;
28
- - 第二步:当前目录生成了名为 page.html 的文件,你可以在这个文件里写界面或调用系统 API 。
29
-
30
- ### 方式二:单独引用
12
+ :: debug sdk
13
+ npm run sys-shim pack -- --input https://example.com/
14
+ ```
31
15
 
32
- - 安装: `npm i sys-shim`
33
- - 导入:
34
- - esm 方式 `import Sys from 'sys-shim'`
35
- - cjs 方式 `const Sys = require('sys-shim')`
36
- - umd 方式 `<script src="./node_modules/sys-shim/browser/main.umd.min.js"></script>`
37
- - 使用:
16
+ ## 使用
38
17
 
39
18
  ``` js
40
- new Sys('ws://127.0.0.1:10005?token=tokentokentoken').then(main => {
41
- main.native.win.msgbox(`hello`, `title`)
19
+ // npm i sys-shim
20
+
21
+ import Sys from 'sys-shim'
22
+ new Sys({
23
+ log: true,
24
+ wsUrl: 'ws://127.0.0.1:10005?token=tokentokentoken',
25
+ }).then(shim => {
26
+ shim.native.process(`notepad`) // 调用系统记事本
42
27
  })
43
28
  ```
44
29
 
45
- ### 方式三:使用脚手架模板开发
46
-
47
- - [命令行](https://wll8.github.io/sys-shim-doc/docs/cli/sys-shim.html)
48
- - 服务
49
- - 界面
50
-
51
-
52
- ## 贡献
53
-
54
- 如果你想参与这个项目的开发。
55
-
56
- node v18.19.0
30
+ ## 发布
57
31
 
58
32
  ``` bat
59
- rem 安装依赖
60
- pnpm i
61
-
62
- rem 生成库文件 sys.js
63
- pnpm gen.res
64
-
65
- rem 获取 main.exe, 可以通过编译或下载得到
66
- pnpm main:build
67
-
68
- rem 启动项目
69
- pnpm dev
70
-
71
- rem 发布 npm
72
- pnpm gen.npm.push
33
+ :: 生成 sdk 到 /store/bin/res
34
+ npm run gen.res
73
35
 
36
+ :: 生成 npm 包
37
+ npm run gen.npm.pack
74
38
  ```
75
-
76
- ## todo
77
-
78
- - [ ] fix: 当端口变更后,localstorage 等信息可能丢失
79
- - https://github.com/tauri-apps/tauri/issues/896
80
- - https://github.com/tauri-apps/tauri/commit/0d63732b962e71b98430f8d7b34ea5b59a2e8bb4?diff=split&w=0
81
- - https://github.com/tauri-apps/tauri/blob/9f75d06228fcb7036cf7a4e215abc7bc8d1a0a56/tooling/api/src/webview.ts#L613
82
- - https://github.com/maemon4095/tauri-custom-protocol
83
- - https://github.com/tauri-apps/tauri/issues/6330
84
- - https://docs.rs/tauri/latest/tauri/struct.Builder.html#method.register_uri_scheme_protocol
85
- - https://github.com/tauri-apps/tauri/issues/323
86
- - https://github.com/tauri-apps/wry/pull/65/files#diff-72a48c45fe590fb0a06f7e3635f417381ea5199505b3e8f706a54ec39211d5e1R99
87
- - https://www.electronjs.org/docs/latest/api/protocol#protocolregisterschemesasprivilegedcustomschemes
88
- - https://github.com/MicrosoftEdge/WebView2Feedback/issues/73
89
- - [ ] feat: buffer 自动转换
90
- - [ ] fix: 应正确接收稀疏返回值
91
- - 例如: `return {1, null, 3}`
92
- - [ ] feat: 流式传输数据
93
- - 例如: 实时向 native 保存下载的数据
94
- - [ ] refactor: 整理代码
95
- - [ ] 统一文档和代码中 sys-shim 的全局名称为 Sys, 实例化名称为 shim
96
- - [ ] 移除代码中的全局名称引用, 登录 window.msg, window.sys 使用当前 this 实现获取引用
97
- - [ ] 替换 doc.md 的内容为文档站点地址
98
- - [ ] 移除 App.js 中的用例
99
- - [ ] feat: 自动从终端输出中读取 url 入口
100
- - [ ] doc: 更新文档
101
- - [ ] 安装
102
- - [ ] 通过 main
103
- - [ ] 通过 nodejs
104
- - [ ] 使用本地前端代码
105
- - [ ] 使用线上 url 链接
106
- - [ ] 集成到正在开发的前端项目
107
- - [ ] 打包
108
- - [ ] 使用
109
- - [ ] 发布给用户
110
- - [ ] 报毒:因为软件的性质问题,会被误报,等到达 v1.0.0 版本之后,会向各安全平台提交核验申请,在此之前可以要求用户关闭杀毒软件或配置白名单,或自己向安全平台提审。
@@ -7,21 +7,41 @@ import { fileURLToPath } from 'node:url'
7
7
  import process from 'node:process'
8
8
  import minimist from 'minimist'
9
9
  import {fn as pack} from './pack.mjs'
10
+ import { getPath } from 'sys-shim-bin'
10
11
 
12
+ const binPath = getPath()
11
13
  const __filename = fileURLToPath(import.meta.url)
12
14
  const __dirname = path.dirname(__filename)
15
+ const pkgPath = `${__dirname}/../../../`
13
16
 
14
- const cwd = `${__dirname}/../shim/win`
17
+ const cwd = `${pkgPath}/script/npm-pkg/shim/win`
18
+ const pkg = JSON.parse(fs.readFileSync(`${pkgPath}/package.json`, `utf8`))
15
19
  const argv = minimist(process.argv.slice(2))
16
20
  const argv0 = argv._[0]
17
21
 
18
22
  new Promise(async () => {
23
+ printLogo()
19
24
  if(argv0 === `pack`) {
20
25
  await pack(argv)
21
26
  } else {
22
- cp.execSync(`${cwd}/main.exe`, {
27
+ cp.execSync(binPath, {
23
28
  cwd,
24
29
  stdio: `inherit`,
25
30
  })
26
31
  }
27
32
  })
33
+
34
+
35
+ function printLogo() {
36
+ const vTag = `version: `
37
+ const logText = fs.readFileSync(`${__dirname}/logo.txt`, `utf8`)
38
+ const versionLogo = logText.replace(new RegExp(`(${vTag})(.*)`), (match, $1, $2) => {
39
+ const vStr = pkg.version
40
+ const vLength = vStr.length
41
+ const vLine = vLength > $2.length // 如果版本号替换到版本标志后面
42
+ ? `${$1}${vStr}`
43
+ : match.replace(new RegExp(`(${vTag})(.{${vLength}})`), `$1${vStr}`)
44
+ return vLine
45
+ })
46
+ console.log(versionLogo)
47
+ }
@@ -0,0 +1,9 @@
1
+ _ _
2
+ version: 0.0.0 | | (_)
3
+ ___ _ _ ___ ______ ___| |__ _ _ __ ___
4
+ / __| | | / __|______/ __| '_ \| | '_ ` _ \
5
+ \__ \ |_| \__ \ \__ \ | | | | | | | | |
6
+ |___/\__, |___/ |___/_| |_|_|_| |_| |_|
7
+ __/ |
8
+ |___/
9
+
@@ -7,10 +7,14 @@ import os from 'node:os'
7
7
  import filenamify from 'filenamify'
8
8
  import download from 'download'
9
9
  import shelljs from 'shelljs'
10
+ import iconv from 'iconv-lite'
10
11
  import {
11
12
  simpleTemplate,
12
13
  } from '../../../src/util.js'
13
14
  import process from 'node:process'
15
+ import { getPath } from 'sys-shim-bin'
16
+
17
+ const binPath = getPath()
14
18
 
15
19
  const __filename = url.fileURLToPath(import.meta.url)
16
20
  const __dirname = path.dirname(__filename)
@@ -90,7 +94,7 @@ function zip(cfg) {
90
94
  const icon = cfg.icon
91
95
  const out = cfg.out
92
96
  const input = cfg.input
93
- const unzip = cfg.unzip
97
+ const unzip = (cfg.unzip || ``).replace(/\//g, `\\`)
94
98
  const nameSuffix = cfg.nameSuffix
95
99
 
96
100
  /**
@@ -106,14 +110,15 @@ function zip(cfg) {
106
110
  const comment = (() => {
107
111
  const file = `${os.tmpdir()}/comment.txt`
108
112
  const text = `
109
- Path=${path.normalize(unzip)}
113
+ Path=${unzip}
110
114
  Setup=main
111
115
  Silent=1
112
116
  Overwrite=1
113
117
  Update=U
114
118
  Shortcut=D, main, , "sys-shim app", "${cfg.out}", favicon.ico
115
119
  `.split(`\n`).map(item => item.trim()).join(`\n`).trim()
116
- fs.writeFileSync(file, text)
120
+ const gbkText = iconv.encode(text, `gbk`)
121
+ fs.writeFileSync(file, gbkText)
117
122
  return file
118
123
  })()
119
124
 
@@ -136,6 +141,7 @@ function zip(cfg) {
136
141
  const outName = nameSuffix ? `${out}-${dayjs(Date.now()).format(`YYYY-MM-DD-HH-mm-ss`)}` : out
137
142
  const cmd = `"${zipBin}" a -r -ep1 -y -ibck -sfx -iicon"${icon}" -z"${comment}" "${outName}" "${input}/*"`
138
143
  cp.execSync(cmd, {stdio: `inherit`})
144
+ return outName
139
145
  }
140
146
 
141
147
  function getIndex(cfg) {
@@ -155,16 +161,21 @@ function genFile(cfg) {
155
161
  shelljs.rm(`-fr`, newCfg.input)
156
162
  shelljs.mkdir(`-p`, newCfg.input)
157
163
  shelljs.cp(`-fr`, `${pkgDir}/template/pack/*`, newCfg.input)
158
- shelljs.cp(`-f`, `${pkgDir}/script/npm-pkg/shim/win/main.exe`, newCfg.input)
164
+ shelljs.cp(`-f`, binPath, newCfg.input)
159
165
  shelljs.cp(`-f`, `${pkgDir}/script/npm-pkg/shim/win/favicon.ico`, newCfg.input)
160
166
  shelljs.cp(`-f`, cfg.icon, `${newCfg.input}/favicon.ico`)
161
167
  determinePathType(cfg.input) !== `url` && fs.statSync(cfg.input).isDirectory() && shelljs.cp(`-fr`, `${cfg.input}/*`, newCfg.input)
168
+ let runConfig = {}
162
169
  if(fs.existsSync(`${cfg.input}/package.json`) === false) {
163
170
  const newStr = simpleTemplate(fs.readFileSync(`${newCfg.input}/package.json`, `utf8`), {
164
171
  page: getIndex(cfg),
165
172
  })
166
173
  fs.writeFileSync(`${newCfg.input}/package.json`, newStr)
174
+ runConfig = JSON.parse(newStr)
175
+ } else {
176
+ runConfig = require(`${cfg.input}/package.json`)
167
177
  }
178
+ console.log(`Runtime configuration:`, runConfig)
168
179
  return newCfg
169
180
  }
170
181
 
@@ -174,7 +185,7 @@ export async function fn(argv) {
174
185
  const {input, icon} = genFile(cfg)
175
186
  cfg.input = input
176
187
  cfg.icon = icon
177
- console.log(cfg)
178
- await zip(cfg)
179
-
188
+ console.log(`Program build parameters:`, cfg)
189
+ const name = await zip(cfg)
190
+ console.log(`Build results:`, [`${name}.exe`])
180
191
  }