#!/usr/bin/env bash

NODE_MIRROR="http://nodejs.org/dist"
BIN_PREFIX="node"

# Output lists of versions
plug_list_versions() {
    # show only >= 0.10.0
    echo $(curl -s "$NODE_MIRROR/" | \
                grep -v "node-" | \
                egrep -o '[0-9]+\.[0-9]+\.[0-9]+' | \
                sort  | \
                grep -A 1000000 "0.10.0" | \
                uniq | sort | 
                sort -u -k 1,1n -k 2,2n -k 3,3n -t .)
}

# Return full url for tarball for download
# and future installation
#
# Input:
#   $1 — version for installation
plug_url_for_download() {
    local version=$1
    local arch=$(nv_get_system_arch "x86" "x64")
    local system=$(nv_get_system "linux" "darwin")
    echo "$NODE_MIRROR/v${version}/${BIN_PREFIX}-v${version}-${system}-${arch}.tar.gz"
}

# Like we build
plug_build() {
    local src_path=$1
    local build_path=$2
    cp -r "$src_path"/*/* "$build_path"
}
