janofidel 1.0.0 → 1.0.4
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/jano.js +27 -17
- package/package.json +1 -1
- package/src/runner.js +29 -4
package/bin/jano.js
CHANGED
|
@@ -1,42 +1,52 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const { processFile } = require('../src/engine');
|
|
2
|
+
const { processFile } = require('../src/engine');
|
|
3
3
|
const { runCode } = require('../src/runner');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const pkg = require('../package.json');
|
|
5
6
|
|
|
6
|
-
// Branding
|
|
7
|
+
// Branding Colors
|
|
7
8
|
const RED_BG = '\x1b[41m';
|
|
8
9
|
const WHITE_TEXT = '\x1b[37m';
|
|
9
10
|
const BOLD = '\x1b[1m';
|
|
10
11
|
const RESET = '\x1b[0m';
|
|
11
12
|
|
|
12
|
-
const logo = `${RED_BG}${WHITE_TEXT}${BOLD} ጃ ${RESET} ${RED_BG}${WHITE_TEXT}${BOLD} ፊ ${RESET} ${BOLD}ጃኖ ፊደል (Jano Fidel)${RESET}\n`;
|
|
13
|
+
const logo = `${RED_BG}${WHITE_TEXT}${BOLD} ጃ ${RESET} ${RED_BG}${WHITE_TEXT}${BOLD} ፊ ${RESET} ${BOLD}ጃኖ ፊደል (Jano Fidel)${RESET} v${pkg.version}\n`;
|
|
13
14
|
|
|
14
|
-
const
|
|
15
|
+
const args = process.argv.slice(2);
|
|
16
|
+
const fileArg = args[0];
|
|
15
17
|
|
|
16
|
-
// 1.
|
|
17
|
-
if (
|
|
18
|
+
// 1. Handle Version Flag
|
|
19
|
+
if (args.includes('--version') || args.includes('-v')) {
|
|
18
20
|
console.log(logo);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
process.exit(0);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 2. Handle Help Flag or No Arguments
|
|
25
|
+
if (args.includes('--help') || args.includes('-h') || !fileArg) {
|
|
26
|
+
console.log(logo);
|
|
27
|
+
console.log(`${BOLD}አጠቃቀም (Usage):${RESET}`);
|
|
28
|
+
console.log(" jano <ፋይል_ስም.jf>");
|
|
29
|
+
|
|
30
|
+
console.log(`\n${BOLD}ትዕዛዞች (Flags):${RESET}`);
|
|
31
|
+
console.log(" -v, --version የስሪት ቁጥሩን ያሳያል (Show version)");
|
|
32
|
+
console.log(" -h, --help ይህንን መመሪያ ያሳያል (Show help)");
|
|
33
|
+
|
|
34
|
+
console.log(`\n${BOLD}ምሳሌ (Example):${RESET}`);
|
|
35
|
+
console.log(" jano ሰላም.jf");
|
|
36
|
+
process.exit(0);
|
|
21
37
|
}
|
|
22
38
|
|
|
23
|
-
//
|
|
39
|
+
// 3. Main Execution
|
|
24
40
|
const filePath = path.resolve(process.cwd(), fileArg);
|
|
25
41
|
|
|
26
42
|
if (!filePath.endsWith('.jf')) {
|
|
27
|
-
console.error(
|
|
43
|
+
console.error(`${BOLD}${RED_BG} ስህተት ${RESET} ፋይሉ በ '.jf' ማለቅ አለበት።`);
|
|
28
44
|
process.exit(1);
|
|
29
45
|
}
|
|
30
46
|
|
|
31
|
-
// 3. The Execution Flow
|
|
32
47
|
try {
|
|
33
|
-
// Note: Use your existing processFile which reads the code and adds the prelude
|
|
34
48
|
const jsCode = processFile(filePath);
|
|
35
|
-
|
|
36
|
-
// This calls your professional runner with the styled boxes
|
|
37
49
|
runCode(jsCode, filePath);
|
|
38
|
-
|
|
39
50
|
} catch (err) {
|
|
40
|
-
|
|
41
|
-
console.error(`\n[የጃኖ ስህተት]: ${err.message}`);
|
|
51
|
+
console.error(`\n${BOLD}${RED_BG} የጃኖ ስህተት ${RESET}: ${err.message}`);
|
|
42
52
|
}
|
package/package.json
CHANGED
package/src/runner.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const { spawn } = require('child_process');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
|
-
const
|
|
4
|
+
const { version } = require('../package.json'); // Pull version from package.json
|
|
5
5
|
|
|
6
|
-
// --- 1. Helpers
|
|
6
|
+
// --- 1. Helpers ---
|
|
7
7
|
|
|
8
8
|
const style = {
|
|
9
9
|
red: (t) => `\x1b[31m${t}\x1b[0m`,
|
|
@@ -12,6 +12,30 @@ const style = {
|
|
|
12
12
|
reset: '\x1b[0m'
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Handles CLI flags before running code
|
|
17
|
+
* @param {string[]} args
|
|
18
|
+
*/
|
|
19
|
+
function handleFlags(args) {
|
|
20
|
+
if (args.includes('--version') || args.includes('-v')) {
|
|
21
|
+
console.log(`ጃኖ ፊደል (Jano Fidel) - Version ${version}`);
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
25
|
+
console.log(`
|
|
26
|
+
${style.bold("ጃኖ ፊደል (Jano Fidel) CLI")}
|
|
27
|
+
|
|
28
|
+
${style.bold("አጠቃቀም (Usage):")}
|
|
29
|
+
jano <ፋይል_ስም.jf>
|
|
30
|
+
|
|
31
|
+
${style.bold("ትዕዛዞች (Flags):")}
|
|
32
|
+
-v, --version የስሪት ቁጥሩን ያሳያል (Show version)
|
|
33
|
+
-h, --help ይህንን መመሪያ ያሳያል (Show help)
|
|
34
|
+
`);
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
15
39
|
function getExitSummary(code) {
|
|
16
40
|
if (code === 1) return "ያልተጠበቀ ስህተት አጋጥሟል (Uncaught Error)";
|
|
17
41
|
if (code === 130) return "ተጠቃሚው ፕሮግራሙን አቋርጦታል (User Interrupted)";
|
|
@@ -28,6 +52,9 @@ function remapStack(data, tempFilePath, originalFileName) {
|
|
|
28
52
|
// --- 2. Main Execution Function ---
|
|
29
53
|
|
|
30
54
|
function runCode(jsCode, originalFilePath) {
|
|
55
|
+
// Check flags from the actual command line
|
|
56
|
+
handleFlags(process.argv.slice(2));
|
|
57
|
+
|
|
31
58
|
const fileName = path.basename(originalFilePath);
|
|
32
59
|
const dirName = path.dirname(path.resolve(originalFilePath));
|
|
33
60
|
const tempFile = path.join(dirName, `.${path.basename(originalFilePath, '.jf')}.tmp.js`);
|
|
@@ -35,7 +62,6 @@ function runCode(jsCode, originalFilePath) {
|
|
|
35
62
|
try {
|
|
36
63
|
fs.writeFileSync(tempFile, jsCode, 'utf8');
|
|
37
64
|
|
|
38
|
-
// Preload the hook to handle imports
|
|
39
65
|
const hookPath = require.resolve('./hook');
|
|
40
66
|
const child = spawn('node', ['-r', hookPath, tempFile], {
|
|
41
67
|
stdio: ['inherit', 'inherit', 'pipe'],
|
|
@@ -47,7 +73,6 @@ function runCode(jsCode, originalFilePath) {
|
|
|
47
73
|
process.stderr.write(remappedError);
|
|
48
74
|
});
|
|
49
75
|
|
|
50
|
-
// --- THE BOX UI LOGIC HERE ---
|
|
51
76
|
child.on('close', (code) => {
|
|
52
77
|
if (fs.existsSync(tempFile)) {
|
|
53
78
|
try { fs.unlinkSync(tempFile); } catch(e) {}
|