sys-shim 0.0.1-23 → 0.0.1-6
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 +7 -58
- package/readme.md +61 -25
- package/script/bin/sys-shim.cjs +6 -0
- package/script/npm-pkg/browser/main.esm.min.js +3 -3
- package/script/npm-pkg/browser/main.umd.min.js +3 -3
- package/script/npm-pkg/node/main.min.cjs +1 -1
- package/script/npm-pkg/node/main.min.mjs +1 -1
- package/script/npm-pkg/shim/win/main.exe +0 -0
- package/script/npm-pkg/bin/index.mjs +0 -47
- package/script/npm-pkg/bin/logo.txt +0 -9
- package/script/npm-pkg/bin/pack.mjs +0 -192
- package/script/npm-pkg/lib/winrar/x32/Default.SFX +0 -0
- package/script/npm-pkg/lib/winrar/x32/WinCon.SFX +0 -0
- package/script/npm-pkg/lib/winrar/x32/WinRAR.exe +0 -0
- package/script/npm-pkg/lib/winrar/x32/Zip.SFX +0 -0
- package/script/npm-pkg/lib/winrar/x64/Default.SFX +0 -0
- package/script/npm-pkg/lib/winrar/x64/Default64.SFX +0 -0
- package/script/npm-pkg/lib/winrar/x64/WinCon.SFX +0 -0
- package/script/npm-pkg/lib/winrar/x64/WinCon64.SFX +0 -0
- package/script/npm-pkg/lib/winrar/x64/WinRAR.exe +0 -0
- package/script/npm-pkg/lib/winrar/x64/Zip.SFX +0 -0
- package/script/npm-pkg/lib/winrar/x64/Zip64.SFX +0 -0
- package/script/npm-pkg/shim/win/favicon.ico +0 -0
- package/src/proxy-deep.js +0 -104
- package/src/util.js +0 -395
- package/template/pack/package.json +0 -8
- package/template/pack/preload.js +0 -9
- package/template/pack/readme.md +0 -6
Binary file
|
@@ -1,47 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
|
3
|
-
import cp from 'node:child_process'
|
4
|
-
import fs from 'node:fs'
|
5
|
-
import path from 'node:path'
|
6
|
-
import { fileURLToPath } from 'node:url'
|
7
|
-
import process from 'node:process'
|
8
|
-
import minimist from 'minimist'
|
9
|
-
import {fn as pack} from './pack.mjs'
|
10
|
-
import { getPath } from 'sys-shim-bin'
|
11
|
-
|
12
|
-
const binPath = getPath()
|
13
|
-
const __filename = fileURLToPath(import.meta.url)
|
14
|
-
const __dirname = path.dirname(__filename)
|
15
|
-
const pkgPath = `${__dirname}/../../../`
|
16
|
-
|
17
|
-
const cwd = `${pkgPath}/script/npm-pkg/shim/win`
|
18
|
-
const pkg = JSON.parse(fs.readFileSync(`${pkgPath}/package.json`, `utf8`))
|
19
|
-
const argv = minimist(process.argv.slice(2))
|
20
|
-
const argv0 = argv._[0]
|
21
|
-
|
22
|
-
new Promise(async () => {
|
23
|
-
printLogo()
|
24
|
-
if(argv0 === `pack`) {
|
25
|
-
await pack(argv)
|
26
|
-
} else {
|
27
|
-
cp.execSync(binPath, {
|
28
|
-
cwd,
|
29
|
-
stdio: `inherit`,
|
30
|
-
})
|
31
|
-
}
|
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
|
-
}
|
@@ -1,192 +0,0 @@
|
|
1
|
-
import cp from 'node:child_process'
|
2
|
-
import fs from 'node:fs'
|
3
|
-
import dayjs from 'dayjs'
|
4
|
-
import path from 'node:path'
|
5
|
-
import url from 'node:url'
|
6
|
-
import os from 'node:os'
|
7
|
-
import filenamify from 'filenamify'
|
8
|
-
import download from 'download'
|
9
|
-
import shelljs from 'shelljs'
|
10
|
-
import iconv from 'iconv-lite'
|
11
|
-
import {
|
12
|
-
simpleTemplate,
|
13
|
-
} from '../../../src/util.js'
|
14
|
-
import process from 'node:process'
|
15
|
-
import { getPath } from 'sys-shim-bin'
|
16
|
-
|
17
|
-
const binPath = getPath()
|
18
|
-
|
19
|
-
const __filename = url.fileURLToPath(import.meta.url)
|
20
|
-
const __dirname = path.dirname(__filename)
|
21
|
-
const pkgDir = path.join(__dirname, `../../../`)
|
22
|
-
|
23
|
-
function determinePathType(filePath) {
|
24
|
-
if((/^(http:\/\/|https:\/\/).+/i).test(filePath)) {
|
25
|
-
return `url`
|
26
|
-
} else if (path.isAbsolute(filePath)) {
|
27
|
-
return `abs`
|
28
|
-
} else if (filePath.startsWith(`./`) || filePath.startsWith(`../`)) {
|
29
|
-
return `relative`
|
30
|
-
} else {
|
31
|
-
return `sys`
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
/**
|
37
|
-
* 获取默认配置
|
38
|
-
*/
|
39
|
-
async function parseArgv(argv) {
|
40
|
-
const cfg = {
|
41
|
-
nameSuffix: true,
|
42
|
-
input: ``,
|
43
|
-
binPath: ``,
|
44
|
-
icon: ``,
|
45
|
-
out: ``,
|
46
|
-
unzip: ``,
|
47
|
-
password: ``,
|
48
|
-
...argv,
|
49
|
-
}
|
50
|
-
if(determinePathType(argv.input) === `url`) {
|
51
|
-
cfg.icon = cfg.icon || await getIcon(`${cfg.input}/favicon.ico`)
|
52
|
-
cfg.out = cfg.out || filenamify(cfg.input)
|
53
|
-
} else {
|
54
|
-
cfg.icon = cfg.icon || await getIcon(`${cfg.input}/favicon.ico`)
|
55
|
-
cfg.out = cfg.out || path.parse(cfg.input).name
|
56
|
-
}
|
57
|
-
cfg.unzip = argv.unzip || `sys-shim-app/${cfg.out}`
|
58
|
-
return cfg
|
59
|
-
}
|
60
|
-
|
61
|
-
/**
|
62
|
-
* 如果不存在 icon 则返回默认 icon
|
63
|
-
*/
|
64
|
-
async function getIcon(iconPath) {
|
65
|
-
if(fs.existsSync(iconPath)) {
|
66
|
-
return iconPath
|
67
|
-
} else {
|
68
|
-
let icon = iconPath
|
69
|
-
try {
|
70
|
-
if(determinePathType(iconPath) === `url`) {
|
71
|
-
const res = new url.URL(iconPath)
|
72
|
-
icon = `${res.protocol}//${res.host}/favicon.ico`
|
73
|
-
const tempIcon = `${os.tmpdir()}/${filenamify(icon)}`
|
74
|
-
fs.writeFileSync(tempIcon, await download(icon))
|
75
|
-
if(fs.readFileSync(tempIcon, `utf8`).match(/<html[\s\S]*<\/html/i)) {
|
76
|
-
throw new Error(`非图片文件`)
|
77
|
-
} else {
|
78
|
-
return tempIcon
|
79
|
-
}
|
80
|
-
} else if(fs.existsSync(iconPath) === false) {
|
81
|
-
throw new Error(`文件不存在`)
|
82
|
-
}
|
83
|
-
} catch (error) {
|
84
|
-
console.warn(`从 ${icon} 获取图标错误:`)
|
85
|
-
console.warn(String(error))
|
86
|
-
console.warn(`将使用默认图标`)
|
87
|
-
return `${pkgDir}/script/npm-pkg/shim/win/favicon.ico`
|
88
|
-
}
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
function zip(cfg) {
|
93
|
-
const archDir = process.arch === `x64` ? `x64` : `x32`
|
94
|
-
const zipBin = `${pkgDir}/script/npm-pkg/lib/winrar/${archDir}/WinRAR.exe`
|
95
|
-
const icon = cfg.icon
|
96
|
-
const out = cfg.out
|
97
|
-
const input = cfg.input
|
98
|
-
const unzip = (cfg.unzip || ``).replace(/\//g, `\\`)
|
99
|
-
const nameSuffix = cfg.nameSuffix
|
100
|
-
|
101
|
-
/**
|
102
|
-
* Path 解压后运行
|
103
|
-
* Silent 解压对话框 1 隐藏 2 显示
|
104
|
-
* Overwrite 解压覆盖询问 0 询问 1 覆盖 2 跳过
|
105
|
-
* Update 更新 U 解压不存在的或较新的 F 只更新目标位置已存在的
|
106
|
-
* Shortcut 创建快捷方式
|
107
|
-
* D 桌面创建
|
108
|
-
* P 在开始菜单/程序中创建
|
109
|
-
* T 在启动菜单中创建
|
110
|
-
*/
|
111
|
-
const comment = (() => {
|
112
|
-
const file = `${os.tmpdir()}/comment.txt`
|
113
|
-
const text = `
|
114
|
-
Path=${unzip}
|
115
|
-
Setup=main
|
116
|
-
Silent=1
|
117
|
-
Overwrite=1
|
118
|
-
Update=U
|
119
|
-
Shortcut=D, main, , "sys-shim app", "${cfg.out}", favicon.ico
|
120
|
-
`.split(`\n`).map(item => item.trim()).join(`\n`).trim()
|
121
|
-
const gbkText = iconv.encode(text, `gbk`)
|
122
|
-
fs.writeFileSync(file, gbkText)
|
123
|
-
return file
|
124
|
-
})()
|
125
|
-
|
126
|
-
/**
|
127
|
-
* a 添加压缩
|
128
|
-
* -r 递归
|
129
|
-
* -ep1 从名称中排除主文件夹
|
130
|
-
* -inul 关闭错误信息
|
131
|
-
* -y 假设全部的询问回应皆为“是”
|
132
|
-
* -sfx 创建自解压文件 默认为 Default.SFX 模块,修改示例 -sfxWinCon.SFX
|
133
|
-
* -iicon 指定自解压图标
|
134
|
-
* -iimg 指定自解压图片
|
135
|
-
* -m 设置压缩等级,-m0 为存储,-m5 为最优,默认 -m3 标准
|
136
|
-
* -p 使用密码,例如 -pMyPassWord
|
137
|
-
* -hp 使用密码,并加密文件名
|
138
|
-
* -z 从文件中读取注释
|
139
|
-
* -ibck 在后台运行 WinRAR
|
140
|
-
* -idv 显示详细输出
|
141
|
-
*/
|
142
|
-
const outName = nameSuffix ? `${out}-${dayjs(Date.now()).format(`YYYY-MM-DD-HH-mm-ss`)}` : out
|
143
|
-
const cmd = `"${zipBin}" a -r -ep1 -y -ibck -sfx -iicon"${icon}" -z"${comment}" "${outName}" "${input}/*"`
|
144
|
-
cp.execSync(cmd, {stdio: `inherit`})
|
145
|
-
return outName
|
146
|
-
}
|
147
|
-
|
148
|
-
function getIndex(cfg) {
|
149
|
-
if(determinePathType(cfg.input) === `url`) {
|
150
|
-
return cfg.input
|
151
|
-
} else {
|
152
|
-
const indexFile = `index.html`
|
153
|
-
return fs.existsSync(`${cfg.input}/${indexFile}`) ? indexFile : `page.html`
|
154
|
-
}
|
155
|
-
}
|
156
|
-
|
157
|
-
function genFile(cfg) {
|
158
|
-
const newCfg = {
|
159
|
-
input: `${os.tmpdir()}/pack.temp`,
|
160
|
-
icon: `${os.tmpdir()}/pack.temp/favicon.ico`,
|
161
|
-
}
|
162
|
-
shelljs.rm(`-fr`, newCfg.input)
|
163
|
-
shelljs.mkdir(`-p`, newCfg.input)
|
164
|
-
shelljs.cp(`-fr`, `${pkgDir}/template/pack/*`, newCfg.input)
|
165
|
-
shelljs.cp(`-f`, cfg.binPath || binPath, newCfg.input)
|
166
|
-
shelljs.cp(`-f`, `${pkgDir}/script/npm-pkg/shim/win/favicon.ico`, newCfg.input)
|
167
|
-
shelljs.cp(`-f`, cfg.icon, `${newCfg.input}/favicon.ico`)
|
168
|
-
determinePathType(cfg.input) !== `url` && fs.statSync(cfg.input).isDirectory() && shelljs.cp(`-fr`, `${cfg.input}/*`, newCfg.input)
|
169
|
-
let runConfig = {}
|
170
|
-
if(fs.existsSync(`${cfg.input}/package.json`) === false) {
|
171
|
-
const newStr = simpleTemplate(fs.readFileSync(`${newCfg.input}/package.json`, `utf8`), {
|
172
|
-
page: getIndex(cfg),
|
173
|
-
})
|
174
|
-
fs.writeFileSync(`${newCfg.input}/package.json`, newStr)
|
175
|
-
runConfig = JSON.parse(newStr)
|
176
|
-
} else {
|
177
|
-
runConfig = JSON.parse(fs.readFileSync(`${cfg.input}/package.json`, `utf8`))
|
178
|
-
}
|
179
|
-
console.log(`Runtime configuration:`, runConfig)
|
180
|
-
return newCfg
|
181
|
-
}
|
182
|
-
|
183
|
-
|
184
|
-
export async function fn(argv) {
|
185
|
-
const cfg = await parseArgv(argv)
|
186
|
-
const {input, icon} = genFile(cfg)
|
187
|
-
cfg.input = input
|
188
|
-
cfg.icon = icon
|
189
|
-
console.log(`Program build parameters:`, cfg)
|
190
|
-
const name = await zip(cfg)
|
191
|
-
console.log(`Build results:`, [`${name}.exe`])
|
192
|
-
}
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
package/src/proxy-deep.js
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
'use strict'
|
2
|
-
|
3
|
-
function parsePath(text) {
|
4
|
-
return text.split(`.`)
|
5
|
-
}
|
6
|
-
|
7
|
-
function push(arr, el) {
|
8
|
-
const newArr = arr.slice()
|
9
|
-
newArr.push(el)
|
10
|
-
return newArr
|
11
|
-
}
|
12
|
-
|
13
|
-
// names of the traps that can be registered with ES6's Proxy object
|
14
|
-
const trapNames = [
|
15
|
-
`apply`,
|
16
|
-
`construct`,
|
17
|
-
`defineProperty`,
|
18
|
-
`deleteProperty`,
|
19
|
-
`enumerate`,
|
20
|
-
`get`,
|
21
|
-
`getOwnPropertyDescriptor`,
|
22
|
-
`getPrototypeOf`,
|
23
|
-
`has`,
|
24
|
-
`isExtensible`,
|
25
|
-
`ownKeys`,
|
26
|
-
`preventExtensions`,
|
27
|
-
`set`,
|
28
|
-
`setPrototypeOf`,
|
29
|
-
]
|
30
|
-
|
31
|
-
// a list of paramer indexes that indicate that the a recieves a key at that parameter
|
32
|
-
// this information will be used to update the path accordingly
|
33
|
-
const keys = {
|
34
|
-
get: 1,
|
35
|
-
set: 1,
|
36
|
-
deleteProperty: 1,
|
37
|
-
has: 1,
|
38
|
-
defineProperty: 1,
|
39
|
-
getOwnPropertyDescriptor: 1,
|
40
|
-
}
|
41
|
-
|
42
|
-
export function DeepProxy(rootTarget, traps, options) {
|
43
|
-
|
44
|
-
let path = []
|
45
|
-
let _userData = {}
|
46
|
-
|
47
|
-
if (options !== undefined && typeof options.path !== `undefined`) {
|
48
|
-
path = parsePath(options.path)
|
49
|
-
}
|
50
|
-
if (options !== undefined && typeof options.userData !== `undefined`) {
|
51
|
-
_userData = options.userData
|
52
|
-
}
|
53
|
-
|
54
|
-
function createProxy(target, path, userData = {}) {
|
55
|
-
|
56
|
-
// avoid creating a new object between two traps
|
57
|
-
const context = { rootTarget, path }
|
58
|
-
Object.assign(context, _userData, userData)
|
59
|
-
|
60
|
-
const realTraps = {}
|
61
|
-
|
62
|
-
for (const trapName of trapNames) {
|
63
|
-
const keyParamIdx = keys[trapName]
|
64
|
-
, trap = traps[trapName]
|
65
|
-
|
66
|
-
if (typeof trap !== `undefined`) {
|
67
|
-
|
68
|
-
if (typeof keyParamIdx !== `undefined`) {
|
69
|
-
|
70
|
-
realTraps[trapName] = function () {
|
71
|
-
|
72
|
-
const key = arguments[keyParamIdx]
|
73
|
-
|
74
|
-
// update context for this trap
|
75
|
-
context.nest = function (nestedTarget, { userData = {} } = {}) {
|
76
|
-
if (nestedTarget === undefined)
|
77
|
-
nestedTarget = rootTarget
|
78
|
-
return createProxy(nestedTarget, push(path, key), userData)
|
79
|
-
}
|
80
|
-
return trap.apply(context, arguments)
|
81
|
-
}
|
82
|
-
} else {
|
83
|
-
|
84
|
-
realTraps[trapName] = function () {
|
85
|
-
|
86
|
-
// update context for this trap
|
87
|
-
context.nest = function (nestedTarget, { userData = {} } = {}) {
|
88
|
-
if (nestedTarget === undefined)
|
89
|
-
nestedTarget = {}
|
90
|
-
return createProxy(nestedTarget, path, userData)
|
91
|
-
}
|
92
|
-
|
93
|
-
return trap.apply(context, arguments)
|
94
|
-
}
|
95
|
-
}
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
return new Proxy(target, realTraps)
|
100
|
-
}
|
101
|
-
|
102
|
-
return createProxy(rootTarget, path)
|
103
|
-
|
104
|
-
}
|