Last active
October 4, 2020 23:59
-
-
Save deffjay/8230568 to your computer and use it in GitHub Desktop.
AutoGrunt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Jeff Day - 2013 | |
# Sublime plugin that invokes Grunt whenever the user saves a file within the current project. | |
# call to RSYNC project to remote server via RSync | |
# | |
# October 27, 2013 - Updated this to work using Sublime Text 3 (Jeff) | |
# November 10, 2013 - Now compatible with OSX Mavericks (Jeff) | |
# January 2, 2014 - Switched over to Grunt (Tom) | |
import sublime, sublime_plugin | |
import json, os, subprocess, functools | |
import subprocess | |
class AutoGruntCommand(sublime_plugin.EventListener): | |
def on_post_save_async(self, view): | |
cmd = "Grunt" | |
# Check if we're in a Sublime Text Project | |
if not view.window().folders(): | |
return | |
projectFolder = view.window().folders()[0] | |
# We only want to rsync files in the project | |
if not projectFolder in view.file_name(): | |
return | |
splitVal="\n" | |
print("AutoGrunt - We are running on: " + sublime.platform()) | |
if sublime.platform() == "windows": | |
#jeff needs to fix this, so it works with his weird windows ways | |
cmd = "grunt sync --no-color" | |
splitVal="\r\n" | |
elif sublime.platform() == "osx": | |
#need this for osx as osx puts all it's executable in /usr/local/bin instead of /usr/bin | |
# Tweak line below as needed for your $PATH | |
cmd = 'grunt sync --no-color' | |
elif sublime.platform() == "linux": | |
cmd = cmdPath + 'grunt sync --no-color' | |
else: | |
print("AutoGrunt - Unknown Platform:" + sublime.platform()) | |
return | |
# Execute the Grunt command | |
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,cwd=projectFolder) | |
out, err = p.communicate() | |
out = out.decode("utf-8") | |
err = err.decode("utf-8") | |
output = "\n" | |
sublimeError = "" | |
for line in out.split(splitVal): | |
print(line) | |
if "error" in line.lower():#super ghetto fix till grunt supports stderr | |
sublimeError+="Error with AutoGrunt, check sublime console\n" | |
if sublimeError != "": | |
sublime.error_message(sublimeError) | |
if len(err) > 0: | |
print("Error running Grunt!: " + err) | |
sublime.set_timeout(functools.partial(self.updateStatus, view, 'AutoGrunt Done!'), 100) | |
def updateStatus(self, view, text): | |
sublime.status_message(text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment