-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial code and first release v1.0.0
- Loading branch information
Showing
3 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "Chrome Extension Exporter", | ||
"description": "Exports Chrome Extension files from the current project as ZIP, excluding the .git directory and .zip files. Used for quick local distribution.", | ||
"version": "1.0.0", | ||
"author": "iRonin.IT (https://www.ironin.it)", | ||
"platforms": ["*"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
""" | ||
Plugin Name: Chrome Extension Exporter | ||
Description: This Sublime Text plugin exports Chrome Extension files from the current project as ZIP, excluding the .git directory and .zip files. Used for quick local distribution. | ||
Version: 1.0.0 | ||
Author: iRonin.IT (https://www.ironin.it) | ||
""" | ||
|
||
import os | ||
import json | ||
import zipfile | ||
from datetime import datetime | ||
import sublime | ||
import sublime_plugin | ||
|
||
class ChromeExtensionExporterCommand(sublime_plugin.TextCommand): | ||
command_name = "Chrome Extension Exporter" | ||
|
||
def run(self, edit): | ||
# Get the current file path. | ||
file_path = self.view.file_name() | ||
|
||
if file_path is None: | ||
sublime.message_dialog("No file open.") | ||
return | ||
|
||
# Get the current project path. | ||
project_path = os.path.dirname(file_path) | ||
|
||
# Check if manifest.json exists in the project root. | ||
manifest_path = os.path.join(project_path, "manifest.json") | ||
if not os.path.isfile(manifest_path): | ||
sublime.message_dialog("manifest.json file not found in project root.") | ||
return | ||
|
||
# Read the manifest.json file and extract the version. | ||
with open(manifest_path, 'r') as manifest_file: | ||
manifest = json.load(manifest_file) | ||
version = manifest.get('version', '') | ||
|
||
# Get the current timestamp. | ||
timestamp = datetime.now().strftime('%Y%m%d%H%M') | ||
|
||
# Output zip file will be in the same directory as the project, with the project's name, version and timestamp. | ||
output_filename = os.path.join(project_path, os.path.basename(project_path) + "-" + version + "-" + timestamp + ".zip") | ||
|
||
# Load user settings for exclusion patterns. | ||
settings = sublime.load_settings('ExportChromeExtension.sublime-settings') | ||
excluded_dirs = settings.get('excluded_dirs', ['.git']) | ||
excluded_extensions = settings.get('excluded_extensions', ['.zip']) | ||
|
||
# Open the zip file in write mode. | ||
with zipfile.ZipFile(output_filename, 'w', zipfile.ZIP_DEFLATED) as zf: | ||
for root, dirs, files in os.walk(project_path): | ||
# Exclude directories based on user settings. | ||
dirs[:] = [d for d in dirs if d not in excluded_dirs and not any(f.endswith(tuple(excluded_extensions)) for f in os.listdir(os.path.join(root, d)))] | ||
|
||
# Write each file to the zip file, excluding files based on user settings. | ||
for file in files: | ||
if not file.endswith(tuple(excluded_extensions)): | ||
full_path = os.path.join(root, file) | ||
relative_path = os.path.relpath(full_path, project_path) | ||
zf.write(full_path, relative_path) | ||
|
||
sublime.message_dialog("Chrome Extension exported successfully.") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,38 @@ | ||
# sublimetext-chrome-extension-exporter | ||
Sublime Text plugin to export Chrome Extension code from CWD as ZIP excluding .git and .zip, configurable | ||
# Export Chrome Extension for Sublime Text | ||
|
||
This Sublime Text plugin allows you to export your Chrome Extension files from the current project into a ZIP file. It excludes specified directories and file types, which you can customize via the settings. The resulting ZIP file will include the version number from the `manifest.json` file and a timestamp in its filename. | ||
|
||
## Installation | ||
|
||
You can install this plugin via [Package Control](https://packagecontrol.io/installation). | ||
|
||
1. Open "Package Control: Install Package" from the Command Palette (`Ctrl+Shift+P`). | ||
2. Search for "Export Chrome Extension" and hit Enter to install. | ||
|
||
If you prefer a manual installation, clone this repository into your Sublime Text's Packages directory. | ||
|
||
## Usage | ||
|
||
Once the plugin is installed, you can use it by running the "Export Chrome Extension" command from the Command Palette (`Ctrl+Shift+P`). The plugin will create a ZIP file in the root directory of your current project. | ||
|
||
## Configuration | ||
|
||
You can customize the directories and file types that are excluded when creating the ZIP file. To do this, open the `ExportChromeExtension.sublime-settings` file and modify the `excluded_dirs` and `excluded_extensions` settings. | ||
|
||
Here is an example of what the settings file might look like: | ||
|
||
```json | ||
{ | ||
"excluded_dirs": [".git"], | ||
"excluded_extensions": [".zip"] | ||
} | ||
``` | ||
|
||
## Support | ||
|
||
If you encounter any issues or have any questions about this plugin, please create an issue on the [GitHub repository](https://github.com/iRoninIT/sublimetext-chrome-extension-exporter). | ||
|
||
## Author | ||
|
||
[iRonin.IT - Software Development Agency](https://www.ironin.it) | ||
|