├── Jsbox ├── Default (Windows).sublime-keymap ├── Jsbox.sublime-commands ├── Jsbox.sublime-settings ├── README.md ├── dependencies.json └── jsbox.py ├── README.md └── imgs ├── README.md └── jsbox_plugin.png /Jsbox/Default (Windows).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["ctrl+p"], "command": "jsboxsyncfile" } 3 | ] -------------------------------------------------------------------------------- /Jsbox/Jsbox.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | {"caption": "Jsbox: Sync File", "command": "jsboxsyncfile"}, 3 | {"caption": "Jsbox: Download File", "command": "jsboxdownloadfile"} 4 | ] -------------------------------------------------------------------------------- /Jsbox/Jsbox.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | "host": "192.168.2.115" 3 | } -------------------------------------------------------------------------------- /Jsbox/README.md: -------------------------------------------------------------------------------- 1 | # Jsbox 2 | -------------------------------------------------------------------------------- /Jsbox/dependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "*": { 3 | "*": [ 4 | "requests" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /Jsbox/jsbox.py: -------------------------------------------------------------------------------- 1 | import json 2 | import sublime 3 | import sublime_plugin 4 | import urllib 5 | import os 6 | import requests 7 | import re 8 | import shutil 9 | 10 | SETTINGS_FILE = 'Jsbox.sublime-settings' 11 | 12 | 13 | class JsboxsyncfileCommand(sublime_plugin.TextCommand): 14 | def run(self, edit): 15 | settings = sublime.load_settings(SETTINGS_FILE) 16 | host = settings.get('host') 17 | 18 | file_name = os.path.abspath(self.view.file_name()) 19 | directory = os.path.dirname(file_name) 20 | 21 | is_package = False 22 | # print(directory) 23 | while directory: 24 | print(directory) 25 | needed_files = ['assets', 'scripts', 'strings', 'config.json', 'main.js'] 26 | directory_files = os.listdir(directory) 27 | legal_dir = all([i in directory_files for i in needed_files]) 28 | if legal_dir or os.path.dirname(directory) == directory: 29 | is_package = legal_dir 30 | break 31 | directory = os.path.dirname(directory) 32 | 33 | print("是否安装包:{}".format(is_package)) 34 | 35 | if is_package: 36 | output_path = os.path.join(directory, '.output') 37 | if not os.path.exists(output_path): 38 | os.mkdir(output_path) 39 | zipfile_name = os.path.basename(directory) 40 | print("目录名称: {}, 文件名: {}".format(output_path, directory)) 41 | file_name = shutil.make_archive(os.path.join(output_path, "shuangpin"), 'zip', root_dir=directory, base_dir=None) 42 | print("压缩文件名: {}".format(file_name)) 43 | # file_name = name 44 | 45 | def upload(): 46 | url = 'http://{}/upload'.format(host) 47 | files = {'files[]': open(file_name, 'rb')} 48 | r = requests.post(url, files=files) 49 | print(r.status_code) 50 | if r.status_code != 200: 51 | sublime.error_message('fail') 52 | sublime.set_timeout_async(upload, 0) 53 | 54 | class JsboxdownloadfileCommand(sublime_plugin.TextCommand): 55 | def run(self, edit): 56 | window = sublime.active_window() 57 | new_file = window.new_file() 58 | settings = sublime.load_settings(SETTINGS_FILE) 59 | host = settings.get('host') 60 | url = 'http://{}/list?path=/'.format(host) 61 | resp = requests.get(url) 62 | resp.encoding = 'utf-8' 63 | scripts = resp.json() 64 | # print(map(lambda x: x['name'], resp.json())) 65 | def load(x): 66 | downloadurl = 'http://{}/download?path={}'.format(host, scripts[x]['path']) 67 | resp2 = requests.get(downloadurl) 68 | resp2.encoding = 'utf-8' 69 | new_file.insert(edit, 0, resp2.text) 70 | new_file.set_name(scripts[x]['name']) 71 | new_file.set_line_endings('Unix') 72 | new_file.show_popup_menu(list(map(lambda x: x['name'], scripts)), load) 73 | 74 | 75 | class JsboxEventListener(sublime_plugin.EventListener): 76 | def on_post_save_async(self, view): 77 | filename = view.file_name() 78 | # print(os.path.basename(filename)) 79 | if filename.endswith('.js') or filename.endswith('.json'): 80 | # print('文件以js或json结尾') 81 | view.run_command('jsboxsyncfile') 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jsbox_sublime 2 | A ST3 plugin for Jsbox 3 | 4 | 在SublimeText3下开发Jsbox脚本的插件 5 | 6 | ### 插件下载 7 | 8 | 1. **git clone** 或者 **下载** 仓库中 **Jsbox** 文件夹 9 | 2. 将 **Jsbox** 文件夹拷贝到 **Sublime Text 3/Packages** 目录下 10 | 11 | ### 配置Host 12 | 13 | 修改 **Jsbox/Jsbox.sublime-settings** 文件,将host字段改为APP中对应的字段。 14 | 15 | ```json 16 | { 17 | "host": "192.168.xxx.xxx" 18 | } 19 | ``` 20 | 21 | ### 加载插件依赖 22 | 23 | 1. 打开 **Sublime Text 3** 24 | 2. **Ctrl + Shift + P** 呼出 **Package Control** 25 | 3. 输入 **Satisfy Dependencies** 安装插件依赖 26 | 27 | ### 命令简介 28 | 29 | ![](https://github.com/Fndroid/jsbox_sublime/blob/master/imgs/jsbox_plugin.png?raw=true) 30 | 31 | 1. Download File: 从手机中下载脚本 32 | 2. Sync File: 同步脚本文件或安装包(将安装包或js文件发送到APP) 33 | 34 | ### 保存推送 35 | 36 | 当脚本或应用中有文件触发保存,将触发一次 **Sync File** 命令 37 | 38 | ### 最后 39 | 40 | 1. 暂时没做补全(我基本不用代码提示。。。),有人乐意可以自己做一下 41 | 2. 快捷键只有Windows下的,有兴趣可以自己加 42 | -------------------------------------------------------------------------------- /imgs/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /imgs/jsbox_plugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fndroid/jsbox_sublime/9d17017c078ce76d5cb8b44af613ca8fa4276d14/imgs/jsbox_plugin.png --------------------------------------------------------------------------------