Repository: ekalinin/nodeenv (language: python)

Issue:
Add ability to install latest LTS version
It would be great to have a flag to allow users to install the latest LTS build of node.


Discussion / hints:
the information is available in the api to do this -- just need to parse that out

I propose `-n lts` in addition to the current `-n latest`

Fix patch:
diff --git a/nodeenv.py b/nodeenv.py
index 3686bc1..0610db1 100755
--- a/nodeenv.py
+++ b/nodeenv.py
@@ -226,6 +226,7 @@ def parse_args(check=True):
         '--node=0.4.3 will use the node-v0.4.3 '
         'to create the new environment. '
         'The default is last stable version (`latest`). '
+        'Use `lts` to use the latest LTS release. '
         'Use `system` to use system-wide node.')
 
     parser.add_option(
@@ -997,6 +998,13 @@ def get_last_stable_node_version():
     return _get_versions_json()[0]['version'].lstrip('v')
 
 
+def get_last_lts_node_version():
+    """
+    Return the last node.js version marked as LTS
+    """
+    return next((v['version'].lstrip('v') for v in _get_versions_json() if v['lts']), None)
+
+
 def get_env_dir(opt, args):
     if opt.python_virtualenv:
         if hasattr(sys, 'real_prefix'):
@@ -1052,8 +1060,10 @@ def main():
     if src_base_url is None:
         src_base_url = 'https://%s/download/release' % src_domain
 
-    if not opt.node or opt.node.lower() == "latest":
+    if not opt.node or opt.node.lower() == 'latest':
         opt.node = get_last_stable_node_version()
+    elif opt.node.lower() == 'lts':
+        opt.node = get_last_lts_node_version()
 
     if opt.list:
         print_node_versions()


Test patch:
diff --git a/tests/nodeenv_test.py b/tests/nodeenv_test.py
index d3a92c4..e1b6517 100644
--- a/tests/nodeenv_test.py
+++ b/tests/nodeenv_test.py
@@ -130,3 +130,13 @@ def rewind(_):
                 nodeenv.main()
                 mock_urlopen.assert_called_with(url)
                 mock_logger.assert_called()
+
+
+@pytest.mark.usefixtures('mock_index_json')
+def test_get_latest_node_version():
+    assert nodeenv.get_last_stable_node_version() == '13.5.0'
+
+
+@pytest.mark.usefixtures('mock_index_json')
+def test_get_lts_node_version():
+    assert nodeenv.get_last_lts_node_version() == '12.14.0'