From c653e58d1af4ede895bd09c8b44d30d8cf76b8f8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Apr 2026 17:49:23 +0000 Subject: [PATCH 1/3] Initial plan From 3c36c6c19ea9f25b29688581d697dfa0bcb34148 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Apr 2026 17:59:32 +0000 Subject: [PATCH 2/3] refactor: replace templateManager property/param passing with App container get Remove templateManager from CommandType interface, BasePromptSession constructor, PromptSession constructor, SchematicsPromptSession constructor. All commands and sessions now get templateManager from App.container.get(TEMPLATE_MANAGER). Clean up cli.ts by removing all manual templateManager assignments and TODO comment. Ensure ng-schematics entry points set TEMPLATE_MANAGER in container. Agent-Logs-Url: https://github.com/IgniteUI/igniteui-cli/sessions/34deef7a-062f-44fe-86f9-7eac03eabc8f Co-authored-by: damyanpetev <3198469+damyanpetev@users.noreply.github.com> --- packages/cli/lib/PromptSession.ts | 7 ------- packages/cli/lib/cli.ts | 10 +--------- packages/cli/lib/commands/add.ts | 16 ++++++++-------- packages/cli/lib/commands/build.ts | 6 +++--- packages/cli/lib/commands/generate.ts | 10 +++++----- packages/cli/lib/commands/list.ts | 10 +++++----- packages/cli/lib/commands/new.ts | 14 +++++++------- packages/cli/lib/commands/start.ts | 1 - packages/cli/lib/commands/types.ts | 3 --- packages/cli/lib/commands/upgrade.ts | 6 +++--- packages/core/prompt/BasePromptSession.ts | 5 ++++- packages/ng-schematics/src/component/index.ts | 5 +++-- packages/ng-schematics/src/ng-new/index.ts | 5 +++-- .../src/prompt/SchematicsPromptSession.ts | 6 ++---- 14 files changed, 44 insertions(+), 60 deletions(-) diff --git a/packages/cli/lib/PromptSession.ts b/packages/cli/lib/PromptSession.ts index 076b23504..25edeaf07 100644 --- a/packages/cli/lib/PromptSession.ts +++ b/packages/cli/lib/PromptSession.ts @@ -7,14 +7,9 @@ import { default as add } from "./commands/add"; import { configure as aiConfigure } from "./commands/ai-config"; import { default as start } from "./commands/start"; import { default as upgrade } from "./commands/upgrade"; -import { TemplateManager } from "./TemplateManager"; export class PromptSession extends BasePromptSession { - constructor(templateManager: TemplateManager) { - super(templateManager); - } - public static async chooseTerm() { const answer = await InquirerWrapper.input({ default: null, @@ -39,7 +34,6 @@ export class PromptSession extends BasePromptSession { let projLibrary: ProjectLibrary; let theme: string; - add.templateManager = this.templateManager as TemplateManager; this.config = ProjectConfig.getConfig(); const defaultProjName = "IG Project"; @@ -100,7 +94,6 @@ export class PromptSession extends BasePromptSession { } protected async upgradePackages() { - upgrade.templateManager = this.templateManager as TemplateManager; await upgrade.upgrade({ skipInstall: true, _: ["upgrade"], $0: "upgrade" }); } diff --git a/packages/cli/lib/cli.ts b/packages/cli/lib/cli.ts index eadad1aa8..7fd4194b5 100644 --- a/packages/cli/lib/cli.ts +++ b/packages/cli/lib/cli.ts @@ -32,17 +32,9 @@ export async function run(args = null) { App.initialize(); const templateManager = new TemplateManager(); - // TODO: Refactor all code to use TemplateManager from the App container: App.container.set(TEMPLATE_MANAGER, templateManager); newCommand.addChoices(templateManager.getFrameworkIds()); - newCommand.templateManager = templateManager; - add.templateManager = templateManager; - build.templateManager = templateManager; - start.templateManager = templateManager; - generate.templateManager = templateManager; - list.templateManager = templateManager; - upgrade.templateManager = templateManager; const yargsModule = args ? yargs(args) : yargs; await yargsModule @@ -140,7 +132,7 @@ export async function run(args = null) { } else { Util.log("Starting Step by step mode.", "green"); Util.log("For available commands, stop this execution and use --help.", "green"); - const prompts = new PromptSession(templateManager); + const prompts = new PromptSession(); prompts.start(); } } diff --git a/packages/cli/lib/commands/add.ts b/packages/cli/lib/commands/add.ts index 1c071bd12..cd2078ded 100644 --- a/packages/cli/lib/commands/add.ts +++ b/packages/cli/lib/commands/add.ts @@ -1,6 +1,6 @@ import { - AddTemplateArgs, GoogleAnalytics, PackageManager, - ProjectConfig, ProjectLibrary, Template, Util + AddTemplateArgs, App, BaseTemplateManager, GoogleAnalytics, PackageManager, + ProjectConfig, ProjectLibrary, TEMPLATE_MANAGER, Template, Util } from "@igniteui/cli-core"; import { PromptSession } from "./../PromptSession"; import { AddCommandType, PositionalArgs } from "./types"; @@ -9,7 +9,6 @@ import { ArgumentsCamelCase } from "yargs"; const command: AddCommandType = { command: "add [template] [name]", describe: "adds template by its ID", - templateManager: null, builder: { "template": { alias: "t", @@ -61,18 +60,19 @@ const command: AddCommandType = { Util.error("Showcases projects don't support the add command", "red"); return; } - const framework = command.templateManager.getFrameworkById(config.project.framework); + const templateManager = App.container.get(TEMPLATE_MANAGER); + const framework = templateManager.getFrameworkById(config.project.framework); if (!framework) { Util.error("Framework not supported", "red"); return; } - const frameworkLibrary = command.templateManager.getProjectLibrary( + const frameworkLibrary = templateManager.getProjectLibrary( config.project.framework, config.project.projectType ) as ProjectLibrary; if (!argv.template && !argv.name) { - const prompts = new PromptSession(command.templateManager); + const prompts = new PromptSession(); await prompts.chooseActionLoop(frameworkLibrary); return; } @@ -108,7 +108,7 @@ const command: AddCommandType = { skipRoute: argv.skipRoute }); await PackageManager.flushQueue(true); - await PackageManager.ensureIgniteUISource(config.packagesInstalled, command.templateManager); + await PackageManager.ensureIgniteUISource(config.packagesInstalled, templateManager); } }, async addTemplate(fileName: string, template: Template, options?: AddTemplateArgs): Promise { @@ -150,7 +150,7 @@ const command: AddCommandType = { } if (!fail && templatePaths.length) { template.registerInProject(process.cwd(), fileName, options || {}); - command.templateManager.updateProjectConfiguration(template); + App.container.get(TEMPLATE_MANAGER).updateProjectConfiguration(template); template.packages.forEach(x => PackageManager.queuePackage(x)); Util.log(`${Util.greenCheck()} View '${name}' added.`); return true; diff --git a/packages/cli/lib/commands/build.ts b/packages/cli/lib/commands/build.ts index f12d42919..b9dd0934e 100644 --- a/packages/cli/lib/commands/build.ts +++ b/packages/cli/lib/commands/build.ts @@ -1,4 +1,4 @@ -import { GoogleAnalytics, PackageManager, ProjectConfig, Util } from "@igniteui/cli-core"; +import { App, BaseTemplateManager, GoogleAnalytics, PackageManager, ProjectConfig, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core"; import * as fs from "fs"; import * as path from "path"; import { BuildCommandType, PositionalArgs } from "./types"; @@ -10,7 +10,6 @@ const command: BuildCommandType = { builder: (yargs) => { return yargs.usage(""); // do not show any usage instructions before the commands }, - templateManager: null, async handler(argv: ArgumentsCamelCase) { GoogleAnalytics.post({ @@ -21,7 +20,8 @@ const command: BuildCommandType = { }, async build() { Util.log("Build started."); - await PackageManager.ensureIgniteUISource(true, command.templateManager); + const templateManager = App.container.get(TEMPLATE_MANAGER); + await PackageManager.ensureIgniteUISource(true, templateManager); if (!ProjectConfig.hasLocalConfig()) { Util.error("Add command is supported only on existing project created with igniteui-cli", "red"); diff --git a/packages/cli/lib/commands/generate.ts b/packages/cli/lib/commands/generate.ts index ae66fb9e6..840bae6e2 100644 --- a/packages/cli/lib/commands/generate.ts +++ b/packages/cli/lib/commands/generate.ts @@ -1,4 +1,4 @@ -import { GoogleAnalytics, ProjectLibrary, Util } from "@igniteui/cli-core"; +import { App, BaseTemplateManager, GoogleAnalytics, ProjectLibrary, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core"; import * as path from "path"; import { default as config } from "./config"; import { CommandType, PositionalArgs } from "./types"; @@ -27,18 +27,19 @@ async function handler(argv: ArgumentsCamelCase) { return; } - if (command.templateManager.getFrameworkById(argv.framework) === undefined) { + const templateManager = App.container.get(TEMPLATE_MANAGER); + if (templateManager.getFrameworkById(argv.framework) === undefined) { return Util.error("Framework not supported", "red"); } let projectLib: ProjectLibrary; if (argv.type) { - projectLib = command.templateManager.getProjectLibrary(argv.framework, argv.type) as ProjectLibrary; + projectLib = templateManager.getProjectLibrary(argv.framework, argv.type) as ProjectLibrary; if (!projectLib) { return Util.error(`Project type '${argv.type}' not found in framework '${argv.framework}'`); } } else { - projectLib = command.templateManager.getProjectLibrary(argv.framework) as ProjectLibrary; + projectLib = templateManager.getProjectLibrary(argv.framework) as ProjectLibrary; argv.type = projectLib.projectType; } @@ -78,7 +79,6 @@ const command: CommandType = { aliases: ["g"], command: "generate", describe: "generates custom template", - templateManager: null, builder: yargs => { yargs .command({ diff --git a/packages/cli/lib/commands/list.ts b/packages/cli/lib/commands/list.ts index 8b8db2f84..2050a3eeb 100644 --- a/packages/cli/lib/commands/list.ts +++ b/packages/cli/lib/commands/list.ts @@ -1,4 +1,4 @@ -import { Config, Framework, GoogleAnalytics, ProjectConfig, ProjectLibrary, Util } from "@igniteui/cli-core"; +import { App, BaseTemplateManager, Config, Framework, GoogleAnalytics, ProjectConfig, ProjectLibrary, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core"; import { CommandType, PositionalArgs } from "./types"; import { ArgumentsCamelCase } from "yargs"; @@ -21,7 +21,6 @@ const command: CommandType = { type: "string" } }, - templateManager: null, handler(argv: ArgumentsCamelCase) { GoogleAnalytics.post({ t: "screenview", @@ -40,19 +39,20 @@ const command: CommandType = { const templatesByGroup = []; const controlGroups: string[] = []; - const framework: Framework = command.templateManager.getFrameworkById(argv.framework); + const templateManager = App.container.get(TEMPLATE_MANAGER); + const framework: Framework = templateManager.getFrameworkById(argv.framework); if (!framework) { return Util.error("Wrong framework provided", "red"); } let projectLib: ProjectLibrary; if (argv.type) { - projectLib = command.templateManager.getProjectLibrary(argv.framework, argv.type) as ProjectLibrary; + projectLib = templateManager.getProjectLibrary(argv.framework, argv.type) as ProjectLibrary; if (!projectLib) { return Util.error(`Project type '${argv.type}' not found in framework '${argv.framework}'`, "red"); } } else { - projectLib = command.templateManager.getProjectLibrary(argv.framework) as ProjectLibrary; + projectLib = templateManager.getProjectLibrary(argv.framework) as ProjectLibrary; } let maxIdLength = 0; diff --git a/packages/cli/lib/commands/new.ts b/packages/cli/lib/commands/new.ts index c29b1e261..463d6b973 100644 --- a/packages/cli/lib/commands/new.ts +++ b/packages/cli/lib/commands/new.ts @@ -1,8 +1,7 @@ -import { GoogleAnalytics, PackageManager, ProjectConfig, ProjectLibrary, Util } from "@igniteui/cli-core"; +import { App, BaseTemplateManager, GoogleAnalytics, PackageManager, ProjectConfig, ProjectLibrary, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core"; import * as path from "path"; import { PromptSession } from "./../PromptSession"; import { NewCommandType, PositionalArgs } from "./types"; -import { TemplateManager } from "../TemplateManager"; import { ArgumentsCamelCase, Choices } from "yargs"; // explicit typing because `type: "string"` will be inferred as `type: string` which yargs will not like @@ -66,8 +65,9 @@ const command: NewCommandType = { if (ProjectConfig.hasLocalConfig()) { return Util.error("There is already an existing project.", "red"); } + const templateManager = App.container.get(TEMPLATE_MANAGER); if (!argv.name) { - const prompts = new PromptSession(command.templateManager || new TemplateManager()); + const prompts = new PromptSession(); await prompts.start(); return; } @@ -87,20 +87,20 @@ const command: NewCommandType = { Util.error(`Folder "${argv.name}" already exists!`, "red"); return; } - if (command.templateManager?.getFrameworkById(argv.framework) === undefined) { + if (templateManager?.getFrameworkById(argv.framework) === undefined) { return Util.error("Framework not supported", "red"); } let projectLib: ProjectLibrary; if (argv.type) { - projectLib = command.templateManager?.getProjectLibrary(argv.framework, argv.type) as ProjectLibrary; + projectLib = templateManager?.getProjectLibrary(argv.framework, argv.type) as ProjectLibrary; if (!projectLib) { return Util.error(`Project type "${argv.type}" not found in framework '${argv.framework}'`); } } else { - projectLib = command.templateManager?.getProjectLibrary(argv.framework) as ProjectLibrary; + projectLib = templateManager?.getProjectLibrary(argv.framework) as ProjectLibrary; } - if (command.templateManager?.getFrameworkById(argv.framework).id === "angular" && projectLib.projectType === "igx-ts") { + if (templateManager?.getFrameworkById(argv.framework).id === "angular" && projectLib.projectType === "igx-ts") { Util.warn("Psst! Did you know you can use our schematics package with Angular CLI to create and modify your projects?", "yellow"); Util.warn("Read more at: https://www.infragistics.com/products/ignite-ui-angular/angular/components/general/cli-overview", "yellow"); } diff --git a/packages/cli/lib/commands/start.ts b/packages/cli/lib/commands/start.ts index 9607a4a45..2150a9dba 100644 --- a/packages/cli/lib/commands/start.ts +++ b/packages/cli/lib/commands/start.ts @@ -22,7 +22,6 @@ const execSyncNpmStart = (port: number, options: ExecSyncOptions): void => { const command: StartCommandType = { command: "start", describe: "starts the project", - templateManager: null, builder: (yargs) => { return yargs .option("port", { diff --git a/packages/cli/lib/commands/types.ts b/packages/cli/lib/commands/types.ts index cbf6a3fe5..73eb767cb 100644 --- a/packages/cli/lib/commands/types.ts +++ b/packages/cli/lib/commands/types.ts @@ -1,5 +1,4 @@ import { ArgumentsCamelCase, CommandModule } from "yargs"; -import { TemplateManager } from "../TemplateManager"; import { AddTemplateArgs, Template } from "@igniteui/cli-core"; export const ADD_COMMAND_NAME = "add"; @@ -71,8 +70,6 @@ export interface PositionalArgs { } export interface CommandType extends CommandModule<{}, any> { - templateManager?: TemplateManager; - /** Handler function that will be called by yargs after the command line has been parsed. */ handler(/** do not use `this` in handler */this: void, argv: ArgumentsCamelCase); } diff --git a/packages/cli/lib/commands/upgrade.ts b/packages/cli/lib/commands/upgrade.ts index e1166156e..0700e34b4 100644 --- a/packages/cli/lib/commands/upgrade.ts +++ b/packages/cli/lib/commands/upgrade.ts @@ -1,11 +1,10 @@ -import { GoogleAnalytics, ProjectConfig, type ProjectTemplate, Util } from "@igniteui/cli-core"; +import { App, BaseTemplateManager, GoogleAnalytics, ProjectConfig, TEMPLATE_MANAGER, type ProjectTemplate, Util } from "@igniteui/cli-core"; import { PositionalArgs, UpgradeCommandType } from "./types"; import { ArgumentsCamelCase } from "yargs"; const command: UpgradeCommandType = { command: "upgrade-packages", describe: "upgrades Ignite UI Packages", - templateManager: null, builder: (yargs) => { return yargs .option("skip-install", { @@ -37,7 +36,8 @@ const command: UpgradeCommandType = { case "react": case "webcomponents": if (projectType === "igx-ts" || projectType === "igr-ts" || projectType === "igc-ts") { - const projectLibrary = command.templateManager.getProjectLibrary(framework, projectType); + const templateManager = App.container.get(TEMPLATE_MANAGER); + const projectLibrary = templateManager.getProjectLibrary(framework, projectType); let project: ProjectTemplate; if (!config.project.projectTemplate || !projectLibrary.hasProject(config.project.projectTemplate)) { // in case project template is missing from the config we provide backward. diff --git a/packages/core/prompt/BasePromptSession.ts b/packages/core/prompt/BasePromptSession.ts index 0c1de0a0c..c239df603 100644 --- a/packages/core/prompt/BasePromptSession.ts +++ b/packages/core/prompt/BasePromptSession.ts @@ -6,13 +6,16 @@ import { FrameworkId, ProjectLibrary, ProjectTemplate, Template } from "../types"; import { App, ChoiceItem, GoogleAnalytics, ProjectConfig, Util } from "../util"; +import { TEMPLATE_MANAGER } from "../util/GlobalConstants"; import { Task, TaskRunner, WIZARD_BACK_OPTION } from "./TaskRunner"; import { InquirerWrapper } from "./InquirerWrapper"; export abstract class BasePromptSession { protected config: Config; - constructor(protected templateManager: BaseTemplateManager) { } + protected get templateManager(): BaseTemplateManager { + return App.container.get(TEMPLATE_MANAGER); + } /** * Start questions session for project creation diff --git a/packages/ng-schematics/src/component/index.ts b/packages/ng-schematics/src/component/index.ts index 1f550df0c..44d517a00 100644 --- a/packages/ng-schematics/src/component/index.ts +++ b/packages/ng-schematics/src/component/index.ts @@ -5,7 +5,7 @@ import { } from "@angular-devkit/schematics"; import { NodePackageInstallTask, RunSchematicTask } from "@angular-devkit/schematics/tasks"; import { IgniteUIForAngularTemplate } from "@igniteui/angular-templates"; -import { App, FS_TYPE_TOKEN, FsTypes, GoogleAnalytics, ProjectConfig, Util } from "@igniteui/cli-core"; +import { App, FS_TYPE_TOKEN, FsTypes, GoogleAnalytics, ProjectConfig, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core"; import { SchematicsPromptSession } from "../prompt/SchematicsPromptSession"; import { SchematicsTemplateManager } from "../SchematicsTemplateManager"; import { setVirtual } from "../utils/NgFileSystem"; @@ -75,6 +75,7 @@ export function component(options: ComponentOptions): Rule { }); const addedComponents: TemplateOptions[] = []; const templateManager = new SchematicsTemplateManager(); + App.container.set(TEMPLATE_MANAGER, templateManager); const projLib = templateManager.getProjectLibrary("angular", "igx-ts"); /** * MDNT @@ -90,7 +91,7 @@ export function component(options: ComponentOptions): Rule { void properties; // cache templates for use inside chooseActionLoop let prompt: SchematicsPromptSession; if (!options.template || !options.name) { - prompt = new SchematicsPromptSession(templateManager); + prompt = new SchematicsPromptSession(); prompt.setContext(context, tree, options.name as string); setVirtual(tree); await prompt.chooseActionLoop(projLib); diff --git a/packages/ng-schematics/src/ng-new/index.ts b/packages/ng-schematics/src/ng-new/index.ts index bb4deb766..e9a728a21 100644 --- a/packages/ng-schematics/src/ng-new/index.ts +++ b/packages/ng-schematics/src/ng-new/index.ts @@ -12,7 +12,7 @@ import { TaskId, Tree } from "@angular-devkit/schematics"; import { NodePackageInstallTask, RepositoryInitializerTask, RunSchematicTask } from "@angular-devkit/schematics/tasks"; -import { App, GoogleAnalytics, ProjectLibrary, ProjectTemplate, Util } from "@igniteui/cli-core"; +import { App, GoogleAnalytics, ProjectLibrary, ProjectTemplate, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core"; import { defer, Observable } from "rxjs"; import { NewProjectOptions } from "../app-projects/schema"; import { SchematicsPromptSession } from "../prompt/SchematicsPromptSession"; @@ -36,7 +36,8 @@ export function newProject(options: OptionsSchema): Rule { let projLibrary: ProjectLibrary; let projectOptions: NewProjectOptions; const templateManager = new SchematicsTemplateManager(); - const prompt = new SchematicsPromptSession(templateManager); + App.container.set(TEMPLATE_MANAGER, templateManager); + const prompt = new SchematicsPromptSession(); // TODO: const defaultProjName = "IG Project"; diff --git a/packages/ng-schematics/src/prompt/SchematicsPromptSession.ts b/packages/ng-schematics/src/prompt/SchematicsPromptSession.ts index 8babc54f7..825270149 100644 --- a/packages/ng-schematics/src/prompt/SchematicsPromptSession.ts +++ b/packages/ng-schematics/src/prompt/SchematicsPromptSession.ts @@ -1,7 +1,7 @@ import { SchematicContext, Tree } from "@angular-devkit/schematics"; import { IgniteUIForAngularTemplate } from "@igniteui/angular-templates"; import { - BasePromptSession, BaseTemplateManager, Framework, + BasePromptSession, Framework, IUserInputOptions, ProjectConfig, ProjectLibrary, ProjectTemplate, PromptTaskContext, Task } from "@igniteui/cli-core"; import { of } from "rxjs"; @@ -14,9 +14,7 @@ export class SchematicsPromptSession extends BasePromptSession { public projectName: string; public userAnswers: Map; - constructor( - templateManager: BaseTemplateManager) { - super(templateManager); + constructor() { this.config = ProjectConfig.getConfig(); } From 967d973d9521f28c5956485d73abe861dc432967 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Apr 2026 18:08:55 +0000 Subject: [PATCH 3/3] test: update all tests to use App container for templateManager Replace all command.templateManager assignments and PromptSession(templateManager) constructor calls in tests with App.container.set(TEMPLATE_MANAGER, ...) and App.container.get(TEMPLATE_MANAGER) patterns. Fix container spy interactions where spyOn(App.container, 'get') needs to handle both TEMPLATE_MANAGER and other tokens via callFake. Agent-Logs-Url: https://github.com/IgniteUI/igniteui-cli/sessions/34deef7a-062f-44fe-86f9-7eac03eabc8f Co-authored-by: damyanpetev <3198469+damyanpetev@users.noreply.github.com> --- packages/cli/lib/commands/mcp.ts | 1 - packages/core/packages/PackageManager.ts | 4 +- .../src/prompt/SchematicsPromptSession.ts | 1 + spec/unit/PromptSession-spec.ts | 41 ++++++---- spec/unit/add-spec.ts | 29 ++++---- spec/unit/generate-spec.ts | 22 +++--- spec/unit/list-spec.ts | 26 +++---- spec/unit/new-spec.ts | 74 ++++++++++--------- spec/unit/upgrade-spec.ts | 6 +- 9 files changed, 110 insertions(+), 94 deletions(-) diff --git a/packages/cli/lib/commands/mcp.ts b/packages/cli/lib/commands/mcp.ts index 6b18fbdbb..3832f32c3 100644 --- a/packages/cli/lib/commands/mcp.ts +++ b/packages/cli/lib/commands/mcp.ts @@ -7,7 +7,6 @@ import { ArgumentsCamelCase } from "yargs"; const command: CommandType = { command: "mcp", describe: "Starts the Ignite UI MCP server for AI assistant integration", - templateManager: null, builder: (yargs) => { return yargs .option("remote", { diff --git a/packages/core/packages/PackageManager.ts b/packages/core/packages/PackageManager.ts index 183bcbd87..8af24a028 100644 --- a/packages/core/packages/PackageManager.ts +++ b/packages/core/packages/PackageManager.ts @@ -1,6 +1,6 @@ import { exec } from "child_process"; import * as path from "path"; -import { TemplateManager } from "../../cli/lib/TemplateManager"; +import { BaseTemplateManager } from "../templates"; import { Config, FS_TOKEN, IFileSystem, ProjectTemplate } from "../types"; import { App, ProjectConfig, Util } from "../util"; @@ -31,7 +31,7 @@ export class PackageManager { */ public static async ensureIgniteUISource( installNow: boolean = false, - templateManager: TemplateManager, + templateManager: BaseTemplateManager, verbose: boolean = false ) { const config = ProjectConfig.localConfig(); diff --git a/packages/ng-schematics/src/prompt/SchematicsPromptSession.ts b/packages/ng-schematics/src/prompt/SchematicsPromptSession.ts index 825270149..be7e367d7 100644 --- a/packages/ng-schematics/src/prompt/SchematicsPromptSession.ts +++ b/packages/ng-schematics/src/prompt/SchematicsPromptSession.ts @@ -15,6 +15,7 @@ export class SchematicsPromptSession extends BasePromptSession { public userAnswers: Map; constructor() { + super(); this.config = ProjectConfig.getConfig(); } diff --git a/spec/unit/PromptSession-spec.ts b/spec/unit/PromptSession-spec.ts index b3d0fcabf..fecd8b486 100644 --- a/spec/unit/PromptSession-spec.ts +++ b/spec/unit/PromptSession-spec.ts @@ -1,5 +1,5 @@ import { App, BaseTemplate, Config, ControlExtraConfigType, GoogleAnalytics, InquirerWrapper, PackageManager, ProjectConfig, - ProjectLibrary, ProjectTemplate, Template, Util } from "@igniteui/cli-core"; + ProjectLibrary, ProjectTemplate, Template, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core"; import * as path from "path"; import { default as add } from "../../packages/cli/lib/commands/add"; import * as aiConfig from "../../packages/cli/lib/commands/ai-config"; @@ -160,7 +160,8 @@ describe("Unit - PromptSession", () => { getProjectLibraryByName: mockProjectLibrary }); mockTemplate.templatePaths = ["test"]; - const mockSession = new PromptSession(mockTemplate); + App.container.set(TEMPLATE_MANAGER, mockTemplate); + const mockSession = new PromptSession(); const mockQuestion = { type: "list", name: "theme", @@ -210,7 +211,8 @@ describe("Unit - PromptSession", () => { const mockTemplate = jasmine.createSpyObj("mockTemplate", { getProjectLibrary: mockLibrary }); - const mockSession = new PromptSession(mockTemplate); + App.container.set(TEMPLATE_MANAGER, mockTemplate); + const mockSession = new PromptSession(); spyOn(ProjectConfig, "hasLocalConfig").and.returnValue(true); const mockProjectConfig = { project: { @@ -264,16 +266,18 @@ describe("Unit - PromptSession", () => { getProjectLibraryByName: mockProjectLibrary }); mockTemplate.templatePaths = ["test"]; - const mockSession = new PromptSession(mockTemplate); + App.container.set(TEMPLATE_MANAGER, mockTemplate); + const mockSession = new PromptSession(); spyOn(Util, "greenCheck").and.returnValue(""); spyOn(Util, "log"); spyOn(Util, "directoryExists").and.returnValue(false); spyOn(Util, "fileExists").and.returnValue(false); + const mockTm = App.container.get(TEMPLATE_MANAGER); const mockFileSystem = { fileExists: jasmine.createSpy().and.returnValue(false), readFile: jasmine.createSpy().and.returnValue(JSON.stringify({ key: "value" })) }; - spyOn(App.container, 'get').and.returnValue(mockFileSystem); + spyOn(App.container, 'get').and.callFake((token: any) => token === TEMPLATE_MANAGER ? mockTm : mockFileSystem as any); spyOn(Util, "isAlphanumericExt").and.returnValue(true); spyOn(Util, "gitInit"); spyOn(InquirerWrapper, "input").and.returnValues( @@ -341,7 +345,8 @@ describe("Unit - PromptSession", () => { getProjectLibraryByName: mockProjectLibrary }); mockTemplate.templatePaths = ["test"]; - const mockSession = new PromptSession(mockTemplate); + App.container.set(TEMPLATE_MANAGER, mockTemplate); + const mockSession = new PromptSession(); const mockQuestion = { type: "list", name: "theme", @@ -463,7 +468,8 @@ describe("Unit - PromptSession", () => { getProjectLibraryNames: projectLibraries, getProjectLibraryByName: mockProjectLibrary }); - const mockSession = new PromptSession(mockTemplate); + App.container.set(TEMPLATE_MANAGER, mockTemplate); + const mockSession = new PromptSession(); const mockProjectConfig = { project: { defaultPort: 4200 @@ -540,7 +546,8 @@ describe("Unit - PromptSession", () => { getProjectLibrary: mockProjectLibrary, getProjectLibraryByName: mockProjectLibrary }); - const mockSession = new PromptSession(mockTemplate); + App.container.set(TEMPLATE_MANAGER, mockTemplate); + const mockSession = new PromptSession(); const mockProjectConfig = { packagesInstalled: true, project: { @@ -660,7 +667,8 @@ describe("Unit - PromptSession", () => { getProjectLibraryNames: projectLibraries, getProjectLibraryByName: mockProjectLibrary }); - const mockSession = new PromptSession(mockTemplate); + App.container.set(TEMPLATE_MANAGER, mockTemplate); + const mockSession = new PromptSession(); const mockProjectConfig = { project: { defaultPort: 4200 @@ -745,7 +753,8 @@ describe("Unit - PromptSession", () => { } as unknown as Config; spyOn(ProjectConfig, "localConfig").and.returnValue(mockProjectConfig); spyOn(ProjectConfig, "hasLocalConfig").and.returnValue(true); - const mockSession = new PromptSession(mockTemplate); + App.container.set(TEMPLATE_MANAGER, mockTemplate); + const mockSession = new PromptSession(); spyOn(mockSession, "chooseActionLoop").and.callThrough(); spyOn(InquirerWrapper, "select").and.returnValues( Promise.resolve("Complete & Run"), @@ -787,7 +796,8 @@ describe("Unit - PromptSession", () => { spyOn(ProjectConfig, "localConfig").and.returnValue(mockProjectConfig); spyOn(ProjectConfig, "setConfig"); - const mockSession = new PromptSession({} as any); + App.container.set(TEMPLATE_MANAGER, {} as any); + const mockSession = new PromptSession(); spyOn(mockSession as any, "generateActionChoices").and.returnValues([]); spyOn(mockSession as any, "getUserInput").and.returnValues( Promise.resolve("Complete & Run"), @@ -810,7 +820,8 @@ describe("Unit - PromptSession", () => { } } as unknown as Config; spyOn(ProjectConfig, "getConfig").and.returnValue(mockProjectConfig); - const mockSession = new PromptSession(new TemplateManager()); + App.container.set(TEMPLATE_MANAGER, new TemplateManager()); + const mockSession = new PromptSession(); spyOn(Util, "isAlphanumericExt").and.callThrough(); spyOn(Util, "gitInit"); spyOn(Util, "log"); @@ -847,7 +858,8 @@ describe("Unit - PromptSession", () => { } } as unknown as Config; spyOn(ProjectConfig, "getConfig").and.returnValue(mockProjectConfig); - const mockSession = new PromptSession(new TemplateManager()); + App.container.set(TEMPLATE_MANAGER, new TemplateManager()); + const mockSession = new PromptSession(); spyOn(Util, "isAlphanumericExt").and.callThrough(); spyOn(Util, "gitInit"); spyOn(Util, "log"); @@ -875,7 +887,8 @@ describe("Unit - PromptSession", () => { } as unknown as ProjectLibrary; const mockTemplate = jasmine.createSpyObj("mockTemplate", ["getProjectLibrary"]); - const mockSession = new PromptSession(mockTemplate); + App.container.set(TEMPLATE_MANAGER, mockTemplate); + const mockSession = new PromptSession(); spyOn(InquirerWrapper, "select").and.returnValue(Promise.resolve("empty")); diff --git a/spec/unit/add-spec.ts b/spec/unit/add-spec.ts index feccff8d2..61da2e5ec 100644 --- a/spec/unit/add-spec.ts +++ b/spec/unit/add-spec.ts @@ -1,6 +1,6 @@ import { IgniteUIForAngularTemplate, AngularTypeScriptFileUpdate } from "@igniteui/angular-templates"; import { - App, BaseTemplate, Config, GoogleAnalytics, PackageManager, ProjectConfig, ProjectLibrary, ProjectTemplate, Template, TemplateDelimiters, TypeScriptUtils, Util + App, BaseTemplate, Config, GoogleAnalytics, PackageManager, ProjectConfig, ProjectLibrary, ProjectTemplate, Template, TEMPLATE_MANAGER, TemplateDelimiters, TypeScriptUtils, Util } from "@igniteui/cli-core"; import * as path from "path"; import * as ts from "typescript"; @@ -116,10 +116,10 @@ describe("Unit - Add command", () => { const mockTemplate = createMockTemplate(mockBaseTemplate); const mockProjLib = createMockLibrary(mockTemplate, mockProjectTemplate); - addCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: mockProjLib - }); + })); const promptSession = PromptSession.prototype; spyOn(promptSession, "chooseActionLoop"); @@ -196,25 +196,25 @@ describe("Unit - Add command", () => { const mockTemplate = jasmine.createSpyObj("Template", ["generateConfig", "registerInProject"]); mockTemplate.templatePaths = ["test"]; mockTemplate.packages = ["tslib" , "test-pack"]; - addCmd.templateManager = jasmine.createSpyObj("TemplateManager", ["updateProjectConfiguration"]); + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", ["updateProjectConfiguration"])); await addCmd.addTemplate("template with packages", mockTemplate); expect(mockTemplate.generateConfig).toHaveBeenCalled(); expect(mockTemplate.registerInProject).toHaveBeenCalled(); expect(Util.processTemplates).toHaveBeenCalledTimes(1); - expect(addCmd.templateManager.updateProjectConfiguration).toHaveBeenCalled(); + expect(App.container.get(TEMPLATE_MANAGER).updateProjectConfiguration).toHaveBeenCalled(); expect(PackageManager.queuePackage).toHaveBeenCalledTimes(2); expect(PackageManager.queuePackage).toHaveBeenCalledWith("tslib"); expect(PackageManager.queuePackage).toHaveBeenCalledWith("test-pack"); spyOn(ProjectConfig, "hasLocalConfig").and.returnValue(true); - addCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: mockTemplate, getProjectLibrary: jasmine.createSpyObj("ProjectLibrary", { getTemplateById: mockTemplate, hasTemplate: true }) - }); + })); spyOn(addCmd, "addTemplate"); spyOn(PackageManager, "flushQueue").and.returnValue(Promise.resolve()); @@ -251,23 +251,24 @@ describe("Unit - Add command", () => { const mockLibrary = jasmine.createSpyObj("frameworkLibrary", ["hasTemplate", "getTemplateById"]); mockLibrary.hasTemplate.and.returnValue(true); mockLibrary.getTemplateById.and.returnValue(mockTemplate); - addCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: mockLibrary, updateProjectConfiguration: () => {} - }); + })); spyOn(ProjectConfig, "getConfig").and.returnValue(mockProjectConfig); spyOn(ProjectConfig, "hasLocalConfig").and.returnValue(true); spyOn(addCmd, "addTemplate").and.callThrough(); spyOn(PackageManager, "flushQueue").and.returnValue(Promise.resolve()); spyOn(PackageManager, "ensureIgniteUISource"); spyOn(Util, "directoryExists").and.returnValue(true); + const mockTm = App.container.get(TEMPLATE_MANAGER); const mockVirtFs = { fileExists: (file: string): boolean => { return false; } }; - spyOn(App.container, "get").and.returnValue(mockVirtFs); + spyOn(App.container, "get").and.callFake((token: any) => token === TEMPLATE_MANAGER ? mockTm : mockVirtFs as any); spyOn(mockVirtFs, "fileExists").and.callFake(file => { if (file === "src/app/app-routing-module.ts") { return true; @@ -309,7 +310,7 @@ describe("Unit - Add command", () => { true ); expect(finalizeSpy).toHaveBeenCalledTimes(2); - expect(addCmd.templateManager.updateProjectConfiguration).toHaveBeenCalledTimes(1); + expect(App.container.get(TEMPLATE_MANAGER).updateProjectConfiguration).toHaveBeenCalledTimes(1); }); it("Should properly accept skip-route args when passed", async () => { @@ -330,11 +331,11 @@ describe("Unit - Add command", () => { const mockLibrary = jasmine.createSpyObj("frameworkLibrary", { getTemplateById: mockTemplate, hasTemplate: true }); - addCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: mockLibrary, updateProjectConfiguration: () => {} - }); + })); const directoryPath = path.join("My/Example/Path"); spyOn(Util, "processTemplates").and.returnValue(Promise.resolve(true)); @@ -365,7 +366,7 @@ describe("Unit - Add command", () => { directoryPath, "test-file-name", jasmine.objectContaining({ skipRoute: true }) ); - expect(addCmd.templateManager.updateProjectConfiguration).toHaveBeenCalledWith(mockTemplate); + expect(App.container.get(TEMPLATE_MANAGER).updateProjectConfiguration).toHaveBeenCalledWith(mockTemplate); }); it("Should not add component and should log error if wrong path is passed to module", async () => { diff --git a/spec/unit/generate-spec.ts b/spec/unit/generate-spec.ts index 20ba9808c..2679a3c6a 100644 --- a/spec/unit/generate-spec.ts +++ b/spec/unit/generate-spec.ts @@ -1,4 +1,4 @@ -import { GoogleAnalytics, Util } from "@igniteui/cli-core"; +import { App, GoogleAnalytics, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core"; import os from "os"; import * as fs from "fs"; import * as path from "path"; @@ -43,10 +43,10 @@ describe("Unit - Generate command", () => { const projectLib = { generateTemplateFolderPath: "somePath" }; - generateCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: projectLib - }); + })); spyOn(config, "addHandler").and.stub(); @@ -116,9 +116,9 @@ describe("Unit - Generate command", () => { spyOn(Util, "isAlphanumericExt").and.returnValue(true); spyOn(Util, "directoryExists").and.returnValue(false); - generateCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: undefined - }); + })); await generateCmd.handler({ name: "custom-template", framework: "wrongFramework", type: "js", _: ["generate"], $0: "generate" }); @@ -132,10 +132,10 @@ describe("Unit - Generate command", () => { spyOn(Util, "isAlphanumericExt").and.returnValue(true); spyOn(Util, "directoryExists").and.returnValue(false); - generateCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: undefined - }); + })); await generateCmd.handler({ name: "custom-template", framework: "jquery", type: "wrongType", _: ["generate"], $0: "generate" }); @@ -150,10 +150,10 @@ describe("Unit - Generate command", () => { spyOn(Util, "directoryExists").and.returnValue(false); spyOn(Util, "processTemplates").and.returnValue(new Promise((res, rej) => { res(false); })); - generateCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: {} - }); + })); await generateCmd.handler({ name: "custom-template", framework: "jquery", type: "js", _: ["generate"], $0: "generate" }); @@ -171,10 +171,10 @@ describe("Unit - Generate command", () => { const projectLib = { generateTemplateFolderPath: "somePath" }; - generateCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: projectLib - }); + })); spyOn(config, "addHandler").and.stub(); diff --git a/spec/unit/list-spec.ts b/spec/unit/list-spec.ts index 7403e2823..d1519f233 100644 --- a/spec/unit/list-spec.ts +++ b/spec/unit/list-spec.ts @@ -1,4 +1,4 @@ -import { Config, GoogleAnalytics, ProjectConfig, Util } from "@igniteui/cli-core"; +import { App, Config, GoogleAnalytics, ProjectConfig, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core"; import { default as listCmd } from "../../packages/cli/lib/commands/list"; describe("Unit - List command", () => { @@ -29,10 +29,10 @@ describe("Unit - List command", () => { templates: mockTemplates }; - listCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: framework, getProjectLibrary: projectLib - }); + })); await listCmd.handler({ framework: "jQuery", type: "js", _: ["list"], $0: "list" }); @@ -66,10 +66,10 @@ describe("Unit - List command", () => { templates: mockTemplates }; - listCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: framework, getProjectLibrary: projectLib - }); + })); await listCmd.handler({ _: ["list"], $0: "list" }); expect(Util.error).toHaveBeenCalledTimes(0); @@ -88,9 +88,9 @@ describe("Unit - List command", () => { }); it("Should log error if called with wrong framework", async () => { - listCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: undefined - }); + })); await listCmd.handler({ framework: "wrongOne", type: "js", _: ["list"], $0: "list" }); @@ -100,9 +100,9 @@ describe("Unit - List command", () => { it("Should log error if called without framework outside a project", async () => { spyOn(ProjectConfig, "hasLocalConfig").and.returnValue(false); - listCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: undefined - }); + })); await listCmd.handler({ _: ["list"], $0: "list" }); @@ -111,10 +111,10 @@ describe("Unit - List command", () => { }); it("Should log error if called with wrong type", async () => { - listCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: undefined - }); + })); await listCmd.handler({ framework: "angular", type: "wrongType", _: ["list"], $0: "list" }); @@ -129,10 +129,10 @@ describe("Unit - List command", () => { templates: mockTemplates }; - listCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: framework, getProjectLibrary: projectLib - }); + })); await listCmd.handler({ framework: "react", _: ["list"], $0: "list" }); diff --git a/spec/unit/new-spec.ts b/spec/unit/new-spec.ts index 0c9efc7cf..3bedc2308 100644 --- a/spec/unit/new-spec.ts +++ b/spec/unit/new-spec.ts @@ -1,4 +1,4 @@ -import { App, BaseTemplate, Config, GoogleAnalytics, PackageManager, ProjectConfig, ProjectTemplate, Util } from "@igniteui/cli-core"; +import { App, BaseTemplate, Config, GoogleAnalytics, PackageManager, ProjectConfig, ProjectTemplate, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core"; import * as path from "path"; import { default as newCmd } from "../../packages/cli/lib/commands/new"; import { PromptSession } from "../../packages/cli/lib/PromptSession"; @@ -76,29 +76,29 @@ describe("Unit - New command", () => { it("Logs error for wrong framework", async () => { spyOn(Util, "error"); //spied getFrameworkById won't return anything, i.e. not found - newCmd.templateManager = jasmine.createSpyObj("TemplateManager", ["getFrameworkById", "getProjectLibrary"]); + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", ["getFrameworkById", "getProjectLibrary"])); await newCmd.handler({ name: "Test", framework: "jq", _: ["new"], $0: "new" }); - expect(newCmd.templateManager.getFrameworkById).toHaveBeenCalledWith("jq"); + expect(App.container.get(TEMPLATE_MANAGER).getFrameworkById).toHaveBeenCalledWith("jq"); expect(Util.error).toHaveBeenCalledWith("Framework not supported", "red"); //no further attempts to get project: - expect(newCmd.templateManager.getProjectLibrary).toHaveBeenCalledTimes(0); + expect(App.container.get(TEMPLATE_MANAGER).getProjectLibrary).toHaveBeenCalledTimes(0); expect(Util.log).toHaveBeenCalledTimes(0); }); it("Logs error for wrong project type", async () => { spyOn(Util, "error"); - newCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, // return nothing, i.e. not found getProjectLibrary: undefined - }); + })); await newCmd.handler({ name: "Test", framework: "jq", type: "js", _: ["new"], $0: "new"}); - expect(newCmd.templateManager.getFrameworkById).toHaveBeenCalledWith("jq"); - expect(newCmd.templateManager.getProjectLibrary).toHaveBeenCalledWith("jq", "js"); + expect(App.container.get(TEMPLATE_MANAGER).getFrameworkById).toHaveBeenCalledWith("jq"); + expect(App.container.get(TEMPLATE_MANAGER).getProjectLibrary).toHaveBeenCalledWith("jq", "js"); expect(Util.error).toHaveBeenCalledWith(`Project type "js" not found in framework 'jq'`); //no further attempts to get project: expect(Util.log).toHaveBeenCalledTimes(0); @@ -113,15 +113,15 @@ describe("Unit - New command", () => { projectType: "type", themes: ["ig"] }; - newCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: mockProjLib - }); + })); spyOn(mockProjLib, "getProject"); await newCmd.handler({ name: "Test", framework: "jq", type: "js", theme: "mega-custom", _: ["new"], $0: "new" }); - expect(newCmd.templateManager.getFrameworkById).toHaveBeenCalledWith("jq"); - expect(newCmd.templateManager.getProjectLibrary).toHaveBeenCalledWith("jq", "js"); + expect(App.container.get(TEMPLATE_MANAGER).getFrameworkById).toHaveBeenCalledWith("jq"); + expect(App.container.get(TEMPLATE_MANAGER).getProjectLibrary).toHaveBeenCalledWith("jq", "js"); expect(Util.error).toHaveBeenCalledWith("Theme not supported"); //no further attempts to get project: expect(Util.log).toHaveBeenCalledTimes(0); @@ -132,10 +132,10 @@ describe("Unit - New command", () => { spyOn(ProjectConfig, "getConfig").and.returnValue(null); const mockProjLib = {}; - newCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: mockProjLib - }); + })); const promptSession = PromptSession.prototype; spyOn(promptSession, "start"); @@ -154,15 +154,15 @@ describe("Unit - New command", () => { projectType: "type", themes: ["ig"] }; - newCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: mockProjLib - }); + })); spyOn(mockProjLib, "getProject"); await newCmd.handler({ name: "Test", framework: "jq", type: "type", _: ["new"], $0: "new" }); - expect(newCmd.templateManager.getFrameworkById).toHaveBeenCalledWith("jq"); - expect(newCmd.templateManager.getProjectLibrary).toHaveBeenCalledWith("jq", "type"); + expect(App.container.get(TEMPLATE_MANAGER).getFrameworkById).toHaveBeenCalledWith("jq"); + expect(App.container.get(TEMPLATE_MANAGER).getProjectLibrary).toHaveBeenCalledWith("jq", "type"); expect(Util.log).toHaveBeenCalledWith("Project Name: Test, framework jq, type type, theme ig"); expect(mockProjLib.getProject).toHaveBeenCalled(); expect(Util.error).toHaveBeenCalledWith("Project template not found"); @@ -187,10 +187,10 @@ describe("Unit - New command", () => { projectType: "js", themes: ["ig"] }; - newCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: mockProjLib - }); + })); //spyOn(newCmd.template, "getFrameworkById").and.returnValue({}); //spyOn(newCmd.template, "getProjectLibrary").and.returnValue(mockProjLib); @@ -199,16 +199,17 @@ describe("Unit - New command", () => { spyOn(Util, "directoryExists").and.returnValue(false); spyOn(Util, "fileExists").and.returnValue(false); + const mockTm = App.container.get(TEMPLATE_MANAGER); const mockFileSystem = { fileExists: jasmine.createSpy().and.returnValue(false), readFile: jasmine.createSpy().and.returnValue(JSON.stringify({ key: "value" })) }; - spyOn(App.container, 'get').and.returnValue(mockFileSystem); + spyOn(App.container, 'get').and.callFake((token: any) => token === TEMPLATE_MANAGER ? mockTm : mockFileSystem as any); await newCmd.handler({ name: "Test", framework: "jq", theme: "ig", _: ["new"], $0: "new" }); - expect(newCmd.templateManager.getFrameworkById).toHaveBeenCalledWith("jq"); - expect(newCmd.templateManager.getProjectLibrary).toHaveBeenCalledWith("jq"); + expect(App.container.get(TEMPLATE_MANAGER).getFrameworkById).toHaveBeenCalledWith("jq"); + expect(App.container.get(TEMPLATE_MANAGER).getProjectLibrary).toHaveBeenCalledWith("jq"); expect(Util.log).toHaveBeenCalledWith("Project Name: Test, framework jq, type js, theme ig"); expect(mockProjectTemplate.generateConfig).toHaveBeenCalledWith("Test", "ig"); expect(Util.processTemplates) @@ -235,26 +236,27 @@ describe("Unit - New command", () => { projectType: "type", themes: ["ig"] }; - newCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: mockProjLib - }); + })); spyOn(process, "cwd").and.returnValue("Mock dir"); spyOn(Util, "processTemplates").and.returnValue(Promise.resolve(true)); spyOn(Util, "directoryExists").and.returnValue(false); spyOn(Util, "fileExists").and.returnValue(false); + const mockTm = App.container.get(TEMPLATE_MANAGER); const mockFileSystem = { fileExists: jasmine.createSpy().and.returnValue(false), readFile: jasmine.createSpy().and.returnValue(JSON.stringify({ key: "value" })) }; - spyOn(App.container, 'get').and.returnValue(mockFileSystem); + spyOn(App.container, 'get').and.callFake((token: any) => token === TEMPLATE_MANAGER ? mockTm : mockFileSystem as any); await newCmd.handler({ name: "Test", framework: "jq", type: "type", theme: "ig", _: ["new"], $0: "new" }); - expect(newCmd.templateManager.getFrameworkById).toHaveBeenCalledWith("jq"); - expect(newCmd.templateManager.getProjectLibrary).toHaveBeenCalledWith("jq", "type"); + expect(App.container.get(TEMPLATE_MANAGER).getFrameworkById).toHaveBeenCalledWith("jq"); + expect(App.container.get(TEMPLATE_MANAGER).getProjectLibrary).toHaveBeenCalledWith("jq", "type"); expect(mockTemplate.generateConfig).toHaveBeenCalledWith("Test", "ig"); expect(Util.processTemplates) .toHaveBeenCalledWith("test", path.join("Mock dir", "Test"), mockConfig, mockBaseTemplate.delimiters, false); @@ -280,10 +282,10 @@ describe("Unit - New command", () => { projectType: "type", themes: ["ig"] }; - newCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: mockProjLib - }); + })); await newCmd.handler({ name: projectName, framework: "jq", _: ["new"], $0: "new" }); @@ -311,10 +313,10 @@ describe("Unit - New command", () => { projectType: "type", themes: ["ig"] }; - newCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: mockProjLib - }); + })); spyOn(Util, "gitInit"); spyOn(Util, "directoryExists").and.returnValue(false); @@ -339,10 +341,10 @@ describe("Unit - New command", () => { projectType: "type", themes: ["ig"] }; - newCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: mockProjLib - }); + })); const mockProjectConfig = { skipGit: true } as unknown as Config; spyOn(ProjectConfig, "getConfig").and.returnValue(mockProjectConfig); @@ -366,10 +368,10 @@ describe("Unit - New command", () => { projectType: "type", themes: ["ig"] }; - newCmd.templateManager = jasmine.createSpyObj("TemplateManager", { + App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", { getFrameworkById: {}, getProjectLibrary: mockProjLib - }); + })); spyOn(Util, "gitInit"); diff --git a/spec/unit/upgrade-spec.ts b/spec/unit/upgrade-spec.ts index 606929974..051b7ee15 100644 --- a/spec/unit/upgrade-spec.ts +++ b/spec/unit/upgrade-spec.ts @@ -1,6 +1,6 @@ import { - BaseTemplate, BaseTemplateManager, Config, GoogleAnalytics, PackageManager, ProjectConfig, - ProjectLibrary, ProjectTemplate, Template, Util + App, BaseTemplate, BaseTemplateManager, Config, GoogleAnalytics, PackageManager, ProjectConfig, + ProjectLibrary, ProjectTemplate, Template, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core"; import { default as upgradeCmd } from "../../packages/cli/lib/commands/upgrade"; @@ -107,7 +107,7 @@ describe("Unit - Upgrade command", () => { }; const mockTemplateManager: Partial = { getProjectLibrary: () => null }; - upgradeCmd.templateManager = mockTemplateManager as any; + App.container.set(TEMPLATE_MANAGER, mockTemplateManager); spyOn(mockTemplateManager, "getProjectLibrary").and.returnValue(mockProjLib); spyOn(mockProjLib, "getProject").and.returnValue(mockProjTemplate); const upgradeIgniteUIPackagesSpy = spyOn(mockProjTemplate, "upgradeIgniteUIPackages");