Skip to content

Commit

Permalink
Added Build: Eval for JavaScript/TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
NawfalAhmed committed Aug 16, 2022
1 parent a81aebd commit 86ac68f
Show file tree
Hide file tree
Showing 5 changed files with 1,689 additions and 0 deletions.
9 changes: 9 additions & 0 deletions SublimeUserSettings/Builds/Node - Eval.sublime-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"shell_cmd": "node /Users/nawfalahmed/Sublime/evalNode/evalNode.js \"$file\"",
"file_regex": "(...*?):([0-9]*):?([0-9]*)",
"selector": "(source.jsx, source.js, source.tsx, source.ts)",
"working_dir": "$file_path",
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
"focus": true
}
28 changes: 28 additions & 0 deletions evalNode/evalNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import ts from 'typescript'
const { transpile } = ts

import fs from 'fs'
const { readFileSync } = fs

const keypress = async () => {
process.stdin.setRawMode(true)
return new Promise(resolve => process.stdin.once('data', () => {
process.stdin.setRawMode(false)
resolve()
}))
}
const messages = []
function alert(message) {
messages.push(message)
}
(async () => {
const data = readFileSync(process.argv[2], 'utf8')
let result = transpile(data)
let last = await eval(result)
for (let message of messages) {
console.log(message, "[Enter]",)
await keypress()
}
if (last != undefined)
console.log(last)
})().then(process.exit)
Loading

0 comments on commit 86ac68f

Please sign in to comment.