aaden-cli 1.1.113 → 1.1.117

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.
Files changed (4) hide show
  1. package/aws.js +43 -0
  2. package/dist/index.js +53970 -14660
  3. package/index.js +55 -16
  4. package/package.json +4 -1
package/index.js CHANGED
@@ -7,9 +7,10 @@ const InnerKenTimeStampFormat = 'YYYYMMDDHHmmss'
7
7
  const prompts = require('prompts')
8
8
  const GlobalDeviceId = 'notset'
9
9
 
10
- const { program } = require('commander')
10
+ const {program} = require('commander')
11
11
  const cli = require('./modules/cli-utils')
12
- const { hillo } = require('hillo')
12
+ const {hillo} = require('hillo')
13
+ const {uploadFile} = require('./aws')
13
14
  const version = require('./package.json').version
14
15
 
15
16
  program.version(version)
@@ -53,6 +54,12 @@ program.command('db').action(enterDatabase)
53
54
  program.command('printer-test').action(testPrinter)
54
55
  program.command('enable-mile-pay').action(enableMilePay)
55
56
  program.command('start-mile-pay').action(startService)
57
+ program.command('mile-pay-option')
58
+ .option('-k, --access-key <accessKey>')
59
+ .option('-s, --access-secret <accessSecret>')
60
+ .option('-m, --merchant-no <merchantNo>')
61
+ .action(milePayOption)
62
+
56
63
 
57
64
  if (program.debug) {
58
65
  debugInfo()
@@ -80,17 +87,17 @@ async function selectOption () {
80
87
  message: 'Select what you want to do next? ' +
81
88
  '请选择下一步要进行的操作',
82
89
  choices: [
83
- { title: 'Upgrade Aaden-cli 手动更新Aaden-cli到最新版本', description: '', value: 'upgrade' },
84
- { title: 'Backup all backend data 备份后端数据库数据', description: '操作数据库数据前请先备份', value: 'backup' },
85
- { title: 'Full update 全更新', description: '更新前请先备份', value: 'full-update' },
86
- { title: 'Check Tse 检查Tse设备', description: '', value: 'check-tse' },
87
- { title: 'Start Ngrok 打开Ngrok服务', description: '', value: 'ngrok' },
88
- { title: 'Install Aaden Kasse 安装最新版Aaden Kasse', value: `install ${GlobalDeviceId}` },
89
- { title: 'Add Dishes 执行上菜脚本app.py', description: '-p ImgPath -i DishCSVPath -a AttrPath', value: 'add-dish' },
90
- { title: 'Check version 检查后端版本号', description: '', value: 'check-version' },
91
- { title: 'Patch 打补丁', description: '请勿手动执行', value: 'patch' },
92
- { title: 'Remove all data 删除所有数据', description: '谨慎操作'.red, value: 'remove-all-data' },
93
- { title: 'Setup Tse 安装Tse', description: '谨慎操作'.red + ' 每个设备只能安装一次TSE', value: 'setup-tse' },
90
+ {title: 'Upgrade Aaden-cli 手动更新Aaden-cli到最新版本', description: '', value: 'upgrade'},
91
+ {title: 'Backup all backend data 备份后端数据库数据', description: '操作数据库数据前请先备份', value: 'backup'},
92
+ {title: 'Full update 全更新', description: '更新前请先备份', value: 'full-update'},
93
+ {title: 'Check Tse 检查Tse设备', description: '', value: 'check-tse'},
94
+ {title: 'Start Ngrok 打开Ngrok服务', description: '', value: 'ngrok'},
95
+ {title: 'Install Aaden Kasse 安装最新版Aaden Kasse', value: `install ${GlobalDeviceId}`},
96
+ {title: 'Add Dishes 执行上菜脚本app.py', description: '-p ImgPath -i DishCSVPath -a AttrPath', value: 'add-dish'},
97
+ {title: 'Check version 检查后端版本号', description: '', value: 'check-version'},
98
+ {title: 'Patch 打补丁', description: '请勿手动执行', value: 'patch'},
99
+ {title: 'Remove all data 删除所有数据', description: '谨慎操作'.red, value: 'remove-all-data'},
100
+ {title: 'Setup Tse 安装Tse', description: '谨慎操作'.red + ' 每个设备只能安装一次TSE', value: 'setup-tse'},
94
101
  {
95
102
  title: 'Mount Tse 永久挂载Tse设备', description: '谨慎操作'.red + ' ' +
96
103
  '进行此操作会导致TSE重新自检,使用前请先检查是否已经正确插入Tse设备(Tse设备是否正常亮灯)', value: 'mount-tse'
@@ -100,7 +107,7 @@ async function selectOption () {
100
107
  description: '输入本设备的DeviceId,更新Ngrok配置',
101
108
  value: `update-ngrok-config ${GlobalDeviceId}`
102
109
  },
103
- { title: 'Exit 退出', description: 'return to terminal', value: 'return-terminal' }
110
+ {title: 'Exit 退出', description: 'return to terminal', value: 'return-terminal'}
104
111
  ],
105
112
  initial: 1
106
113
  })
@@ -277,7 +284,15 @@ async function backup (full = true) {
277
284
  'cd ' + backupHome,
278
285
  'sudo rsync -av --delete /var/www/html/ .'
279
286
  ]
287
+
280
288
  cli.executeInShell(command, program.debug)
289
+ setTimeout(() => {
290
+ const homedir = require('os').homedir()
291
+ const fileName = [homedir, 'backups', timeStamp, `${timeStamp}@cli.sql`].join('/')
292
+ uploadFile(fileName)
293
+ }, 8000)
294
+
295
+
281
296
  }
