Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to use locally installed coffee #234

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion CoffeeScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,22 @@ def _run(cmd, args=[], source="", cwd=None, env=None):
okay = proc.returncode == 0
return {"okay": okay, "out": stat[0].decode(locale.getdefaultlocale()[1]), "err": stat[1].decode(locale.getdefaultlocale()[1])}
else:
bindir = settings_get('binDir', '/usr/local/bin')
if bindir.startswith("./"):
bindir = current_project_folder() + bindir[1:]

if env is None:
env = {"PATH": settings_get('binDir', '/usr/local/bin')}
env = {"PATH": bindir}

# adding custom PATHs from settings
customEnv = settings_get('envPATH', "")
if customEnv:
env["PATH"] = env["PATH"]+":"+customEnv

# adding environment path
if len(os.environ.get("PATH")):
env["PATH"] = env["PATH"]+":"+os.environ.get("PATH")

if source == "":
command = [cmd] + args
else:
Expand All @@ -76,6 +85,26 @@ def _run(cmd, args=[], source="", cwd=None, env=None):
okay = proc.returncode == 0
return {"okay": okay, "out": stat[0].decode('utf-8'), "err": stat[1].decode('utf-8')}

# From https://github.com/pderichs/sublime_rubocop/blob/master/rubocop_command.py
# Return the the first path of the project
def current_project_folder():
if int(sublime.version()) >= 3000:
project = sublime.active_window().project_data()
project_base_path = os.path.dirname(sublime.active_window().project_file_name())
if not (project is None):
if 'folders' in project:
folders = project['folders']
if len(folders) > 0:
first_folder = folders[0]
if 'path' in first_folder:
path = first_folder['path']
return (path if os.path.isabs(path) else os.path.join(project_base_path, path)) or ''
else:
folders = sublime.active_window().folders()
if (not (folders is None)) and (len(folders) > 0):
return folders[0]
return ''


def brew(args, source, cwd=None, callback=None):
"""
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ Go to `Preferences > Package Settings > Better CoffeeScript > Settings - User` t
/*
The directory containing your coffee binary. Usually
/usr/local/bin.
If binDir begins with "./", then it is replaced by the first path of the project.
Set bindir to "./node_modules/.bin", and it will use the locally installed coffee.
*/
"binDir": "/usr/local/bin"

Expand Down