Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions packages/cli/lib/PromptSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";

Expand Down Expand Up @@ -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" });
}

Expand Down
10 changes: 1 addition & 9 deletions packages/cli/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,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 registeredCommands: CommandType[] = [
newCommand, add, build, start, generate, config, doc, test, list, upgrade, mcp, aiConfig
Expand Down Expand Up @@ -74,7 +66,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();
}
}
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/lib/commands/add.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -11,7 +11,6 @@ let yargsContext: Argv | undefined;
const command: AddCommandType = {
command: "add [template] [name]",
describe: "Adds a component or view template to the current project",
templateManager: null,
builder: (yargs) => {
yargsContext = yargs;
return yargs
Expand Down Expand Up @@ -76,18 +75,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<BaseTemplateManager>(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;
}
Expand Down Expand Up @@ -123,7 +123,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<boolean> {
Expand Down Expand Up @@ -165,7 +165,7 @@ const command: AddCommandType = {
}
if (!fail && templatePaths.length) {
template.registerInProject(process.cwd(), fileName, options || {});
command.templateManager.updateProjectConfiguration(template);
App.container.get<BaseTemplateManager>(TEMPLATE_MANAGER).updateProjectConfiguration(template);
template.packages.forEach(x => PackageManager.queuePackage(x));
Util.log(`${Util.greenCheck()} View '${name}' added.`);
return true;
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/lib/commands/build.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -8,7 +8,6 @@ const command: BuildCommandType = {
command: "build",
describe: "Builds the project",
builder: (yargs) => yargs,
templateManager: null,
async handler(argv: ArgumentsCamelCase<PositionalArgs>) {

GoogleAnalytics.post({
Expand All @@ -19,7 +18,8 @@ const command: BuildCommandType = {
},
async build() {
Util.log("Build started.");
await PackageManager.ensureIgniteUISource(true, command.templateManager);
const templateManager = App.container.get<BaseTemplateManager>(TEMPLATE_MANAGER);
await PackageManager.ensureIgniteUISource(true, templateManager);

if (!ProjectConfig.hasLocalConfig()) {
Util.error("Build command is supported only on existing project created with igniteui-cli", "red");
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/lib/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -27,18 +27,19 @@ async function handler(argv: ArgumentsCamelCase<PositionalArgs>) {
return;
}

if (command.templateManager.getFrameworkById(argv.framework) === undefined) {
const templateManager = App.container.get<BaseTemplateManager>(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;
}

Expand Down Expand Up @@ -78,7 +79,6 @@ const command: CommandType = {
aliases: ["g"],
command: "generate",
describe: "Generates custom templates (see subcommands)",
templateManager: null,
builder: yargs => {
yargs
.command({
Expand Down
15 changes: 8 additions & 7 deletions packages/cli/lib/commands/list.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -23,7 +23,6 @@ const command: CommandType = {
.example("$0 list", "Show all frameworks and their project templates")
.example("$0 list -f angular", "List component templates for Angular");
},
templateManager: null,
handler(argv: ArgumentsCamelCase<PositionalArgs>) {
GoogleAnalytics.post({
t: "screenview",
Expand All @@ -49,19 +48,20 @@ const command: CommandType = {
const templatesByGroup = [];
const controlGroups: string[] = [];

const framework: Framework = command.templateManager.getFrameworkById(argv.framework);
const templateManager = App.container.get<BaseTemplateManager>(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;
Expand Down Expand Up @@ -115,9 +115,10 @@ const command: CommandType = {
};

function listAllFrameworks() {
const frameworkIds: string[] = command.templateManager.getFrameworkIds();
const templateManager = App.container.get<BaseTemplateManager>(TEMPLATE_MANAGER);
const frameworkIds: string[] = templateManager.getFrameworkIds();
const frameworks: Framework[] = frameworkIds
.map(id => command.templateManager.getFrameworkById(id))
.map(id => templateManager.getFrameworkById(id))
.filter(f => !!f);

GoogleAnalytics.post({
Expand Down
1 change: 0 additions & 1 deletion packages/cli/lib/commands/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/lib/commands/new.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -71,8 +70,9 @@ const command: NewCommandType = {
if (ProjectConfig.hasLocalConfig()) {
return Util.error("There is already an existing project.", "red");
}
const templateManager = App.container.get<BaseTemplateManager>(TEMPLATE_MANAGER);
if (!argv.name) {
const prompts = new PromptSession(command.templateManager || new TemplateManager());
const prompts = new PromptSession();
await prompts.start();
return;
}
Expand All @@ -92,20 +92,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");
}
Expand Down
1 change: 0 additions & 1 deletion packages/cli/lib/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
3 changes: 0 additions & 3 deletions packages/cli/lib/commands/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ArgumentsCamelCase, CommandModule } from "yargs";
import { TemplateManager } from "../TemplateManager";
import { AddTemplateArgs, Template } from "@igniteui/cli-core";

export interface PositionalArgs {
Expand Down Expand Up @@ -40,8 +39,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<PositionalArgs>);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/lib/commands/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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",
aliases: ["upgrade"],
describe: "Upgrades Ignite UI packages",
templateManager: null,
builder: (yargs) => {
return yargs
.option("skip-install", {
Expand Down Expand Up @@ -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<BaseTemplateManager>(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.
Expand Down
4 changes: 2 additions & 2 deletions packages/core/packages/PackageManager.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion packages/core/prompt/BasePromptSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BaseTemplateManager>(TEMPLATE_MANAGER);
}

/**
* Start questions session for project creation
Expand Down
5 changes: 3 additions & 2 deletions packages/ng-schematics/src/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
Loading