fix: 星云SDK支持纯web
This commit is contained in:
parent
50954e4158
commit
aeea6d5b4a
@ -7,7 +7,7 @@ import {
|
|||||||
timestampToArray,
|
timestampToArray,
|
||||||
uint8ArrayToString
|
uint8ArrayToString
|
||||||
} from './format'
|
} from './format'
|
||||||
import { buildNumber, configs, version } from './env'
|
import { configs } from './env'
|
||||||
import { cmdIds, Result, subCmdIds } from './constant'
|
import { cmdIds, Result, subCmdIds } from './constant'
|
||||||
import {
|
import {
|
||||||
closeBLEConnection,
|
closeBLEConnection,
|
||||||
@ -28,7 +28,7 @@ import {
|
|||||||
updatePasswordRequest,
|
updatePasswordRequest,
|
||||||
uploadRecordRequest
|
uploadRecordRequest
|
||||||
} from './api'
|
} from './api'
|
||||||
import { getStorage, setStorage } from './export'
|
import { buildNumber, getStorage, setStorage, version } from './export'
|
||||||
import log from './log'
|
import log from './log'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
13
env.js
13
env.js
@ -1,7 +1,12 @@
|
|||||||
// 版本号
|
// uni版本号
|
||||||
export const version = '1.0.0'
|
export const uniVersion = '1.0.0'
|
||||||
// 构建号
|
// uni构建号
|
||||||
export const buildNumber = 1
|
export const uniBuildNumber = 1
|
||||||
|
|
||||||
|
// web版本号
|
||||||
|
export const webVersion = '1.0.0'
|
||||||
|
// web构建号
|
||||||
|
export const webBuildNumber = 1
|
||||||
|
|
||||||
// 环境配置
|
// 环境配置
|
||||||
export const configs = {
|
export const configs = {
|
||||||
|
|||||||
19
export.js
19
export.js
@ -3,6 +3,7 @@ import { getStorageWeb, removeStorageWeb, setStorageWeb } from './web/storage'
|
|||||||
import requestUni from './uni/request'
|
import requestUni from './uni/request'
|
||||||
import requestWeb from './web/request'
|
import requestWeb from './web/request'
|
||||||
import starCloudInstance from './star-cloud'
|
import starCloudInstance from './star-cloud'
|
||||||
|
import { uniBuildNumber, uniVersion, webBuildNumber, webVersion } from './env'
|
||||||
|
|
||||||
export const setStorage = (key, value) => {
|
export const setStorage = (key, value) => {
|
||||||
if (starCloudInstance.platform === 1) {
|
if (starCloudInstance.platform === 1) {
|
||||||
@ -39,3 +40,21 @@ export const request = async params => {
|
|||||||
return await requestWeb(params)
|
return await requestWeb(params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const version = () => {
|
||||||
|
if (starCloudInstance.platform === 1) {
|
||||||
|
return uniVersion
|
||||||
|
}
|
||||||
|
if (starCloudInstance.platform === 2) {
|
||||||
|
return webVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const buildNumber = () => {
|
||||||
|
if (starCloudInstance.platform === 1) {
|
||||||
|
return uniBuildNumber
|
||||||
|
}
|
||||||
|
if (starCloudInstance.platform === 2) {
|
||||||
|
return webBuildNumber
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,18 +1,17 @@
|
|||||||
const JavaScriptObfuscator = require('javascript-obfuscator')
|
import JavaScriptObfuscator from 'javascript-obfuscator'
|
||||||
const fs = require('fs')
|
import fs from 'fs'
|
||||||
const path = require('path')
|
import path from 'path'
|
||||||
const ignore = require('ignore')
|
import ignore from 'ignore'
|
||||||
|
import { uniVersion } from './env.js' // 导入 webVersion
|
||||||
|
|
||||||
const sourceDir = __dirname
|
// 获取当前目录和构建目标目录
|
||||||
const distDir = path.join(__dirname, 'dist')
|
const sourceDir = path.dirname(new URL(import.meta.url).pathname)
|
||||||
const gitignorePath = path.join(__dirname, '.gitignore')
|
const distDir = path.join(sourceDir, 'dist')
|
||||||
|
const gitignorePath = path.join(sourceDir, '.gitignore')
|
||||||
|
|
||||||
// 定义需要排除的文件和文件夹
|
// 定义需要排除的文件和文件夹
|
||||||
const excludedFilesAndDirs = [distDir, 'node_modules']
|
const excludedFilesAndDirs = [distDir, 'node_modules']
|
||||||
|
|
||||||
// 将 .gitignore 路径转换为相对路径
|
|
||||||
const relativeGitignorePath = path.relative(sourceDir, gitignorePath)
|
|
||||||
|
|
||||||
// 读取 .gitignore 文件并解析
|
// 读取 .gitignore 文件并解析
|
||||||
const ig = ignore().add(fs.readFileSync(gitignorePath, 'utf-8'))
|
const ig = ignore().add(fs.readFileSync(gitignorePath, 'utf-8'))
|
||||||
|
|
||||||
@ -23,6 +22,19 @@ const createDir = dir => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修改 package.json 文件
|
||||||
|
const updatePackageJsonForWeb = () => {
|
||||||
|
const packageJsonPath = path.join(sourceDir, 'package.json')
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
|
||||||
|
|
||||||
|
packageJson.name = 'star-cloud-uni'
|
||||||
|
packageJson.main = './uni/index.js'
|
||||||
|
packageJson.version = uniVersion
|
||||||
|
|
||||||
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
||||||
|
console.log('Uni build configuration updated in package.json!')
|
||||||
|
}
|
||||||
|
|
||||||
// 处理文件
|
// 处理文件
|
||||||
const processFile = (filePath, targetPath) => {
|
const processFile = (filePath, targetPath) => {
|
||||||
const code = fs.readFileSync(filePath, 'utf-8')
|
const code = fs.readFileSync(filePath, 'utf-8')
|
||||||
@ -69,13 +81,27 @@ const traverseAndProcess = (currentDir, targetDir) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 针对 web/index.js 文件,不进行混淆,直接复制到 dist 目录
|
// 针对 uni/index.js 文件,不进行混淆,直接复制到 dist 目录
|
||||||
if (sourcePath === path.join(__dirname, 'uni', 'index.js')) {
|
if (sourcePath === path.join(sourceDir, 'uni', 'index.js')) {
|
||||||
console.log(`复制入口文件: ${sourcePath}`)
|
console.log(`复制入口文件: ${sourcePath}`)
|
||||||
fs.copyFileSync(sourcePath, targetPath)
|
fs.copyFileSync(sourcePath, targetPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sourcePath === path.join(sourceDir, 'constant.js')) {
|
||||||
|
console.log(`复制入口文件: ${sourcePath}`)
|
||||||
|
fs.copyFileSync(sourcePath, targetPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 针对 uni.md 文件,直接复制到 dist 目录,并重命名为 README.md
|
||||||
|
if (sourcePath === path.join(sourceDir, 'uni.md')) {
|
||||||
|
console.log(`复制 uni.md 文件并重命名为 README.md: ${sourcePath}`)
|
||||||
|
const readmePath = path.join(targetDir, 'README.md')
|
||||||
|
fs.copyFileSync(sourcePath, readmePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 对其他 JS 文件进行混淆
|
// 对其他 JS 文件进行混淆
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
traverseAndProcess(sourcePath, targetPath)
|
traverseAndProcess(sourcePath, targetPath)
|
||||||
@ -96,6 +122,7 @@ if (fs.existsSync(distDir)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createDir(distDir)
|
createDir(distDir)
|
||||||
|
updatePackageJsonForWeb() // 在开始混淆前先修改 package.json
|
||||||
traverseAndProcess(sourceDir, distDir)
|
traverseAndProcess(sourceDir, distDir)
|
||||||
|
|
||||||
console.log('混淆完成,输出目录为 dist!')
|
console.log('混淆完成,输出目录为 dist!')
|
||||||
|
|||||||
@ -1,18 +1,17 @@
|
|||||||
const JavaScriptObfuscator = require('javascript-obfuscator')
|
import JavaScriptObfuscator from 'javascript-obfuscator'
|
||||||
const fs = require('fs')
|
import fs from 'fs'
|
||||||
const path = require('path')
|
import path from 'path'
|
||||||
const ignore = require('ignore')
|
import ignore from 'ignore'
|
||||||
|
import { webVersion } from './env.js' // 导入 webVersion
|
||||||
|
|
||||||
const sourceDir = __dirname
|
// 获取当前目录和构建目标目录
|
||||||
const distDir = path.join(__dirname, 'dist')
|
const sourceDir = path.dirname(new URL(import.meta.url).pathname)
|
||||||
const gitignorePath = path.join(__dirname, '.gitignore')
|
const distDir = path.join(sourceDir, 'dist')
|
||||||
|
const gitignorePath = path.join(sourceDir, '.gitignore')
|
||||||
|
|
||||||
// 定义需要排除的文件和文件夹
|
// 定义需要排除的文件和文件夹
|
||||||
const excludedFilesAndDirs = [distDir, 'node_modules']
|
const excludedFilesAndDirs = [distDir, 'node_modules']
|
||||||
|
|
||||||
// 将 .gitignore 路径转换为相对路径
|
|
||||||
const relativeGitignorePath = path.relative(sourceDir, gitignorePath)
|
|
||||||
|
|
||||||
// 读取 .gitignore 文件并解析
|
// 读取 .gitignore 文件并解析
|
||||||
const ig = ignore().add(fs.readFileSync(gitignorePath, 'utf-8'))
|
const ig = ignore().add(fs.readFileSync(gitignorePath, 'utf-8'))
|
||||||
|
|
||||||
@ -23,6 +22,19 @@ const createDir = dir => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修改 package.json 文件
|
||||||
|
const updatePackageJsonForWeb = () => {
|
||||||
|
const packageJsonPath = path.join(sourceDir, 'package.json')
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
|
||||||
|
|
||||||
|
packageJson.name = 'star-cloud-web-1'
|
||||||
|
packageJson.main = './web/index.js'
|
||||||
|
packageJson.version = webVersion
|
||||||
|
|
||||||
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
||||||
|
console.log('Web build configuration updated in package.json!')
|
||||||
|
}
|
||||||
|
|
||||||
// 处理文件
|
// 处理文件
|
||||||
const processFile = (filePath, targetPath) => {
|
const processFile = (filePath, targetPath) => {
|
||||||
const code = fs.readFileSync(filePath, 'utf-8')
|
const code = fs.readFileSync(filePath, 'utf-8')
|
||||||
@ -70,12 +82,26 @@ const traverseAndProcess = (currentDir, targetDir) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 针对 web/index.js 文件,不进行混淆,直接复制到 dist 目录
|
// 针对 web/index.js 文件,不进行混淆,直接复制到 dist 目录
|
||||||
if (sourcePath === path.join(__dirname, 'web', 'index.js')) {
|
if (sourcePath === path.join(sourceDir, 'web', 'index.js')) {
|
||||||
console.log(`复制入口文件: ${sourcePath}`)
|
console.log(`复制入口文件: ${sourcePath}`)
|
||||||
fs.copyFileSync(sourcePath, targetPath)
|
fs.copyFileSync(sourcePath, targetPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sourcePath === path.join(sourceDir, 'constant.js')) {
|
||||||
|
console.log(`复制入口文件: ${sourcePath}`)
|
||||||
|
fs.copyFileSync(sourcePath, targetPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 针对 web.md 文件,直接复制到 dist 目录,并重命名为 README.md
|
||||||
|
if (sourcePath === path.join(sourceDir, 'web.md')) {
|
||||||
|
console.log(`复制 web.md 文件并重命名为 README.md: ${sourcePath}`)
|
||||||
|
const readmePath = path.join(targetDir, 'README.md')
|
||||||
|
fs.copyFileSync(sourcePath, readmePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 对其他 JS 文件进行混淆
|
// 对其他 JS 文件进行混淆
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
traverseAndProcess(sourcePath, targetPath)
|
traverseAndProcess(sourcePath, targetPath)
|
||||||
@ -96,6 +122,7 @@ if (fs.existsSync(distDir)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createDir(distDir)
|
createDir(distDir)
|
||||||
|
updatePackageJsonForWeb() // 在开始混淆前先修改 package.json
|
||||||
traverseAndProcess(sourceDir, distDir)
|
traverseAndProcess(sourceDir, distDir)
|
||||||
|
|
||||||
console.log('混淆完成,输出目录为 dist!')
|
console.log('混淆完成,输出目录为 dist!')
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "star-cloud",
|
"name": "star-cloud-web-1",
|
||||||
"version": "1.0.2",
|
"version": "1.0.0",
|
||||||
|
"type": "module",
|
||||||
"main": "./web/index.js",
|
"main": "./web/index.js",
|
||||||
"author": "zzc059",
|
"author": "zzc059",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -16,4 +17,4 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"javascript-obfuscator": "^4.1.1"
|
"javascript-obfuscator": "^4.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
84
uni.md
Normal file
84
uni.md
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
## 星云SDK
|
||||||
|
|
||||||
|
### 1. 安装
|
||||||
|
|
||||||
|
```git
|
||||||
|
npm install star-cloud-uni
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 使用
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import {
|
||||||
|
init,
|
||||||
|
Result,
|
||||||
|
register,
|
||||||
|
logout,
|
||||||
|
getOfflinePassword,
|
||||||
|
removeBadLock,
|
||||||
|
getLockSupportFeatures,
|
||||||
|
getServerTimestamp
|
||||||
|
} from 'star-cloud-uni'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化星云
|
||||||
|
* @param params
|
||||||
|
* @param {String} params.clientId 客户端Id
|
||||||
|
* @param {String} params.clientSecret 客户端密码
|
||||||
|
* @param {Array<AccountInfo>} params.accounts 账号列表,后续方法中需传入uid,若未传入则默认使用第一个账号
|
||||||
|
* @param {String} params.env 环境
|
||||||
|
*/
|
||||||
|
init(params)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册星云
|
||||||
|
* @returns Result
|
||||||
|
*/
|
||||||
|
const { code, data, message } = await register()
|
||||||
|
if (code === Result.Success.code) {
|
||||||
|
// 逻辑代码
|
||||||
|
} else {
|
||||||
|
// 错误处理
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出登录
|
||||||
|
* @param params
|
||||||
|
* @param {Number} params.uid 用户ID
|
||||||
|
* @returns Result
|
||||||
|
*/
|
||||||
|
const { code, data, message } = await logout(params)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取离线密码
|
||||||
|
* @param params
|
||||||
|
* @param {Number} [params.uid] 用户ID
|
||||||
|
* @param {OfflinePassword} params.password 密码信息
|
||||||
|
* @returns Result
|
||||||
|
*/
|
||||||
|
const data = await getOfflinePassword(params)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除坏锁
|
||||||
|
* @param params
|
||||||
|
* @param {Number} [params.uid] 用户ID
|
||||||
|
* @param {List[Number]} params.lockIds 锁Id列表
|
||||||
|
* @returns Result
|
||||||
|
*/
|
||||||
|
const data = await removeBadLock(params)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取服务器时间
|
||||||
|
* @returns Result
|
||||||
|
*/
|
||||||
|
const data = await getServerTimestamp()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取锁支持项
|
||||||
|
* @param params
|
||||||
|
* @param {Number} [params.uid] 用户ID
|
||||||
|
* @param {Number} params.lockId 锁 Id
|
||||||
|
* @returns Result
|
||||||
|
*/
|
||||||
|
const data = await getLockSupportFeatures(params)
|
||||||
|
```
|
||||||
@ -9,7 +9,6 @@ export { Result }
|
|||||||
* @property {Number} uid 用户ID
|
* @property {Number} uid 用户ID
|
||||||
* @property {String} username 用户名
|
* @property {String} username 用户名
|
||||||
* @property {String} password 密码
|
* @property {String} password 密码
|
||||||
* @property {String} token token 非必填
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -9,7 +9,6 @@ export { Result }
|
|||||||
* @property {Number} uid 用户ID
|
* @property {Number} uid 用户ID
|
||||||
* @property {String} username 用户名
|
* @property {String} username 用户名
|
||||||
* @property {String} password 密码
|
* @property {String} password 密码
|
||||||
* @property {String} token token 非必填
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user