Created
April 11, 2018 07:16
-
-
Save thachnuida/b9f113f2ae67a58c16031f5ad434cf25 to your computer and use it in GitHub Desktop.
Auto insert import other js files in current folder to current file
This file contains hidden or 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
# Add to key binding { "keys": ["ctrl+1"], "command": "require_js_files"} | |
import sublime | |
import sublime_plugin | |
import os | |
class RequireJsFilesCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
current_folder = os.path.dirname(self.view.file_name()) | |
current_file_name = os.path.basename(self.view.file_name()) | |
for file in os.listdir(current_folder): | |
if file.endswith('.js') and file != current_file_name: | |
self.view.insert(edit, 0, "import _name_ from './{0}';\n".format(os.path.splitext(file)[0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment