angular-three 2.0.0-beta.18 → 2.0.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin/package.json +2 -1
- package/plugin/src/generators/init/compat.d.ts +3 -1
- package/plugin/src/generators/init/files/experience/experience.component.html.__tmpl__ +4 -0
- package/plugin/src/generators/init/files/experience/experience.component.ts.__tmpl__ +17 -0
- package/plugin/src/generators/init/generator.d.ts +5 -1
- package/plugin/src/generators/init/generator.js +106 -1
- package/plugin/src/generators/init/generator.js.map +1 -1
- package/plugin/src/generators/init/schema.json +12 -1
package/package.json
CHANGED
package/plugin/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core';
|
|
2
|
+
import { Mesh, BoxGeometry, MeshBasicMaterial } from 'three';
|
|
3
|
+
|
|
4
|
+
extend({ Mesh, BoxGeometry, MeshBasicMaterial });
|
|
5
|
+
|
|
6
|
+
@Component({
|
|
7
|
+
standalone: true,
|
|
8
|
+
templateUrl: './experience.component.html',
|
|
9
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
|
10
|
+
})
|
|
11
|
+
export class Experience {
|
|
12
|
+
onBeforeRender({ object, state: { delta }}: NgtBeforeRenderEvent<Mesh>) {
|
|
13
|
+
object.rotation.x += delta;
|
|
14
|
+
object.rotation.y += delta;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
5
|
+
const enquirer_1 = require("enquirer");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const typescript_1 = require("typescript");
|
|
4
8
|
const utils_1 = require("../utils");
|
|
5
9
|
const versions_1 = require("../versions");
|
|
6
|
-
async function default_1(tree) {
|
|
10
|
+
async function default_1(tree, { project }) {
|
|
7
11
|
devkit_1.logger.log('Initializing Angular Three...');
|
|
8
12
|
const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
|
|
9
13
|
const version = packageJson['dependencies']?.['angular-three'] ||
|
|
@@ -19,6 +23,107 @@ async function default_1(tree) {
|
|
|
19
23
|
return json;
|
|
20
24
|
});
|
|
21
25
|
(0, utils_1.addMetadataJson)(tree, 'angular-three/metadata.json');
|
|
26
|
+
const { generateExperience } = await (0, enquirer_1.prompt)({
|
|
27
|
+
type: 'select',
|
|
28
|
+
name: 'generateExperience',
|
|
29
|
+
message: 'Generate an Experience component?',
|
|
30
|
+
choices: [
|
|
31
|
+
{ value: 'append', name: 'append', message: 'Append <ngt-canvas /> to AppComponent template' },
|
|
32
|
+
{ value: 'replace', name: 'replace', message: 'Replace AppComponent template with <ngt-canvas />' },
|
|
33
|
+
{ value: 'none', name: 'none', message: 'Do not generate an Experience component' },
|
|
34
|
+
],
|
|
35
|
+
initial: 2,
|
|
36
|
+
});
|
|
37
|
+
if (generateExperience !== 'none') {
|
|
38
|
+
const isNx = tree.exists('nx.json');
|
|
39
|
+
const rootProjectJson = (0, devkit_1.readJson)(tree, 'project.json');
|
|
40
|
+
if (!project) {
|
|
41
|
+
if (isNx) {
|
|
42
|
+
if (!rootProjectJson) {
|
|
43
|
+
throw new Error(`
|
|
44
|
+
It seems like your workspace is an Integrated workspace but you did not provide a "project" name.
|
|
45
|
+
Please retry the generator with a "--project" specified.`);
|
|
46
|
+
}
|
|
47
|
+
const rootName = rootProjectJson['name'];
|
|
48
|
+
if (rootName === packageJson['name']) {
|
|
49
|
+
project = rootName;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!project) {
|
|
54
|
+
throw new Error(`
|
|
55
|
+
Angular Three generator could not find a default "project".
|
|
56
|
+
Please retry the generator with a "--project" specified.`);
|
|
57
|
+
}
|
|
58
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
59
|
+
const sourceRoot = projectConfig.sourceRoot;
|
|
60
|
+
if (sourceRoot) {
|
|
61
|
+
// generate Experience component
|
|
62
|
+
(0, devkit_1.generateFiles)(tree, (0, node_path_1.join)(__dirname, 'files'), sourceRoot, { __tmpl__: '' });
|
|
63
|
+
const { isStandalone } = await (0, enquirer_1.prompt)({
|
|
64
|
+
type: 'confirm',
|
|
65
|
+
initial: false,
|
|
66
|
+
name: 'isStandalone',
|
|
67
|
+
message: 'Is your project standalone?',
|
|
68
|
+
});
|
|
69
|
+
const appComponentPath = `${sourceRoot}/app.component.ts`;
|
|
70
|
+
const exist = tree.exists(appComponentPath);
|
|
71
|
+
const appComponentTemplatePath = `${sourceRoot}/app.component.html`;
|
|
72
|
+
const templateExist = tree.exists(appComponentTemplatePath);
|
|
73
|
+
const appComponentContent = exist ? tree.read(appComponentPath, 'utf8') : null;
|
|
74
|
+
const appComponentTemplateContent = templateExist ? tree.read(appComponentTemplatePath, 'utf8') : null;
|
|
75
|
+
if (isStandalone) {
|
|
76
|
+
if (!appComponentContent) {
|
|
77
|
+
devkit_1.logger.warn(`
|
|
78
|
+
AppComponent not found at ${appComponentPath}. Angular Three was initialized successfully but an Experience component was not generated.`);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
let updatedContent = tsquery_1.tsquery.replace(appComponentContent, 'Identifier[name="imports"] ~ ArrayLiteralExpression', (node) => typescript_1.factory
|
|
82
|
+
.updateArrayLiteralExpression(node, [
|
|
83
|
+
...node.elements,
|
|
84
|
+
typescript_1.factory.createIdentifier('NgtCanvas'),
|
|
85
|
+
])
|
|
86
|
+
.getFullText());
|
|
87
|
+
updatedContent = tsquery_1.tsquery.replace(updatedContent, 'SourceFile', (node) => {
|
|
88
|
+
return `
|
|
89
|
+
import { NgtCanvas } from 'angular-three';
|
|
90
|
+
import { Experience } from './experience/experience.component';
|
|
91
|
+
${node.getFullText()}`;
|
|
92
|
+
});
|
|
93
|
+
updatedContent = tsquery_1.tsquery.replace(updatedContent, 'ClassDeclaration', (node) => typescript_1.factory
|
|
94
|
+
.updateClassDeclaration(node, node.modifiers, node.name, node.typeParameters, node.heritageClauses, [
|
|
95
|
+
typescript_1.factory.createPropertyDeclaration([], 'scene', undefined, undefined, typescript_1.factory.createIdentifier('Experience')),
|
|
96
|
+
...node.members,
|
|
97
|
+
])
|
|
98
|
+
.getFullText());
|
|
99
|
+
if (appComponentTemplateContent) {
|
|
100
|
+
const updatedTemplateContent = generateExperience === 'append'
|
|
101
|
+
? `
|
|
102
|
+
${appComponentTemplateContent}
|
|
103
|
+
<ngt-canvas [sceneGraph]="scene" />`
|
|
104
|
+
: `<ngt-canvas [sceneGraph]="scene" />`;
|
|
105
|
+
tree.write(appComponentTemplatePath, updatedTemplateContent);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
updatedContent = tsquery_1.tsquery.replace(updatedContent, 'Identifier[name="template"] ~ NoSubstitutionTemplateLiteral', (node) => {
|
|
109
|
+
return generateExperience === 'append'
|
|
110
|
+
? `
|
|
111
|
+
${node.getFullText()}
|
|
112
|
+
<ngt-canvas [sceneGraph]="scene" />`
|
|
113
|
+
: `<ngt-canvas [sceneGraph]="scene" />`;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
tree.write(appComponentPath, updatedContent);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
devkit_1.logger.warn(`
|
|
124
|
+
"sourceRoot" not found. Angular Three was initialized successfully but an Experience component was not generated.`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
22
127
|
return () => {
|
|
23
128
|
(0, devkit_1.installPackagesTask)(tree);
|
|
24
129
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../libs/plugin/src/generators/init/generator.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../libs/plugin/src/generators/init/generator.ts"],"names":[],"mappings":";;AAAA,uCASoB;AACpB,uDAAoD;AACpD,uCAAkC;AAClC,yCAAiC;AACjC,2CAMoB;AACpB,oCAA2C;AAC3C,0CAAuF;AAMxE,KAAK,oBAAW,IAAU,EAAE,EAAE,OAAO,EAAU;IAC7D,eAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAE5C,MAAM,WAAW,GAAG,IAAA,iBAAQ,EAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAEnD,MAAM,OAAO,GACZ,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC,eAAe,CAAC;QAC9C,WAAW,CAAC,iBAAiB,CAAC,EAAE,CAAC,eAAe,CAAC;QACjD,gCAAqB,CAAC;IAEvB,IAAA,qCAA4B,EAC3B,IAAI,EACJ,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,wBAAa,EAAE,EAClD,EAAE,cAAc,EAAE,6BAAkB,EAAE,CACtC,CAAC;IAEF,eAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IAC1C,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,eAAe,CAAC;IAEhG,IAAA,mBAAU,EAAC,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE;QACvC,IAAI,CAAC,CAAC,cAAc,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,YAAY,KAAK,KAAK,EAAE;YAC9F,IAAI,CAAC,eAAe,CAAC,YAAY,GAAG,IAAI,CAAC;SACzC;QACD,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAC;IAEH,IAAA,uBAAe,EAAC,IAAI,EAAE,6BAA6B,CAAC,CAA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;IAED,OAAO,GAAG,EAAE;QACX,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC;AACH,CAAC;AAhKD,4BAgKC"}
|
|
@@ -2,5 +2,16 @@
|
|
|
2
2
|
"$schema": "http://json-schema.org/schema",
|
|
3
3
|
"cli": "nx",
|
|
4
4
|
"$id": "Init",
|
|
5
|
-
"title": "Init Angular Three"
|
|
5
|
+
"title": "Init Angular Three",
|
|
6
|
+
"properties": {
|
|
7
|
+
"project": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "The name of the project to add the Tailwind CSS setup for.",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "argv",
|
|
12
|
+
"index": 0
|
|
13
|
+
},
|
|
14
|
+
"x-prompt": "What project would you like to add the Angular Three setup?"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
6
17
|
}
|