예제 #1
0
 public static DevEgg FromRelativeProject(string name, Type projectType, string relativeProjectDirectoryPath)
 {
     var codeBase = new Uri(projectType.Assembly.CodeBase).AbsolutePath;
      var projectName = new FileInfo(codeBase).Name.Pass(x => x.Substring(0, x.Length - 4));
      var csprojName = $"{projectName}.csproj";
      var progress = new CliProgressSpinner($"{name}");
      progress.Update("Finding Project File");
      var matches = Directory.GetFiles(NestDeployerConstants.RootSolutionDirectoryPath, csprojName, SearchOption.AllDirectories);
      if (matches.Length == 0) {
     throw new FileNotFoundException($"Couldn't find {csprojName}!");
      } else if (matches.Length > 1) {
     throw new AmbiguousMatchException($"Found more than one match for {csprojName}: {matches.Join(", ")}");
      }
      var match = matches.First();
      var matchDirectory = Path.GetDirectoryName(match);
      var finalPath = Path.GetFullPath(Path.Combine(matchDirectory, relativeProjectDirectoryPath));
      progress.Update(finalPath);
      return new DevEgg() {
     Name = name,
     SourceDirectory = Path.Combine(finalPath, "bin", "Debug")
      };
 }
      public static void ClientLikeDeployAndInit(DevDeployment developmentDeployment) {
         var clientDeploymentPath = Path.Combine(nestClientPath, NestConstants.kDeploymentsDirectoryName, developmentDeployment.Name);
         fileSystemProxy.PrepareDirectory(clientDeploymentPath);

         // create cache directory
         var cacheDirectoryPath = IoUtilities.CombinePath(clientDeploymentPath, NestConstants.kCacheDirectoryName);
         IoUtilities.PrepareDirectory(cacheDirectoryPath);

         // setup bundles directory
         var clientBundlesPath = Path.Combine(clientDeploymentPath, "bundles");
         fileSystemProxy.PrepareDirectory(clientBundlesPath);

         // deploy bundles
         foreach (var developmentBundle in developmentDeployment.Bundles) {
            var bundlePath = Path.Combine(clientBundlesPath, developmentBundle.Name);
            fileSystemProxy.PrepareDirectory(bundlePath);

            var bundle = BundleFactory.Local(bundlePath);
            foreach (var egg in developmentBundle.Eggs) {
               var progress = new CliProgressSpinner($"Installing egg {developmentBundle.Name}/{egg.Name}.");
               progress.Update("...");
               bundle.InstallEggAsync(EggFactory.InMemory(egg.Name, egg.SourceDirectory, "dev")).Wait();
               progress.Update("Done");
            }

            if (!string.IsNullOrWhiteSpace(developmentBundle.InitScript)) {
               var deployedInitJsonPath = Path.Combine(bundlePath, "init.json");
               File.WriteAllText(deployedInitJsonPath, developmentBundle.InitScript);
            }
         }

         // deploy init, sort of a hack
         var clientBundle = BundleFactory.Local(clientDeploymentPath);
         var developmentInitEgg = DevEgg.FromProject("init", typeof(InitNestBundleDummy));
         clientBundle.InstallEggAsync(EggFactory.InMemory("init", developmentInitEgg.SourceDirectory, "dev")).Wait();

         var initEggDirectory = IoUtilities.CombinePath(clientDeploymentPath, "init");
         var deployedInitPath = Path.Combine(initEggDirectory, "init.exe");

         // start init
         Console.WriteLine("Starting init: " + deployedInitPath);
         Process.Start(
            new ProcessStartInfo(
               deployedInitPath,
               $"-p {developmentDeployment.NestClusterPort}") {
               UseShellExecute = true
            });

         // await ctrl+c for kill nest
         var spinner = new CliProgressSpinner("Ctrl+C = Kill Nest");
         Console.CancelKeyPress += (s, e) => {
            var commanderName = "dev-nest-commander";
            var commanderProject = DevEgg.FromProject(commanderName, typeof(CommanderNestBundleDummy));
            var commanderPath = Path.Combine(commanderProject.SourceDirectory, commanderName + ".exe");

            Process.Start(
               new ProcessStartInfo(
                  commanderPath,
                  $"-p {developmentDeployment.NestClusterPort} -c kill-nest") {
                  UseShellExecute = true
               });
            e.Cancel = false;
         };
         while (true) {
            spinner.Update();
            Thread.Sleep(125);
         }
      }