|
1 | 1 | import sublime_plugin |
2 | | -import sublime |
3 | | -import os |
4 | | -from ..libs.global_vars import IS_ST2 |
| 2 | + |
| 3 | +from ..libs.global_vars import * |
| 4 | +from ..libs import cli |
5 | 5 |
|
6 | 6 |
|
7 | 7 | class TypescriptBuildCommand(sublime_plugin.WindowCommand): |
8 | 8 | def run(self): |
| 9 | + if get_node_path() is None: |
| 10 | + print("Cannot found node. Build cancelled.") |
| 11 | + return |
| 12 | + |
9 | 13 | file_name = self.window.active_view().file_name() |
10 | | - directory = os.path.dirname(file_name) |
11 | | - if "tsconfig.json" in os.listdir(directory): |
12 | | - self.window.run_command("exec", { |
13 | | - "cmd": ["tsc"], |
14 | | - "file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$", |
15 | | - "shell": True |
16 | | - }) |
17 | | - else: |
18 | | - sublime.active_window().show_input_panel( |
19 | | - "Build parameters: ", |
20 | | - "", # initial text |
21 | | - self.compile_inferred_project, |
22 | | - None, # on change |
23 | | - None # on cancel |
24 | | - ) |
| 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 | + "file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$", |
| 21 | + "shell": True |
| 22 | + }) |
| 23 | + else: |
| 24 | + sublime.active_window().show_input_panel( |
| 25 | + "Build parameters: ", |
| 26 | + "", # initial text |
| 27 | + self.compile_inferred_project, |
| 28 | + None, # on change |
| 29 | + None # on cancel |
| 30 | + ) |
25 | 31 |
|
26 | 32 | def compile_inferred_project(self, params=""): |
27 | 33 | file_name = self.window.active_view().file_name() |
28 | | - if not IS_ST2: |
29 | | - cmd = "tsc {0} {1}".format(file_name, params) |
30 | | - self.window.run_command("exec", { |
31 | | - "shell_cmd": cmd, |
32 | | - "file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$" |
33 | | - }) |
34 | | - else: |
35 | | - cmd = "tsc {0} {1}".format(file_name, params) |
36 | | - self.window.run_command("exec", { |
37 | | - "cmd": [cmd], |
38 | | - "file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$", |
39 | | - "shell": True |
40 | | - }) |
| 34 | + cmd = [get_node_path(), TSC_PATH, file_name] |
| 35 | + if params != "": |
| 36 | + cmd.extend(params.split(' ')) |
| 37 | + self.window.run_command("exec", { |
| 38 | + "cmd": cmd, |
| 39 | + "file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$", |
| 40 | + "shell": True |
| 41 | + }) |
0 commit comments