示例#1
0
    public virtual async Task ExecuteAsync(CommandLineArgs commandLineArgs)
    {
        if (commandLineArgs.Target == null)
        {
            throw new CliUsageException(
                      "Package name is missing!" +
                      Environment.NewLine + Environment.NewLine +
                      GetUsageInfo()
                      );
        }

        var isAngularPackage = false;
        var isNugetPackage   = true;

        if (commandLineArgs.Target.StartsWith("@"))
        {
            isAngularPackage = true;
            isNugetPackage   = false;
        }

        var version        = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long);
        var withSourceCode = commandLineArgs.Options.ContainsKey(Options.SourceCode.Long);

        if (isNugetPackage)
        {
            var addSourceCodeToSolutionFile = withSourceCode && commandLineArgs.Options.ContainsKey("add-to-solution-file");

            await ProjectNugetPackageAdder.AddAsync(
                GetSolutionFile(commandLineArgs),
                GetProjectFile(commandLineArgs),
                commandLineArgs.Target,
                version,
                true,
                withSourceCode,
                addSourceCodeToSolutionFile
                );
        }
        else if (isAngularPackage)
        {
            await ProjectNpmPackageAdder.AddAngularPackageAsync(
                GetAngularDirectory(commandLineArgs),
                commandLineArgs.Target,
                version,
                withSourceCode
                );
        }
    }
示例#2
0
 public SolutionModuleAdder(
     IJsonSerializer jsonSerializer,
     ProjectNugetPackageAdder projectNugetPackageAdder,
     DbContextFileBuilderConfigureAdder dbContextFileBuilderConfigureAdder,
     EfCoreMigrationManager efCoreMigrationManager,
     DerivedClassFinder derivedClassFinder,
     ProjectNpmPackageAdder projectNpmPackageAdder,
     NpmGlobalPackagesChecker npmGlobalPackagesChecker,
     IRemoteServiceExceptionHandler remoteServiceExceptionHandler,
     SourceCodeDownloadService sourceCodeDownloadService,
     SolutionFileModifier solutionFileModifier,
     NugetPackageToLocalReferenceConverter nugetPackageToLocalReferenceConverter,
     AngularSourceCodeAdder angularSourceCodeAdder,
     NewCommand newCommand,
     BundleCommand bundleCommand,
     CliHttpClientFactory cliHttpClientFactory,
     ICmdHelper cmdHelper,
     ILocalEventBus localEventBus)
 {
     JsonSerializer                        = jsonSerializer;
     ProjectNugetPackageAdder              = projectNugetPackageAdder;
     DbContextFileBuilderConfigureAdder    = dbContextFileBuilderConfigureAdder;
     EfCoreMigrationManager                = efCoreMigrationManager;
     DerivedClassFinder                    = derivedClassFinder;
     ProjectNpmPackageAdder                = projectNpmPackageAdder;
     NpmGlobalPackagesChecker              = npmGlobalPackagesChecker;
     RemoteServiceExceptionHandler         = remoteServiceExceptionHandler;
     SourceCodeDownloadService             = sourceCodeDownloadService;
     SolutionFileModifier                  = solutionFileModifier;
     NugetPackageToLocalReferenceConverter = nugetPackageToLocalReferenceConverter;
     AngularSourceCodeAdder                = angularSourceCodeAdder;
     NewCommand            = newCommand;
     BundleCommand         = bundleCommand;
     CmdHelper             = cmdHelper;
     LocalEventBus         = localEventBus;
     _cliHttpClientFactory = cliHttpClientFactory;
     Logger = NullLogger <SolutionModuleAdder> .Instance;
 }
示例#3
0
    private async Task AddNugetAndNpmReferences(ModuleWithMastersInfo module, string[] projectFiles,
                                                bool useDotnetCliToInstall)
    {
        var webPackagesWillBeAddedToBlazorServerProject = SouldWebPackagesBeAddedToBlazorServerProject(module, projectFiles);

        await PublishEventAsync(3, "Adding nuget package references");

        foreach (var nugetPackage in module.NugetPackages)
        {
            var isProjectTiered = await IsProjectTiered(projectFiles);

            var nugetTarget =
                isProjectTiered && nugetPackage.TieredTarget != NuGetPackageTarget.Undefined
                    ? nugetPackage.TieredTarget
                    : nugetPackage.Target;

            if (webPackagesWillBeAddedToBlazorServerProject)
            {
                if (nugetTarget == NuGetPackageTarget.Web)
                {
                    nugetTarget = NuGetPackageTarget.BlazorServer;
                }
                else if (!isProjectTiered && nugetTarget == NuGetPackageTarget.SignalR)
                {
                    nugetTarget = NuGetPackageTarget.BlazorServer;
                }
            }

            var targetProjectFile = ProjectFinder.FindNuGetTargetProjectFile(projectFiles, nugetTarget);
            if (targetProjectFile == null)
            {
                Logger.LogDebug($"Target project is not available for this NuGet package '{nugetPackage.Name}'");
                continue;
            }

            await ProjectNugetPackageAdder.AddAsync(null, targetProjectFile, nugetPackage, null, useDotnetCliToInstall);
        }

        var mvcNpmPackages = module.NpmPackages?.Where(p => p.ApplicationType.HasFlag(NpmApplicationType.Mvc))
                             .ToList();

        if (!mvcNpmPackages.IsNullOrEmpty())
        {
            var targetProjects = ProjectFinder.FindNpmTargetProjectFile(projectFiles);
            if (targetProjects.Any())
            {
                await PublishEventAsync(4, "Adding npm package references for MVC");

                NpmGlobalPackagesChecker.Check();

                foreach (var targetProject in targetProjects)
                {
                    foreach (var npmPackage in mvcNpmPackages)
                    {
                        await ProjectNpmPackageAdder.AddMvcPackageAsync(Path.GetDirectoryName(targetProject), npmPackage);
                    }
                }
            }
            else
            {
                Logger.LogDebug("Target project is not available for NPM packages.");
            }
        }
    }
示例#4
0
 public AddPackageCommand(ProjectNugetPackageAdder projectNugetPackageAdder)
 {
     ProjectNugetPackageAdder = projectNugetPackageAdder;
     Logger = NullLogger <AddPackageCommand> .Instance;
 }