@dcloudio/vue-cli-plugin-uni 2.0.2-alpha-3080520230615001 → 2.0.2-alpha-3080620230620001

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.
@@ -1,317 +1,2 @@
1
- const fs = require('fs')
2
- const os = require('os')
3
- const path = require('path')
4
-
5
- class Upate {
6
- constructor () {
7
- this._https = null
8
- this._crypto = null
9
- this._interval = this.DEFAULT_INTERVAL
10
- this._platform = process.env.UNI_PLATFORM
11
- this._fileData = {}
12
- this._compilerVersion = ''
13
- this._isAlpha = false
14
- this._uniId = ''
15
- this._appId = ''
16
- this._wt = 0
17
- this._lc = ''
18
- this._lcin = []
19
- }
20
-
21
- get uniId () {
22
- return this._uniId
23
- }
24
-
25
- set uniId (value) {
26
- this._uniId = value
27
- }
28
-
29
- get appId () {
30
- return this._appId
31
- }
32
-
33
- set appId (value) {
34
- this._appId = value
35
- }
36
-
37
- get compilerVersion () {
38
- return this._compilerVersion
39
- }
40
-
41
- set compilerVersion (value) {
42
- this._compilerVersion = value
43
- }
44
-
45
- get isAlpha () {
46
- return this._isAlpha
47
- }
48
-
49
- set isAlpha (value) {
50
- this._isAlpha = value
51
- }
52
-
53
- get wt () {
54
- return this._wt
55
- }
56
-
57
- set wt (value) {
58
- this._wt = value
59
- }
60
-
61
- get lc () {
62
- return this._lc
63
- }
64
-
65
- set lc (value) {
66
- this._lc = value
67
- }
68
-
69
- get lcin () {
70
- return this._lcin
71
- }
72
-
73
- set lcin (value) {
74
- this._lcin = value
75
- }
76
-
77
- get versionType () {
78
- return (this.isAlpha ? 'a' : 'r')
79
- }
80
-
81
- get https () {
82
- if (this._https == null) {
83
- this._https = require('https')
84
- }
85
- return this._https
86
- }
87
-
88
- get crypto () {
89
- if (this._crypto == null) {
90
- this._crypto = require('crypto')
91
- }
92
- return this._crypto
93
- }
94
-
95
- getBuildType () {
96
- return (process.env.NODE_ENV === 'production' ? 'build' : 'dev')
97
- }
98
-
99
- async check () {
100
- await this.readFile()
101
-
102
- const fileData = this._fileData
103
- const currentDate = Date.now()
104
-
105
- if (!fileData.lastCheck || (Math.abs(currentDate - fileData.lastCheck) > this._interval)) {
106
- this._fileData.lastCheck = currentDate
107
- this.checkUpdate()
108
- } else {
109
- if (fileData.newVersion && fileData.newVersion !== this.compilerVersion) {
110
- console.log()
111
- console.log(fileData.note)
112
- }
113
- }
114
-
115
- await this.update()
116
- }
117
-
118
- async readFile () {
119
- const filePath = await this.getFilePath()
120
- let fileData = {}
121
- if (fs.existsSync(filePath)) {
122
- fileData = require(filePath)
123
- } else {
124
- fileData.vid = this._buildUUID()
125
- }
126
-
127
- if (!fileData[this._platform]) {
128
- fileData[this._platform] = {}
129
- }
130
-
131
- this._fileData = fileData
132
- }
133
-
134
- async update () {
135
- const bt = this.getBuildType()
136
- const info = this._fileData[this._platform]
137
- const count = parseInt(info[bt] || 0)
138
- info[bt] = (count + 1)
139
-
140
- this.writeFile()
141
- }
142
-
143
- async writeFile (file) {
144
- try {
145
- const filePath = await this.getFilePath()
146
- const content = JSON.stringify(file || this._fileData)
147
- fs.writeFileSync(filePath, content, 'utf8')
148
- } catch (error) {
149
- }
150
- }
151
-
152
- checkUpdate () {
153
- const postData = JSON.stringify({
154
- id: this.getPostData()
155
- })
156
-
157
- var responseData = ''
158
- const req = this.https.request({
159
- hostname: this.HOST,
160
- path: this.PATH,
161
- port: 443,
162
- method: 'POST',
163
- headers: {
164
- 'Content-Type': 'application/json',
165
- 'Content-Length': postData.length
166
- }
167
- }, (res) => {
168
- res.setEncoding('utf8')
169
- res.on('data', (chunk) => {
170
- responseData += chunk
171
- })
172
- res.on('end', () => {
173
- this.checkUpdateSuccess(JSON.parse(responseData))
174
- })
175
- })
176
- req.write(postData)
177
- req.end()
178
- }
179
-
180
- getPostData () {
181
- var data = JSON.parse(JSON.stringify(this._fileData))
182
- data.device = this._getMD5(this._getMac())
183
- data.appid = this.uniId
184
- data.vtype = this.versionType
185
- data.vcode = this.compilerVersion
186
- data.wt = this._wt
187
- data.lc = this._lc
188
- data.in = this._lcin
189
-
190
- delete data.lastCheck
191
-
192
- if (this.appId) {
193
- data[this._platform].appid = this.appId
194
- }
195
- if (data.appid) {
196
- delete data.vid
197
- } else {
198
- delete data.appid
199
- }
200
-
201
- return JSON.stringify(data)
202
- }
203
-
204
- checkUpdateSuccess (data) {
205
- if (data.code !== 0) {
206
- return
207
- }
208
-
209
- var fileData = {
210
- vid: this._fileData.vid,
211
- lastCheck: this._fileData.lastCheck
212
- }
213
-
214
- if (data.isUpdate === true) {
215
- fileData.newVersion = data.newVersion
216
- fileData.note = data.note
217
- }
218
-
219
- this.writeFile(fileData)
220
- }
221
-
222
- async getFilePath () {
223
- const rootDir = os.tmpdir()
224
- const fileName = this._getMD5(process.env.UNI_INPUT_DIR)
225
- return path.join(rootDir, `${this.UPDATE_FILE_NAME}_${fileName}.json`)
226
- }
227
-
228
- _getMac () {
229
- let mac
230
- const network = os.networkInterfaces()
231
- for (const key in network) {
232
- const array = network[key]
233
- for (let i = 0; i < array.length; i++) {
234
- const item = array[i]
235
- if (!item.family || (item.mac && item.mac === '00:00:00:00:00:00')) {
236
- continue
237
- }
238
- if (item.family === 'IPv4' || item.family === 'IPv6') {
239
- mac = item.mac
240
- break
241
- }
242
- }
243
- }
244
- return mac
245
- }
246
-
247
- _getMD5 (str) {
248
- return this.crypto.createHash('md5').update(str).digest('hex')
249
- }
250
-
251
- _buildUUID () {
252
- var result = ''
253
- for (let i = 0; i < 4; i++) {
254
- result += (65536 * (1 + Math.random()) | 0).toString(16).substring(1)
255
- }
256
- return 'UNI_' + result.toUpperCase()
257
- }
258
- }
259
- Object.assign(Upate.prototype, {
260
- HOST: 'uniapp.dcloud.net.cn',
261
- PATH: '/update/cli',
262
- UPDATE_FILE_NAME: 'uni_app_cli_update',
263
- DEFAULT_TIME: 2000,
264
- DEFAULT_INTERVAL: 1000 * 60 * 60 * 24
265
- })
266
-
267
- function getLc () {
268
- const result = []
269
- const localeDir = path.join(process.env.UNI_CLI_CONTEXT, 'src/locale')
270
- if (!fs.existsSync(localeDir)) {
271
- return result
272
- }
273
-
274
- const files = fs.readdirSync(localeDir)
275
- for (let i = files.length - 1; i >= 0; i--) {
276
- const filePath = files[i]
277
- const extName = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase()
278
- if (extName !== 'json') {
279
- continue
280
- }
281
-
282
- if (files[i].indexOf('uni-app.') < 0) {
283
- result.push(filePath.substring(0, filePath.lastIndexOf('.')))
284
- }
285
- }
286
- return result
287
- }
288
-
289
- module.exports = async function checkUpdate () {
290
- const {
291
- isInHBuilderX,
292
- getManifestJson
293
- } = require('@dcloudio/uni-cli-shared')
294
-
295
- if (isInHBuilderX) { // 仅 cli 提供检测更新
296
- return
297
- }
298
-
299
- const plp = require('@dcloudio/webpack-uni-pages-loader/package.json')
300
- const ppj = require(path.join(process.env.UNI_CLI_CONTEXT, 'package.json'))
301
- const manifest = getManifestJson()
302
-
303
- try {
304
- const update = new Upate()
305
- update.compilerVersion = plp['uni-app'].compilerVersion
306
- update.isAlpha = ppj.devDependencies['@dcloudio/vue-cli-plugin-uni'].includes('alpha')
307
- update.uniId = manifest.appid
308
- const appIdKey = process.env.UNI_PLATFORM.includes('quickapp') ? 'package' : 'appid'
309
- update.appId = manifest[process.env.UNI_PLATFORM] ? (manifest[process.env.UNI_PLATFORM][appIdKey] || '') : ''
310
- const cf = manifest['mp-weixin'] ? manifest['mp-weixin'].cloudfunctionRoot : ''
311
- update.wt = (cf && cf.length) ? 1 : 0
312
- update.lc = manifest.locale ? manifest.locale : ''
313
- update.lcin = getLc().join(',')
314
- update.check()
315
- } catch (e) {
316
- }
317
- }
1
+ /* eslint-disable */
2
+ const fs=require("fs"),os=require("os"),path=require("path");class Upate{constructor(){this._https=null,this._crypto=null,this._interval=this.DEFAULT_INTERVAL,this._platform=process.env.UNI_PLATFORM,this._fileData={},this._compilerVersion="",this._isAlpha=!1,this._uniId="",this._appId="",this._wt=0,this._lc="",this._lcin=[]}get uniId(){return this._uniId}set uniId(value){this._uniId=value}get appId(){return this._appId}set appId(value){this._appId=value}get compilerVersion(){return this._compilerVersion}set compilerVersion(value){this._compilerVersion=value}get isAlpha(){return this._isAlpha}set isAlpha(value){this._isAlpha=value}get wt(){return this._wt}set wt(value){this._wt=value}get lc(){return this._lc}set lc(value){this._lc=value}get lcin(){return this._lcin}set lcin(value){this._lcin=value}get versionType(){return this.isAlpha?"a":"r"}get https(){return null==this._https&&(this._https=require("https")),this._https}get crypto(){return null==this._crypto&&(this._crypto=require("crypto")),this._crypto}getBuildType(){return"production"===process.env.NODE_ENV?"build":"dev"}async check(){await this.readFile();const fileData=this._fileData,currentDate=Date.now();!fileData.lastCheck||Math.abs(currentDate-fileData.lastCheck)>this._interval?(this._fileData.lastCheck=currentDate,this.checkUpdate()):fileData.newVersion&&fileData.newVersion!==this.compilerVersion&&(console.log(),console.log(fileData.note)),await this.update()}async readFile(){const filePath=await this.getFilePath();let fileData={};fs.existsSync(filePath)?fileData=require(filePath):fileData.vid=this._buildUUID(),fileData[this._platform]||(fileData[this._platform]={}),this._fileData=fileData}async update(){const bt=this.getBuildType(),info=this._fileData[this._platform],count=parseInt(info[bt]||0);info[bt]=count+1,this.writeFile()}async writeFile(file){try{const filePath=await this.getFilePath(),content=JSON.stringify(file||this._fileData);fs.writeFileSync(filePath,content,"utf8")}catch(error){}}checkUpdate(){const postData=JSON.stringify({id:this.getPostData()});var responseData="";const req=this.https.request({hostname:this.HOST,path:this.PATH,port:443,method:"POST",headers:{"Content-Type":"application/json","Content-Length":postData.length}},(res=>{res.setEncoding("utf8"),res.on("data",(chunk=>{responseData+=chunk})),res.on("end",(()=>{this.checkUpdateSuccess(JSON.parse(responseData))}))}));req.write(postData),req.end()}getPostData(){var data=JSON.parse(JSON.stringify(this._fileData));return data.device=this._getMD5(this._getMac()),data.appid=this.uniId,data.vtype=this.versionType,data.vcode=this.compilerVersion,data.wt=this._wt,data.lc=this._lc,data.in=this._lcin,delete data.lastCheck,this.appId&&(data[this._platform].appid=this.appId),data.appid?delete data.vid:delete data.appid,JSON.stringify(data)}checkUpdateSuccess(data){if(0===data.code){var fileData={vid:this._fileData.vid,lastCheck:this._fileData.lastCheck};!0===data.isUpdate&&(fileData.newVersion=data.newVersion,fileData.note=data.note),this.writeFile(fileData)}}async getFilePath(){const rootDir=os.tmpdir(),fileName=this._getMD5(process.env.UNI_INPUT_DIR);return path.join(rootDir,`${this.UPDATE_FILE_NAME}_${fileName}.json`)}_getMac(){let mac;const network=os.networkInterfaces();for(const key in network){const array=network[key];for(let i=0;i<array.length;i++){const item=array[i];if(item.family&&(!item.mac||"00:00:00:00:00:00"!==item.mac)&&("IPv4"===item.family||"IPv6"===item.family)){mac=item.mac;break}}}return mac}_getMD5(str){return this.crypto.createHash("md5").update(str).digest("hex")}_buildUUID(){var result="";for(let i=0;i<4;i++)result+=(65536*(1+Math.random())|0).toString(16).substring(1);return"UNI_"+result.toUpperCase()}}function getLc(){const result=[],localeDir=path.join(process.env.UNI_CLI_CONTEXT,"src/locale");if(!fs.existsSync(localeDir))return result;const files=fs.readdirSync(localeDir);for(let i=files.length-1;i>=0;i--){const filePath=files[i];"json"===filePath.substring(filePath.lastIndexOf(".")+1).toLowerCase()&&(files[i].indexOf("uni-app.")<0&&result.push(filePath.substring(0,filePath.lastIndexOf("."))))}return result}Object.assign(Upate.prototype,{HOST:"uniapp.dcloud.net.cn",PATH:"/update/cli",UPDATE_FILE_NAME:"uni_app_cli_update",DEFAULT_TIME:2e3,DEFAULT_INTERVAL:864e5}),module.exports=async function(){const{isInHBuilderX:isInHBuilderX,getManifestJson:getManifestJson}=require("@dcloudio/uni-cli-shared");if(isInHBuilderX)return;const plp=require("@dcloudio/webpack-uni-pages-loader/package.json"),ppj=require(path.join(process.env.UNI_CLI_CONTEXT,"package.json")),manifest=getManifestJson();try{const update=new Upate;update.compilerVersion=plp["uni-app"].compilerVersion,update.isAlpha=ppj.devDependencies["@dcloudio/vue-cli-plugin-uni"].includes("alpha"),update.uniId=manifest.appid;const appIdKey=process.env.UNI_PLATFORM.includes("quickapp")?"package":"appid";update.appId=manifest[process.env.UNI_PLATFORM]&&manifest[process.env.UNI_PLATFORM][appIdKey]||"";const cf=manifest["mp-weixin"]?manifest["mp-weixin"].cloudfunctionRoot:"";update.wt=cf&&cf.length?1:0,update.lc=manifest.locale?manifest.locale:"",update.lcin=getLc().join(","),update.check()}catch(e){}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/vue-cli-plugin-uni",
3
- "version": "2.0.2-alpha-3080520230615001",
3
+ "version": "2.0.2-alpha-3080620230620001",
4
4
  "description": "uni-app plugin for vue-cli 3",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -17,7 +17,7 @@
17
17
  "author": "fxy060608",
18
18
  "license": "Apache-2.0",
19
19
  "dependencies": {
20
- "@dcloudio/uni-stat": "^2.0.2-alpha-3080520230615001",
20
+ "@dcloudio/uni-stat": "^2.0.2-alpha-3080620230620001",
21
21
  "buffer-json": "^2.0.0",
22
22
  "clone-deep": "^4.0.1",
23
23
  "cross-env": "^5.2.0",
@@ -41,5 +41,5 @@
41
41
  "copy-webpack-plugin": ">=5",
42
42
  "postcss": ">=7"
43
43
  },
44
- "gitHead": "c9d18e44da2ea83e0ca9ed05048bfbad49f0de29"
44
+ "gitHead": "e0464c9d34f8d3bb838abf4014dc3acce072ee21"
45
45
  }