Example #1
0
        public static void Run(UseOptions opts)
        {
            if (opts.Version == null)
            {
                opts.Version = Utils.getLocalNPMRCVersion().Version;
            }
            if (opts.Version == null)
            {
                Console.Error.WriteLine("Please specifiy a version to install");
                return;
            }
            List <NodeVersion> versions = List.GetLocalVersions();

            NodeVersion target = VersionResolver.Resolve(versions, opts.Version);

            if (target == null)
            {
                Console.Error.WriteLine("No version matching: " + opts.Version + " found in installed versions.  Run 'nvm install " + opts.Version + "' to install it");
            }
            else
            {
                File.WriteAllText(Path.Combine(Utils.GetContainer(), "node-version"), target.Version);
                Link.LinkWithID(target, Environment.GetEnvironmentVariable("NVM_LINK_ID"));
                Console.WriteLine("Now using Node.JS " + target.Version);
            }
        }
Example #2
0
        public static void Run(LinkOptions opts)
        {
            NodeVersion current = Utils.getCurrentNodeVersion();

            LinkWithID(current, opts.LinkID);
            if (current != null)
            {
                Console.WriteLine("Now using Node.JS " + current.Version);
            }
        }
Example #3
0
        public static NodeVersion getLocalNPMRCVersion()
        {
            string npmrc = Path.Combine(Directory.GetCurrentDirectory(), ".npmrc");

            if (!File.Exists(npmrc))
            {
                return(null);
            }
            NodeVersion tmp = new NodeVersion();

            tmp.Version = File.ReadAllText(npmrc);
            return(tmp);
        }
        private static NodeVersion Resolve(List <NodeVersion> versions, int major, int minor, int patch)
        {
            NodeVersion target = null;

            foreach (NodeVersion v in versions)
            {
                if (v.GetSemVer().Major == major && v.GetSemVer().Minor == minor && v.GetSemVer().Patch == patch &&
                    (target == null || target.GetSemVer().CompareByPrecedence(v.GetSemVer()) < 0))
                {
                    target = v;
                }
            }
            return(target);
        }
Example #5
0
        public static List <NodeVersion> GetLocalVersions()
        {
            string[]           dirs     = Directory.GetDirectories(Utils.GetNodeContainer());
            List <NodeVersion> versions = new List <NodeVersion>();

            foreach (string versionPath in dirs)
            {
                NodeVersion tmp = new NodeVersion();
                tmp.Version = Path.GetFileName(versionPath);
                if (tmp.Version.StartsWith("v"))
                {
                    versions.Add(tmp);
                }
            }
            versions.Sort();
            return(versions);
        }
Example #6
0
        public static NodeVersion getCurrentNodeVersion()
        {
            string nodeVersionPath = Path.Combine(GetContainer(), "node-version");

            if (!File.Exists(nodeVersionPath))
            {
                return(null);
            }
            string      lastVersion = File.ReadAllText(nodeVersionPath);
            NodeVersion tmp         = new NodeVersion();

            tmp.Version = lastVersion;
            if (NodeDownloaded(tmp))
            {
                return(tmp);
            }
            return(null);
        }
Example #7
0
        public static void Run(InstallOptions opts)
        {
            if (opts.Version == null)
            {
                opts.Version = Utils.getLocalNPMRCVersion().Version;
            }
            if (opts.Version == null)
            {
                Console.Error.WriteLine("Please specifiy a version to install");
                return;
            }
            NodeVersion toInstall = VersionResolver.Resolve(opts.Version);

            if (toInstall == null)
            {
                Console.Error.WriteLine("Invalid version provided, couldn't resolve version \"" + opts.Version + "\"");
            }
            else
            {
                Download(toInstall);
            }
        }
Example #8
0
        public static void LinkWithID(NodeVersion v, string linkID)
        {
            string containerPath = Utils.GetContainer();
            string linkPath      = Path.Combine(containerPath, ".links", "link-" + linkID);

            Directory.CreateDirectory(linkPath);

            List <string> nodeLink = new List <string>();

            nodeLink.Add("@echo OFF");
            if (v != null)
            {
                nodeLink.Add(Path.Combine(Utils.GetNodeVersionContainer(v), "node.exe") + " %*");
            }
            else
            {
                nodeLink.Add("echo No Node.JS version installed.  Use 'nvm install [version]' to install one");
            }
            File.WriteAllLines(Path.Combine(linkPath, "node.cmd"), nodeLink);

            List <String> npmLink = new List <string>();

            npmLink.Add("@echo OFF");
            if (v != null)
            {
                npmLink.Add(Path.Combine(Utils.GetNodeVersionContainer(v), "npm.cmd") + " %*");
            }
            else
            {
                npmLink.Add("echo No Node.JS version installed.  Use 'nvm install [version]' to install one");
            }

            EnsurePrefixSet();

            File.WriteAllLines(Path.Combine(linkPath, "npm.cmd"), npmLink);
        }
Example #9
0
 public static bool NPMDownloaded(NodeVersion v)
 {
     return(File.Exists(Path.Combine(GetNodeContainer(), v.Version, "npm.cmd")));
 }
Example #10
0
 public static string GetNPMVersionContainer(NodeVersion v)
 {
     return(CreateDirectory(Path.Combine(GetNPMContainer(), v.Npm)));
 }