@ilrksy/kelatescript 1.0.0 → 1.0.1

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.
@@ -5,19 +5,33 @@ const path = require('path');
5
5
  const babel = require('@babel/core');
6
6
  const kelantanPlugin = require('../plugin');
7
7
 
8
- const filePath = process.argv[2];
8
+ const args = process.argv.slice(2);
9
+ const command = args[0];
9
10
 
10
- if (!filePath) {
11
- console.log('Sila masukkan fail: kelantanscript <fail.ks>');
11
+ if (!command || command === '--help' || command === '-h') {
12
+ console.log('Penggunaan: kelatescript <fail.ks>');
13
+ process.exit(0);
14
+ }
15
+
16
+ const filePath = path.resolve(command);
17
+
18
+ if (!fs.existsSync(filePath)) {
19
+ console.error(`Ralat: Fail '${command}' tak jumpa bohh!`);
12
20
  process.exit(1);
13
21
  }
14
22
 
15
- const sourceCode = fs.readFileSync(path.resolve(filePath), 'utf-8');
23
+ // 1. Baca kod asal Kelantan
24
+ let sourceCode = fs.readFileSync(filePath, 'utf-8');
25
+
26
+ // 2. Pre-process perkataan asas supaya menjadi JS yang sah untuk diparse oleh Babel
27
+ sourceCode = sourceCode
28
+ .replace(/\bpoyok\b/g, 'const')
29
+ .replace(/\bbuat\b/g, 'let');
16
30
 
17
- // Transpile kod Kelantan ke JS
31
+ // 3. Masukkan ke Babel untuk pemprosesan lanjut
18
32
  const { code } = babel.transformSync(sourceCode, {
19
33
  plugins: [kelantanPlugin]
20
34
  });
21
35
 
22
- // Jalankan kod JavaScript yang dihasilkan
23
- eval(code);
36
+ // 4. Jalankan kod
37
+ eval(code);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ilrksy/kelatescript",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Bahasa pengaturcaraan berasaskan dialek Kelantan",
5
5
  "main": "index.js",
6
6
  "bin": {
package/test.ks ADDED
@@ -0,0 +1,7 @@
1
+ poyok nama = "Abe We";
2
+ royak("Gomo Kelate Gomo, " + nama);
3
+
4
+
5
+
6
+
7
+