@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.
- package/bin/kelantanscript.js +21 -7
- package/package.json +1 -1
- package/test.ks +7 -0
package/bin/kelantanscript.js
CHANGED
|
@@ -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
|
|
8
|
+
const args = process.argv.slice(2);
|
|
9
|
+
const command = args[0];
|
|
9
10
|
|
|
10
|
-
if (!
|
|
11
|
-
console.log('
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
|
23
|
-
eval(code);
|
|
36
|
+
// 4. Jalankan kod
|
|
37
|
+
eval(code);
|
package/package.json
CHANGED