282
297
 
283
298
  async function updateCheck (channel = '') {
@@ -550,7 +565,7 @@ async function enableMilePay () {
550
565
  'mkdir log',
551
566
  'cd /etc/systemd/system',
552
567
  'sudo wget https://innerken.com/biomace/biomace.service',
553
- 'aaden-cli start-mile-pay',
568
+ 'aaden-cli start-mile-pay'
554
569
  ], program.debug)
555
570
  }
556
571
 
@@ -567,10 +582,34 @@ async function startService () {
567
582
  'sudo systemctl enable biomace.service',
568
583
  'sudo service biomace start',
569
584
  'echo "请输入数据库密码(和开机密码,sudo密码相同)"',
570
- 'mysql -uaaden -Daaden -p < /home/aaden/biomace/mile-pay-pay-method.sql',
585
+ 'mysql -uaaden -Daaden -p < /home/aaden/biomace/mile-pay-pay-method.sql'
571
586
  ], program.debug)
572
587
  }
573
588
 
589
+ async function milePayOption (options) {
590
+ const operations = {
591
+ accessKey: (accessKey, res) => res.replace(/access-key: +[a-zA-Z0-9]+/g, 'access-key: ' + accessKey),
592
+ accessSecret: (accessSecret, res) => res.replace(/access-secret: +[a-zA-Z0-9]+/g, 'access-secret: ' + accessSecret),
593
+ merchantNo: (merchantNo, res) => res.replace(/merchant-no: +\d+/g, 'merchant-no: ' + merchantNo)
594
+ }
595
+
596
+ Object.entries(operations).forEach(entry => {
597
+ const [key, value] = entry
598
+ const newValue = options[key]
599
+ if (newValue !== undefined) {
600
+ editMilePaySettings(newValue, value)
601
+ console.log(`${key} 已变更为 ${newValue}`)
602
+ }
603
+ })
604
+ }
605
+
606
+ function editMilePaySettings (newValue, transform) {
607
+ const filePath = '/home/aaden/biomace/application.yml'
608
+ const res = fs.readFileSync(filePath).toString()
609
+ const out = transform(newValue, res)
610
+ fs.writeFileSync(filePath, out)
611
+ }
612
+
574
613
  function returnTerminal () {
575
614
 
576
615
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aaden-cli",
3
- "version": "1.1.113",
3
+ "version": "1.1.117",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -34,5 +34,8 @@
34
34
  "prompts": "^2.4.0",
35
35
  "read-ini-file": "^3.0.0",
36
36
  "release-it": "^13.6.3"
37
+ },
38
+ "dependencies": {
39
+ "aws-sdk": "^2.1046.0"
37
40
  }
38
41
  }