Ejemplo n.º 1
0
def package(pkg_name, version=None, local=False):
    """
    Require a Node.js package.

    If the package is not installed, and no *version* is specified, the
    latest available version will be installed.

    If a *version* is specified, and a different version of the package
    is already installed, it will be updated to the specified version.

    If `local` is ``True``, the package will be installed locally.

    ::

        from fabtools import require

        # Install package system-wide
        require.nodejs.package('foo')

        # Install package locally
        require.nodejs.package('bar', local=True)

    """
    pkg_version = nodejs.package_version(pkg_name, local=local)
    if version:
        if pkg_version != version:
            nodejs.install_package(pkg_name, version, local=local)
    else:
        if pkg_version is None:
            nodejs.install_package(pkg_name, local=local)
Ejemplo n.º 2
0
def install_nodejs():
    """
    Test low level API
    """

    from fabtools import nodejs
    from fabtools import require
    from fabtools.files import is_file

    # Upload local copy of source archive to speed up tests
    local_cache = '~/.vagrant.d/cache/fabtools/node-v%s.tar.gz' % nodejs.DEFAULT_VERSION
    if os.path.exists(local_cache):
        put(local_cache)

    # Install Node.js from source
    if nodejs.version() != nodejs.DEFAULT_VERSION:
        nodejs.install_from_source()

    assert is_file('/usr/local/bin/node')
    assert nodejs.version() == nodejs.DEFAULT_VERSION

    # Install / uninstall global package
    if not nodejs.package_version('underscore'):
        nodejs.install_package('underscore', version='1.4.2')

    assert nodejs.package_version('underscore') == '1.4.2'
    assert is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    nodejs.uninstall_package('underscore')

    assert nodejs.package_version('underscore') == None
    assert not is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    # Install / uninstall local package
    if not nodejs.package_version('underscore', local=True):
        nodejs.install_package('underscore', version='1.4.2', local=True)

    assert is_file('node_modules/underscore/underscore.js')
    assert nodejs.package_version('underscore', local=True) == '1.4.2'

    nodejs.uninstall_package('underscore', local=True)

    assert nodejs.package_version('underscore', local=True) == None
    assert not is_file('node_modules/underscore/underscore.js')

    # Install dependencies from package.json file
    require.directory('nodetest')
    with cd('nodetest'):
        require.file('package.json', contents=json.dumps({
            'name': 'nodetest',
            'version': '1.0.0',
            'dependencies': {
                'underscore': '1.4.2'
            }
        }))

        nodejs.install_dependencies()

        assert is_file('node_modules/underscore/underscore.js')
        assert nodejs.package_version('underscore', local=True) == '1.4.2'
Ejemplo n.º 3
0
def install_nodejs():
    """
    Test low level API
    """

    from fabtools import nodejs
    from fabtools import require
    from fabtools.files import is_file

    # Install Node.js from source
    if nodejs.version() != nodejs.DEFAULT_VERSION:
        nodejs.install_from_source()

    assert is_file('/usr/local/bin/node')
    assert nodejs.version() == nodejs.DEFAULT_VERSION

    # Install / uninstall global package
    if not nodejs.package_version('underscore'):
        nodejs.install_package('underscore', version='1.4.2')

    assert nodejs.package_version('underscore') == '1.4.2'
    assert is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    nodejs.uninstall_package('underscore')

    assert nodejs.package_version('underscore') is None
    assert not is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    # Install / uninstall local package
    if not nodejs.package_version('underscore', local=True):
        nodejs.install_package('underscore', version='1.4.2', local=True)

    assert is_file('node_modules/underscore/underscore.js')
    assert nodejs.package_version('underscore', local=True) == '1.4.2'

    nodejs.uninstall_package('underscore', local=True)

    assert nodejs.package_version('underscore', local=True) is None
    assert not is_file('node_modules/underscore/underscore.js')

    # Install dependencies from package.json file
    require.directory('nodetest')
    with cd('nodetest'):
        require.file('package.json',
                     contents=json.dumps({
                         'name': 'nodetest',
                         'version': '1.0.0',
                         'dependencies': {
                             'underscore': '1.4.2'
                         }
                     }))

        nodejs.install_dependencies()

        assert is_file('node_modules/underscore/underscore.js')
        assert nodejs.package_version('underscore', local=True) == '1.4.2'
