# Path: lib/utils/fileutils.py
# def file_exists(filename):
#     """ returns weather the file exists """
#     return os.path.isfile(os.path.normcase(filename))
# 
# Path: lib/utils/utils.py
# def replace_variables(value, variables):
#     if hasattr(sublime, 'expand_variables'): # ST3, Build 3068
#         # stringify dict
#         for k in variables.keys():
#             variables[k] = str(variables[k]);
#         return sublime.expand_variables(value, variables)
#     else:
#         # sort keys after length, to get $file_path before $file
#         keys = list(variables.keys())
#         keys.sort(key=len, reverse=True)
#         for k in keys:
#             key = "${%s}" % k
#             if key in value:
#                 value = value.replace(key, str(variables[k]))
#     return value
# 
# Path: lib/utils/debug.py
# def Debug(classification, text):
#     if 'all' in print_classifications or classification in print_classifications:
#         print("ArcticTypescript: %s: %s" % (classification.ljust(8), text))
#     if classification not in possible_classifications:
#         print("ArcticTypescript: debug: got unknown debug message classification: %s. " \
#             "Consider adding this to possible_classifications" % classification)
#     sys.stdout.flush()


import os
import sys
from .fileutils import file_exists
from .utils import replace_variables
from .debug import Debug


def default_node_path(node_path, project=None):
    if node_path == 'none':
        Debug('notify', 'The setting node_path is set to "none". That is depreciated. Remove the setting.')
        node_path = None

    if node_path == "" or node_path is None:
        if sys.platform == "linux":
            return "nodejs"
        elif sys.platform == "nt":
            return "node"
        elif sys.platform == "darwin":
            return "/usr/local/bin/node"
        else:
            return "node"
    else:
        return expand_variables(node_path, project)


def default_tsc_path(tsc_path=None, project=None):
    if tsc_path is not None and tsc_path:
        tsc_path = expand_variables(tsc_path, project)
        return tsc_path

    # search node_modules
    if project:
        node_modules_dir = search_node_modules(project.tsconfigdir)
        if node_modules_dir:
            tsc_path = os.path.join(node_modules_dir, ".bin", "tsc")

# Path: lib/utils/fileutils.py
# def file_exists(filename):
#     """ returns weather the file exists """
#     return os.path.isfile(os.path.normcase(filename))
# 
# Path: lib/utils/utils.py
# def replace_variables(value, variables):
#     if hasattr(sublime, 'expand_variables'): # ST3, Build 3068
#         # stringify dict
#         for k in variables.keys():
#             variables[k] = str(variables[k]);
#         return sublime.expand_variables(value, variables)
#     else:
#         # sort keys after length, to get $file_path before $file
#         keys = list(variables.keys())
#         keys.sort(key=len, reverse=True)
#         for k in keys:
#             key = "${%s}" % k
#             if key in value:
#                 value = value.replace(key, str(variables[k]))
#     return value
# 
# Path: lib/utils/debug.py
# def Debug(classification, text):
#     if 'all' in print_classifications or classification in print_classifications:
#         print("ArcticTypescript: %s: %s" % (classification.ljust(8), text))
#     if classification not in possible_classifications:
#         print("ArcticTypescript: debug: got unknown debug message classification: %s. " \
#             "Consider adding this to possible_classifications" % classification)
#     sys.stdout.flush()


# Path: lib/utils/pathutils.py
import os
import sys
from .fileutils import file_exists
from .utils import replace_variables
from .debug import Debug



def default_node_path(node_path, project=None):
    if node_path == 'none':
        Debug('notify', 'The setting node_path is set to "none". That is depreciated. Remove the setting.')
        node_path = None

    if node_path == "" or node_path is None:
        if sys.platform == "linux":
            return "nodejs"
        elif sys.platform == "nt":
            return "node"
        elif sys.platform == "darwin":
            return "/usr/local/bin/node"
        else:
            return "node"
    else:
        return expand_variables(node_path, project)


def default_tsc_path(tsc_path=None, project=None):
    if tsc_path is not None and tsc_path:
        tsc_path = expand_variables(tsc_path, project)
        return tsc_path

    # search node_modules
    if project:
        node_modules_dir = search_node_modules(project.tsconfigdir)
        if node_modules_dir:
            tsc_path = os.path.join(node_modules_dir, ".bin", "tsc")

            if file_exists(tsc_path):