@chahuadev/framework 5.0.0 → 5.0.2

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 (3) hide show
  1. package/index.js +18 -97
  2. package/install.js +61 -0
  3. package/package.json +4 -8
package/index.js CHANGED
@@ -1,110 +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
- const packageMap = {
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
- // Determine which package to use based on OS and architecture
19
- const packageKey = `${platform}-${arch}`;
20
- const packageName = packageMap[packageKey];
21
-
22
- if (!packageName) {
23
- const supportedPlatforms = Object.keys(packageMap).join(', ');
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
- try {
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, prioritize Portable EXE over Installer EXE
41
- const files = fs.readdirSync(binDir);
42
-
43
- // Step 1: Look for Portable EXE (preferred - runs without installation)
44
- let exeFile = files.find(f => f.includes('Portable') && f.endsWith('.exe'));
45
-
46
- // Step 2: If no Portable, look for regular EXE matching architecture
47
- if (!exeFile) {
48
- const exeFiles = files.filter(f => f.endsWith('.exe') && !f.includes('.msi'));
49
- exeFile = arch === 'ia32'
50
- ? exeFiles.find(f => f.includes('ia32')) || exeFiles.find(f => !f.includes('x64'))
51
- : exeFiles.find(f => !f.includes('ia32')) || exeFiles[0];
52
- }
53
-
54
- if (!exeFile) {
55
- throw new Error(`No executable found in ${binDir} for ${arch}`);
56
- }
57
- exePath = path.join(binDir, exeFile);
58
- } else if (platform === 'linux') {
59
- // For Linux, look for AppImage dynamically (version-independent)
60
- const files = fs.readdirSync(binDir);
61
-
62
- // Step 1: Look for .AppImage file
63
- const appImageFile = files.find(f => f.endsWith('.AppImage'));
64
-
65
- if (appImageFile) {
66
- exePath = path.join(binDir, appImageFile);
67
- } else {
68
- // Step 2: Fall back to linux-unpacked directory
69
- const unpackedDir = path.join(binDir, 'linux-unpacked');
70
- if (fs.existsSync(unpackedDir)) {
71
- const exeFiles = fs.readdirSync(unpackedDir);
72
- const exe = exeFiles.find(f => f.toLowerCase().includes('chahuadev') || f.toLowerCase().includes('framework'));
73
- exePath = path.join(unpackedDir, exe || exeFiles[0]);
74
- } else {
75
- throw new Error(`No executable found in ${binDir}`);
76
- }
77
- }
78
- } else if (platform === 'darwin') {
79
- // For macOS, look for .app or executable
80
- const files = fs.readdirSync(binDir).filter(f => f.endsWith('.app') || !f.includes('.'));
81
- const exeFile = files[0];
82
- if (!exeFile) {
83
- throw new Error(`No executable found in ${binDir} for macOS`);
84
- }
85
- exePath = path.join(binDir, exeFile);
86
- } else {
87
- throw new Error(`Unknown platform: ${platform}`);
88
- }
89
-
90
- // Make the executable file (chmod +x on Unix-like systems)
91
- if (platform !== 'win32') {
92
- fs.chmodSync(exePath, 0o755);
93
- }
94
-
95
- // Pass all arguments to the executable
96
- const args = process.argv.slice(2);
97
- const result = spawnSync(exePath, args, { stdio: 'inherit' });
98
-
99
- // Exit with the same code as the executable
100
- process.exit(result.status || 0);
20
+ const exePath = path.join(__dirname, 'bin', exeName);
101
21
 
102
- } catch (error) {
103
- if (error.code === 'MODULE_NOT_FOUND') {
104
- console.error(`Error: The ${packageName} package is not installed.`);
105
- console.error(`Make sure to run: npm install ${packageName}`);
106
- } else {
107
- console.error('Failed to start Chahuadev Framework:', error.message);
108
- }
22
+ if (!fs.existsSync(exePath)) {
23
+ console.error(`Executable not found: ${exePath}`);
24
+ console.error('Try running "npm install" again to download the binary.');
109
25
  process.exit(1);
110
- }
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,61 @@
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
+ // เช็ก 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
+ // สร้างโฟลเดอร์ 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
+
40
+ // ฟังก์ชันสำหรับดาวน์โหลดไฟล์และจัดการ Redirect
41
+ function downloadFile(url, dest) {
42
+ const file = fs.createWriteStream(dest);
43
+ https.get(url, (response) => {
44
+ if (response.statusCode === 301 || response.statusCode === 302) {
45
+ downloadFile(response.headers.location, dest); // วิ่งตามลิงก์ Redirect
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
+ });
53
+ }
54
+ }).on('error', (err) => {
55
+ fs.unlink(dest, () => {});
56
+ console.error('Download failed:', err.message);
57
+ process.exit(1);
58
+ });
59
+ }
60
+
61
+ downloadFile(downloadUrl, filePath);
package/package.json CHANGED
@@ -1,19 +1,15 @@
1
1
  {
2
2
  "name": "@chahuadev/framework",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "description": "Chahuadev Framework",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "chahuadev-framework": "index.js"
8
8
  },
9
- "optionalDependencies": {
10
- "@chahuadev/framework-win32-x64": "^5.0.0",
11
- "@chahuadev/framework-win32-ia32": "^5.0.0",
12
- "@chahuadev/framework-linux-x64": "^5.0.0",
13
- "@chahuadev/framework-darwin-x64": "^5.0.0",
14
- "@chahuadev/framework-darwin-arm64": "^5.0.0"
9
+ "scripts": {
10
+ "postinstall": "node install.js"
15
11
  },
16
12
  "publishConfig": {
17
13
  "access": "public"
18
14
  }
19
- }
15
+ }