Skip to content

Commit

Permalink
fix: also support 18
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Jan 5, 2025
1 parent 45f47af commit 3753282
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
24 changes: 21 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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&#64;${packageJson.version} ${process.argv.slice(2).join(" ")}`,
};
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand Down
11 changes: 8 additions & 3 deletions src/utils/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
<ngt-group #model [parameters]="options()">
Expand Down Expand Up @@ -729,7 +734,7 @@ export class ${componentName} {
if (animations.ready()) {
this.animations.set(animations);
}
})
}${options.ngVer < 19 ? ", { allowSignalWrites: true }" : ""})
`
: ""
}
Expand All @@ -740,7 +745,7 @@ export class ${componentName} {
if (!model) return;
objectEvents.ngtObjectEvents.set(model);
});
}${options.ngVer < 19 ? ", { allowSignalWrites: true }" : ""});
}
}`;
}
Expand Down

0 comments on commit 3753282

Please sign in to comment.