-
Notifications
You must be signed in to change notification settings - Fork 262
/
Nodejs.py
81 lines (58 loc) · 1.99 KB
/
Nodejs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import sys
import shellenv
import sublime
import sublime_plugin
# import lib's modules
from .lib.nodejs_debug import debug, info
from .lib.nodejs_constants import *
from .lib.nodejs_paths import *
from .lib.nodejs_commands import *
from .lib.nodejs_nvm import *
debug('PLUGIN_PATH', PLUGIN_PATH)
debug('PLUGIN_LIB_DIR', PLUGIN_LIB_DIR)
debug('PLUGIN_DEBUG_FILE', PLUGIN_DEBUG_FILE)
debug('UGLIFY_PATH', UGLIFY_PATH)
debug('BUILDER_PATH', BUILDER_PATH)
debug('SHELLENV', shellenv.get_env())
def generate_completions():
info('Running `node_builddocs` to generate Node.js completions')
sublime.active_window().run_command('node_builddocs')
def is_there_node_exe():
# TODO: check if there is a some NODE executable exists on the system
pass
def is_there_npm_exe():
# TODO: check if there is a some NPM executable exists on the system
pass
def check_and_install_dependencies():
"""
The function is dosen't check whether npm/node is installed or not.
"""
# check if already installed
if os.path.exists(PLUGIN_PACKAGE_LOCK):
return
# merge /usr/local/{bin,sbin}
cmd = ['npm', 'install', '-s']
exec_options = {
'quiet': True,
'working_dir': PLUGIN_PATH
}
if os.name != 'nt':
# update paths for searching executables
exec_options['cmd'] = cmd
exec_options['env'] = {}
exec_options['env'].update({'PATH': shellenv.get_env()[1]['PATH']})
else:
exec_options['shell_cmd'] = ' '.join(cmd)
info('Running `npm install` to install plugin dependencies')
sublime.active_window().run_command('exec', exec_options)
def create_output_panel():
view = sublime.active_window().create_output_panel("nodejs")
view.set_read_only(True)
def plugin_loaded():
check_and_install_dependencies()
generate_completions()
if Nvm.is_installed():
info('Node.js version from NVM is ' + Nvm.node_version())
def plugin_unloaded():
info('Unloaded ' + PLUGIN_VERSION)