aaden-cli 1.6.88 → 1.6.90

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.
@@ -0,0 +1,260 @@
1
+ # Aaden CLI Development Guidelines
2
+
3
+ This document provides guidelines and instructions for developing and maintaining the Aaden CLI project.
4
+
5
+ ## Special Note from Human
6
+ 1. don't create test script if not asked to.
7
+
8
+ ## Build and Configuration
9
+
10
+ ### Prerequisites
11
+
12
+ - Node.js (v12 or higher recommended)
13
+ - npm (v6 or higher recommended)
14
+ - Git
15
+
16
+ ### Build Process
17
+
18
+ The project uses [@vercel/ncc](https://github.com/vercel/ncc) to compile the application into a single file. This process is automatically triggered during the release process, but can also be run manually:
19
+
20
+ ```bash
21
+ # Install dependencies if not already installed
22
+ npm install
23
+
24
+ # Build the project manually
25
+ npx ncc build index.js -o dist -C
26
+ ```
27
+
28
+ The `-C` flag ensures that assets are copied to the dist directory.
29
+
30
+ ### Release Process
31
+
32
+ The project uses [release-it](https://github.com/release-it/release-it) for versioning and releasing. The release process is configured in the `package.json` file:
33
+
34
+ ```json
35
+ "release-it": {
36
+ "hooks": {
37
+ "after:bump": "ncc build index.js -o dist -C"
38
+ },
39
+ "github.release": true,
40
+ "git": {
41
+ "commitMessage": "aaden-cli: release v${version}",
42
+ "requireCleanWorkingDir": false
43
+ }
44
+ }
45
+ ```
46
+
47
+ To create a new release:
48
+
49
+ ```bash
50
+ npm run update
51
+ ```
52
+
53
+ This will:
54
+ 1. Add all changes to git
55
+ 2. Bump the version according to release-it's prompts
56
+ 3. Build the project using ncc
57
+ 4. Create a git commit with the new version
58
+ 5. Create a GitHub release
59
+
60
+ ## Testing
61
+
62
+ ### Running Existing Tests
63
+
64
+ The project includes a basic test script that can be run with:
65
+
66
+ ```bash
67
+ npm test
68
+ ```
69
+
70
+ ### Creating New Tests
71
+
72
+ For more comprehensive testing, a structured approach is recommended. Here's an example of how to create and run tests:
73
+
74
+ 1. Create a test file (e.g., `my-test.js`) with the following structure:
75
+
76
+ ```javascript
77
+ const assert = require('assert');
78
+ const path = require('path');
79
+ const fs = require('fs');
80
+
81
+ // Test suite
82
+ const tests = {
83
+ // Test function
84
+ testSomething: () => {
85
+ console.log('Testing something...');
86
+
87
+ // Your test logic here
88
+ assert.strictEqual(true, true, 'This should be true');
89
+
90
+ console.log('✅ Test passed');
91
+ return true;
92
+ }
93
+ };
94
+
95
+ // Run all tests
96
+ console.log('Running tests...\n');
97
+ let passedTests = 0;
98
+ let failedTests = 0;
99
+
100
+ for (const [testName, testFunction] of Object.entries(tests)) {
101
+ try {
102
+ const result = testFunction();
103
+ if (result) {
104
+ passedTests++;
105
+ } else {
106
+ failedTests++;
107
+ console.error(`❌ Test ${testName} failed`);
108
+ }
109
+ } catch (error) {
110
+ failedTests++;
111
+ console.error(`❌ Test ${testName} failed with error: ${error.message}`);
112
+ }
113
+ console.log(''); // Add a newline between tests
114
+ }
115
+
116
+ // Print test summary
117
+ console.log(`\nTest summary: ${passedTests} passed, ${failedTests} failed`);
118
+
119
+ // Exit with appropriate code
120
+ process.exit(failedTests > 0 ? 1 : 0);
121
+ ```
122
+
123
+ 2. Run the test:
124
+
125
+ ```bash
126
+ node my-test.js
127
+ ```
128
+
129
+ ### Testing Best Practices
130
+
131
+ - Use Node.js's built-in `assert` module for assertions
132
+ - Group related tests in a test suite
133
+ - Provide clear error messages
134
+ - Test both success and failure cases
135
+ - Test edge cases
136
+ - Use descriptive test names
137
+
138
+ ## Code Style and Development Guidelines
139
+
140
+ ### Code Style
141
+
142
+ - Use CommonJS module system (require/module.exports)
143
+ - No semicolons at the end of statements
144
+ - Use single quotes for strings
145
+ - Use 4 spaces for indentation
146
+ - Use descriptive function and variable names
147
+ - Use color coding for console output (via the colors package)
148
+
149
+ ### Error Handling
150
+
151
+ - Use try/catch blocks for error handling
152
+ - Log errors with color highlighting
153
+ - Return objects with result status
154
+
155
+ ### Shell Command Execution
156
+
157
+ The project includes utility functions for executing shell commands in `modules/cli-utils.js`:
158
+
159
+ ```javascript
160
+ // Execute a shell command asynchronously
161
+ executeInShell(cmd, debug = false)
162
+
163
+ // Execute a shell command synchronously
164
+ executeInShellSync(cmd)
165
+ ```
166
+
167
+ Example usage:
168
+
169
+ ```javascript
170
+ const cli = require('./modules/cli-utils');
171
+
172
+ // Asynchronous execution
173
+ async function runCommand() {
174
+ const { result, code } = await cli.executeInShell(['command1', 'command2'], false);
175
+ if (result) {
176
+ console.log('Command executed successfully');
177
+ } else {
178
+ console.log('Command failed');
179
+ }
180
+ }
181
+
182
+ // Synchronous execution
183
+ function runCommandSync() {
184
+ const { result, output } = cli.executeInShellSync('command');
185
+ if (result) {
186
+ console.log('Output:', output);
187
+ } else {
188
+ console.log('Command failed');
189
+ }
190
+ }
191
+ ```
192
+
193
+ ### Adding New Commands
194
+
195
+ To add a new command to the CLI:
196
+
197
+ 1. Define the command in `index.js`:
198
+
199
+ ```javascript
200
+ program.command('new-command').action(newCommandFunction)
201
+ ```
202
+
203
+ 2. Implement the command function:
204
+
205
+ ```javascript
206
+ function newCommandFunction() {
207
+ // Command implementation
208
+ }
209
+ ```
210
+
211
+ 3. If the command requires shell execution, use the cli-utils module:
212
+
213
+ ```javascript
214
+ async function newCommandFunction() {
215
+ const command = [
216
+ 'command1',
217
+ 'command2'
218
+ ]
219
+ await cli.executeInShell(command, program.debug)
220
+ }
221
+ ```
222
+
223
+ ## Deployment
224
+
225
+ The project includes deployment scripts in the `AadenDeploy` directory:
226
+
227
+ - `aadensetup.sh`: Main installation script
228
+ - `update.sh`: For updating the system
229
+ - `upgrade.sh`: For upgrading components
230
+ - `mountTSE.sh`: For mounting the TSE device
231
+
232
+ To deploy the application:
233
+
234
+ ```bash
235
+ # Install on a new device
236
+ ./AadenDeploy/aadensetup.sh <deviceId> <channel>
237
+
238
+ # Update an existing installation
239
+ ./AadenDeploy/update.sh
240
+
241
+ # Upgrade the CLI itself
242
+ ./AadenDeploy/upgrade.sh
243
+ ```
244
+
245
+ ## Project Structure
246
+
247
+ - `index.js`: Main entry point
248
+ - `dist/index.js`: Compiled version (generated by ncc)
249
+ - `modules/`: Utility modules
250
+ - `AadenDeploy/`: Deployment scripts
251
+ - `files/`: Files needed for deployment
252
+ - `ngrok/`: Ngrok service configuration
253
+ - `Utils/`: Utility scripts
254
+ - `package.json`: Project configuration and dependencies
255
+
256
+ ## Additional Resources
257
+
258
+ - [Commander.js Documentation](https://github.com/tj/commander.js)
259
+ - [Vercel NCC Documentation](https://github.com/vercel/ncc)
260
+ - [Release-It Documentation](https://github.com/release-it/release-it)
@@ -0,0 +1,8 @@
1
+ # version=1 important: do NOT remove this line
2
+ /var/www/html/Resource/printlog/*.log {
3
+ compress
4
+ daily
5
+ rotate 14
6
+ missingok
7
+ notifempty
8
+ }
@@ -5,6 +5,7 @@ Const ForReading = 1
5
5
  Const ForWriting = 2
6
6
  Const ForAppending = 8
7
7
  Const CreateIfNotExist = True
8
+ Const AadenVersion = "1.6.88"
8
9
 
9
10
  ' Global Variable Declarations
10
11
  Dim fso, WshShell
@@ -46,6 +47,9 @@ Else
46
47
  WriteLog logFilePath, "Script is correctly located in the Startup folder."
47
48
  End If
48
49
 
50
+ ' Log the current Aaden CLI version
51
+ WriteLog logFilePath, "Aaden CLI version: " & AadenVersion
52
+
49
53
  ' Define the Aaden Desktop executable file path
50
54
  Dim appDataPath, aadenExePath
51
55
  appDataPath = WshShell.ExpandEnvironmentStrings("%LOCALAPPDATA%")
@@ -54,20 +58,61 @@ aadenExePath = appDataPath & "\Programs\aaden\Aaden Desktop.exe"
54
58
  ' Expected content of the file
55
59
  Dim expectedContent
56
60
  expectedContent = "@echo off" & vbCrLf & _
61
+ "setlocal enabledelayedexpansion" & vbCrLf & _
57
62
  "echo %date% %time% - Starting WSL and Aaden Desktop >> C:\AadenPOS\operation.log" & vbCrLf & _
58
- "wsl.exe --distribution Ubuntu --exec dbus-launch true" & vbCrLf & _
59
- "start """" /wait """ & aadenExePath & """" & vbCrLf & _
60
- "echo %date% %time% - Aaden Desktop closed, starting WSL monitoring >> C:\AadenPOS\operation.log" & vbCrLf & _
61
- "rem Monitor and restart WSL if it dies" & vbCrLf & _
62
- ":monitor_loop" & vbCrLf & _
63
- "timeout /t 60 /nobreak > nul" & vbCrLf & _
64
- "wsl.exe --distribution Ubuntu --exec echo ""Checking WSL status..."" > nul 2>&1" & vbCrLf & _
65
- "if %errorlevel% neq 0 (" & vbCrLf & _
66
- " echo %date% %time% - WSL is not running. Restarting... >> C:\AadenPOS\operation.log" & vbCrLf & _
67
- " wsl.exe --distribution Ubuntu --exec dbus-launch true" & vbCrLf & _
68
- " echo %date% %time% - WSL restart attempted >> C:\AadenPOS\operation.log" & vbCrLf & _
63
+ "" & vbCrLf & _
64
+ "set WSL_UTF8=1" & vbCrLf & _
65
+ "" & vbCrLf & _
66
+ "REM Start Aaden Desktop application once at the beginning" & vbCrLf & _
67
+ "start """" """ & aadenExePath & """" & vbCrLf & _
68
+ "" & vbCrLf & _
69
+ "REM Initial WSL startup" & vbCrLf & _
70
+ "call :start_distro" & vbCrLf & _
71
+ "echo %date% %time% - Starting WSL monitoring >> C:\AadenPOS\operation.log" & vbCrLf & _
72
+ "goto main" & vbCrLf & _
73
+ "" & vbCrLf & _
74
+ "REM Function to check WSL status" & vbCrLf & _
75
+ ":check_status" & vbCrLf & _
76
+ "wsl -l --running | FINDSTR Ubuntu >nul 2>&1" & vbCrLf & _
77
+ "if %errorlevel% equ 0 (" & vbCrLf & _
78
+ " set ""STATUS=running""" & vbCrLf & _
79
+ ") else (" & vbCrLf & _
80
+ " set ""STATUS=down""" & vbCrLf & _
81
+ ")" & vbCrLf & _
82
+ "goto :eof" & vbCrLf & _
83
+ "" & vbCrLf & _
84
+ "REM Function to start distro" & vbCrLf & _
85
+ ":start_distro" & vbCrLf & _
86
+ "wsl --exec dbus-launch true" & vbCrLf & _
87
+ "if %errorlevel% equ 0 (" & vbCrLf & _
88
+ " echo %DATE% %TIME% - WSL started successfully >> C:\AadenPOS\operation.log" & vbCrLf & _
89
+ ") else (" & vbCrLf & _
90
+ " echo %DATE% %TIME% - Failed to start WSL (error code: %errorlevel%) >> C:\AadenPOS\operation.log" & vbCrLf & _
91
+ ")" & vbCrLf & _
92
+ "goto :eof" & vbCrLf & _
93
+ "" & vbCrLf & _
94
+ "REM Main monitoring loop" & vbCrLf & _
95
+ ":main" & vbCrLf & _
96
+ "timeout /t 15 /nobreak > nul" & vbCrLf & _
97
+ "" & vbCrLf & _
98
+ "call :check_status" & vbCrLf & _
99
+ "if ""%STATUS%""==""running"" (" & vbCrLf & _
100
+ " goto main" & vbCrLf & _
101
+ ")" & vbCrLf & _
102
+ "" & vbCrLf & _
103
+ "echo %date% %time% - WSL Ubuntu is down, trying to start >> C:\AadenPOS\operation.log" & vbCrLf & _
104
+ "call :start_distro" & vbCrLf & _
105
+ "" & vbCrLf & _
106
+ "timeout /t 5 /nobreak >nul" & vbCrLf & _
107
+ "" & vbCrLf & _
108
+ "call :check_status" & vbCrLf & _
109
+ "if ""%STATUS%""==""running"" (" & vbCrLf & _
110
+ " echo %DATE% %TIME% - WSL restart successful >> C:\AadenPOS\operation.log" & vbCrLf & _
111
+ ") else (" & vbCrLf & _
112
+ " echo %DATE% %TIME% - WSL restart failed, will try again in next cycle >> C:\AadenPOS\operation.log" & vbCrLf & _
69
113
  ")" & vbCrLf & _
70
- "goto monitor_loop"
114
+ "" & vbCrLf & _
115
+ "goto main"
71
116
 
72
117
  ' Ensure the folder exists
73
118
  If Not fso.FolderExists(folderPath) Then
package/dist/index.js CHANGED
@@ -18507,7 +18507,7 @@ module.exports = JSON.parse('{"name":"axios","version":"0.19.2","description":"P
18507
18507
  /***/ ((module) => {
18508
18508
 
18509
18509
  "use strict";
18510
- module.exports = {"i8":"1.6.88"};
18510
+ module.exports = {"i8":"1.6.90"};
18511
18511
 
18512
18512
  /***/ })
18513
18513
 
@@ -18644,6 +18644,7 @@ program.command('export-tse').action(exportTse)
18644
18644
  program.command('fix-ngrok').action(fixNgrok)
18645
18645
  program.command('do-log').action(doLog)
18646
18646
  program.command('clean-backup-space').action(doCompress)
18647
+ program.command('ensure-print-log-rotate').action(ensurePrintLogRotate)
18647
18648
 
18648
18649
  if (program.debug) {
18649
18650
  debugInfo()
@@ -19303,6 +19304,37 @@ function downloadBroadcast() {
19303
19304
  cli.executeInShell(command, program.debug)
19304
19305
  }
19305
19306
 
19307
+
19308
+ function sudo() {
19309
+ return 'echo "Innerken322." | sudo -S'
19310
+ }
19311
+
19312
+ function ensurePrintLogRotate() {
19313
+ const targetVersion = 1
19314
+ const confPath = '/etc/logrotate.d/printlog'
19315
+ try {
19316
+ const printLogRotateConf = fs.readFileSync(confPath).toString()
19317
+ const firstLine = printLogRotateConf.split('\n')[0]
19318
+ const versionRegex = /\d+/
19319
+ if (!firstLine.search(versionRegex)) {
19320
+ throw new Error('no version detected')
19321
+ }
19322
+ const currentVersion = firstLine.match(/\d+/)[0];
19323
+ const currentVersionNum = parseInt(currentVersion, 10)
19324
+ if (currentVersionNum < targetVersion) {
19325
+ throw new Error('version low')
19326
+ }
19327
+ console.log('no need to set logrotate')
19328
+ } catch (e) {
19329
+ const command = []
19330
+ const sourcePath = `${__dirname}/../AadenDeploy/Utils/printlogRotate.conf`
19331
+
19332
+ command.push(`${sudo()} cp ${sourcePath} ${confPath}`)
19333
+
19334
+ cli.executeInShell(command, program.debug)
19335
+ }
19336
+ }
19337
+
19306
19338
  })();
19307
19339
 
19308
19340
  module.exports = __webpack_exports__;
package/index.js CHANGED
@@ -63,6 +63,7 @@ program.command('export-tse').action(exportTse)
63
63
  program.command('fix-ngrok').action(fixNgrok)
64
64
  program.command('do-log').action(doLog)
65
65
  program.command('clean-backup-space').action(doCompress)
66
+ program.command('ensure-print-log-rotate').action(ensurePrintLogRotate)
66
67
 
67
68
  if (program.debug) {
68
69
  debugInfo()
@@ -721,3 +722,34 @@ function downloadBroadcast() {
721
722
 
722
723
  cli.executeInShell(command, program.debug)
723
724
  }
725
+
726
+
727
+ function sudo() {
728
+ return 'echo "Innerken322." | sudo -S'
729
+ }
730
+
731
+ function ensurePrintLogRotate() {
732
+ const targetVersion = 1
733
+ const confPath = '/etc/logrotate.d/printlog'
734
+ try {
735
+ const printLogRotateConf = fs.readFileSync(confPath).toString()
736
+ const firstLine = printLogRotateConf.split('\n')[0]
737
+ const versionRegex = /\d+/
738
+ if (!firstLine.search(versionRegex)) {
739
+ throw new Error('no version detected')
740
+ }
741
+ const currentVersion = firstLine.match(/\d+/)[0];
742
+ const currentVersionNum = parseInt(currentVersion, 10)
743
+ if (currentVersionNum < targetVersion) {
744
+ throw new Error('version low')
745
+ }
746
+ console.log('no need to set logrotate')
747
+ } catch (e) {
748
+ const command = []
749
+ const sourcePath = `${__dirname}/../AadenDeploy/Utils/printlogRotate.conf`
750
+
751
+ command.push(`${sudo()} cp ${sourcePath} ${confPath}`)
752
+
753
+ cli.executeInShell(command, program.debug)
754
+ }
755
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aaden-cli",
3
- "version": "1.6.88",
3
+ "version": "1.6.90",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,179 +0,0 @@
1
-
2
-
3
- ## Aaden配置说明
4
- ---
5
-
6
- 下载地址[https://2.gp/a72RO]
7
-
8
- 请将本文件夹整个拷贝到目标电脑上
9
-
10
- 右键目标电脑上到文件夹
11
-
12
- 选择在此打开终端
13
-
14
- 打开终端后 输入
15
-
16
- ./aadensetup.sh
17
-
18
- 如果提示权限不够,需要右键sh文件,给予她执行权限
19
-
20
- 按照流程配置要求配置,请注意查看所有提示文字
21
-
22
- ----
23
-
24
- 执行结束后,建立一个最高权限的匿名用户,在终端中执行下面的语句
25
-
26
- mysql < aaden.sql
27
-
28
- ---
29
-
30
- 更改服务器权限
31
-
32
- 将var/www/html 目录改为777权限,注意选择需要recurisive。
33
-
34
-
35
- ---
36
-
37
- ## 配置CronJob
38
-
39
-
40
- 进入webmin
41
-
42
- 在搜索栏中搜索cronjob 选择 Scheduled Cron Jobs
43
-
44
- 在右上角选择create a new Schedule cron job后进入创建CronJob窗口
45
-
46
- 选择Execute cron job as root 或 aaden
47
-
48
- command 一栏中填写
49
- ```
50
- /var/www/html/crontab.sh > /dev/null 2>&1
51
- ```
52
-
53
- When to execute 一项选择 每分钟执行一次
54
-
55
- Times and dates selected below ..
56
-
57
- 后面全部选择All
58
-
59
- 然后点Create
60
-
61
- 然后会退出
62
-
63
- 然后点击Save and run now
64
-
65
- 看到这样的显示说明正常
66
-
67
- 下面同理,命令换成
68
-
69
- 每小时执行一次
70
-
71
- command:
72
- ```
73
- wget -O /dev/null "http://localhost/PHP/AccessLog.php?op=reportStatus"
74
- ```
75
-
76
-
77
-
78
-
79
- ## 最后一步
80
-
81
- 记录ip,并获取其他安装包
82
-
83
- ---
84
-
85
- 如果自动配置失败,此处以下是之前保留的手动配置脚本
86
-
87
- ## 结构说明
88
-
89
- 注:ip内容为服务器的ip,如果在服务器本身上访问,可以使用Localhost代替
90
-
91
- 1. 依赖环境
92
- PHP,Mysql,Webmin,Crontab,sshserver,net-tools
93
-
94
- webmin网址: https://{{ip}}:10000
95
-
96
- 2. 数据库
97
-
98
- 默认用户名:aaden
99
-
100
- 默认密码:Innerken322.
101
-
102
- 默认库名:aaden
103
-
104
-
105
- 订单 DishesOrder表,DishesOrderDetail表,Zbon表
106
-
107
- 打印记录 PrintQuest
108
-
109
- 操作记录 AccessLog
110
-
111
- ### 重要表:
112
-
113
- 菜品 Dishes,Category
114
-
115
- 跑堂 Servant
116
-
117
- 桌子 Tables
118
-
119
- 打印机 Printers
120
-
121
-
122
- 1. 后台
123
-
124
- PHP,Resource 必须放在一起
125
-
126
- PHP,Resource 默认应该部署在/var/www/html/
127
-
128
- PHP文件夹中,有两个地方是重要的配置文件,第一个是PHP/DB/DBDriver.php 看第一行,使用的是哪一个config文件。进入Configs目录中找到对应的文件,更改相关数据库信息。
129
- 第二个是PHP/GlobalSettings.php,
130
- edit
131
-
132
- $SERVEMAIL="support@innerken.com"; 这里可以设置客服邮箱,
133
-
134
- $DEVICE_NAME='IKDEV';//取名字
135
-
136
- $DEVICE_ID=1;//分一个
137
-
138
-
139
- 第三个是PHP/Bon/BonBase.php
140
-
141
- const LINE_LENGTH = self::LINE_LENGTH_80;
142
-
143
- 改为对应的打印机毫米数
144
-
145
-
146
- 根链接:http://{{ip}}/PHP/
147
- ->
148
- 如果有改动,需要告知技术人员,并且更改前台代码
149
-
150
- 其中,Resource文件夹必须拥有777权限,否则会导致菜品图片无法上传。
151
-
152
-
153
-
154
- 1. 前台
155
- 前台
156
- 源码/usr/lib/aaden下 找到resources 文件夹
157
-
158
- app/app/下的index.js
159
-
160
- 这个文件负责控制窗口和命令行的开关
161
-
162
- // win.webContents.openDevTools();
163
-
164
- 该行,如果取消注释,那么就会打开命令行
165
-
166
- app/app/htmlTpl/js/common/tpl.js
167
-
168
- 注:需要改变 DEVICEID
169
-
170
-
171
-
172
- 1. 扫码点餐
173
-
174
-
175
- 目录在/var/www/html/ScanToOrder/asset/js/GlobalSetting.js
176
-
177
- 更改
178
-
179
- Configs.DEVICEID=1;