fix: 星云SDK支持纯web
This commit is contained in:
parent
ad0555da60
commit
8702c936a5
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
.idea
|
||||
node_modules
|
||||
dist
|
||||
|
||||
@ -13,7 +13,7 @@ import {
|
||||
closeBLEConnection,
|
||||
searchAndConnectDevice,
|
||||
writeBLECharacteristicValue
|
||||
} from '@/starCloud/uni/basic'
|
||||
} from './uni/basic'
|
||||
import {
|
||||
addCustomPasswordRequest,
|
||||
changeAdminKeyboardPwdRequest,
|
||||
|
||||
101
obfuscate.js
Normal file
101
obfuscate.js
Normal file
@ -0,0 +1,101 @@
|
||||
const JavaScriptObfuscator = require('javascript-obfuscator')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const ignore = require('ignore')
|
||||
|
||||
const sourceDir = __dirname
|
||||
const distDir = path.join(__dirname, 'dist')
|
||||
const gitignorePath = path.join(__dirname, '.gitignore')
|
||||
|
||||
// 定义需要排除的文件和文件夹
|
||||
const excludedFilesAndDirs = [distDir, 'node_modules']
|
||||
|
||||
// 将 .gitignore 路径转换为相对路径
|
||||
const relativeGitignorePath = path.relative(sourceDir, gitignorePath)
|
||||
|
||||
// 读取 .gitignore 文件并解析
|
||||
const ig = ignore().add(fs.readFileSync(gitignorePath, 'utf-8'))
|
||||
|
||||
// 创建目录
|
||||
const createDir = dir => {
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true })
|
||||
}
|
||||
}
|
||||
|
||||
// 处理文件
|
||||
const processFile = (filePath, targetPath) => {
|
||||
const code = fs.readFileSync(filePath, 'utf-8')
|
||||
|
||||
if (!code.trim()) {
|
||||
console.log(`跳过空文件: ${filePath}`)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const obfuscatedCode = JavaScriptObfuscator.obfuscate(code, {
|
||||
compact: true,
|
||||
controlFlowFlattening: true,
|
||||
deadCodeInjection: true,
|
||||
stringArray: true,
|
||||
stringArrayEncoding: ['base64'],
|
||||
stringArrayThreshold: 0.75
|
||||
}).getObfuscatedCode()
|
||||
|
||||
fs.writeFileSync(targetPath, obfuscatedCode)
|
||||
console.log(`混淆完成: ${filePath}`)
|
||||
} catch (error) {
|
||||
console.error(`混淆失败: ${filePath}`)
|
||||
console.error(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历并处理文件
|
||||
const traverseAndProcess = (currentDir, targetDir) => {
|
||||
createDir(targetDir)
|
||||
|
||||
fs.readdirSync(currentDir).forEach(file => {
|
||||
const sourcePath = path.join(currentDir, file)
|
||||
const targetPath = path.join(targetDir, file)
|
||||
const stats = fs.statSync(sourcePath)
|
||||
|
||||
// 如果是 node_modules 文件夹或者被 .gitignore 忽略的文件或文件夹,跳过
|
||||
if (
|
||||
sourcePath.includes('node_modules') || // 排除 node_modules 文件夹
|
||||
ig.ignores(path.relative(sourceDir, sourcePath)) || // 过滤 .gitignore 忽略的文件
|
||||
excludedFilesAndDirs.some(excludedPath => sourcePath.startsWith(excludedPath)) // 排除其他指定路径
|
||||
) {
|
||||
console.log(`跳过文件或文件夹: ${sourcePath}`)
|
||||
return
|
||||
}
|
||||
|
||||
// 针对 web/index.js 文件,不进行混淆,直接复制到 dist 目录
|
||||
if (sourcePath === path.join(__dirname, 'web', 'index.js')) {
|
||||
console.log(`复制入口文件: ${sourcePath}`)
|
||||
fs.copyFileSync(sourcePath, targetPath)
|
||||
return
|
||||
}
|
||||
|
||||
// 对其他 JS 文件进行混淆
|
||||
if (stats.isDirectory()) {
|
||||
traverseAndProcess(sourcePath, targetPath)
|
||||
} else if (sourcePath.endsWith('.js')) {
|
||||
processFile(sourcePath, targetPath)
|
||||
} else if (sourcePath.endsWith('.json')) {
|
||||
console.log(`跳过 JSON 文件: ${sourcePath}`)
|
||||
fs.copyFileSync(sourcePath, targetPath)
|
||||
} else {
|
||||
console.log(`跳过非 JS 文件: ${sourcePath}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 清理已存在的 dist 目录
|
||||
if (fs.existsSync(distDir)) {
|
||||
fs.rmSync(distDir, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
createDir(distDir)
|
||||
traverseAndProcess(sourceDir, distDir)
|
||||
|
||||
console.log('混淆完成,输出目录为 dist!')
|
||||
1219
package-lock.json
generated
Normal file
1219
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
19
package.json
Normal file
19
package.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "star-cloud",
|
||||
"version": "1.0.2",
|
||||
"main": "./web/index.js",
|
||||
"author": "zzc059",
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"build": "node obfuscate.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"buffer": "^6.0.3",
|
||||
"crc": "^4.3.2",
|
||||
"js-md5": "^0.8.3",
|
||||
"sm-crypto": "^0.3.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"javascript-obfuscator": "^4.1.1"
|
||||
}
|
||||
}
|
||||
@ -47,7 +47,7 @@ export const getOfflinePassword = async params => {
|
||||
* 移除坏锁
|
||||
* @param params
|
||||
* @param {AccountInfo} params.accountInfo 账号信息
|
||||
* @param {List[int]} params.lockIds 锁Id列表
|
||||
* @param {Array[int]} params.lockIds 锁Id列表
|
||||
* @returns Result
|
||||
*/
|
||||
export const removeBadLock = async params => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user