-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtypescript.lua
More file actions
51 lines (45 loc) · 2.25 KB
/
typescript.lua
File metadata and controls
51 lines (45 loc) · 2.25 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
--- Typescript language actions
local M = {}
--- Frontend - options displayed on telescope
M.options = {
{ text = "Run this file", value = "option1" },
{ text = "Run program", value = "option2" }
}
--- Backend - overseer tasks performed on option selected
function M.action(selected_option)
local utils = require("compiler.utils")
local overseer = require("overseer")
local current_file = vim.fn.expand('%:p') -- current file
local entry_point = utils.os_path(vim.fn.getcwd() .. "/src/index.ts") -- working_directory/index.ts
local output_dir = utils.os_path(vim.fn.getcwd() .. "/dist/") -- working_directory/dist/
local arguments = "--outDir " .. utils.os_path(output_dir, true)
local final_message = "--task finished--"
if selected_option == "option1" then
local current_file_js = output_dir .. vim.fn.fnamemodify(current_file, ":t:r") .. ".js"
local task = overseer.new_task({
name = "- Typescript interpreter",
strategy = { "orchestrator",
tasks = {{ name = "- Run this file → \"" .. current_file .. "\"",
cmd = "npx tsc " .. arguments .. -- transpile to js
" && node \"" .. current_file_js .. "\"" .. -- run program (interpreted)
" && echo \"" .. current_file .. "\"" .. -- echo
" && echo \"" .. final_message .. "\"",
components = { "default_extended" }
},},},})
task:start()
elseif selected_option == "option2" then
local entry_point_js = output_dir .. vim.fn.fnamemodify(entry_point, ":t:r") .. ".js"
local task = overseer.new_task({
name = "- Typescript interpreter",
strategy = { "orchestrator",
tasks = {{ name = "- Run this program → \"" .. entry_point .. "\"",
cmd = "npx tsc " .. arguments .. -- transpile to js
" && node \"" .. entry_point_js .. "\"" .. -- run program (interpreted)
" && echo \"" .. entry_point .. "\"" .. -- echo
" && echo \"" .. final_message .. "\"",
components = { "default_extended" }
},},},})
task:start()
end
end
return M