From 375328253245b4ab226b39d634ddbb53b8e0436c Mon Sep 17 00:00:00 2001 From: nartc Date: Sun, 5 Jan 2025 10:16:44 -0600 Subject: [PATCH] fix: also support 18 --- cli.js | 24 +++++++++++++++++++++--- package.json | 3 ++- src/utils/parser.js | 11 ++++++++--- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/cli.js b/cli.js index 7389e7a..7028a91 100755 --- a/cli.js +++ b/cli.js @@ -5,6 +5,7 @@ import meow from "meow"; import { dirname } from "node:path"; import { readPackageUpSync } from "read-pkg-up"; import { fileURLToPath } from "node:url"; +import { parse } from "semver"; import gltf from "./src/index.js"; const __filename = fileURLToPath(import.meta.url); @@ -75,11 +76,27 @@ const cli = meow( }, ); -console.log("dirname", __dirname); -console.log("process.cwd", process.cwd()); - +const { packageJson: cwdPackageJson } = readPackageUpSync({ + cwd: process.cwd(), +}); const { packageJson } = readPackageUpSync({ cwd: __dirname }); +let ngVer; + +if (cwdPackageJson.dependencies["@angular/core"]) { + const parsed = parse(cwdPackageJson.dependencies["@angular/core"]); + ngVer = parsed.major; + + if (ngVer < 18) { + console.error("Angular version must be >= 18"); + process.exit(1); + } + + console.log("Detected Angular version: ", parsed.version); +} else { + console.warn("Executing outside of Angular workspace"); +} + if (cli.input.length === 0) { console.log(cli.help); } else { @@ -106,6 +123,7 @@ if (cli.input.length === 0) { showLog, timeout: 0, delay: 1, + ngVer, header: `Auto-generated by: https://github.com/angular-threejs/gltf Command: npx angular-three-gltf@${packageJson.version} ${process.argv.slice(2).join(" ")}`, }; diff --git a/package.json b/package.json index a9663b9..c916b1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-three-gltf", - "version": "1.1.6", + "version": "1.1.7", "description": "GLTF to Angular Three converter", "scripts": { "cleanup": "rimraf node_modules" @@ -49,6 +49,7 @@ "meshoptimizer": "^0.22.0", "prettier": "^3.4.2", "read-pkg-up": "^11.0.0", + "semver": "^7.6.3", "sharp": "^0.33.5", "three": "0.122.0", "three-stdlib": "^2.35.2" diff --git a/src/utils/parser.js b/src/utils/parser.js index e4a32ba..0a84c05 100644 --- a/src/utils/parser.js +++ b/src/utils/parser.js @@ -662,7 +662,12 @@ ${options.preload ? `injectGLTF.preload(() => ${url})` : ""} ${printTypes(objects, animations)} @Component({ - selector: '${selector}', + selector: '${selector}',${ + options.ngVer < 19 + ? ` + standalone: true,` + : "" + } template: \` @if (gltf();as gltf) { @@ -729,7 +734,7 @@ export class ${componentName} { if (animations.ready()) { this.animations.set(animations); } - }) + }${options.ngVer < 19 ? ", { allowSignalWrites: true }" : ""}) ` : "" } @@ -740,7 +745,7 @@ export class ${componentName} { if (!model) return; objectEvents.ngtObjectEvents.set(model); - }); + }${options.ngVer < 19 ? ", { allowSignalWrites: true }" : ""}); } }`; }