Ejemplo n.º 4
0
def install_nodejs():
    """
    Test low level API
    """

    from fabtools import nodejs
    from fabtools import require
    from fabtools.files import is_file

    # Install Node.js from source
    if nodejs.version() != nodejs.DEFAULT_VERSION:
        nodejs.install_from_source()

    assert is_file('/usr/local/bin/node')
    assert nodejs.version() == nodejs.DEFAULT_VERSION

    # Install / uninstall global package
    if not nodejs.package_version('underscore'):
        nodejs.install_package('underscore', version='1.4.2')

    assert nodejs.package_version('underscore') == '1.4.2'
    assert is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    nodejs.uninstall_package('underscore')

    assert nodejs.package_version('underscore') is None
    assert not is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    # Install / uninstall local package
    if not nodejs.package_version('underscore', local=True):
        nodejs.install_package('underscore', version='1.4.2', local=True)

    assert is_file('node_modules/underscore/underscore.js')
    assert nodejs.package_version('underscore', local=True) == '1.4.2'

    nodejs.uninstall_package('underscore', local=True)

    assert nodejs.package_version('underscore', local=True) is None
    assert not is_file('node_modules/underscore/underscore.js')

    # Install dependencies from package.json file
    require.directory('nodetest')
    with cd('nodetest'):
        require.file('package.json', contents=json.dumps({
            'name': 'nodetest',
            'version': '1.0.0',
            'dependencies': {
                'underscore': '1.4.2'
            }
        }))

        nodejs.install_dependencies()

        assert is_file('node_modules/underscore/underscore.js')
        assert nodejs.package_version('underscore', local=True) == '1.4.2'
Ejemplo n.º 5
0
def test_install_and_uninstall_local_package(nodejs):

    from fabtools.nodejs import install_package, package_version, uninstall_package

    if not package_version('underscore', local=True):
        install_package('underscore', version='1.4.2', local=True)

    assert is_file('node_modules/underscore/underscore.js')
    assert package_version('underscore', local=True) == '1.4.2'

    uninstall_package('underscore', local=True)

    assert package_version('underscore', local=True) is None
    assert not is_file('node_modules/underscore/underscore.js')
Ejemplo n.º 6
0
def test_install_and_uninstall_local_package(nodejs):

    from fabtools.nodejs import install_package, package_version, uninstall_package

    if not package_version('underscore', local=True):
        install_package('underscore', version='1.4.2', local=True)

    assert is_file('node_modules/underscore/underscore.js')
    assert package_version('underscore', local=True) == '1.4.2'

    uninstall_package('underscore', local=True)

    assert package_version('underscore', local=True) is None
    assert not is_file('node_modules/underscore/underscore.js')
Ejemplo n.º 7
0
def test_install_and_uninstall_global_package(nodejs):

    from fabtools.nodejs import install_package, package_version, uninstall_package

    if not package_version('underscore'):
        install_package('underscore', version='1.4.2')

    assert package_version('underscore') == '1.4.2'
    assert is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    uninstall_package('underscore')

    assert package_version('underscore') is None
    assert not is_file('/usr/local/lib/node_modules/underscore/underscore.js')
Ejemplo n.º 8
0
def test_install_and_uninstall_local_package(nodejs):

    from fabtools.nodejs import install_package, package_version, uninstall_package

    if not package_version("underscore", local=True):
        install_package("underscore", version="1.4.2", local=True)

    assert is_file("node_modules/underscore/underscore.js")
    assert package_version("underscore", local=True) == "1.4.2"

    uninstall_package("underscore", local=True)

    assert package_version("underscore", local=True) is None
    assert not is_file("node_modules/underscore/underscore.js")
Ejemplo n.º 9
0
def test_install_and_uninstall_global_package(nodejs):

    from fabtools.nodejs import install_package, package_version, uninstall_package

    # This is not in root's PATH on RedHat systems
    with path('/usr/local/bin'):

        if not package_version('underscore'):
            install_package('underscore', version='1.4.2')

        assert package_version('underscore') == '1.4.2'
        assert is_file('/usr/local/lib/node_modules/underscore/underscore.js')

        uninstall_package('underscore')

        assert package_version('underscore') is None
        assert not is_file('/usr/local/lib/node_modules/underscore/underscore.js')
Ejemplo n.º 10
0
def test_install_and_uninstall_global_package(nodejs):

    from fabtools.nodejs import install_package, package_version, uninstall_package

    # This is not in root's PATH on RedHat systems
    with path("/usr/local/bin"):

        if not package_version("underscore"):
            install_package("underscore", version="1.4.2")

        assert package_version("underscore") == "1.4.2"
        assert is_file("/usr/local/lib/node_modules/underscore/underscore.js")

        uninstall_package("underscore")

        assert package_version("underscore") is None
        assert not is_file("/usr/local/lib/node_modules/underscore/underscore.js")
Ejemplo n.º 11
0
def ensure_deps_node():
    sudo('curl -sL https://deb.nodesource.com/setup_10.x | bash -')
    require.deb.packages(['nodejs'])
    for package in ['yarn', '@angular/cli']:
        nodejs.install_package(package)