aaden-cli 1.6.69 → 1.6.71

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/dist/index.js CHANGED
@@ -23,43 +23,60 @@ function showCommand(arr) {
23
23
  console.log('')
24
24
  }
25
25
 
26
- function executeInShell(cmd, debug = false, needResult = false) {
27
- let _cmd = commandBuilder(cmd)
26
+
27
+ function executeInShellSync(cmd) {
28
+ let _cmd = commandBuilder([cmd])
28
29
  try {
29
- showCommand(cmd)
30
- if (debug) {
31
- return {
32
- result: false
33
- }
34
- }
35
- if (needResult) {
36
- const res = spawnSync(_cmd, [], {
37
- shell: true, stdio: 'pipe', encoding: 'utf-8'
38
- })
39
- return {
40
- result: true, output: res.stdout
41
- }
42
- } else {
43
- spawn(_cmd, [], {
44
- shell: true, stdio: 'inherit',
45
- })
46
- return {
47
- result: true
48
- }
30
+ showCommand([cmd])
31
+ const res = spawnSync(_cmd, [], {
32
+ shell: true, stdio: 'pipe', encoding: 'utf-8'
33
+ })
34
+ return {
35
+ result: true, output: res.stdout
49
36
  }
50
-
51
37
  } catch (e) {
52
38
  console.log(getLine('*'))
53
39
  console.log(e.bgRed)
54
40
  console.log(_cmd)
55
41
  console.log(getLine('*'))
56
42
  }
57
- console.log(getLine('*'))
58
43
  return {result: false}
59
44
  }
60
45
 
46
+ function executeInShell(cmd, debug = false) {
47
+ let _cmd = commandBuilder(cmd)
48
+ return new Promise(resolve => {
49
+ try {
50
+ showCommand(cmd)
51
+ if (debug) {
52
+ resolve({result: false})
53
+ return
54
+ }
55
+
56
+
57
+ const child = spawn(_cmd, [], {
58
+ shell: true, stdio: 'inherit',
59
+ })
60
+ child.on('close', (code) => {
61
+ resolve({result: true, code})
62
+ })
63
+
64
+
65
+ } catch (e) {
66
+ console.log(getLine('*'))
67
+ console.log(e.bgRed)
68
+ console.log(_cmd)
69
+ console.log(getLine('*'))
70
+ console.log(getLine('*'))
71
+ resolve({result: false})
72
+ }
73
+
74
+ })
75
+
76
+ }
77
+
61
78
  module.exports = {
62
- getLine, executeInShell
79
+ getLine, executeInShell, executeInShellSync,
63
80
  }
64
81
 
65
82
 
@@ -98,22 +115,27 @@ async function deviceEcho(data) {
98
115
  return
99
116
  }
100
117
  const {name, adress1, postCode, city, state} = await getNiceRestaurantInfo()
101
- await hillo.jsonPost('https://cloud-v2.aaden.io/deviceLog/create', {
102
- deviceId: myDeviceId,
103
- frontendVersion: frontendVersion,
104
- cliVersion,
105
- backendVersion: await getCurrentBackendVersion(),
106
- timestamp: dayjs().valueOf(),
107
- accessFrom: 'aaden-cli v' + cliVersion,
108
- diskUsage,
109
- lastUptime: upTime,
110
- ngrokOk: ngrokIsNew,
111
- deviceName: `${name}\n${adress1}\n${postCode} ${city} ${state}`
112
- })
113
- console.log('report to remote server complete')
118
+ const waitSecond = parseInt(myDeviceId) % 30 * 1000
119
+ setTimeout(async () => {
120
+ await hillo.jsonPost('https://cloud-v2.aaden.io/deviceLog/create', {
121
+ deviceId: myDeviceId,
122
+ frontendVersion: frontendVersion,
123
+ cliVersion,
124
+ backendVersion: await getCurrentBackendVersion(),
125
+ timestamp: dayjs().valueOf(),
126
+ accessFrom: 'aaden-cli v' + cliVersion,
127
+ diskUsage,
128
+ lastUptime: upTime,
129
+ ngrokOk: ngrokIsNew,
130
+ deviceName: `${name}\n${adress1}\n${postCode} ${city} ${state}`
131
+ })
132
+ console.log('report to remote server complete')
133
+ }, waitSecond)
134
+
135
+
114
136
  }
115
137
 
116
- async function logAction(content) {
138
+ async function logAction(content, result = 0) {
117
139
  const deviceId = await getCurrentDeviceId()
118
140
  console.log(
119
141
  '*******************************************************\n' +
@@ -123,7 +145,7 @@ async function logAction(content) {
123
145
  )
124
146
  await hillo.jsonPost("https://cloud-v2.aaden.io/deviceLog/createEvent", {
125
147
  deviceId,
126
- content,
148
+ content: content + ' result:' + result,
127
149
  type: '系统生成',
128
150
  operator: "aaden-cli v" + version
129
151
  })
@@ -18478,7 +18500,7 @@ module.exports = JSON.parse('{"name":"axios","version":"0.19.2","description":"P
18478
18500
  /***/ ((module) => {
18479
18501
 
18480
18502
  "use strict";
18481
- module.exports = {"i8":"1.6.69"};
18503
+ module.exports = {"i8":"1.6.71"};
18482
18504
 
18483
18505
  /***/ })
18484
18506
 
@@ -18560,7 +18582,7 @@ const colors = __nccwpck_require__(3045)
18560
18582
  const fs = __nccwpck_require__(7147)
18561
18583
  const InnerKenTimeStampFormat = 'YYYYMMDDHHmmss'
18562
18584
  const prompts = __nccwpck_require__(9646)
18563
- const {deviceEcho,logAction} = __nccwpck_require__(7415)
18585
+ const {deviceEcho, logAction} = __nccwpck_require__(7415)
18564
18586
  const GlobalDeviceId = 'notset'
18565
18587
 
18566
18588
  const {program} = __nccwpck_require__(1904)
@@ -18571,7 +18593,6 @@ hillo.initial('http://localhost/PHP/')
18571
18593
  program.version(version)
18572
18594
 
18573
18595
 
18574
-
18575
18596
  console.log(
18576
18597
  '*******************************************************\n' +
18577
18598
  'Aaden CLI'.bgCyan + ' Version:' + version.bgRed + '\n' +
@@ -18697,11 +18718,11 @@ async function fixNgrok() {
18697
18718
  logAction("手动修复了ngrok")
18698
18719
  }
18699
18720
 
18700
- function testPrinter() {
18721
+ async function testPrinter() {
18701
18722
  const command = [
18702
18723
  `wget localhost/PHP/Complex.php?op=testAllPrinter`
18703
18724
  ]
18704
- cli.executeInShell(command, program.debug)
18725
+ await cli.executeInShell(command, program.debug)
18705
18726
  }
18706
18727
 
18707
18728
 
@@ -18770,7 +18791,7 @@ async function runMultiple(files) {
18770
18791
  arr.push('./' + f)
18771
18792
  return arr
18772
18793
  }, [])
18773
- cli.executeInShell(command, program.debug)
18794
+ await cli.executeInShell(command, program.debug)
18774
18795
  }
18775
18796
 
18776
18797
  async function run(filePath) {
@@ -18778,10 +18799,10 @@ async function run(filePath) {
18778
18799
  ...getPrivilegeCMD(filePath),
18779
18800
  './' + filePath
18780
18801
  ]
18781
- cli.executeInShell(command, program.debug)
18802
+ await cli.executeInShell(command, program.debug)
18782
18803
  }
18783
18804
 
18784
- function fullUpdate() {
18805
+ async function fullUpdate() {
18785
18806
  const command = [
18786
18807
  'sudo apt install git -y',
18787
18808
  'aaden-cli backup',
@@ -18792,8 +18813,8 @@ function fullUpdate() {
18792
18813
  'aaden-cli auto-write-gdpdu',
18793
18814
  'sudo systemctl daemon-reload'
18794
18815
  ]
18795
- cli.executeInShell(command, program.debug)
18796
- logAction("进行了full-update")
18816
+ const {code} = await cli.executeInShell(command, program.debug)
18817
+ await logAction("进行了full-update", code)
18797
18818
  }
18798
18819
 
18799
18820
  async function updateNgrokConfig(deviceId) {
@@ -18833,7 +18854,7 @@ tunnels:
18833
18854
  tcp: 22
18834
18855
  remote_port: ${parseInt(deviceId) + 10000}" > ngrok-config.yml`
18835
18856
  ]
18836
- cli.executeInShell(command, program.debug)
18857
+ await cli.executeInShell(command, program.debug)
18837
18858
  }
18838
18859
 
18839
18860
  async function startNgrokService() {
@@ -18842,7 +18863,7 @@ async function startNgrokService() {
18842
18863
  'cd AadenDeploy/ngrok',
18843
18864
  './ngrok -config=/etc/aaden/ngrok-config.yml start-all --log=/etc/aaden/ngrok.log'
18844
18865
  ]
18845
- cli.executeInShell(command, program.debug)
18866
+ await cli.executeInShell(command, program.debug)
18846
18867
  }
18847
18868
 
18848
18869
  async function doCompress() {
@@ -18851,8 +18872,8 @@ async function doCompress() {
18851
18872
  'cd',
18852
18873
  'sudo rm -rf backups'
18853
18874
  ]
18854
- cli.executeInShell(command, program.debug)
18855
- logAction("清理了空间")
18875
+ const result = cli.executeInShell(command, program.debug)
18876
+ logAction("清理了空间", result.code)
18856
18877
  }
18857
18878
 
18858
18879
  async function backup() {
@@ -18876,8 +18897,8 @@ async function backup() {
18876
18897
  'sudo rsync -av --delete /var/www/html/Resource ./Resource'
18877
18898
  ]
18878
18899
 
18879
- cli.executeInShell(command, program.debug)
18880
- logAction("执行了手动备份")
18900
+ const {code} = await cli.executeInShell(command, program.debug)
18901
+ logAction("执行了手动备份", code)
18881
18902
 
18882
18903
  }
18883
18904
 
@@ -18918,7 +18939,7 @@ async function migrate() {
18918
18939
  'vendor/bin/phinx migrate',
18919
18940
  'cd'
18920
18941
  ]
18921
- cli.executeInShell(command, program.debug)
18942
+ await cli.executeInShell(command, program.debug)
18922
18943
 
18923
18944
  } catch (e) {
18924
18945
  console.error(e)
@@ -18939,7 +18960,7 @@ async function convertDataBaseCharset() {
18939
18960
  'cd AadenDeploy/Utils',
18940
18961
  `./updateDataBaseCharSet.sh`
18941
18962
  ]
18942
- cli.executeInShell(command, program.debug)
18963
+ await cli.executeInShell(command, program.debug)
18943
18964
  } else {
18944
18965
  console.log('已经转换完成')
18945
18966
  }
@@ -18962,7 +18983,7 @@ async function loadNewVersion() {
18962
18983
  'cd AadenDeploy/files',
18963
18984
  `./getFile.sh`
18964
18985
  ]
18965
- cli.executeInShell(command, program.debug)
18986
+ await cli.executeInShell(command, program.debug)
18966
18987
  } else {
18967
18988
  console.log('后端文件已经是最新')
18968
18989
  }
@@ -18983,7 +19004,7 @@ async function rollback() {
18983
19004
  'cd AadenDeploy',
18984
19005
  `./update.sh`
18985
19006
  ])
18986
- cli.executeInShell(command, program.debug)
19007
+ await cli.executeInShell(command, program.debug)
18987
19008
  } catch (e) {
18988
19009
  console.error(e)
18989
19010
  }
@@ -19009,8 +19030,8 @@ async function update(channel = '') {
19009
19030
  'cd AadenDeploy',
19010
19031
  `./update.sh ${channel}`
19011
19032
  ])
19012
- cli.executeInShell(command, program.debug)
19013
- logAction("进行了手动更新update")
19033
+ const {code} = await cli.executeInShell(command, program.debug)
19034
+ await logAction("进行了手动更新update",code)
19014
19035
  } catch (e) {
19015
19036
  console.error(e)
19016
19037
  }
