Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding schema to template dependency 13.2.x #1270

Merged
merged 9 commits into from
Jul 11, 2024
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "igniteui-cli",
"version": "13.2.3",
"version": "13.2.4-beta.3",
"description": "CLI tool for creating Ignite UI projects",
"keywords": [
"CLI",
Expand Down Expand Up @@ -78,8 +78,8 @@
"all": true
},
"dependencies": {
"@igniteui/angular-templates": "~17.2.1323",
"@igniteui/cli-core": "~13.2.3",
"@igniteui/angular-templates": "~17.2.1324-beta.3",
"@igniteui/cli-core": "~13.2.4-beta.3",
"chalk": "^2.3.2",
"fs-extra": "^3.0.1",
"glob": "^7.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@igniteui/cli-core",
"version": "13.2.3",
"version": "13.2.4-beta.3",
"description": "Base types and functionality for Ignite UI CLI",
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions packages/core/types/TemplateDependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export interface TemplateDependency {
/** Add an identifier into `ngModule` provides metadata */
provide?: string | string[];

/** Add an identifier into `ngModule` schema metadata */
schema?: string | string[];

/** The package/path(TBD) to import the dependency from */
from?: string;

Expand Down
74 changes: 46 additions & 28 deletions packages/core/typescript/TypeScriptFileUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class TypeScriptFileUpdate {
declarations: string[],
imports: Array<{ name: string, root: boolean, standalone?: boolean }>,
providers: string[],
schemas: Array<{ name: string, standalone?: boolean }>,
exports: string[]
};

Expand Down Expand Up @@ -52,8 +53,8 @@ export class TypeScriptFileUpdate {
}

// should we support both standalone and module-based components in the same app?
if (this.ngMetaEdits.imports.some(x => x.standalone)) {
transforms.push(this.componentMetaTransformer);
if (this.ngMetaEdits.imports.some(x => x.standalone) || (this.ngMetaEdits.schemas.some(x => x.standalone))) {
transforms.push(this.componentMetaTransformer);
} else if (Object.keys(this.ngMetaEdits).filter(x => this.ngMetaEdits[x].length).length) {
transforms.push(this.ngModuleTransformer);
}
Expand Down Expand Up @@ -141,13 +142,14 @@ export class TypeScriptFileUpdate {
declare: this.asArray(dep.declare, variables),
import: this.asArray(dep.import, variables),
provide: this.asArray(dep.provide, variables),
schema: this.asArray(dep.schema, variables),
// tslint:disable-next-line:object-literal-sort-keys
export: this.asArray(dep.export, variables)
};

if (dep.from) {
// request import
const identifiers = [...copy.import, ...copy.declare, ...copy.provide];
const identifiers = [...copy.import, ...copy.declare, ...copy.provide, ...copy.schema];
this.requestImport(identifiers, Util.applyConfigTransformation(dep.from, variables));
}
const imports = copy.import
Expand All @@ -163,6 +165,11 @@ export class TypeScriptFileUpdate {
.filter(x => !this.ngMetaEdits.providers.find(p => p === x));
this.ngMetaEdits.providers.push(...providers);

const schemas = copy.schema
.map(x => ({ name: x, root: dep.root }))
.filter(x => !this.ngMetaEdits.schemas.find(s => s.name === x.name));
this.ngMetaEdits.schemas.push(...schemas);

const exportsArr = copy.export
.filter(x => !this.ngMetaEdits.exports.find(p => p === x));
this.ngMetaEdits.exports.push(...exportsArr);
Expand All @@ -174,18 +181,24 @@ export class TypeScriptFileUpdate {
public addStandaloneImport(dep: TemplateDependency, variables?: { [key: string]: string }) {
const copy = {
import: this.asArray(dep.import, variables),
provide: this.asArray(dep.provide, variables)
provide: this.asArray(dep.provide, variables),
schema: this.asArray(dep.schema, variables)
};
if (dep.from) {
// request import
const identifiers = [...copy.import, ...copy.provide];
const identifiers = [...copy.import, ...copy.provide, ...copy.schema];
this.requestImport(identifiers, Util.applyConfigTransformation(dep.from, variables));
}

const imports = copy.import
.map(x => ({ name: x, root: dep.root, standalone: true }))
.filter(x => !this.ngMetaEdits.imports.find(i => i.name === x.name));
this.ngMetaEdits.imports.push(...imports);

const schemas = copy.schema
.map(x => ({ name: x, root: dep.root, standalone: true}))
.filter(x => !this.ngMetaEdits.schemas.find(i => i.name === x.name));
this.ngMetaEdits.schemas.push(...schemas);
}

/**
Expand Down Expand Up @@ -249,6 +262,7 @@ export class TypeScriptFileUpdate {
declarations: [],
imports: [],
providers: [],
schemas: [],
exports: []
};
this.createdStringLiterals = [];
Expand Down Expand Up @@ -547,23 +561,19 @@ export class TypeScriptFileUpdate {
const objProperties = ts.visitNodes(obj.properties, visitor);
const newProps = [];
for (const prop of missingProperties) {
let arrayExpr;
switch (prop) {
case "imports":
const importDeps = this.ngMetaEdits.imports;
arrayExpr = ts.factory.createArrayLiteralExpression(
importDeps.map(x => TsUtils.createIdentifier(x.name, x.root ? "forRoot" : ""))
);
break;
case "declarations":
case "providers":
case "exports":
arrayExpr = ts.factory.createArrayLiteralExpression(
this.ngMetaEdits[prop].map(x => ts.factory.createIdentifier(x))
);
break;
if (this.ngMetaEdits[prop].length) {
const expr = ts.factory.createArrayLiteralExpression(
this.ngMetaEdits[prop].map(x => {
if (typeof x === "string") {
return TsUtils.createIdentifier(x);
}
if (typeof x === "object" && "name" in x) {
return TsUtils.createIdentifier(x.name, x.root ? "forRoot" : "")
}
})
);
newProps.push(ts.factory.createPropertyAssignment(prop, expr));
}
newProps.push(ts.factory.createPropertyAssignment(prop, arrayExpr));
}

return ts.factory.updateObjectLiteralExpression(obj, [
Expand All @@ -585,6 +595,11 @@ export class TypeScriptFileUpdate {
.filter(x => alreadyImported.indexOf(x.name) === -1)
.map(x => TsUtils.createIdentifier(x.name, x.root ? "forRoot" : ""));
break;
case "schemas":
identifiers = this.ngMetaEdits.schemas
.filter(x => alreadyImported.indexOf(x.name) === -1)
.map(x => TsUtils.createIdentifier(x.name));
break;
case "declarations":
case "providers":
case "exports":
Expand Down Expand Up @@ -618,19 +633,22 @@ export class TypeScriptFileUpdate {
protected componentMetaTransformer: ts.TransformerFactory<ts.Node> =
<T extends ts.Node>(context: ts.TransformationContext) => (rootNode: T) => {
const visitComponent: ts.Visitor = (node: ts.Node): ts.Node => {
let importsExpr = null;
const prop = "imports";
const properties = Object.keys(this.ngMetaEdits);
if (node.kind === ts.SyntaxKind.ObjectLiteralExpression &&
node.parent &&
node.parent.kind === ts.SyntaxKind.CallExpression) {
const obj = (node as ts.ObjectLiteralExpression);
const objProperties = ts.visitNodes(obj.properties, visitor);
const newProps = [];
const importDeps = this.ngMetaEdits.imports;
importsExpr = ts.factory.createArrayLiteralExpression(
importDeps.map(x => TsUtils.createIdentifier(x.name))
);
newProps.push(ts.factory.createPropertyAssignment(prop, importsExpr));
const missingProperties = properties.filter(x => !obj.properties.find(o => o.name.getText() === x));
for (const prop of missingProperties) {
if (this.ngMetaEdits[prop].length) {
const expr = ts.factory.createArrayLiteralExpression(
this.ngMetaEdits[prop].map(x => TsUtils.createIdentifier(x.name))
);
newProps.push(ts.factory.createPropertyAssignment(prop, expr));
}
}
return context.factory.updateObjectLiteralExpression(obj, [
...objProperties,
...newProps
Expand Down
4 changes: 2 additions & 2 deletions packages/igx-templates/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@igniteui/angular-templates",
"version": "17.2.1323",
"version": "17.2.1324-beta.3",
"description": "Templates for Ignite UI for Angular projects and components",
"repository": {
"type": "git",
Expand All @@ -12,7 +12,7 @@
"author": "Infragistics",
"license": "MIT",
"dependencies": {
"@igniteui/cli-core": "~13.2.3",
"@igniteui/cli-core": "~13.2.4-beta.3",
"typescript": "~5.4.3"
}
}
6 changes: 3 additions & 3 deletions packages/ng-schematics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@igniteui/angular-schematics",
"version": "17.2.1323",
"version": "17.2.1324-beta.3",
"description": "Ignite UI for Angular Schematics for ng new and ng generate",
"repository": {
"type": "git",
Expand All @@ -20,8 +20,8 @@
"dependencies": {
"@angular-devkit/core": "~14.0.0",
"@angular-devkit/schematics": "~14.0.0",
"@igniteui/angular-templates": "~17.2.1323",
"@igniteui/cli-core": "~13.2.3",
"@igniteui/angular-templates": "~17.2.1324-beta.3",
"@igniteui/cli-core": "~13.2.4-beta.3",
"@schematics/angular": "~14.0.0",
"rxjs": "^6.6.3"
},
Expand Down
Loading