@chahuadev/framework 5.0.2 → 5.0.4
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/README.md +10 -40
- package/install.js +51 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# @chahuadev/framework
|
|
2
1
|
|
|
3
2
|
The official core executable framework for Chahuadev.
|
|
4
3
|
|
|
@@ -19,7 +18,7 @@ This package provides a seamless way to integrate and run the Chahuadev Framewor
|
|
|
19
18
|
If you want to use the framework from your terminal anywhere on your system:
|
|
20
19
|
|
|
21
20
|
```bash
|
|
22
|
-
npm install -g @chahuadev/framework
|
|
21
|
+
npm install -g @chahuadev/framework --foreground-scripts
|
|
23
22
|
```
|
|
24
23
|
|
|
25
24
|
After installation, simply launch it:
|
|
@@ -36,7 +35,7 @@ The framework will:
|
|
|
36
35
|
If you want to integrate the framework into your specific project:
|
|
37
36
|
|
|
38
37
|
```bash
|
|
39
|
-
npm install @chahuadev/framework
|
|
38
|
+
npm install -g @chahuadev/framework --foreground-scripts
|
|
40
39
|
```
|
|
41
40
|
|
|
42
41
|
---
|
|
@@ -55,35 +54,10 @@ chahuadev-framework --dev-mode
|
|
|
55
54
|
chahuadev-framework --help
|
|
56
55
|
```
|
|
57
56
|
|
|
58
|
-
### 2. Node.js API
|
|
59
|
-
If installed locally in your project:
|
|
60
|
-
|
|
61
|
-
```javascript
|
|
62
|
-
const framework = require('@chahuadev/framework');
|
|
63
|
-
|
|
64
|
-
// The framework will auto-detect and run with appropriate binary
|
|
65
|
-
framework.run();
|
|
66
|
-
|
|
67
|
-
// Get path to the executable
|
|
68
|
-
const path = framework.getExecutablePath();
|
|
69
|
-
console.log('Executable:', path);
|
|
70
|
-
```
|
|
71
57
|
|
|
72
58
|
---
|
|
73
59
|
|
|
74
|
-
## How It Works
|
|
75
|
-
|
|
76
|
-
This package uses **`optionalDependencies`** to handle platform-specific binaries:
|
|
77
60
|
|
|
78
|
-
```json
|
|
79
|
-
{
|
|
80
|
-
"optionalDependencies": {
|
|
81
|
-
"@chahuadev/framework-win32-x64": "^1.1.0",
|
|
82
|
-
"@chahuadev/framework-win32-ia32": "^1.1.0",
|
|
83
|
-
"@chahuadev/framework-linux-x64": "^1.1.0"
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
61
|
|
|
88
62
|
**When you install:**
|
|
89
63
|
1. npm detects your OS and architecture
|
|
@@ -113,14 +87,12 @@ This ensures:
|
|
|
113
87
|
|
|
114
88
|
```
|
|
115
89
|
@chahuadev/
|
|
116
|
-
├── framework/
|
|
117
|
-
│ └── index.js
|
|
118
|
-
|
|
119
|
-
│ └──
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
└── framework-linux-x64/
|
|
123
|
-
└── bin/ (Linux x64 AppImage)
|
|
90
|
+
├── framework/
|
|
91
|
+
│ └── index.js
|
|
92
|
+
│ └── install.js
|
|
93
|
+
│ └── package.json
|
|
94
|
+
│ └── README.md
|
|
95
|
+
|
|
124
96
|
```
|
|
125
97
|
|
|
126
98
|
---
|
|
@@ -130,13 +102,13 @@ This ensures:
|
|
|
130
102
|
### "Command not found: chahuadev-framework"
|
|
131
103
|
Make sure you installed globally:
|
|
132
104
|
```bash
|
|
133
|
-
npm install -g @chahuadev/framework
|
|
105
|
+
npm install -g @chahuadev/framework --foreground-scripts
|
|
134
106
|
```
|
|
135
107
|
|
|
136
108
|
### "Module not found"
|
|
137
109
|
If using locally, ensure it's installed:
|
|
138
110
|
```bash
|
|
139
|
-
npm install @chahuadev/framework
|
|
111
|
+
npm install -g @chahuadev/framework --foreground-scripts
|
|
140
112
|
```
|
|
141
113
|
|
|
142
114
|
### "Unsupported platform"
|
|
@@ -149,7 +121,5 @@ Proprietary - Chahua Development Thailand
|
|
|
149
121
|
|
|
150
122
|
---
|
|
151
123
|
|
|
152
|
-
## Support
|
|
153
|
-
For issues or questions, visit: https://github.com/chahuadev/chahuadev-framework
|
|
154
124
|
|
|
155
125
|
|
package/install.js
CHANGED
|
@@ -9,7 +9,7 @@ const arch = os.arch();
|
|
|
9
9
|
let downloadUrl = '';
|
|
10
10
|
let fileName = '';
|
|
11
11
|
|
|
12
|
-
// เช็ก OS เพื่อเลือกลิงก์ดาวน์โหลด
|
|
12
|
+
// 1. เช็ก OS เพื่อเลือกลิงก์ดาวน์โหลด
|
|
13
13
|
if (platform === 'win32') {
|
|
14
14
|
if (arch === 'ia32') {
|
|
15
15
|
downloadUrl = 'https://huggingface.co/datasets/chahuadev/chahuadev-framework-binaries/resolve/main/Chahuadev%20Framework-win-ia32.exe?download=true';
|
|
@@ -28,7 +28,7 @@ if (!downloadUrl) {
|
|
|
28
28
|
process.exit(1);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// สร้างโฟลเดอร์ bin เพื่อเก็บไฟล์ที่โหลดมา
|
|
31
|
+
// 2. สร้างโฟลเดอร์ bin เพื่อเก็บไฟล์ที่โหลดมา
|
|
32
32
|
const binDir = path.join(__dirname, 'bin');
|
|
33
33
|
if (!fs.existsSync(binDir)) {
|
|
34
34
|
fs.mkdirSync(binDir);
|
|
@@ -36,26 +36,63 @@ if (!fs.existsSync(binDir)) {
|
|
|
36
36
|
|
|
37
37
|
const filePath = path.join(binDir, fileName);
|
|
38
38
|
console.log(`Downloading Chahuadev Framework for ${platform} (${arch})...`);
|
|
39
|
+
console.log(`Please wait, this may take a few minutes depending on your connection.\n`);
|
|
39
40
|
|
|
40
|
-
//
|
|
41
|
+
// 3. ฟังก์ชันดาวน์โหลดพร้อมระบบโชว์ Progress Bar
|
|
41
42
|
function downloadFile(url, dest) {
|
|
42
|
-
const file = fs.createWriteStream(dest);
|
|
43
43
|
https.get(url, (response) => {
|
|
44
|
+
// จัดการกรณีลิงก์ถูก Redirect
|
|
44
45
|
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
45
|
-
downloadFile(response.headers.location, dest);
|
|
46
|
-
} else {
|
|
47
|
-
response.pipe(file);
|
|
48
|
-
file.on('finish', () => {
|
|
49
|
-
file.close();
|
|
50
|
-
if (platform !== 'win32') fs.chmodSync(dest, 0o755); // ให้สิทธิ์รันบน Linux
|
|
51
|
-
console.log('Download completed successfully!');
|
|
52
|
-
});
|
|
46
|
+
return downloadFile(response.headers.location, dest);
|
|
53
47
|
}
|
|
48
|
+
|
|
49
|
+
// ดึงขนาดไฟล์ทั้งหมดมาเพื่อคำนวณ %
|
|
50
|
+
const totalBytes = parseInt(response.headers['content-length'], 10);
|
|
51
|
+
let downloadedBytes = 0;
|
|
52
|
+
|
|
53
|
+
const file = fs.createWriteStream(dest);
|
|
54
|
+
|
|
55
|
+
// ดักจับข้อมูลตอนที่กำลังโหลดทีละก้อน (chunk)
|
|
56
|
+
response.on('data', (chunk) => {
|
|
57
|
+
downloadedBytes += chunk.length;
|
|
58
|
+
|
|
59
|
+
if (!isNaN(totalBytes)) {
|
|
60
|
+
// คำนวณเปอร์เซ็นต์
|
|
61
|
+
const percent = ((downloadedBytes / totalBytes) * 100).toFixed(2);
|
|
62
|
+
const downloadedMB = (downloadedBytes / (1024 * 1024)).toFixed(2);
|
|
63
|
+
const totalMB = (totalBytes / (1024 * 1024)).toFixed(2);
|
|
64
|
+
|
|
65
|
+
// วาดหลอด Progress Bar
|
|
66
|
+
const barLength = 30;
|
|
67
|
+
const filledLength = Math.round((barLength * downloadedBytes) / totalBytes);
|
|
68
|
+
const bar = '█'.repeat(filledLength) + '-'.repeat(barLength - filledLength);
|
|
69
|
+
|
|
70
|
+
process.stdout.write(`\r[${bar}] ${percent}% (${downloadedMB} MB / ${totalMB} MB)`);
|
|
71
|
+
} else {
|
|
72
|
+
const downloadedMB = (downloadedBytes / (1024 * 1024)).toFixed(2);
|
|
73
|
+
process.stdout.write(`\rDownloading... ${downloadedMB} MB`);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
response.pipe(file);
|
|
78
|
+
|
|
79
|
+
file.on('finish', () => {
|
|
80
|
+
file.close();
|
|
81
|
+
console.log('\n\n✅ Download completed successfully!');
|
|
82
|
+
|
|
83
|
+
// *** ชี้เป้าหมายที่อยู่ไฟล์แบบชัดเจน ***
|
|
84
|
+
console.log(`📂 File saved to: ${dest}\n`);
|
|
85
|
+
|
|
86
|
+
// ให้สิทธิ์รันบน Linux
|
|
87
|
+
if (platform !== 'win32') fs.chmodSync(dest, 0o755);
|
|
88
|
+
});
|
|
89
|
+
|
|
54
90
|
}).on('error', (err) => {
|
|
55
|
-
fs.unlink(dest, () => {});
|
|
56
|
-
console.error('Download failed:', err.message);
|
|
91
|
+
fs.unlink(dest, () => {}); // ถ้า error ให้ลบไฟล์ที่โหลดค้างทิ้ง
|
|
92
|
+
console.error('\n❌ Download failed:', err.message);
|
|
57
93
|
process.exit(1);
|
|
58
94
|
});
|
|
59
95
|
}
|
|
60
96
|
|
|
97
|
+
// เริ่มดาวน์โหลด
|
|
61
98
|
downloadFile(downloadUrl, filePath);
|