public bool Run(string projectDir, bool generateSpritesFile) { var projDir = _cache.TryGetItem(projectDir) as IDirectoryCache; if (projDir == null) { return(false); } _cache.UpdateIfNeeded(projDir); var assetsDir = projDir.TryGetChild(_assetsDirName) as IDirectoryCache; if (assetsDir == null) { return(false); } var srcPath = PathUtils.Join(projectDir, _srcDirName); var assets = InspectAssets(assetsDir, srcPath); var assetsContentBuilder = new AssetsContentBuilder(); assetsContentBuilder.Build(assets); var changed = WriteContent(srcPath, _assetsFileName, assetsContentBuilder.Content, projectDir); if (generateSpritesFile) { var spritesContentBuilder = new SpritesContentBuilder(); spritesContentBuilder.Build(assets); changed |= WriteContent(srcPath, _spritesFileName, spritesContentBuilder.Content, projectDir); } return(changed); }
public static TSProject FindInfoForModule(IDirectoryCache projectDir, IDirectoryCache dir, IDiskCache diskCache, ILogger logger, string moduleName, out string diskName) { if (projectDir.TryGetChildNoVirtual("node_modules") is IDirectoryCache pnmdir) { diskCache.UpdateIfNeeded(pnmdir); if (pnmdir.TryGetChild(moduleName, true) is IDirectoryCache mdir) { diskName = mdir.Name; diskCache.UpdateIfNeeded(mdir); return(Get(mdir, diskCache, logger, diskName)); } } while (dir != null) { if (diskCache.TryGetItem(PathUtils.Join(dir.FullPath, "node_modules")) is IDirectoryCache nmdir) { diskCache.UpdateIfNeeded(nmdir); if (nmdir.TryGetChild(moduleName, true) is IDirectoryCache mdir) { diskName = mdir.Name; diskCache.UpdateIfNeeded(mdir); return(Get(mdir, diskCache, logger, diskName)); } } dir = dir.Parent; } diskName = null; return(null); }
public IEnumerable <string> Generate(PackagePathVersion[] before, PackagePathVersion[] after) { var beforeDict = before.ToDictionary(version => version.Name); foreach (var packagePathVersion in after) { if (beforeDict.TryGetValue(packagePathVersion.Name, out var beforePackage)) { if (beforePackage.Version == packagePathVersion.Version) { continue; } var file = _diskCache.TryGetItem(PathUtils.Join(packagePathVersion.Path, "CHANGELOG.md")) as IFileCache; if (file == null) { continue; } var diffLines = file.Utf8Content.Split('\n').Select(l => l.TrimEnd('\r')).Aggregate( (new List <string>(), false), (acc, line) => { var read = acc.Item2; var possiblyVersion = line.Split(' ', StringSplitOptions.RemoveEmptyEntries) .ElementAtOrDefault(1); if (possiblyVersion == packagePathVersion.Version) { read = true; } if (possiblyVersion == beforePackage.Version) { read = false; } if (read) { acc.Item1.Add(line); } return(acc.Item1, read); }, acc => acc.Item1); if (diffLines.Count == 0) { continue; } yield return($"# {packagePathVersion.Name}"); yield return($"# {beforePackage.Version} => {packagePathVersion.Version}"); foreach (var line in diffLines) { yield return(line); } yield return(""); } } }
public ReadOnlySpan <byte> ReadUtf8(string fileName) { var item = _diskCache.TryGetItem(PathUtils.Join(_root, fileName)); if (item.IsFile && !item.IsInvalid) { return(((IFileCache)item).ByteContent); } return(new ReadOnlySpan <byte>()); }
public IEnumerable <string> Generate(PackagePathVersion[] before, PackagePathVersion[] after) { var beforeDict = before.ToDictionary(version => version.Name); foreach (var packagePathVersion in after) { if (beforeDict.TryGetValue(packagePathVersion.Name, out var beforePackage)) { if (beforePackage.Version == packagePathVersion.Version) { continue; } var verFrom = TryParseVersion(beforePackage.Version); var verTo = TryParseVersion(packagePathVersion.Version); if (verFrom == null || verTo == null) { continue; } var file = _diskCache.TryGetItem(PathUtils.Join(packagePathVersion.Path, "CHANGELOG.md")) as IFileCache; if (file == null) { continue; } var diffLines = file.Utf8Content.Split('\n').Select(l => l.TrimEnd('\r')).Aggregate( (new List <string>(), false), (acc, line) => { var read = acc.Item2; var verMatch = _lineWithVersion.Match(line); if (verMatch.Success) { var verStr = verMatch.Groups[1].Value; var ver = TryParseVersion(verStr); if (ver != null) { read = verFrom < ver && ver <= verTo; } } if (read) { acc.Item1.Add(line); } return(acc.Item1, read); }, acc => acc.Item1); if (diffLines.Count == 0) { continue; } yield return($"# {packagePathVersion.Name}"); yield return($"# {beforePackage.Version} => {packagePathVersion.Version}"); foreach (var line in diffLines) { yield return(line); } yield return(""); } } }