예제 #1
0
        public async Task <ProjectBuildResult> BuildAsync(ProjectBuildArgs args)
        {
            var templateInfo = GetTemplateInfo(args);

            NormalizeArgs(args, templateInfo);

            var templateFile = await TemplateStore.GetAsync(
                args.TemplateName,
                args.Version
                );

            var apiKey = await ApiKeyService.GetApiKeyOrNullAsync();

            if (apiKey != null)
            {
                args.ExtraProperties["api-key"] = apiKey;
            }

            var context = new ProjectBuildContext(
                templateInfo,
                templateFile,
                args
                );

            ProjectBuildPipelineBuilder.Build(context).Execute();

            if (!templateInfo.DocumentUrl.IsNullOrEmpty())
            {
                Logger.LogInformation("Check the documentation of this template: " + templateInfo.DocumentUrl);
            }

            // Exclude unwanted or known options.
            var options = args.ExtraProperties
                          .Where(x => !x.Key.Equals(CliConsts.Command, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals("tiered", StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.DatabaseProvider.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.DatabaseProvider.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.OutputFolder.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.OutputFolder.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.UiFramework.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.UiFramework.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.Version.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.Version.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Select(x => x.Key).ToList();

            await CliAnalyticsCollect.CollectAsync(new CliAnalyticsCollectInputDto
            {
                Tool             = Options.ToolName,
                Command          = args.ExtraProperties.ContainsKey(CliConsts.Command) ? args.ExtraProperties[CliConsts.Command] : "",
                DatabaseProvider = args.DatabaseProvider.ToProviderName(),
                IsTiered         = args.ExtraProperties.ContainsKey("tiered"),
                UiFramework      = args.UiFramework.ToFrameworkName(),
                Options          = JsonSerializer.Serialize(options),
                ProjectName      = args.SolutionName.FullName,
                TemplateName     = args.TemplateName,
                TemplateVersion  = templateFile.Version
            });

            return(new ProjectBuildResult(context.Result.ZipContent, args.SolutionName.ProjectName));
        }
예제 #2
0
        public async Task <ProjectBuildResult> BuildAsync(ProjectBuildArgs args)
        {
            var packageInfo = await GetPackageInfoAsync(args);

            var templateFile = await SourceCodeStore.GetAsync(
                args.TemplateName,
                SourceCodeTypes.Package,
                args.Version,
                null,
                args.ExtraProperties.ContainsKey(GetSourceCommand.Options.Preview.Long)
                );

            var apiKeyResult = await ApiKeyService.GetApiKeyOrNullAsync();

            if (apiKeyResult?.ApiKey != null)
            {
                args.ExtraProperties["api-key"] = apiKeyResult.ApiKey;
            }

            if (apiKeyResult?.LicenseCode != null)
            {
                args.ExtraProperties["license-code"] = apiKeyResult.LicenseCode;
            }

            var context = new ProjectBuildContext(
                null,
                null,
                packageInfo,
                templateFile,
                args
                );

            PackageProjectBuildPipelineBuilder.Build(context).Execute();

            // Exclude unwanted or known options.
            var options = args.ExtraProperties
                          .Where(x => !x.Key.Equals(CliConsts.Command, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.OutputFolder.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.OutputFolder.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.Version.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.Version.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.TemplateSource.Short, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.TemplateSource.Long, StringComparison.InvariantCultureIgnoreCase))
                          .Select(x => x.Key).ToList();

            await CliAnalyticsCollect.CollectAsync(new CliAnalyticsCollectInputDto
            {
                Tool             = Options.ToolName,
                Command          = args.ExtraProperties.ContainsKey(CliConsts.Command) ? args.ExtraProperties[CliConsts.Command] : "",
                DatabaseProvider = null,
                IsTiered         = null,
                UiFramework      = null,
                Options          = JsonSerializer.Serialize(options),
                ProjectName      = null,
                TemplateName     = args.TemplateName,
                TemplateVersion  = templateFile.Version
            });

            return(new ProjectBuildResult(context.Result.ZipContent, args.TemplateName));
        }
예제 #3
0
        public async Task <ProjectBuildResult> BuildAsync(ProjectBuildArgs args)
        {
            var templateInfo = await GetTemplateInfoAsync(args);

            NormalizeArgs(args, templateInfo);

            var templateFile = await SourceCodeStore.GetAsync(
                args.TemplateName,
                SourceCodeTypes.Template,
                args.Version,
                args.TemplateSource,
                args.ExtraProperties.ContainsKey(NewCommand.Options.Preview.Long)
                );

            DeveloperApiKeyResult apiKeyResult = null;

#if DEBUG
            try
            {
                var apiKeyResultSection = _configuration.GetSection("apiKeyResult");
                if (apiKeyResultSection.Exists())
                {
                    apiKeyResult = apiKeyResultSection.Get <DeveloperApiKeyResult>(); //you can use user secrets
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            if (apiKeyResult == null)
            {
                apiKeyResult = await ApiKeyService.GetApiKeyOrNullAsync();
            }
#else
            apiKeyResult = await ApiKeyService.GetApiKeyOrNullAsync();
#endif

            if (apiKeyResult != null)
            {
                if (apiKeyResult.ApiKey != null)
                {
                    args.ExtraProperties["api-key"] = apiKeyResult.ApiKey;
                }
                else if (templateInfo.Name == AppProTemplate.TemplateName)
                {
                    throw new UserFriendlyException(apiKeyResult.ErrorMessage);
                }
            }

            if (apiKeyResult?.LicenseCode != null)
            {
                args.ExtraProperties["license-code"] = apiKeyResult.LicenseCode;
            }

            var context = new ProjectBuildContext(
                templateInfo,
                null,
                null,
                null,
                templateFile,
                args
                );

            if (context.Template is AppTemplateBase appTemplateBase)
            {
                appTemplateBase.HasDbMigrations = SemanticVersion.Parse(templateFile.Version) < new SemanticVersion(4, 3, 99);
            }

            TemplateProjectBuildPipelineBuilder.Build(context).Execute();

            if (!templateInfo.DocumentUrl.IsNullOrEmpty())
            {
                Logger.LogInformation("Check out the documents at " + templateInfo.DocumentUrl);
            }

            // Exclude unwanted or known options.
            var options = args.ExtraProperties
                          .Where(x => !x.Key.Equals(CliConsts.Command, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.Tiered.Long, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.Preview.Long, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.DatabaseProvider.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.DatabaseProvider.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.OutputFolder.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.OutputFolder.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.UiFramework.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.UiFramework.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.Mobile.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.Mobile.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.Version.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.Version.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.TemplateSource.Short, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.TemplateSource.Long, StringComparison.InvariantCultureIgnoreCase))
                          .Select(x => x.Key).ToList();

            await CliAnalyticsCollect.CollectAsync(new CliAnalyticsCollectInputDto
            {
                Tool             = Options.ToolName,
                Command          = args.ExtraProperties.ContainsKey(CliConsts.Command) ? args.ExtraProperties[CliConsts.Command] : "",
                DatabaseProvider = args.DatabaseProvider.ToProviderName(),
                IsTiered         = args.ExtraProperties.ContainsKey(NewCommand.Options.Tiered.Long),
                UiFramework      = args.UiFramework.ToFrameworkName(),
                Options          = JsonSerializer.Serialize(options),
                ProjectName      = args.SolutionName.FullName,
                TemplateName     = args.TemplateName,
                TemplateVersion  = templateFile.Version
            });

            return(new ProjectBuildResult(context.Result.ZipContent, args.SolutionName.ProjectName));
        }