Skip to content

Commit 3753282

Browse files
committed
fix: also support 18
1 parent 45f47af commit 3753282

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

cli.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import meow from "meow";
55
import { dirname } from "node:path";
66
import { readPackageUpSync } from "read-pkg-up";
77
import { fileURLToPath } from "node:url";
8+
import { parse } from "semver";
89
import gltf from "./src/index.js";
910

1011
const __filename = fileURLToPath(import.meta.url);
@@ -75,11 +76,27 @@ const cli = meow(
7576
},
7677
);
7778

78-
console.log("dirname", __dirname);
79-
console.log("process.cwd", process.cwd());
80-
79+
const { packageJson: cwdPackageJson } = readPackageUpSync({
80+
cwd: process.cwd(),
81+
});
8182
const { packageJson } = readPackageUpSync({ cwd: __dirname });
8283

84+
let ngVer;
85+
86+
if (cwdPackageJson.dependencies["@angular/core"]) {
87+
const parsed = parse(cwdPackageJson.dependencies["@angular/core"]);
88+
ngVer = parsed.major;
89+
90+
if (ngVer < 18) {
91+
console.error("Angular version must be >= 18");
92+
process.exit(1);
93+
}
94+
95+
console.log("Detected Angular version: ", parsed.version);
96+
} else {
97+
console.warn("Executing outside of Angular workspace");
98+
}
99+
83100
if (cli.input.length === 0) {
84101
console.log(cli.help);
85102
} else {
@@ -106,6 +123,7 @@ if (cli.input.length === 0) {
106123
showLog,
107124
timeout: 0,
108125
delay: 1,
126+
ngVer,
109127
header: `Auto-generated by: https://github.com/angular-threejs/gltf
110128
Command: npx angular-three-gltf&#64;${packageJson.version} ${process.argv.slice(2).join(" ")}`,
111129
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-three-gltf",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"description": "GLTF to Angular Three converter",
55
"scripts": {
66
"cleanup": "rimraf node_modules"
@@ -49,6 +49,7 @@
4949
"meshoptimizer": "^0.22.0",
5050
"prettier": "^3.4.2",
5151
"read-pkg-up": "^11.0.0",
52+
"semver": "^7.6.3",
5253
"sharp": "^0.33.5",
5354
"three": "0.122.0",
5455
"three-stdlib": "^2.35.2"

src/utils/parser.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,12 @@ ${options.preload ? `injectGLTF.preload(() => ${url})` : ""}
662662
${printTypes(objects, animations)}
663663
664664
@Component({
665-
selector: '${selector}',
665+
selector: '${selector}',${
666+
options.ngVer < 19
667+
? `
668+
standalone: true,`
669+
: ""
670+
}
666671
template: \`
667672
@if (gltf();as gltf) {
668673
<ngt-group #model [parameters]="options()">
@@ -729,7 +734,7 @@ export class ${componentName} {
729734
if (animations.ready()) {
730735
this.animations.set(animations);
731736
}
732-
})
737+
}${options.ngVer < 19 ? ", { allowSignalWrites: true }" : ""})
733738
`
734739
: ""
735740
}
@@ -740,7 +745,7 @@ export class ${componentName} {
740745
if (!model) return;
741746
742747
objectEvents.ngtObjectEvents.set(model);
743-
});
748+
}${options.ngVer < 19 ? ", { allowSignalWrites: true }" : ""});
744749
}
745750
}`;
746751
}

0 commit comments

Comments
 (0)