Esempio n. 1
0
        public async static Task <int> RunAndReturn(PackOptions options)
        {
            // make sure the output directory exists
            Directory.CreateDirectory(options.OutputDirectory);

            // working dir, is where we build a structure of what the package will do
            var workingDir = CreateWorkingFolder(options.OutputDirectory, "__umbpack__tmp");

            // buildfolder is the things we zip up.
            var buildFolder = CreateWorkingFolder(options.OutputDirectory, "__umbpack__build");

            /*
             * Console.WriteLine("Option: {0}", options.FolderOrFile);
             * Console.WriteLine("Output Folder: {0}", options.OutputDirectory);
             * Console.WriteLine("Working Folder: {0}", workingDir);
             * Console.WriteLine("Build Folder: {0}", buildFolder);
             */

            var  packageFile = options.FolderOrFile;
            bool isFolder    = false;

            if (!Path.GetExtension(options.FolderOrFile).Equals(".xml", StringComparison.InvariantCultureIgnoreCase))
            {
                // a folder - we assume the package.xml is in that folder
                isFolder    = true;
                packageFile = Path.Combine(options.FolderOrFile, "package.xml");
                Console.WriteLine(Resources.Pack_BuildingFolder, options.FolderOrFile);
            }
            else
            {
                Console.WriteLine(Resources.Pack_BuildingFile);
            }

            if (!File.Exists(packageFile))
            {
                Console.WriteLine(Resources.Pack_MissingXml, packageFile);
                Environment.Exit(2);
            }

            Console.WriteLine(Resources.Pack_LoadingFile, packageFile);

            // load the package xml
            var packageXml = XElement.Load(packageFile);

            Console.WriteLine(Resources.Pack_UpdatingVersion);

            // stamp the package version.
            var version = GetOrSetPackageVersion(packageXml, options.Version);

            Console.WriteLine(Resources.Pack_GetPackageName);
            // work out what we are going to call the package
            var packageFileName = GetPackageFileName(options.OutputDirectory, packageXml, version);

            Console.WriteLine(Resources.Pack_AddPackageFiles);
            // add any files based on what is already in the package.xml
            AddFilesBasedOnPackageXml(packageXml, workingDir);

            // if the source is a folder, grab all the files from that folder
            if (isFolder)
            {
                AddFilesFromFolders(options.FolderOrFile, workingDir);
            }

            Console.WriteLine(Resources.Pack_BuildPackage);
            BuildPackageFolder(packageXml, workingDir, buildFolder);
            Directory.Delete(workingDir, true);

            CreateZip(buildFolder, packageFileName);

            Console.WriteLine(Resources.Pack_Complete);
            Directory.Delete(buildFolder, true);

            return(0);
        }
Esempio n. 2
0
        public async static Task <int> RunAndReturn(PackOptions options)
        {
            // make sure the output directory exists
            Directory.CreateDirectory(options.OutputDirectory);

            // working dir, is where we build a structure of what the package will do
            var workingDir = CreateWorkingFolder(options.OutputDirectory, "__umbpack__tmp");

            // buildfolder is the things we zip up.
            var buildFolder = CreateWorkingFolder(options.OutputDirectory, "__umbpack__build");

            /*
             * Console.WriteLine("Option: {0}", options.FolderOrFile);
             * Console.WriteLine("Output Folder: {0}", options.OutputDirectory);
             * Console.WriteLine("Working Folder: {0}", workingDir);
             * Console.WriteLine("Build Folder: {0}", buildFolder);
             */

            var  packageFile = options.FolderOrFile;
            bool isFolder    = false;

            if (!Path.GetExtension(options.FolderOrFile).Equals(".xml", StringComparison.InvariantCultureIgnoreCase))
            {
                // a folder - we assume the package.xml is in that folder
                isFolder    = true;
                packageFile = Path.Combine(options.FolderOrFile, "package.xml");
                Console.WriteLine(Resources.Pack_BuildingFolder, options.FolderOrFile);
            }
            else
            {
                Console.WriteLine(Resources.Pack_BuildingFile);
            }

            if (!File.Exists(packageFile))
            {
                Console.WriteLine(Resources.Pack_MissingXml, packageFile);
                Environment.Exit(2);
            }

            Console.WriteLine(Resources.Pack_LoadingFile, packageFile);

            // load the package xml
            XElement packageXml = null;

            if (!string.IsNullOrWhiteSpace(options.Properties))
            {
                var packageXmlContents = File.ReadAllText(packageFile);

                var props = options.Properties.Split(";", StringSplitOptions.RemoveEmptyEntries)
                            .Select(x => x.Split('='))
                            .ToDictionary(x => x[0], x => x[1]);

                foreach (var prop in props)
                {
                    packageXmlContents = packageXmlContents.Replace($"${prop.Key}$", prop.Value);
                }

                packageXml = XElement.Parse(packageXmlContents);
            }
            else
            {
                packageXml = XElement.Load(packageFile);
            }

            Console.WriteLine(Resources.Pack_UpdatingVersion);

            // stamp the package version.
            var version = GetOrSetPackageVersion(packageXml, options.Version);

            Console.WriteLine(Resources.Pack_GetPackageName);

            // work out what we are going to call the package
            var packageFileName = !string.IsNullOrWhiteSpace(options.PackageFileName)
                ? options.PackageFileName.EnsureEndsWith(".zip")
                : GetPackageFileName(packageXml, version);

            // work out what where we are going to output the package to
            var packageOutputPath = Path.Combine(options.OutputDirectory, packageFileName);

            Console.WriteLine(Resources.Pack_AddPackageFiles);
            // add any files based on what is already in the package.xml
            AddFilesBasedOnPackageXml(packageXml, workingDir);

            // if the source is a folder, grab all the files from that folder
            if (isFolder)
            {
                AddFilesFromFolders(options.FolderOrFile, workingDir);
            }

            Console.WriteLine(Resources.Pack_BuildPackage);
            BuildPackageFolder(packageXml, workingDir, buildFolder);
            Directory.Delete(workingDir, true);

            CreateZip(buildFolder, packageOutputPath);

            Console.WriteLine(Resources.Pack_Complete);
            Directory.Delete(buildFolder, true);

            return(0);
        }