Exemple #1
0
        public void Exec(SubCommandRunningContext context)
        {
            var outputFile = Path.Combine(_options.OutputFolder ?? Environment.CurrentDirectory, _options.Name ?? "externalreference.rpk");
            var baseUri    = new Uri(_options.BaseUrl);

            if (!baseUri.IsAbsoluteUri)
            {
                throw new InvalidOptionException("BaseUrl should be absolute url.", "BaseUrl");
            }

            var source = _options.Source.TrimEnd('/', '\\');

            using (var package = _options.AppendMode ? ExternalReferencePackageWriter.Append(outputFile, baseUri) : ExternalReferencePackageWriter.Create(outputFile, baseUri))
            {
                var files = FileGlob.GetFiles(source, new string[] { _options.Glob }, null).ToList();
                if (_options.FlatMode)
                {
                    ExternalReferencePackageHelper.AddFiles(package, baseUri, _options.UrlPattern, string.Empty, files);
                }
                else
                {
                    foreach (var g in from f in files
                             group f by Path.GetDirectoryName(f) into g
                             select new
                    {
                        Folder = g.Key.Substring(source.Length).Replace('\\', '/').Trim('/'),
                        Files = g.ToList(),
                    })
                    {
                        if (g.Folder.Length == 0)
                        {
                            ExternalReferencePackageHelper.AddFiles(package, baseUri, _options.UrlPattern, string.Empty, g.Files);
                        }
                        else
                        {
                            ExternalReferencePackageHelper.AddFiles(package, baseUri, _options.UrlPattern, g.Folder + "/", g.Files);
                        }
                    }
                }
            }
        }
Exemple #2
0
 public void AddProjects(ExternalReferencePackageWriter writer, IReadOnlyList <string> projectPaths)
 {
     if (projectPaths == null)
     {
         throw new ArgumentNullException(nameof(projectPaths));
     }
     if (projectPaths.Count == 0)
     {
         throw new ArgumentException("Empty collection is not allowed.", nameof(projectPaths));
     }
     for (int i = 0; i < projectPaths.Count; i++)
     {
         var name = Path.GetFileName(projectPaths[i]);
         ExternalReferencePackageHelper.AddFiles(
             writer,
             new Uri(_options.BaseUrl),
             _options.UrlPattern,
             string.Empty,
             Directory.GetFiles(Path.Combine(projectPaths[i], "api"), "*.yml", SearchOption.TopDirectoryOnly));
     }
 }