예제 #1
0
파일: BuildCommand.cs 프로젝트: xyfy/abp
    public Task ExecuteAsync(CommandLineArgs commandLineArgs)
    {
        var sw = new Stopwatch();

        sw.Start();

        var workingDirectory = commandLineArgs.Options.GetOrNull(
            Options.WorkingDirectory.Short,
            Options.WorkingDirectory.Long
            );

        var dotnetBuildArguments = commandLineArgs.Options.GetOrNull(
            Options.DotnetBuildArguments.Short,
            Options.DotnetBuildArguments.Long
            );

        var buildName = commandLineArgs.Options.GetOrNull(
            Options.BuildName.Short,
            Options.BuildName.Long
            );

        var forceBuild = commandLineArgs.Options.ContainsKey(Options.ForceBuild.Short) ||
                         commandLineArgs.Options.ContainsKey(Options.ForceBuild.Long);

        var buildConfig = DotNetProjectBuildConfigReader.Read(workingDirectory ?? Directory.GetCurrentDirectory());

        buildConfig.BuildName  = buildName;
        buildConfig.ForceBuild = forceBuild;

        if (string.IsNullOrEmpty(buildConfig.SlFilePath))
        {
            var changedProjectFiles = ChangedProjectFinder.FindByRepository(buildConfig);

            var buildSucceededProjects = DotNetProjectBuilder.BuildProjects(
                changedProjectFiles,
                dotnetBuildArguments ?? ""
                );

            var buildStatus = BuildStatusGenerator.Generate(
                buildConfig,
                changedProjectFiles,
                buildSucceededProjects
                );

            RepositoryBuildStatusStore.Set(buildName, buildConfig.GitRepository, buildStatus);
        }
        else
        {
            DotNetProjectBuilder.BuildSolution(
                buildConfig.SlFilePath,
                dotnetBuildArguments ?? ""
                );
        }

        sw.Stop();
        Console.WriteLine("Build operation is completed in " + sw.ElapsedMilliseconds + " (ms)");

        return(Task.CompletedTask);
    }
예제 #2
0
        public async Task BundleAsync(string directory, bool forceBuild, bool bundle, bool minify, string bundleName)
        {
            var projectFiles = Directory.GetFiles(directory, "*.csproj");

            if (!projectFiles.Any())
            {
                throw new BundlingException("No project file found in the directory. The working directory must have a Blazor project file.");
            }

            var projectFilePath = projectFiles[0];

            if (forceBuild)
            {
                var projects = new List <DotNetProjectInfo>()
                {
                    new DotNetProjectInfo(string.Empty, projectFilePath, true)
                };

                DotNetProjectBuilder.BuildProjects(projects, string.Empty);
            }

            var frameworkVersion = GetTargetFrameworkVersion(projectFilePath);
            var projectName      = Path.GetFileNameWithoutExtension(projectFilePath);
            var assemblyFilePath = PathHelper.GetAssemblyFilePath(directory, frameworkVersion, projectName);
            var startupModule    = GetStartupModule(assemblyFilePath);

            var bundleDefinitions = new List <BundleTypeDefinition>();

            FindBundleContributorsRecursively(startupModule, 0, bundleDefinitions);
            bundleDefinitions = bundleDefinitions.OrderByDescending(t => t.Level).ToList();

            var    styleContext  = GetStyleContext(bundleDefinitions);
            var    scriptContext = GetScriptContext(bundleDefinitions);
            string styleDefinitions;
            string scriptDefinitions;

            if (bundle || minify)
            {
                var options = new BundleOptions
                {
                    Directory        = directory,
                    FrameworkVersion = frameworkVersion,
                    ProjectFileName  = projectName,
                    BundleName       = bundleName,
                    Minify           = minify
                };

                styleDefinitions  = StyleBundler.Bundle(options, styleContext);
                scriptDefinitions = ScriptBundler.Bundle(options, scriptContext);
            }
            else
            {
                styleDefinitions  = GenerateStyleDefinitions(styleContext);
                scriptDefinitions = GenerateScriptDefinitions(scriptContext);
            }

            await UpdateDependenciesInHtmlFileAsync(directory, styleDefinitions, scriptDefinitions);
        }
예제 #3
0
        public async Task BundleAsync(string directory, bool forceBuild)
        {
            var projectFiles = Directory.GetFiles(directory, "*.csproj");

            if (!projectFiles.Any())
            {
                throw new BundlingException(
                          "No project file found in the directory. The working directory must have a Blazor project file.");
            }

            var projectFilePath = projectFiles[0];

            var config       = ConfigReader.Read(PathHelper.GetWwwRootPath(directory));
            var bundleConfig = config.Bundle;

            if (forceBuild)
            {
                var projects = new List <DotNetProjectInfo>()
                {
                    new DotNetProjectInfo(string.Empty, projectFilePath, true)
                };

                DotNetProjectBuilder.BuildProjects(projects, string.Empty);
            }

            var frameworkVersion = GetTargetFrameworkVersion(projectFilePath);
            var projectName      = Path.GetFileNameWithoutExtension(projectFilePath);
            var assemblyFilePath = PathHelper.GetAssemblyFilePath(directory, frameworkVersion, projectName);
            var startupModule    = GetStartupModule(assemblyFilePath);

            var bundleDefinitions = new List <BundleTypeDefinition>();

            FindBundleContributorsRecursively(startupModule, 0, bundleDefinitions);
            bundleDefinitions = bundleDefinitions.OrderByDescending(t => t.Level).ToList();

            var    styleContext  = GetStyleContext(bundleDefinitions, bundleConfig.Parameters);
            var    scriptContext = GetScriptContext(bundleDefinitions, bundleConfig.Parameters);
            string styleDefinitions;
            string scriptDefinitions;

            if (bundleConfig.Mode is BundlingMode.Bundle || bundleConfig.Mode is BundlingMode.BundleAndMinify)
            {
                var options = new BundleOptions
                {
                    Directory        = directory,
                    FrameworkVersion = frameworkVersion,
                    ProjectFileName  = projectName,
                    BundleName       = bundleConfig.Name.IsNullOrEmpty() ? "global" : bundleConfig.Name,
                    Minify           = bundleConfig.Mode == BundlingMode.BundleAndMinify
                };

                Logger.LogInformation("Generating style bundle...");
                styleDefinitions = StyleBundler.Bundle(options, styleContext);
                Logger.LogInformation($"Style bundle has been generated successfully.");

                Logger.LogInformation("Generating script bundle...");
                scriptDefinitions = ScriptBundler.Bundle(options, scriptContext);
                Logger.LogInformation($"Script bundle has been generated successfully.");
            }
            else
            {
                Logger.LogInformation("Generating style references...");
                styleDefinitions = GenerateStyleDefinitions(styleContext);
                Logger.LogInformation("Generating script references...");
                scriptDefinitions = GenerateScriptDefinitions(scriptContext);
            }

            await UpdateDependenciesInHtmlFileAsync(directory, styleDefinitions, scriptDefinitions);

            Logger.LogInformation("Script and style references in the index.html file have been updated.");
        }