@@ -19035,7 +19056,7 @@ async function install(deviceId) {
19035
19056
  'cd AadenDeploy',
19036
19057
  `./aadensetup.sh ${deviceId} ${channel}` + (installApp ? ' b' : '')
19037
19058
  ]
19038
- cli.executeInShell(command, program.debug)
19059
+ await cli.executeInShell(command, program.debug)
19039
19060
  } else {
19040
19061
  console.log('Device Id is invalid.')
19041
19062
  }
@@ -19060,13 +19081,13 @@ async function autoUpgrade() {
19060
19081
  logAction("自动执行了更新aaden-cli")
19061
19082
  }
19062
19083
 
19063
- function upgrade() {
19084
+ async function upgrade() {
19064
19085
  const command = [
19065
19086
  ...getPrivilegeCMD('AadenDeploy/upgrade.sh'),
19066
19087
  'cd AadenDeploy',
19067
19088
  `./upgrade.sh`
19068
19089
  ]
19069
- cli.executeInShell(command, program.debug)
19090
+ await cli.executeInShell(command, program.debug)
19070
19091
  }
19071
19092
 
19072
19093
  function getStorageBackendFileVersion() {
@@ -19145,13 +19166,13 @@ async function removeAllData() {
19145
19166
  'echo "请输入数据库密码(和开机密码,sudo密码相同)"',
19146
19167
  'mysql -u aaden -p < AadenDeploy/purge.sql'
19147
19168
  ]
19148
- cli.executeInShell(command, program.debug)
19149
- logAction("清空了数据")
19169
+ const {code} = await cli.executeInShell(command, program.debug)
19170
+ await logAction("清空了数据", code)
19150
19171
  }
19151
19172
 
19152
19173
  function getUpTime() {
19153
19174
  try {
19154
- return cli.executeInShell(['uptime'], program.debug, true).output.split(',')[0].split(' up ')[1]
19175
+ return cli.executeInShellSync('uptime').output.split(',')[0].split(' up ')[1]
19155
19176
  } catch (e) {
19156
19177
  return e.message
19157
19178
  }
@@ -19159,24 +19180,26 @@ function getUpTime() {
19159
19180
  }
19160
19181
 
19161
19182
  async function doLog() {
19162
- const res = cli.executeInShell(['snap info aaden'], program.debug, true)
19183
+ const res = cli.executeInShellSync('snap info aaden')
19163
19184
  const diskUsage =
19164
- cli.executeInShell(['df -h --total | command grep total | df -h --total | command grep total | head -c-3 && echo \'\''],
19165
- program.debug, true).output.split(' ')
19166
- const uptime = cli.executeInShell([''], program.debug, true).output
19185
+ cli.executeInShellSync('df -h --total | command grep total | df -h --total | command grep total | head -c-3 && echo \'\'',)
19186
+ .output.split(' ')
19167
19187
  const log = res.output
19168
19188
  const list = log.split('\n')
19169
19189
  const frontendVersion = list[list.length - 2].replace(/\s+/g, ' ')
19170
19190
  .split(' ')[1]
19171
- await deviceEcho({
19172
- frontendVersion,
19173
- cliVersion: version,
19174
- diskUsage: diskUsage[diskUsage.length - 1].replace('\n', ''),
19175
- upTime: getUpTime(),
19176
- ngrokIsNew: ngrokNewestVersion()
19177
- }
19178
- )
19179
- console.log('finish')
19191
+
19192
+ await deviceEcho({
19193
+ frontendVersion,
19194
+ cliVersion: version,
19195
+ diskUsage: diskUsage[diskUsage.length - 1].replace('\n', ''),
19196
+ upTime: getUpTime(),
19197
+ ngrokIsNew: ngrokNewestVersion()
19198
+ }
19199
+ )
19200
+ console.log('finish')
19201
+
19202
+
19180
19203
 
19181
19204
  process.exit(0)
19182
19205
  }
package/index.js CHANGED
@@ -8,7 +8,7 @@ const colors = require('colors')
8
8
  const fs = require('fs')
9
9
  const InnerKenTimeStampFormat = 'YYYYMMDDHHmmss'
10
10
  const prompts = require('prompts')
11
- const {deviceEcho,logAction} = require('./modules/firebase')
11
+ const {deviceEcho, logAction} = require('./modules/firebase')
12
12
  const GlobalDeviceId = 'notset'
13
13
 
14
14
  const {program} = require('commander')
@@ -19,7 +19,6 @@ hillo.initial('http://localhost/PHP/')
19
19
  program.version(version)
20
20
 
21
21
 
22
-
23
22
  console.log(
24
23
  '*******************************************************\n' +
25
24
  'Aaden CLI'.bgCyan + ' Version:' + version.bgRed + '\n' +
@@ -145,11 +144,11 @@ async function fixNgrok() {
145
144
  logAction("手动修复了ngrok")
146
145
  }
147
146
 
148
- function testPrinter() {
147
+ async function testPrinter() {
149
148
  const command = [
150
149
  `wget localhost/PHP/Complex.php?op=testAllPrinter`
151
150
  ]
152
- cli.executeInShell(command, program.debug)
151
+ await cli.executeInShell(command, program.debug)
153
152
  }
154
153
 
155
154
 
@@ -218,7 +217,7 @@ async function runMultiple(files) {
218
217
  arr.push('./' + f)
219
218
  return arr
220
219
  }, [])
221
- cli.executeInShell(command, program.debug)
220
+ await cli.executeInShell(command, program.debug)
222
221
  }
223
222
 
224
223
  async function run(filePath) {
@@ -226,10 +225,10 @@ async function run(filePath) {
226
225
  ...getPrivilegeCMD(filePath),
227
226
  './' + filePath
228
227
  ]
229
- cli.executeInShell(command, program.debug)
228
+ await cli.executeInShell(command, program.debug)
230
229
  }
231
230
 
232
- function fullUpdate() {
231
+ async function fullUpdate() {
233
232
  const command = [
234
233
  'sudo apt install git -y',
235
234
  'aaden-cli backup',
@@ -240,8 +239,8 @@ function fullUpdate() {
240
239
  'aaden-cli auto-write-gdpdu',
241
240
  'sudo systemctl daemon-reload'
242
241
  ]
243
- cli.executeInShell(command, program.debug)
244
- logAction("进行了full-update")
242
+ const {code} = await cli.executeInShell(command, program.debug)
243
+ await logAction("进行了full-update", code)
245
244
  }
246
245
 
247
246
  async function updateNgrokConfig(deviceId) {
@@ -281,7 +280,7 @@ tunnels:
281
280
  tcp: 22
282
281
  remote_port: ${parseInt(deviceId) + 10000}" > ngrok-config.yml`
283
282
  ]
284
- cli.executeInShell(command, program.debug)
283
+ await cli.executeInShell(command, program.debug)
285
284
  }
286
285
 
287
286
  async function startNgrokService() {
@@ -290,7 +289,7 @@ async function startNgrokService() {
290
289
  'cd AadenDeploy/ngrok',
291
290
  './ngrok -config=/etc/aaden/ngrok-config.yml start-all --log=/etc/aaden/ngrok.log'
292
291
  ]
293
- cli.executeInShell(command, program.debug)
292
+ await cli.executeInShell(command, program.debug)
294
293
  }
295
294
 
296
295
  async function doCompress() {
@@ -299,8 +298,8 @@ async function doCompress() {
299
298
  'cd',
300
299
  'sudo rm -rf backups'
301
300
  ]
302
- cli.executeInShell(command, program.debug)
303
- logAction("清理了空间")
301
+ const result = cli.executeInShell(command, program.debug)
302
+ logAction("清理了空间", result.code)
304
303
  }
305
304
 
306
305
  async function backup() {
@@ -324,8 +323,8 @@ async function backup() {
324
323
  'sudo rsync -av --delete /var/www/html/Resource ./Resource'
325
324
  ]
326
325
 
327
- cli.executeInShell(command, program.debug)
328
- logAction("执行了手动备份")
326
+ const {code} = await cli.executeInShell(command, program.debug)
327
+ logAction("执行了手动备份", code)
329
328
 
330
329
  }
331
330
 
@@ -366,7 +365,7 @@ async function migrate() {
366
365
  'vendor/bin/phinx migrate',
367
366
  'cd'
368
367
  ]
369
- cli.executeInShell(command, program.debug)
368
+ await cli.executeInShell(command, program.debug)
370
369
 
371
370
  } catch (e) {
372
371
  console.error(e)
@@ -387,7 +386,7 @@ async function convertDataBaseCharset() {
387
386
  'cd AadenDeploy/Utils',
388
387
  `./updateDataBaseCharSet.sh`
389
388
  ]
390
- cli.executeInShell(command, program.debug)
389
+ await cli.executeInShell(command, program.debug)
391
390
  } else {
392
391
  console.log('已经转换完成')
393
392
  }
@@ -410,7 +409,7 @@ async function loadNewVersion() {
410
409
  'cd AadenDeploy/files',
411
410
  `./getFile.sh`
412
411
  ]
413
- cli.executeInShell(command, program.debug)
412
+ await cli.executeInShell(command, program.debug)
414
413
  } else {
415
414
  console.log('后端文件已经是最新')
416
415
  }
@@ -431,7 +430,7 @@ async function rollback() {
431
430
  'cd AadenDeploy',
432
431
  `./update.sh`
433
432
  ])
