public void OnStep(IApplication application, string step)
        {
            if (step == ExecutionLifeCycleSteps.BeforeTemplateExecution)
            {
                var outputTarget = CliCommand.GetFrontEndOutputTarget(application);
                if (outputTarget == null)
                {
                    Logging.Log.Warning("Could not find a location to install ngx-bootstrap. Ensure that a Web Client package has been created.");
                    return;
                }
                if (!IsNgxBootrapInstalled(outputTarget.Location))
                {
                    Logging.Log.Info($"Installing Ngx-Bootstrap into Angular app at location [{outputTarget.Location}]");
                    CliCommand.Run(outputTarget.Location, $@"ng add ngx-bootstrap");
                    CliCommand.Run(outputTarget.Location, $@"npm i [email protected]"); // Ensure this version

                    var appComponent = application.FindTemplateInstance(AngularComponentHtmlTemplate.TemplateId, t => t.GetMetadata().FileName == "app.component");
                    if (appComponent != null)
                    {
                        if (File.Exists(appComponent.GetMetadata().GetFilePath()))
                        {
                            Logging.Log.Info($"Overriding app.component.html file.");
                            File.WriteAllText(appComponent.GetMetadata().GetFilePath(), "");
                        }
                    }
                }
                else
                {
                    Logging.Log.Info("Ngx-Bootstrap app already installed. Skipping installation");
                }
            }
        }
Exemplo n.º 2
0
        public bool IsPackageInstalled(IApplication application, string package)
        {
            string appLocation = CliCommand.GetFrontEndOutputTarget(application).Location;

            if (!File.Exists($@"{appLocation}/package.json"))
            {
                return(true);
            }
            using (var file = File.OpenText($@"{appLocation}/package.json"))
            {
                JsonSerializer serializer  = new JsonSerializer();
                var            packageFile = (dynamic)serializer.Deserialize(new JsonTextReader(file));
                return(packageFile.dependencies[package] != null);
            }
        }
Exemplo n.º 3
0
        public void OnStep(IApplication application, string step)
        {
            if (step == ExecutionLifeCycleSteps.AfterMetadataLoad)
            {
                if (!_metadataManager.WebClient(application).GetModuleModels().Any(x => x.IsRootModule() && x.Name == "AppModule"))
                {
                    throw new Exception("No Web Client Package found. Create a new Package and Root Module 'AppModule' in the Web Client designer.");
                }
                application.EventDispatcher.Subscribe <CliInstallationRequest>(request => _installationRequests.Add(request));
            }
            if (step == ExecutionLifeCycleSteps.BeforeTemplateExecution)
            {
                var outputTarget = CliCommand.GetFrontEndOutputTarget(application);
                if (outputTarget == null)
                {
                    Logging.Log.Warning("Could not find a location to install Angular application. Ensure that a Web Client package has been created.");
                    return;
                }
                if (!AngularInstalled(application))
                {
                    Logging.Log.Info($"Installing Angular into project: [{ outputTarget.Name }]");
                    CliCommand.Run(outputTarget.Location, $@"npm i @angular/cli@8 --save-dev"); // Ensure this version - typescript fix
                    // add --skipInstall to skip running the npm i
                    CliCommand.Run(outputTarget.Location, $@"ng new {application.Name} --directory=. --skipGit --style=scss --interactive=false --force=true");
                    CliCommand.Run(outputTarget.Location, $@"npm i @types/[email protected]"); // Ensure this version - typescript fix
                }
                else
                {
                    Logging.Log.Info("Angular app already installed. Skipping Angular CLI installation");
                }

                foreach (var installationRequest in _installationRequests)
                {
                    if (!IsPackageInstalled(application, installationRequest.NpmPackageName))
                    {
                        CliCommand.Run(outputTarget.Location, $"{installationRequest.Command}");
                    }
                }
            }
        }
Exemplo n.º 4
0
        public bool AngularInstalled(IApplication application)
        {
            var project = CliCommand.GetFrontEndOutputTarget(application);

            return(project != null && File.Exists(Path.Combine(project.Location, "angular.json")));
        }