aaden-cli 1.3.13 → 1.3.15
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 +14887 -54661
- package/index.js +8 -64
- package/modules/cli-utils.js +9 -4
- package/modules/firebase.mjs +66 -0
- package/package.json +4 -4
- package/aws.js +0 -42
- package/generateFullSql.js +0 -21
- package/sql/1.sql +0 -1378
- package/sql/clean.sql +0 -8
- package/utils/checkInSet.js +0 -23
- package/utils/renameFile.js +0 -19
package/index.js
CHANGED
|
@@ -13,7 +13,6 @@ const GlobalDeviceId = 'notset'
|
|
|
13
13
|
const {program} = require('commander')
|
|
14
14
|
const cli = require('./modules/cli-utils')
|
|
15
15
|
const {hillo} = require('hillo')
|
|
16
|
-
const {uploadFile} = require('./aws')
|
|
17
16
|
const version = require('./package.json').version
|
|
18
17
|
|
|
19
18
|
program.version(version)
|
|
@@ -43,8 +42,6 @@ program.command('local-version').action(() => {
|
|
|
43
42
|
program.command('backup [noUpload]').action(backup)
|
|
44
43
|
program.command('ngrok').action(startNgrokService)
|
|
45
44
|
program.command('update-ngrok-config <deviceId>').action(updateNgrokConfig)
|
|
46
|
-
program.command('get-database').action(getDatabase)
|
|
47
|
-
program.command('get-newdatabase').action(getNewDatabase)
|
|
48
45
|
program.command('run <filePath>').action(run)
|
|
49
46
|
program.command('patch').action(patch)
|
|
50
47
|
program.command('check-tse').action(checkTse)
|
|
@@ -57,14 +54,8 @@ program.command('db').action(enterDatabase)
|
|
|
57
54
|
program.command('printer-test').action(testPrinter)
|
|
58
55
|
program.command('log').action(log)
|
|
59
56
|
program.command('fix-cronjob').action(fixCronJob)
|
|
60
|
-
program.command('enable-mile-pay').action(enableMilePay)
|
|
61
|
-
program.command('start-mile-pay').action(startService)
|
|
62
57
|
program.command('convert-database').action(convertDataBaseCharset)
|
|
63
|
-
|
|
64
|
-
.option('-k, --access-key <accessKey>')
|
|
65
|
-
.option('-s, --access-secret <accessSecret>')
|
|
66
|
-
.option('-m, --merchant-no <merchantNo>')
|
|
67
|
-
.action(milePayOption)
|
|
58
|
+
|
|
68
59
|
program.command('enable-resource-track').action(enableResourceTrack)
|
|
69
60
|
program.command('start-resource-track').action(startResourceTrack)
|
|
70
61
|
program.command('auto-send-mail').action(editIni)
|
|
@@ -80,6 +71,7 @@ program.command('send-single-bon-without-zip-false').action(editConfigIni(setCon
|
|
|
80
71
|
program.command('auto-write-gdpdu').action(autoWriteGdpdu)
|
|
81
72
|
program.command('export-tse').action(exportTse)
|
|
82
73
|
program.command('fix-ngrok').action(fixNgrok)
|
|
74
|
+
program.command('do-log').action(doLog)
|
|
83
75
|
|
|
84
76
|
if (program.debug) {
|
|
85
77
|
debugInfo()
|
|
@@ -161,7 +153,7 @@ function enterDatabase() {
|
|
|
161
153
|
}
|
|
162
154
|
|
|
163
155
|
function fixNgrok() {
|
|
164
|
-
|
|
156
|
+
run('AadenDeploy/Utils/enableNgrok.sh')
|
|
165
157
|
}
|
|
166
158
|
|
|
167
159
|
function testPrinter() {
|
|
@@ -630,62 +622,14 @@ async function removeAllData() {
|
|
|
630
622
|
cli.executeInShell(command, program.debug)
|
|
631
623
|
}
|
|
632
624
|
|
|
633
|
-
async function enableMilePay() {
|
|
634
|
-
cli.executeInShell([
|
|
635
|
-
'cd /home/aaden',
|
|
636
|
-
'mkdir biomace',
|
|
637
|
-
'cd biomace',
|
|
638
|
-
'wget https://innerken.com/biomace/biomace.sh',
|
|
639
|
-
'wget https://innerken.com/biomace/logback-spring-biomace.xml',
|
|
640
|
-
'wget https://innerken.com/biomace/application.yml',
|
|
641
|
-
'axel -n 6 https://innerken.com/biomace/biomace-0.0.1-SNAPSHOT.jar',
|
|
642
|
-
'wget https://innerken.com/biomace/mile-pay-pay-method.sql',
|
|
643
|
-
'mkdir log',
|
|
644
|
-
'cd /etc/systemd/system',
|
|
645
|
-
'sudo wget https://innerken.com/biomace/biomace.service',
|
|
646
|
-
'aaden-cli start-mile-pay'
|
|
647
|
-
], program.debug)
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
async function startService() {
|
|
651
|
-
const deviceId = getMyDeviceId()
|
|
652
|
-
if (deviceId === -1) return
|
|
653
|
-
const filePath = '/home/aaden/biomace/application.yml'
|
|
654
|
-
const res = fs.readFileSync(filePath).toString()
|
|
655
|
-
const out = res.replace('identifier: IK0001', 'identifier: IK' + deviceId)
|
|
656
|
-
fs.writeFileSync(filePath, out)
|
|
657
|
-
|
|
658
|
-
cli.executeInShell([
|
|
659
|
-
'sudo systemctl start biomace.service',
|
|
660
|
-
'sudo systemctl enable biomace.service',
|
|
661
|
-
'sudo service biomace start',
|
|
662
|
-
'echo "请输入数据库密码(和开机密码,sudo密码相同)"',
|
|
663
|
-
'mysql -uaaden -Daaden -p < /home/aaden/biomace/mile-pay-pay-method.sql'
|
|
664
|
-
], program.debug)
|
|
665
|
-
}
|
|
666
625
|
|
|
667
|
-
async function
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
}
|
|
626
|
+
async function doLog() {
|
|
627
|
+
const res = cli.executeInShell(['snap info aaden-vue-app'])
|
|
628
|
+
const log = res.stdout
|
|
629
|
+
console.log(log.split('\n'))
|
|
630
|
+
await deviceEcho(log, version)
|
|
673
631
|
|
|
674
|
-
Object.entries(operations).forEach(entry => {
|
|
675
|
-
const [key, value] = entry
|
|
676
|
-
const newValue = options[key]
|
|
677
|
-
if (newValue !== undefined) {
|
|
678
|
-
editMilePaySettings(newValue, value)
|
|
679
|
-
console.log(`${key} 已变更为 ${newValue}`)
|
|
680
|
-
}
|
|
681
|
-
})
|
|
682
|
-
}
|
|
683
632
|
|
|
684
|
-
function editMilePaySettings(newValue, transform) {
|
|
685
|
-
const filePath = '/home/aaden/biomace/application.yml'
|
|
686
|
-
const res = fs.readFileSync(filePath).toString()
|
|
687
|
-
const out = transform(newValue, res)
|
|
688
|
-
fs.writeFileSync(filePath, out)
|
|
689
633
|
}
|
|
690
634
|
|
|
691
635
|
async function enableResourceTrack() {
|
package/modules/cli-utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const util = require('util')
|
|
2
2
|
const colors = require('colors')
|
|
3
|
-
const
|
|
3
|
+
const {spawnSync} = require('child_process')
|
|
4
4
|
|
|
5
5
|
function getLine (char, lineLength = 20) {
|
|
6
6
|
return char.repeat(lineLength)
|
|
@@ -21,12 +21,16 @@ function executeInShell (cmd, debug = false) {
|
|
|
21
21
|
try {
|
|
22
22
|
showCommand(cmd)
|
|
23
23
|
if (debug) {
|
|
24
|
-
return
|
|
24
|
+
return {
|
|
25
|
+
result:false
|
|
26
|
+
}
|
|
25
27
|
}
|
|
26
|
-
|
|
28
|
+
return {
|
|
29
|
+
result: true,
|
|
30
|
+
...spawnSync(_cmd, [], {
|
|
27
31
|
shell: true,
|
|
28
32
|
stdio: 'inherit'
|
|
29
|
-
})
|
|
33
|
+
})}
|
|
30
34
|
} catch (e) {
|
|
31
35
|
console.log(getLine('*'))
|
|
32
36
|
console.log(e.bgRed)
|
|
@@ -34,6 +38,7 @@ function executeInShell (cmd, debug = false) {
|
|
|
34
38
|
console.log(getLine('*'))
|
|
35
39
|
}
|
|
36
40
|
console.log(getLine('*'))
|
|
41
|
+
return { result:false}
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
module.exports = {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Import the functions you need from the SDKs you need
|
|
2
|
+
import { initializeApp } from "firebase/app";
|
|
3
|
+
import { getAnalytics } from "firebase/analytics";
|
|
4
|
+
import { doc, getFirestore, setDoc, updateDoc } from 'firebase/firestore'
|
|
5
|
+
import dayjs from "dayjs";
|
|
6
|
+
import hillo from "hillo";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// https://firebase.google.com/docs/web/setup#available-libraries
|
|
10
|
+
|
|
11
|
+
// Your web app's Firebase configuration
|
|
12
|
+
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
|
|
13
|
+
const firebaseConfig = {
|
|
14
|
+
apiKey: "AIzaSyCtvQ3d-HAtHTUg_-505c-qXRnlz8RlZeg",
|
|
15
|
+
authDomain: "aaden-saas.firebaseapp.com",
|
|
16
|
+
projectId: "aaden-saas",
|
|
17
|
+
storageBucket: "aaden-saas.appspot.com",
|
|
18
|
+
messagingSenderId: "169167876904",
|
|
19
|
+
appId: "1:169167876904:web:454ff7fc59672c55cc161d",
|
|
20
|
+
measurementId: "G-21L0J096PE"
|
|
21
|
+
};
|
|
22
|
+
// Initialize Firebase
|
|
23
|
+
const app = initializeApp(firebaseConfig);
|
|
24
|
+
const db = getFirestore(app)
|
|
25
|
+
|
|
26
|
+
const deviceEchoPath = 'DeviceEcho'
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const echoLogPath = 'echoLog'
|
|
30
|
+
hillo.initial('http://localhost/PHP/')
|
|
31
|
+
|
|
32
|
+
export async function deviceEcho (frontEndVersion,cliVersion) {
|
|
33
|
+
const myDeviceId = await getCurrentDeviceId()
|
|
34
|
+
if (parseInt(myDeviceId) === -1) {
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
const timestamp = dayjs().format('YYYY-MM-DD')
|
|
38
|
+
await setDoc(doc(db, deviceEchoPath, myDeviceId, echoLogPath, timestamp), {
|
|
39
|
+
frontendVersion: frontEndVersion,
|
|
40
|
+
cliVersion,
|
|
41
|
+
backendVersion: await getCurrentBackendVersion(),
|
|
42
|
+
timestamp: dayjs().valueOf(),
|
|
43
|
+
restaurantInfo: await getNiceRestaurantInfo(),
|
|
44
|
+
deviceId: myDeviceId,
|
|
45
|
+
accessFrom: location.toString()
|
|
46
|
+
})
|
|
47
|
+
console.log('report to remote server complete')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function getCurrentBackendVersion () {
|
|
51
|
+
return (await hillo.get('MyVersion.php?op=version', {}, {
|
|
52
|
+
mode: 'no-cors'
|
|
53
|
+
})).version
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function getCurrentDeviceId () {
|
|
57
|
+
try {
|
|
58
|
+
return (await hillo.get('AccessLog.php?op=deviceId')).content
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return -1
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export async function getNiceRestaurantInfo () {
|
|
64
|
+
return (await hillo.get('Restaurant.php?op=view')).content[0]
|
|
65
|
+
}
|
|
66
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aaden-cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"@vercel/ncc": "^0.28.5",
|
|
29
29
|
"colors": "^1.4.0",
|
|
30
30
|
"commander": "^5.1.0",
|
|
31
|
-
"dayjs": "^1.
|
|
32
|
-
"hillo": "^1.1.
|
|
31
|
+
"dayjs": "^1.11.10",
|
|
32
|
+
"hillo": "^1.1.23",
|
|
33
33
|
"innerken-js-utils": "^1.0.6",
|
|
34
34
|
"prompts": "^2.4.0",
|
|
35
35
|
"read-ini-file": "^3.0.0",
|
|
36
36
|
"release-it": "^13.6.3"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"
|
|
39
|
+
"firebase": "^10.6.0",
|
|
40
40
|
"ini": "^3.0.1"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/aws.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const AWS = require('aws-sdk')
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
|
|
4
|
-
const id = 'AKIA4TTJEQRYQ7CBPK5W'
|
|
5
|
-
const secret = 'qhdoKOeKHGtCcbLfmNp7hx1ILVbHFbtLB4jEswFI'
|
|
6
|
-
const bucketName = 'aaden-backup-bucket'
|
|
7
|
-
|
|
8
|
-
const s3 = new AWS.S3({
|
|
9
|
-
accessKeyId: id,
|
|
10
|
-
secretAccessKey: secret
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
function getMyDeviceId () {
|
|
14
|
-
const loadIniFile = require('read-ini-file')
|
|
15
|
-
try {
|
|
16
|
-
return loadIniFile.sync('/var/www/html/Resource/config/config.ini').Device.DeviceId
|
|
17
|
-
} catch (e) {
|
|
18
|
-
return -1
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const uploadFile = (fileName) => {
|
|
24
|
-
const fileContent = fs.readFileSync(fileName)
|
|
25
|
-
|
|
26
|
-
const params = {
|
|
27
|
-
Bucket: bucketName,
|
|
28
|
-
Key: getMyDeviceId() + '/backups/' + 'backup.sql',
|
|
29
|
-
Body: fileContent
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
s3.upload(params, function (err, data) {
|
|
33
|
-
if (err) {
|
|
34
|
-
throw err
|
|
35
|
-
}
|
|
36
|
-
console.log(`File uploaded successfully. ${data.Location}`)
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = {
|
|
41
|
-
uploadFile
|
|
42
|
-
}
|
package/generateFullSql.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const sql = fs.readFileSync('sql/1.sql')
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const queries = sql.toString().split(';')
|
|
6
|
-
const res = []
|
|
7
|
-
queries.forEach(q => {
|
|
8
|
-
// console.log(q)
|
|
9
|
-
const lines = q.split('\n')
|
|
10
|
-
// console.log(lines)
|
|
11
|
-
const tableName = lines.find(l => l.includes('INTO'))
|
|
12
|
-
if (tableName) {
|
|
13
|
-
const realTableName = tableName.split('`')[1]
|
|
14
|
-
const ids = lines.filter(l => l.includes('(')).map(l => l.split('(')[1].split(',')[0])
|
|
15
|
-
const query = 'Delete from ' + realTableName + ' where id in (' + ids.join(',') + ');'
|
|
16
|
-
// console.log(query)
|
|
17
|
-
res.push(query)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
})
|
|
21
|
-
fs.writeFileSync('sql/clean.sql', res.join('\n'))
|