@chahuadev/framework 5.0.1 → 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 -78
  2. package/install.js +61 -0
  3. 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
- 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, 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
- } catch (error) {
84
- if (error.code === 'MODULE_NOT_FOUND') {
85
- console.error(`Error: The ${packageName} package is not installed.`);
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,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.1",
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.1",
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
+ }