/// <summary> /// Convert a parsed json dependency entry to a package dependency /// </summary> /// <param name="key">The string key of the dependency</param> /// <param name="value">The object value</param> /// <returns>A package dependency</returns> protected static NpmPackageDependency ConvertKeyValueToDependency(string key, object value) { NpmPackageDependency dependency = new NpmPackageDependency(); dependency.Name = key; dependency.VersionRange = value as string; return dependency; }
/// <summary> /// convert npm outdated output to NpmPackageDependency enumeration /// </summary> /// <param name="outdated">text output</param> /// <returns>enumerable INpmPackageDependency properties</returns> public IEnumerable<INpmPackageDependency> FromOutdatedDependency(string outdated) { if (outdated == null) { return null; } List<INpmPackageDependency> depends = new List<INpmPackageDependency>(); char[] seps = new char[] { '\n' }; string[] lines = outdated.Trim().Split(seps, StringSplitOptions.RemoveEmptyEntries); seps = new char[] { ' ' }; foreach (string line in lines) { string[] tokens = line.Split(seps, StringSplitOptions.RemoveEmptyEntries); int tokenCount = tokens.Length; if (tokenCount > 0) { NpmPackageDependency dependency = new NpmPackageDependency(); seps = new char[] { '@' }; string[] nameVersion = tokens[0].Split(seps); dependency.Name = nameVersion[0]; if (nameVersion.Length > 1) { dependency.VersionRange = nameVersion[1]; } if (tokenCount > 2) { seps = new char[] { '=' }; string[] current = tokens[2].Split(seps); if (current.Length > 1 && current[0] == "current" && current[1] != "MISSING") { dependency.Version = current[1]; } } depends.Add(dependency); } } return depends; }
/// <summary> /// Expected output from outdated /// </summary> /// <returns>Expected result for outdated test</returns> public static List<NpmPackageDependency> Outdated1Expected() { List<NpmPackageDependency> expected = new List<NpmPackageDependency>(); NpmPackageDependency dependency = new NpmPackageDependency(); dependency.Name = "underscore"; dependency.Version = "1.3.0"; dependency.VersionRange = "1.3.1"; expected.Add(dependency); return expected; }
/// <summary> /// Expected output from outdated /// </summary> /// <returns>Expected result for outdated test</returns> public static List<NpmPackageDependency> OutdatedMultiExpected() { List<NpmPackageDependency> expected = new List<NpmPackageDependency>(); NpmPackageDependency dependency = new NpmPackageDependency(); dependency.Name = "outdatedparent"; dependency.Version = "0.5.2"; dependency.VersionRange = "0.5.4"; expected.Add(dependency); dependency = new NpmPackageDependency(); dependency.Name = "outdatedchild"; dependency.Version = "1.3.0"; dependency.VersionRange = "1.3.1"; expected.Add(dependency); return expected; }
/// <summary> /// Expected output from outdated with name /// </summary> /// <returns>Expected result for outdated test</returns> public static NpmPackageDependency OutdatedSingle1Expected() { NpmPackageDependency dependency = new NpmPackageDependency(); dependency.Name = "underscore"; dependency.Version = "1.3.0"; dependency.VersionRange = "1.3.1"; return dependency; }