├── .gitignore ├── images ├── logo.png └── statusbar.png ├── messages.json ├── messages ├── install.txt ├── 1.0.2.txt └── 1.0.1.txt ├── LiveServer.sublime-settings ├── LiveServer.sublime-commands ├── LICENSE ├── plugin.py └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.html -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/molnarmark/sublime-live-server/HEAD/images/logo.png -------------------------------------------------------------------------------- /images/statusbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/molnarmark/sublime-live-server/HEAD/images/statusbar.png -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/install.txt", 3 | "1.0.1": "messages/1.0.1.txt", 4 | "1.0.2": "messages/1.0.2.txt" 5 | } 6 | -------------------------------------------------------------------------------- /messages/install.txt: -------------------------------------------------------------------------------- 1 | Thank you for installing Live Server! 👋 2 | 3 | For usage instructions, head over to the GitHub repository of this project: 4 | https://github.com/molnarmark/sublime-live-server -------------------------------------------------------------------------------- /messages/1.0.2.txt: -------------------------------------------------------------------------------- 1 | 🌍 Live Server 1.0.2 2 | ==================== 3 | 4 | - Having a Sublime Text project open is not a requirement anymore for the server to work. 5 | 6 | Thank you for using Live Server. -------------------------------------------------------------------------------- /messages/1.0.1.txt: -------------------------------------------------------------------------------- 1 | 🌍 Live Server 1.0.1 2 | ==================== 3 | 4 | - Various fixes for Windows users 5 | 6 | ** For Windows users, its enough to set the 'node_executable_path' to 'node.exe' 7 | 8 | Thank you for using Live Server. -------------------------------------------------------------------------------- /LiveServer.sublime-settings: -------------------------------------------------------------------------------- 1 | // Note: These are just mappings to https://github.com/tapio/live-server#usage-from-command-line 2 | { 3 | "node_executable_path": "/usr/bin/node", 4 | "global_node_modules_path": "/usr/local/lib/node_modules", 5 | "port": 8080, 6 | "address": "localhost", 7 | "cors": true, 8 | "browser": "default", 9 | "nobrowser": false, 10 | "wait": 100 11 | } -------------------------------------------------------------------------------- /LiveServer.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Live Server: Start", 4 | "command": "live_server_start" 5 | }, 6 | { 7 | "caption": "Live Server: Stop", 8 | "command": "live_server_stop" 9 | }, 10 | { 11 | "caption": "Live Server: Open In Browser", 12 | "command": "live_server_open_in_browser" 13 | }, 14 | { 15 | "caption": "Preferences: Live Server Settings", 16 | "command": "edit_settings", 17 | "args": { 18 | "base_file": "${packages}/LiveServer/LiveServer.sublime-settings", 19 | "default": "// Live Server Settings\n{\n\t$0\n}\n" 20 | } 21 | } 22 | ] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Mark Molnar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /plugin.py: -------------------------------------------------------------------------------- 1 | import sublime 2 | import sublime_plugin 3 | import subprocess 4 | import os, webbrowser 5 | 6 | SETTINGS_FILE = 'LiveServer.sublime-settings' 7 | SERVER_BINARY_PATH = '/live-server/live-server.js' 8 | PLUGIN_NODE_PATH = os.path.join( 9 | os.path.dirname(os.path.realpath(__file__)), 10 | SERVER_BINARY_PATH 11 | ) 12 | 13 | # handling windows 14 | if os.name == "nt": 15 | PLUGIN_NODE_PATH = SERVER_BINARY_PATH 16 | 17 | SERVER_PROCESS = None 18 | RUNNING_ON_PORT = None 19 | 20 | RUNNING_STATUS_MESSAGE = 'Live Server ✔️' 21 | STATUS_KEY = 'live_server_status' 22 | 23 | def plugin_unloaded(): 24 | if SERVER_PROCESS: 25 | SERVER_PROCESS.terminate() 26 | 27 | class LiveServerViewEventListener(sublime_plugin.ViewEventListener): 28 | def on_activated(self): 29 | if SERVER_PROCESS: 30 | self.view.set_status(STATUS_KEY, RUNNING_STATUS_MESSAGE) 31 | else: 32 | self.view.erase_status(STATUS_KEY) 33 | 34 | class LiveServerStartCommand(sublime_plugin.TextCommand): 35 | def run(self, edit): 36 | global SERVER_PROCESS, RUNNING_ON_PORT 37 | if SERVER_PROCESS: 38 | SERVER_PROCESS.terminate() 39 | 40 | settings = sublime.load_settings(SETTINGS_FILE) 41 | server_path = self.view.window().extract_variables()['file_path'] 42 | 43 | args = [ 44 | '--port={}'.format(settings.get('port')), 45 | '--address={}'.format(settings.get('address')), 46 | '--cors={}'.format(settings.get('cors')), 47 | '--wait={}'.format(settings.get('wait')), 48 | ] 49 | 50 | if (settings.get('browser') != 'default'): 51 | args.append('--browser={}'.format(settings.get('browser'))) 52 | 53 | if settings.get('nobrowser'): 54 | args.append('--no-browser') 55 | 56 | live_server_path = os.path.normpath(settings.get('global_node_modules_path') + PLUGIN_NODE_PATH) 57 | if os.name == 'nt': 58 | SERVER_PROCESS = subprocess.Popen( 59 | [settings.get('node_executable_path'), live_server_path, server_path] + args, 60 | stdout=subprocess.PIPE, 61 | stdin=subprocess.PIPE, 62 | stderr=subprocess.PIPE, 63 | env=os.environ.copy(), 64 | creationflags=0x08000000, 65 | startupinfo=None, 66 | ) 67 | else: 68 | SERVER_PROCESS = subprocess.Popen( 69 | [settings.get('node_executable_path'), live_server_path, server_path] + args, 70 | stdout=subprocess.PIPE, 71 | stdin=subprocess.PIPE, 72 | stderr=subprocess.PIPE, 73 | env=os.environ.copy(), 74 | startupinfo=None, 75 | ) 76 | 77 | RUNNING_ON_PORT = settings.get('port') 78 | 79 | self.view.window().status_message('🎉 Live Server running on {}.'.format(settings.get('port'))) 80 | self.view.set_status(STATUS_KEY, RUNNING_STATUS_MESSAGE) 81 | 82 | class LiveServerStopCommand(sublime_plugin.TextCommand): 83 | def run(self, edit): 84 | global SERVER_PROCESS 85 | SERVER_PROCESS.terminate() 86 | SERVER_PROCESS = None 87 | self.view.window().status_message('❌ Live Server stopped.') 88 | self.view.erase_status(STATUS_KEY) 89 | 90 | class LiveServerOpenInBrowserCommand(sublime_plugin.TextCommand): 91 | def run(self, edit): 92 | if SERVER_PROCESS: 93 | self.view.window().status_message('📖 Opening Live Server..') 94 | webbrowser.open('http://localhost:{}'.format(RUNNING_ON_PORT)) 95 | else: 96 | self.view.window().status_message('❌ Live Server isn\'t running. Nothing to open.') 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 |
78 |
79 |