Skip to content

Commit b13ef25

Browse files
committed
feat(plugin): update plugin to the latest
1 parent aefd2f1 commit b13ef25

File tree

7 files changed

+52
-37
lines changed

7 files changed

+52
-37
lines changed

libs/plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "plugin",
33
"dependencies": {
4-
"@nx/devkit": "^17.0.0",
4+
"@nx/devkit": "^19.0.0",
55
"tslib": "^2.3.0"
66
},
77
"nx-migrations": {

libs/plugin/src/generators/init/files/experience/experience.component.html__tmpl__

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
import { CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core';
2-
import { extend, type NgtBeforeRenderEvent } from 'angular-three';
1+
import { CUSTOM_ELEMENTS_SCHEMA, Component, viewChild, ElementRef, ChangeDetectionStrategy } from '@angular/core';
2+
import { extend, injectBeforeRender } from 'angular-three';
33
import { Mesh, BoxGeometry, MeshBasicMaterial } from 'three';
44

55
extend({ Mesh, BoxGeometry, MeshBasicMaterial });
66

77
@Component({
88
standalone: true,
9-
templateUrl: './experience.component.html',
10-
schemas: [CUSTOM_ELEMENTS_SCHEMA]
9+
template: `
10+
<ngt-mesh #mesh>
11+
<ngt-box-geometry />
12+
<ngt-mesh-basic-material color="hotpink" />
13+
</ngt-mesh>
14+
`,
15+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
16+
changeDetection: ChangeDetectionStrategy.OnPush,
1117
})
1218
export class Experience {
13-
onBeforeRender({ object, state: { delta }}: NgtBeforeRenderEvent<Mesh>) {
14-
object.rotation.x += delta;
15-
object.rotation.y += delta;
19+
meshRef = viewChild.required<ElementRef<Mesh>>('mesh');
20+
21+
constructor() {
22+
injectBeforeRender(({ delta }) => {
23+
const mesh = this.meshRef().nativeElement;
24+
mesh.rotation.x += delta;
25+
mesh.rotation.y += delta;
26+
})
1627
}
1728
}
1829

libs/plugin/src/generators/init/generator.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('init generator', () => {
1111
});
1212

1313
it('should add three dependencies', async () => {
14-
await init(appTree);
14+
await init(appTree, { skipGenerateExperience: true });
1515

1616
const packageJson = readJson(appTree, 'package.json');
1717

@@ -21,15 +21,15 @@ describe('init generator', () => {
2121
});
2222

2323
it('should update skipLibCheck in tsconfig.base.json', async () => {
24-
await init(appTree);
24+
await init(appTree, { skipGenerateExperience: true });
2525

2626
const tsConfig = readJson(appTree, 'tsconfig.base.json');
2727
expect(tsConfig.compilerOptions.skipLibCheck).toEqual(true);
2828
});
2929

3030
it('should update skipLibCheck in tsconfig.json', async () => {
3131
appTree.rename('tsconfig.base.json', 'tsconfig.json');
32-
await init(appTree);
32+
await init(appTree, { skipGenerateExperience: true });
3333

3434
const tsConfig = readJson(appTree, 'tsconfig.json');
3535
expect(tsConfig.compilerOptions.skipLibCheck).toEqual(true);

libs/plugin/src/generators/init/generator.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ import { type ArrayLiteralExpression, type NoSubstitutionTemplateLiteral } from
1717
import { addMetadataJson } from '../utils';
1818
import { ANGULAR_THREE_VERSION, NGXTENSION_VERSION, THREE_TYPE_VERSION, THREE_VERSION } from '../version';
1919

20-
export async function initGenerator(tree: Tree) {
20+
export interface InitGeneratorOptions {
21+
skipGenerateExperience: boolean;
22+
}
23+
24+
export async function initGenerator(
25+
tree: Tree,
26+
{ skipGenerateExperience = false }: Partial<InitGeneratorOptions> = {},
27+
) {
2128
logger.log('Initializing Angular Three...');
2229

2330
const packageJson = readJson(tree, 'package.json');
@@ -45,6 +52,14 @@ export async function initGenerator(tree: Tree) {
4552

4653
addMetadataJson(tree, 'angular-three/metadata.json');
4754

55+
if (skipGenerateExperience) {
56+
await formatFiles(tree);
57+
58+
return () => {
59+
installPackagesTask(tree);
60+
};
61+
}
62+
4863
const { generateExperience } = await prompt<{ generateExperience: 'append' | 'replace' | 'none' }>({
4964
type: 'select',
5065
name: 'generateExperience',
@@ -63,7 +78,7 @@ export async function initGenerator(tree: Tree) {
6378
(project) => project.projectType === 'application',
6479
);
6580
let selectedProject: string;
66-
if (applicationProjects.length > 1) {
81+
if (applicationProjects.length === 1) {
6782
selectedProject = applicationProjects[0].name;
6883
} else {
6984
// prompt
@@ -107,7 +122,7 @@ export async function initGenerator(tree: Tree) {
107122
return warnExperienceWasNotGenerated(tree, `AppComponent was not found`);
108123
}
109124

110-
// TODO: revisit if standalone:true becomes the default
125+
// TODO (chau): revisit if standalone:true becomes the default
111126
const isStandalone = appComponentContent.includes(`standalone: true`);
112127
if (!isStandalone) {
113128
return warnExperienceWasNotGenerated(tree, `AppComponent is not a Standalone Component`);

libs/plugin/src/generators/init/schema.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,13 @@
22
"$schema": "http://json-schema.org/schema",
33
"cli": "nx",
44
"$id": "Init",
5-
"title": "Init Angular Three"
5+
"title": "Init Angular Three",
6+
"type": "object",
7+
"properties": {
8+
"skipGenerateExperience": {
9+
"type": "boolean",
10+
"description": "Skip generating Experience component",
11+
"default": false
12+
}
13+
}
614
}

libs/plugin/src/generators/version.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
export const ANGULAR_THREE_VERSION = '^2.0.0';
2-
export const THREE_VERSION = '^0.159.0';
3-
export const THREE_TYPE_VERSION = '^0.159.0';
4-
5-
export const THREE_STDLIB_VERSION = '^2.0.0';
6-
export const STATS_GL_VERSION = '^1.0.0';
7-
export const MESH_LINE_VERSION = '^3.1.0';
8-
export const THREE_MESH_BVH_VERSION = '^0.6.0';
9-
export const TROIKA_THREE_TEXT_VERSION = '^0.49.0';
10-
11-
export const POSTPROCESSING_VERSION = '^6.0.0';
12-
13-
export const CANNON_WORKER_API_VERSION = '^2.0.0';
14-
export const CANNON_ES_VERSION = '^0.20.0';
15-
export const CANNON_ES_DEBUGGER_VERSION = '^1.0.0';
16-
17-
export const RAPIER_COMPAT_VERSION = '^0.11.2';
18-
19-
export const NGXTENSION_VERSION = '^1.0.0';
2+
export const THREE_VERSION = '^0.166.0';
3+
export const THREE_TYPE_VERSION = '^0.166.0';
4+
export const NGXTENSION_VERSION = '^4.0.0';

0 commit comments

Comments
 (0)