|
| 1 | +import sublime_plugin |
| 2 | + |
| 3 | +from ..libs.global_vars import * |
| 4 | +from ..libs import cli |
| 5 | + |
| 6 | + |
| 7 | +class TypescriptBuildCommand(sublime_plugin.WindowCommand): |
| 8 | + def run(self): |
| 9 | + if get_node_path() is None: |
| 10 | + print("Cannot find node. Build cancelled.") |
| 11 | + return |
| 12 | + |
| 13 | + file_name = self.window.active_view().file_name() |
| 14 | + project_info = cli.service.project_info(file_name) |
| 15 | + if project_info["success"]: |
| 16 | + if "configFileName" in project_info["body"]: |
| 17 | + tsconfig_dir = dirname(project_info["body"]["configFileName"]) |
| 18 | + self.window.run_command("exec", { |
| 19 | + "cmd": [get_node_path(), TSC_PATH, "-p", tsconfig_dir], |
| 20 | + # regex to capture build result for displaying in the output panel |
| 21 | + "file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$" |
| 22 | + }) |
| 23 | + else: |
| 24 | + sublime.active_window().show_input_panel( |
| 25 | + "Build parameters: ", |
| 26 | + "", # initial text |
| 27 | + lambda params: self.compile_inferred_project(file_name, params), |
| 28 | + None, # on change |
| 29 | + None # on cancel |
| 30 | + ) |
| 31 | + |
| 32 | + def compile_inferred_project(self, file_name, params=""): |
| 33 | + cmd = [get_node_path(), TSC_PATH, file_name] |
| 34 | + print(cmd) |
| 35 | + if params != "": |
| 36 | + cmd.extend(params.split(' ')) |
| 37 | + self.window.run_command("exec", { |
| 38 | + "cmd": cmd, |
| 39 | + "file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$" |
| 40 | + }) |
0 commit comments