Beispiel #1
0
        public void pack_run(ChocolateyConfiguration config)
        {
            string nuspecFilePath  = validate_and_return_package_file(config, Constants.ManifestExtension);
            var    nuspecDirectory = _fileSystem.get_full_path(_fileSystem.get_directory_name(nuspecFilePath));

            if (string.IsNullOrWhiteSpace(nuspecDirectory))
            {
                nuspecDirectory = _fileSystem.get_current_directory();
            }

            IDictionary <string, string> properties = new Dictionary <string, string>();

            // Set the version property if the flag is set
            if (!string.IsNullOrWhiteSpace(config.Version))
            {
                properties["version"] = config.Version;
            }

            // Initialize the property provider based on what was passed in using the properties flag
            var propertyProvider = new DictionaryPropertyProvider(properties);

            var basePath = nuspecDirectory;

            if (config.Information.PlatformType != PlatformType.Windows)
            {
                //bug with nuspec and tools/** folder location on Windows.
                basePath = "./";
            }

            var builder = new PackageBuilder(nuspecFilePath, basePath, propertyProvider, includeEmptyDirectories: true);

            if (!string.IsNullOrWhiteSpace(config.Version))
            {
                builder.Version = new SemanticVersion(config.Version);
            }

            string outputFile = builder.Id + "." + builder.Version + Constants.PackageExtension;
            string outputPath = _fileSystem.combine_paths(_fileSystem.get_current_directory(), outputFile);

            this.Log().Info(() => "Attempting to build package from '{0}'.".format_with(_fileSystem.get_file_name(nuspecFilePath)));

            //IPackage package =
            NugetPack.BuildPackage(builder, _fileSystem, outputPath);
            //todo: v1 analyze package
            //if (package != null)
            //{
            //    AnalyzePackage(package);
            //}

            this.Log().Info(ChocolateyLoggers.Important, () => "Successfully created package '{0}'".format_with(outputFile));
        }
Beispiel #2
0
        public void generate_file_from_template(ChocolateyConfiguration configuration, TemplateValues tokens, string template, string fileLocation, Encoding encoding)
        {
            template = TokenReplacer.replace_tokens(tokens, template);
            template = TokenReplacer.replace_tokens(tokens.AdditionalProperties, template);

            if (configuration.RegularOutput)
            {
                this.Log().Info(() => "Generating template to a file{0} at '{1}'".format_with(Environment.NewLine, fileLocation));
            }
            this.Log().Debug(() => "{0}".format_with(template));
            _fileSystem.create_directory_if_not_exists(_fileSystem.get_directory_name(fileLocation));
            _fileSystem.write_file(fileLocation, template, encoding);
        }