private void DrawDependenciesUt() { if (_selectPackageInfo == null) { return; } // todo 缓存 var textAsset = AssetDatabase.LoadAssetAtPath <TextAsset>($"{_selectPackageInfo.assetPath}/package.json"); var packageJsonInfo = PackageJson.Parse(textAsset.text); _ui.DrawDependenciesUt(packageJsonInfo, this); }
public async Task DownloadAndExtractTS(string dir, string versionString) { _logger.Info($"Downloading and extracting TypeScript {versionString}"); var version = new SemVer.Version(versionString); var npmr = new NpmRepositoryAccessor(); var packageEtagAndContent = await npmr.GetPackageInfo("typescript", null); var task = null as Task <byte[]>; try { var packageInfo = new PackageInfo(packageEtagAndContent.content); packageInfo.LazyParseVersions(v => v == version, reader => { var j = PackageJson.Parse(reader); PathUtils.SplitDirAndFile(j.Dist.Tarball, out var tgzName); _logger.Info($"Downloading Tarball {tgzName.ToString()}"); task = npmr.GetPackageTgz("typescript", tgzName.ToString()); }); } catch (Exception) { _logger.Error("Failed to parse TypeScript package info: " + packageEtagAndContent.content.Substring(0, Math.Min(1000, packageEtagAndContent.content.Length))); throw; } if (task != null) { var bytes = await task; _logger.Info($"Extracting {bytes.Length} bytes"); await TarExtractor.ExtractTgzAsync(bytes, async (name, stream, size) => { if (name.StartsWith("package/")) { name = name.Substring("package/".Length); } var fn = PathUtils.Join(dir, name); Directory.CreateDirectory(PathUtils.DirToCreateDirectory(PathUtils.Parent(fn))); using (var targetStream = File.Create(fn)) { var buf = new byte[4096]; while (size > 0) { var read = await stream.ReadAsync(buf, 0, (int)Math.Min((ulong)buf.Length, size)); if (read == 0) { throw new IOException($"Reading {name} failed"); } await targetStream.WriteAsync(buf, 0, read); size -= (ulong)read; } } return(true); }); } else { throw new Exception($"TypeScript version {version} does not exists"); } }