-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrunCode.js
More file actions
90 lines (83 loc) · 3.21 KB
/
runCode.js
File metadata and controls
90 lines (83 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
EnScript is/was made by TriSn0w(gunner) in May of 2022. You are allowed to use this script for learning purposes, but don't advertise it as your own.
Thanks to the contributors for there help: @Aidan-The-Dev
Also, this EnScript version is PTB, not stable. if you want the stable released, go here: https://github.com/Trisn0w/EnScript/releases
*/
let newLines = []
var args = process.argv[2] // gets file name from ClI command
if (!args.endsWith('.en')) {
if (!args.endsWith('.en.native')) {
throw new Error('you must provide a .en or .en.native file!') // if file name does not have a extension of ".en" or ".en.native", throw a error
} else {
// continue!
}
}
if (args.endsWith('.en')) {
const lineByLine = require('n-readlines');
const liner = new lineByLine(args); // setup line reader
let line;
let lineNumber = 0;
while (line = liner.next()) { // while there is another line
let lineString = line.toString('ascii') // make line buffer into ascii string
if (lineString.includes('!!') || lineString == "") { // if
// dont do nothing
} else {
if (!lineString.includes(';')) {
if (!lineString.includes('{') || !lineString.includes('}')) {
throw new SyntaxError('(line ' + (lineNumber + 3) + ') You need to add a ";" at the end of every line!\n\n' + lineString)
} else {
newLines.push(lineString)
}
} else {
if (lineString.includes('import')) {
newLines.push(`${lineString.replace('import ', 'require(\'').replace(';', '') + "');"}`)
} else if (lineString.includes('log ')) {
newLines.push(`${lineString.replace('log ', 'console.log(').replace(';', '')}` + ');')
} else if (lineString.includes('env(\'')) {
newLines.push(`${lineString.replace('env(\'', 'process.env.').replace("'", '').replace("'", '').replace("')", '').replace(')', '')}`)
} else if (lineString.includes(';') && lineString.includes('`')) {
newLines.push(lineString.replace(';', ''));
}
else {
newLines.push(lineString)
}
lineNumber++;
}
}
}
try {
eval(newLines.join(" "))
} catch(err) {
console.log(err)
}
} else if (args.endsWith('.en.native')) {
const lineByLine = require('n-readlines');
const liner = new lineByLine(args); // setup line reader
let line;
let lineNumber = 0;
while (line = liner.next()) { // while there is another line
let lineString = line.toString('ascii') // make line buffer into ascii string
if (lineString.includes('!!') || lineString == "") { // if
// dont do nothing
} else {
if (lineString.includes('import')) {
newLines.push(`${lineString.replace('import ', 'require(\'').replace(';', '') + "');"}`)
} else if (lineString.includes('log ')) {
newLines.push(`${lineString.replace('log ', 'console.log(').replace(';', '')}` + ');')
} else if (lineString.includes('env(\'')) {
newLines.push(`${lineString.replace('env(\'', 'process.env.').replace("'", '').replace("'", '').replace("')", '').replace(')', '')}`)
} else if (lineString.includes(';') && lineString.includes('`')) {
newLines.push(lineString.replace(';', ''));
}
else {
newLines.push(lineString)
}
lineNumber++;
}
}
}
try {
eval(newLines.join('\n'))
} catch(err) {
console.log(err)
}