Ejemplo n.º 1
0
    private static bool ProcessModule(string name, Module info)
    {
        var modulePath  = $"../../../../Atom/{info.Category}/{name}";
        var moduleFiles = Directory.GetFiles(modulePath);

        var codeFiles   = moduleFiles.Where(f => Path.GetExtension(f) == ".cs").OrderBy(f => f).ToList();
        var hashBuilder = new HashBuilder();

        foreach (var file in codeFiles)
        {
            hashBuilder.Add(Path.GetFileName(file));
            hashBuilder.Add(File.ReadAllText(file));
        }
        var sourceHash = hashBuilder.GetHash();

        // normalize tags, if needed
        info.Tags = info.Tags.AsCommaList().ToCommaList();

        // sort dependencies, if needed
        if (info.DependsOn != null)
        {
            info.DependsOn = info.DependsOn.OrderBy(i => i).ToArray();
        }

        // if source files have changed then increase build number
        var updated = false;

        if (sourceHash != info.SourceHash)
        {
            var ver = new Version(info.Version);
            var upd = new Version(ver.Major, ver.Minor, ver.Build + 1);

            info.Version      = upd.ToString();
            info.SourceHash   = sourceHash;
            info.ReleaseNotes = "???";
            updated           = true;
        }

        var nuspecFile = Path.Combine(modulePath, $"Atom.{name}.nuspec");
        var nuspecXml  = CreateNuspecXml(name, info, codeFiles);

        File.WriteAllText(nuspecFile, nuspecXml);

        return(updated);
    }