@chahuadev/framework 5.0.1 → 5.0.3
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/index.js +18 -78
- package/install.js +98 -0
- package/package.json +4 -8
package/index.js
CHANGED
|
@@ -1,91 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { spawnSync } = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
4
5
|
const os = require('os');
|
|
5
6
|
|
|
6
|
-
// Define OS and architecture mapping
|
|
7
7
|
const platform = os.platform();
|
|
8
8
|
const arch = os.arch();
|
|
9
|
-
|
|
10
|
-
'win32-x64': '@chahuadev/framework-win32-x64',
|
|
11
|
-
'win32-ia32': '@chahuadev/framework-win32-ia32',
|
|
12
|
-
'linux-x64': '@chahuadev/framework-linux',
|
|
13
|
-
'linux-arm64': '@chahuadev/framework-linux',
|
|
14
|
-
'darwin-x64': '@chahuadev/framework-darwin-x64',
|
|
15
|
-
'darwin-arm64': '@chahuadev/framework-darwin-arm64',
|
|
16
|
-
};
|
|
9
|
+
let exeName = '';
|
|
17
10
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
console.error(`Error: Chahuadev Framework does not support ${platform} ${arch} (${platform}-${arch}).`);
|
|
25
|
-
console.error(`Supported platforms: ${supportedPlatforms}`);
|
|
11
|
+
if (platform === 'win32') {
|
|
12
|
+
exeName = arch === 'ia32' ? 'Chahuadev Framework-win-ia32.exe' : 'Chahuadev Framework-win-x64.exe';
|
|
13
|
+
} else if (platform === 'linux') {
|
|
14
|
+
exeName = 'Chahuadev Framework.AppImage';
|
|
15
|
+
} else {
|
|
16
|
+
console.error(`Unsupported platform: ${platform}`);
|
|
26
17
|
process.exit(1);
|
|
27
18
|
}
|
|
28
19
|
|
|
29
|
-
|
|
30
|
-
// Resolve the path to the OS-specific package
|
|
31
|
-
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
32
|
-
const packageDir = path.dirname(packageJsonPath);
|
|
33
|
-
const binDir = path.join(packageDir, 'bin');
|
|
34
|
-
|
|
35
|
-
// Find the executable file based on platform and architecture
|
|
36
|
-
const fs = require('fs');
|
|
37
|
-
let exePath;
|
|
38
|
-
|
|
39
|
-
if (platform === 'win32') {
|
|
40
|
-
// For Windows, select EXE based on architecture
|
|
41
|
-
if (arch === 'ia32') {
|
|
42
|
-
exePath = path.join(binDir, 'Chahuadev Framework-win-ia32.exe');
|
|
43
|
-
} else if (arch === 'x64') {
|
|
44
|
-
exePath = path.join(binDir, 'Chahuadev Framework-win-x64.exe');
|
|
45
|
-
} else {
|
|
46
|
-
throw new Error(`Unsupported Windows architecture: ${arch}`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!fs.existsSync(exePath)) {
|
|
50
|
-
throw new Error(`Executable not found: ${exePath}`);
|
|
51
|
-
}
|
|
52
|
-
} else if (platform === 'linux') {
|
|
53
|
-
// For Linux, use AppImage
|
|
54
|
-
exePath = path.join(binDir, 'Chahuadev Framework.AppImage');
|
|
55
|
-
|
|
56
|
-
if (!fs.existsSync(exePath)) {
|
|
57
|
-
throw new Error(`AppImage not found: ${exePath}`);
|
|
58
|
-
}
|
|
59
|
-
} else if (platform === 'darwin') {
|
|
60
|
-
// For macOS, look for .app or executable
|
|
61
|
-
const files = fs.readdirSync(binDir).filter(f => f.endsWith('.app') || !f.includes('.'));
|
|
62
|
-
const exeFile = files[0];
|
|
63
|
-
if (!exeFile) {
|
|
64
|
-
throw new Error(`No executable found in ${binDir} for macOS`);
|
|
65
|
-
}
|
|
66
|
-
exePath = path.join(binDir, exeFile);
|
|
67
|
-
} else {
|
|
68
|
-
throw new Error(`Unknown platform: ${platform}`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Make the executable file (chmod +x on Unix-like systems)
|
|
72
|
-
if (platform !== 'win32') {
|
|
73
|
-
fs.chmodSync(exePath, 0o755);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Pass all arguments to the executable
|
|
77
|
-
const args = process.argv.slice(2);
|
|
78
|
-
const result = spawnSync(exePath, args, { stdio: 'inherit' });
|
|
79
|
-
|
|
80
|
-
// Exit with the same code as the executable
|
|
81
|
-
process.exit(result.status || 0);
|
|
20
|
+
const exePath = path.join(__dirname, 'bin', exeName);
|
|
82
21
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
console.error(`Make sure to run: npm install ${packageName}`);
|
|
87
|
-
} else {
|
|
88
|
-
console.error('Failed to start Chahuadev Framework:', error.message);
|
|
89
|
-
}
|
|
22
|
+
if (!fs.existsSync(exePath)) {
|
|
23
|
+
console.error(`Executable not found: ${exePath}`);
|
|
24
|
+
console.error('Try running "npm install" again to download the binary.');
|
|
90
25
|
process.exit(1);
|
|
91
|
-
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const args = process.argv.slice(2);
|
|
29
|
+
const result = spawnSync(exePath, args, { stdio: 'inherit' });
|
|
30
|
+
|
|
31
|
+
process.exit(result.status || 0);
|
package/install.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const https = require('https');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
|
|
6
|
+
const platform = os.platform();
|
|
7
|
+
const arch = os.arch();
|
|
8
|
+
|
|
9
|
+
let downloadUrl = '';
|
|
10
|
+
let fileName = '';
|
|
11
|
+
|
|
12
|
+
// 1. เช็ก OS เพื่อเลือกลิงก์ดาวน์โหลด
|
|
13
|
+
if (platform === 'win32') {
|
|
14
|
+
if (arch === 'ia32') {
|
|
15
|
+
downloadUrl = 'https://huggingface.co/datasets/chahuadev/chahuadev-framework-binaries/resolve/main/Chahuadev%20Framework-win-ia32.exe?download=true';
|
|
16
|
+
fileName = 'Chahuadev Framework-win-ia32.exe';
|
|
17
|
+
} else if (arch === 'x64') {
|
|
18
|
+
downloadUrl = 'https://huggingface.co/datasets/chahuadev/chahuadev-framework-binaries/resolve/main/Chahuadev%20Framework-win-x64.exe?download=true';
|
|
19
|
+
fileName = 'Chahuadev Framework-win-x64.exe';
|
|
20
|
+
}
|
|
21
|
+
} else if (platform === 'linux') {
|
|
22
|
+
downloadUrl = 'https://huggingface.co/datasets/chahuadev/chahuadev-framework-binaries/resolve/main/Chahuadev%20Framework.AppImage?download=true';
|
|
23
|
+
fileName = 'Chahuadev Framework.AppImage';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!downloadUrl) {
|
|
27
|
+
console.error(`Error: Chahuadev Framework does not support ${platform} ${arch}`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 2. สร้างโฟลเดอร์ bin เพื่อเก็บไฟล์ที่โหลดมา
|
|
32
|
+
const binDir = path.join(__dirname, 'bin');
|
|
33
|
+
if (!fs.existsSync(binDir)) {
|
|
34
|
+
fs.mkdirSync(binDir);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const filePath = path.join(binDir, fileName);
|
|
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`);
|
|
40
|
+
|
|
41
|
+
// 3. ฟังก์ชันดาวน์โหลดพร้อมระบบโชว์ Progress Bar
|
|
42
|
+
function downloadFile(url, dest) {
|
|
43
|
+
https.get(url, (response) => {
|
|
44
|
+
// จัดการกรณีลิงก์ถูก Redirect
|
|
45
|
+
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
46
|
+
return downloadFile(response.headers.location, dest);
|
|
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
|
+
|
|
90
|
+
}).on('error', (err) => {
|
|
91
|
+
fs.unlink(dest, () => {}); // ถ้า error ให้ลบไฟล์ที่โหลดค้างทิ้ง
|
|
92
|
+
console.error('\n❌ Download failed:', err.message);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// เริ่มดาวน์โหลด
|
|
98
|
+
downloadFile(downloadUrl, filePath);
|
package/package.json
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chahuadev/framework",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"description": "Chahuadev Framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"chahuadev-framework": "index.js"
|
|
8
8
|
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"@chahuadev/framework-win32-ia32": "^5.0.1",
|
|
12
|
-
"@chahuadev/framework-linux-x64": "^5.0.1",
|
|
13
|
-
"@chahuadev/framework-darwin-x64": "^5.0.1",
|
|
14
|
-
"@chahuadev/framework-darwin-arm64": "^5.0.1"
|
|
9
|
+
"scripts": {
|
|
10
|
+
"postinstall": "node install.js"
|
|
15
11
|
},
|
|
16
12
|
"publishConfig": {
|
|
17
13
|
"access": "public"
|
|
18
14
|
}
|
|
19
|
-
}
|
|
15
|
+
}
|