Skip to content

Commit

Permalink
Rename SublimeBump to Bump
Browse files Browse the repository at this point in the history
  • Loading branch information
yavorsky committed Nov 11, 2017
1 parent a6d7cd8 commit 895ca0f
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 181 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion Context.sublime-menu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[{
"caption": "SublimeBump",
"caption": "Bump",
"children": [
{
"caption": "Format to the latest version",
Expand Down
12 changes: 6 additions & 6 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[
{
"caption": "Preferences: SublimeBump Settings",
"caption": "Preferences: Bump Settings",
"command": "edit_settings",
"args": {
"base_file": "${packages}/SublimeBump/SublimeBump.sublime-settings",
"default": "${packages}/User/SublimeBump.sublime-settings"
"base_file": "${packages}/Bump/Bump.sublime-settings",
"default": "${packages}/User/Bump.sublime-settings"
}
},
{
"caption": "SublimeBump: Choose Distribution Mode",
"caption": "Bump: Choose Distribution Mode",
"command": "choose_distribution_mode"
},
{
"caption": "SublimeBump: Format To The Latest Version",
"caption": "Bump: Format To The Latest Version",
"command": "bump_latest_version"
},
{
"caption": "SublimeBump: Format To The Next Version",
"caption": "Bump: Format To The Next Version",
"command": "bump_next_version"
}
]
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SublimeBump
Bump
=============

A package allows to preview and manage latest versions of [npm](https://npmjs.com)/[yarn](https://yarnpkg.com) packages easily.
Expand All @@ -14,51 +14,51 @@ For now, it allows:
- Customize tooltip for your needs and taste.


![Demo of latest usage](https://raw.githubusercontent.com/yavorsky/SublimeBump/master/img/preview.gif)
![Demo of latest usage](https://raw.githubusercontent.com/yavorsky/Bump/master/img/preview.gif)

## Installation

#### Install SublimeBump via Package Control
#### Install Bump via Package Control

The easiest and recommended way to install SublimeBump is using [Package Control](https://packagecontrol.io/packages/SublimeBump).
The easiest and recommended way to install Bump is using [Package Control](https://packagecontrol.io/packages/Bump).

From the **main application menu** (CMD + SHIFT + P), navigate to:

`Tools` -> `Command Palette...` -> `Package Control: Install Package`, type the word **SublimeBump**, then select it to complete the installation.
`Tools` -> `Command Palette...` -> `Package Control: Install Package`, type the word **Bump**, then select it to complete the installation.

#### Manual installation

##### via archive
1. Download and extract SublimeBump [zip file](https://github.com/yavorsky/SublimeBump/archive/master.zip) to your Sublime Text Packages directory (Sublime Text -> Preferences -> Browse Packages...).
2. Rename the extracted directory from `SublimeBump-master` to `SublimeBump`.
1. Download and extract Bump [zip file](https://github.com/yavorsky/Bump/archive/master.zip) to your Sublime Text Packages directory (Sublime Text -> Preferences -> Browse Packages...).
2. Rename the extracted directory from `Bump-master` to `Bump`.

##### or via git clone
`git clone https://github.com/yavorsky/SublimeBump.git $HOME/Library/Application\ Support/Sublime\ Text\ 3/Packages/SublimeBump`
`git clone https://github.com/yavorsky/Bump.git $HOME/Library/Application\ Support/Sublime\ Text\ 3/Packages/Bump`

## Usage

Just install the package and focus the line with dependency in `package.json`. SublimeBump will preview latest or next version (according to the distribution mode) of the package in the bottombar or with the tooltip.
Just install the package and focus the line with dependency in `package.json`. Bump will preview latest or next version (according to the distribution mode) of the package in the bottombar or with the tooltip.

#### Main features:

* **Focus the line** inside `dependencies`/`devDependencies`/`peerDependencies`/`optionalDependencies` block to preview latest or next version of the package. If tooltip option in settings is `false` then version will be displayed in the bottom bar.
* **Click on the version in the tooltip** to format current version to the one from tooltip.
* **Click on SublimeBump -> Format to...** latest/next version from the context menu.
* **Click on Bump -> Format to...** latest/next version from the context menu.
* **Choose distribution mode** to change whether or not to fetch unreleased (alpha/beta/etc) version before relaesed.


## Settings

Many options are customizable from the **Command Palette** (super + shift + p) and type **SublimeBump**.
Many options are customizable from the **Command Palette** (super + shift + p) and type **Bump**.

#### distribution_mode

Type: *String*, Default: `latest`

Command: `Choose distribution mode`.

Currently, SublimeBump supports `latest` and `next` distribution tags. By default, the `latest` tag is used by npm to identify the current version of a package. The `next` tag is used by some projects to identify the upcoming version (alpha, beta, etc).
Currently, Bump supports `latest` and `next` distribution tags. By default, the `latest` tag is used by npm to identify the current version of a package. The `next` tag is used by some projects to identify the upcoming version (alpha, beta, etc).

With `next` mode, package trying to fetch latest version, and if no one was registered, it fallbacks to the `latest` version.

Expand All @@ -74,19 +74,19 @@ Whether or not show tooltip near the cursor. If tooltip is disabled, the version

Type: *Array*, Default: `["dependencies", "devDependencies", "peerDependencies"]`

Field name, where SublimeBump will search and show latest version for current package.
Field name, where Bump will search and show latest version for current package.


#### supported_filenames

Type: *Array*, Default: `["package.json"]`

Name of the files when SublimeBump will watch out for your cursor. We haven't universal parser for all formats, but with json files it does its work.
Name of the files when Bump will watch out for your cursor. We haven't universal parser for all formats, but with json files it does its work.


## Key Bindings

SublimeBump has pre-defined keyboard shortcuts. For now, it format package value on the line with the cursor.
Bump has pre-defined keyboard shortcuts. For now, it format package value on the line with the cursor.

| Command | Linux & Windows | MacOS |
| ---------------- | --------------- | -------------- |
Expand All @@ -99,7 +99,7 @@ SublimeBump has pre-defined keyboard shortcuts. For now, it format package value

## License

SublimeBump is released under the MIT License.
Bump is released under the MIT License.

Copyright (c) 2017 Artem Yavorsky.

Expand Down
48 changes: 0 additions & 48 deletions SublimeBump.py

This file was deleted.

139 changes: 33 additions & 106 deletions bump.py
Original file line number Diff line number Diff line change
@@ -1,121 +1,48 @@
import json
import os
import urllib
from string import Template

import sublime
import sublime_plugin

from . import defaults
from . import settings as conf
from . import parser
from . import transfrom
from . import cache
from . import request
from . import log
from . import semver

class Bump:
def get_focused_view_id(self, view):
active_view = view.window().active_view()

for view in view.window().views():
if view == active_view:
return view

def file_supported(self, view):
full_filename = view.file_name()
if not full_filename:
return False
filename = os.path.split(full_filename)[1]
return filename in conf.settings.get('supported_filenames', defaults.get_supported_filenames())

def from_cache_or_fetch(self, package, distribution_mode, vid, callback):
cached = cache.get_by_package(package, distribution_mode, vid)
if cached:
callback(cached)
return

try: request.fetch_package_version(package, distribution_mode, callback)
except urllib.error.URLError as e:
if e.code == 404 and distribution_mode != 'latest':
request.fetch_package_version(package, 'latest', callback)

def run_bump_with_mode(self, view, edit, distribution_mode):
if not self.file_supported(view): return

region = parser.get_active_region(view)
parent_key = parser.get_parent_key(view, region)
target_fields = conf.settings.get('dependency_fields', defaults.get_dependency_fields())

# Prevent parsing values from other fields.
if not parent_key or parent_key not in target_fields:
return

line_text = parser.get_text_from_line(view, region)
if not line_text: return
from . import request
from . import cache
from . import transfrom
from . import commands
from . import settings as conf
from . import persist

package, version = parser.get_current_package(line_text)
vid = view.id()
def plugin_loaded():
"""Entry point for SL plugins."""
conf.plugin_is_loaded = True
conf.settings.load()
log.printf('debug mode:', 'on' if conf.debug_mode() else 'off')

def callback(version):
transfrom.format_version_on_line(view, edit, region, version)
plugin = Bump.shared_plugin()
conf.settings.on_update_call(Bump.on_settings_updated)

self.from_cache_or_fetch(package, distribution_mode, vid, callback)
class Bump(sublime_plugin.EventListener):
def __init__(self, *args, **kwargs):
"""Initialize a new instance."""
super().__init__(*args, **kwargs)

def log_version_for_view(self, view):
if not self.file_supported(view):
return
self.__class__.shared_instance = self

view = self.get_focused_view_id(view)
@classmethod
def shared_plugin(cls):
"""Return the plugin instance."""
return cls.shared_instance

if view is None:
return
@classmethod
def on_settings_updated(cls, setting):
persist.worker.log_version_for_active_view()

vid = view.id()
# Get active region
region = parser.get_active_region(view)
def on_selection_modified_async(self, view):
self.display_version_for_line(view, tooltip=True)

if region == None:
def display_version_for_line(self, view, tooltip=False):
if persist.worker.is_scratch(view):
return

# Get parent package key for active region.
parent_key = parser.get_parent_key(view, region)
target_fields = conf.settings.get('dependency_fields', defaults.get_dependency_fields())

# Prevent parsing values from other fields.
if not parent_key or parent_key not in target_fields:
return

line_text = parser.get_text_from_line(view, region)

if not line_text:
return

package, current_version = parser.get_current_package(line_text)

distribution_mode = conf.settings.get('distribution_mode', defaults.get_distribution_mode())
def callback(version):
cache.set_package(package, distribution_mode, vid, version)
with_tooltip = conf.settings.get('tooltip', defaults.get_tooltip())
has_matched = semver.satisfies(version, current_version)
log.log_version(view, package, version, has_matched, with_tooltip)
self.from_cache_or_fetch(package, distribution_mode, vid, callback)


def log_version_for_active_view(self):
view = sublime.active_window().active_view()
self.log_version_for_view(view)

def is_scratch(self, view):
if view.is_scratch() or view.is_read_only() or view.window() is None or view.settings().get("repl") is not None:
return True
elif (
view.file_name() and
view.file_name().startswith(sublime.packages_path() + os.path.sep) and
not os.path.exists(view.file_name())
):
return True
else:
return False


if 'plugin_is_loaded' not in globals():
worker = Bump()
persist.worker.log_version_for_view(view)
8 changes: 4 additions & 4 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sublime_plugin

from . import defaults
from . import bump
from . import persist
from . import settings as conf

class ChooseSettingCommand(sublime_plugin.WindowCommand):
Expand Down Expand Up @@ -165,15 +165,15 @@ def get_settings(self):
return [[name.capitalize(), description] for name, description in defaults.VERSION_MODES]

def setting_was_changed(self, setting):
bump.worker.log_version_for_active_view()
persist.worker.log_version_for_active_view()

class BumpLatestVersionCommand(sublime_plugin.TextCommand):
def run(self, edit):
bump.worker.run_bump_with_mode(self.view, edit, 'latest')
persist.worker.run_bump_with_mode(self.view, edit, 'latest')

class BumpNextVersionCommand(sublime_plugin.TextCommand):
def run(self, edit):
bump.worker.run_bump_with_mode(self.view, edit, 'next')
persist.worker.run_bump_with_mode(self.view, edit, 'next')

class SublimebumpEditCommand(sublime_plugin.TextCommand):
"""A plugin command used to generate an edit object for a view."""
Expand Down
Loading

0 comments on commit 895ca0f

Please sign in to comment.