434
- cli.executeInShell(command, program.debug)
433
+ await cli.executeInShell(command, program.debug)
435
434
  } catch (e) {
436
435
  console.error(e)
437
436
  }
@@ -457,8 +456,8 @@ async function update(channel = '') {
457
456
  'cd AadenDeploy',
458
457
  `./update.sh ${channel}`
459
458
  ])
460
- cli.executeInShell(command, program.debug)
461
- logAction("进行了手动更新update")
459
+ const {code} = await cli.executeInShell(command, program.debug)
460
+ await logAction("进行了手动更新update",code)
462
461
  } catch (e) {
463
462
  console.error(e)
464
463
  }
@@ -483,7 +482,7 @@ async function install(deviceId) {
483
482
  'cd AadenDeploy',
484
483
  `./aadensetup.sh ${deviceId} ${channel}` + (installApp ? ' b' : '')
485
484
  ]
486
- cli.executeInShell(command, program.debug)
485
+ await cli.executeInShell(command, program.debug)
487
486
  } else {
488
487
  console.log('Device Id is invalid.')
489
488
  }
@@ -508,13 +507,13 @@ async function autoUpgrade() {
508
507
  logAction("自动执行了更新aaden-cli")
509
508
  }
510
509
 
511
- function upgrade() {
510
+ async function upgrade() {
512
511
  const command = [
513
512
  ...getPrivilegeCMD('AadenDeploy/upgrade.sh'),
514
513
  'cd AadenDeploy',
515
514
  `./upgrade.sh`
516
515
  ]
517
- cli.executeInShell(command, program.debug)
516
+ await cli.executeInShell(command, program.debug)
518
517
  }
519
518
 
520
519
  function getStorageBackendFileVersion() {
@@ -593,13 +592,13 @@ async function removeAllData() {
593
592
  'echo "请输入数据库密码(和开机密码,sudo密码相同)"',
594
593
  'mysql -u aaden -p < AadenDeploy/purge.sql'
595
594
  ]
596
- cli.executeInShell(command, program.debug)
597
- logAction("清空了数据")
595
+ const {code} = await cli.executeInShell(command, program.debug)
596
+ await logAction("清空了数据", code)
598
597
  }
599
598
 
600
599
  function getUpTime() {
601
600
  try {
602
- return cli.executeInShell(['uptime'], program.debug, true).output.split(',')[0].split(' up ')[1]
601
+ return cli.executeInShellSync('uptime').output.split(',')[0].split(' up ')[1]
603
602
  } catch (e) {
604
603
  return e.message
605
604
  }
@@ -607,24 +606,26 @@ function getUpTime() {
607
606
  }
608
607
 
609
608
  async function doLog() {
610
- const res = cli.executeInShell(['snap info aaden'], program.debug, true)
609
+ const res = cli.executeInShellSync('snap info aaden')
611
610
  const diskUsage =
612
- cli.executeInShell(['df -h --total | command grep total | df -h --total | command grep total | head -c-3 && echo \'\''],
613
- program.debug, true).output.split(' ')
614
- const uptime = cli.executeInShell([''], program.debug, true).output
611
+ cli.executeInShellSync('df -h --total | command grep total | df -h --total | command grep total | head -c-3 && echo \'\'',)
612
+ .output.split(' ')
615
613
  const log = res.output
616
614
  const list = log.split('\n')
617
615
  const frontendVersion = list[list.length - 2].replace(/\s+/g, ' ')
618
616
  .split(' ')[1]
619
- await deviceEcho({
620
- frontendVersion,
621
- cliVersion: version,
622
- diskUsage: diskUsage[diskUsage.length - 1].replace('\n', ''),
623
- upTime: getUpTime(),
624
- ngrokIsNew: ngrokNewestVersion()
625
- }
626
- )
627
- console.log('finish')
617
+
618
+ await deviceEcho({
619
+ frontendVersion,
620
+ cliVersion: version,
621
+ diskUsage: diskUsage[diskUsage.length - 1].replace('\n', ''),
622
+ upTime: getUpTime(),
623
+ ngrokIsNew: ngrokNewestVersion()
624
+ }
625
+ )
626
+ console.log('finish')
627
+
628
+
628
629
 
629
630
  process.exit(0)
630
631
  }
@@ -16,41 +16,58 @@ function showCommand(arr) {
16
16
  console.log('')
17
17
  }
18
18
 
19
- function executeInShell(cmd, debug = false, needResult = false) {
20
- let _cmd = commandBuilder(cmd)
19
+
20
+ function executeInShellSync(cmd) {
21
+ let _cmd = commandBuilder([cmd])
21
22
  try {
22
- showCommand(cmd)
23
- if (debug) {
24
- return {
25
- result: false
26
- }
27
- }
28
- if (needResult) {
29
- const res = spawnSync(_cmd, [], {
30
- shell: true, stdio: 'pipe', encoding: 'utf-8'
31
- })
32
- return {
33
- result: true, output: res.stdout
34
- }
35
- } else {
36
- spawn(_cmd, [], {
37
- shell: true, stdio: 'inherit',
38
- })
39
- return {
40
- result: true
41
- }
23
+ showCommand([cmd])
24
+ const res = spawnSync(_cmd, [], {
25
+ shell: true, stdio: 'pipe', encoding: 'utf-8'
26
+ })
27
+ return {
28
+ result: true, output: res.stdout
42
29
  }
43
-
44
30
  } catch (e) {
45
31
  console.log(getLine('*'))
46
32
  console.log(e.bgRed)
47
33
  console.log(_cmd)
48
34
  console.log(getLine('*'))
49
35
  }
50
- console.log(getLine('*'))
51
36
  return {result: false}
52
37
  }
53
38
 
39
+ function executeInShell(cmd, debug = false) {
40
+ let _cmd = commandBuilder(cmd)
41
+ return new Promise(resolve => {
42
+ try {
43
+ showCommand(cmd)
44
+ if (debug) {
45
+ resolve({result: false})
46
+ return
47
+ }
48
+
49
+
50
+ const child = spawn(_cmd, [], {
51
+ shell: true, stdio: 'inherit',
52
+ })
53
+ child.on('close', (code) => {
54
+ resolve({result: true, code})
55
+ })
56
+
57
+
58
+ } catch (e) {
59
+ console.log(getLine('*'))
60
+ console.log(e.bgRed)
61
+ console.log(_cmd)
62
+ console.log(getLine('*'))
63
+ console.log(getLine('*'))
64
+ resolve({result: false})
65
+ }
66
+
67
+ })
68
+
69
+ }
70
+
54
71
  module.exports = {
55
- getLine, executeInShell
72
+ getLine, executeInShell, executeInShellSync,
56
73
  }
@@ -19,22 +19,27 @@ export async function deviceEcho(data) {
19
19
  return
20
20
  }
21
21
  const {name, adress1, postCode, city, state} = await getNiceRestaurantInfo()
22
- await hillo.jsonPost('https://cloud-v2.aaden.io/deviceLog/create', {
23
- deviceId: myDeviceId,
24
- frontendVersion: frontendVersion,
25
- cliVersion,
26
- backendVersion: await getCurrentBackendVersion(),
27
- timestamp: dayjs().valueOf(),
28
- accessFrom: 'aaden-cli v' + cliVersion,
29
- diskUsage,
30
- lastUptime: upTime,
31
- ngrokOk: ngrokIsNew,
32
- deviceName: `${name}\n${adress1}\n${postCode} ${city} ${state}`
33
- })
34
- console.log('report to remote server complete')
22
+ const waitSecond = parseInt(myDeviceId) % 30 * 1000
23
+ setTimeout(async () => {
24
+ await hillo.jsonPost('https://cloud-v2.aaden.io/deviceLog/create', {
25
+ deviceId: myDeviceId,
26
+ frontendVersion: frontendVersion,
27
+ cliVersion,
28
+ backendVersion: await getCurrentBackendVersion(),
29
+ timestamp: dayjs().valueOf(),
30
+ accessFrom: 'aaden-cli v' + cliVersion,
31
+ diskUsage,
32
+ lastUptime: upTime,
33
+ ngrokOk: ngrokIsNew,
34
+ deviceName: `${name}\n${adress1}\n${postCode} ${city} ${state}`
35
+ })
36
+ console.log('report to remote server complete')
37
+ }, waitSecond)
38
+
39
+
35
40
  }
36
41
 
37
- export async function logAction(content) {
42
+ export async function logAction(content, result = 0) {
38
43
  const deviceId = await getCurrentDeviceId()
39
44
  console.log(
40
45
  '*******************************************************\n' +
@@ -44,7 +49,7 @@ export async function logAction(content) {
44
49
  )
45
50
  await hillo.jsonPost("https://cloud-v2.aaden.io/deviceLog/createEvent", {
46
51
  deviceId,
47
- content,
52
+ content: content + ' result:' + result,
48
53
  type: '系统生成',
49
54
  operator: "aaden-cli v" + version
50
55
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aaden-cli",
3
- "version": "1.6.69",
3
+ "version": "1.6.71",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {