Skip to content

Commit b5bd817

Browse files
committed
fix(plugin): get literal value of templateUrl if available
1 parent 4ec080a commit b5bd817

File tree

1 file changed

+11
-3
lines changed
  • libs/plugin/src/generators/init

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
Project,
2020
PropertyAssignment,
2121
ScriptKind,
22+
StringLiteral,
2223
SyntaxKind,
2324
} from 'ts-morph';
2425
import { addMetadataJson } from '../../utils';
@@ -259,9 +260,16 @@ export async function initGenerator(tree: Tree, options: InitGeneratorSchema) {
259260
});
260261

261262
if (templateUrlMetadata) {
262-
const templateUrl = templateUrlMetadata.getInitializer().getText();
263-
const templateUrlPath = join(componentPath, templateUrl);
264-
const templateContent = tree.read(templateUrlPath, 'utf-8');
263+
const templateUrl = (
264+
templateUrlMetadata.getInitializer() as StringLiteral | NoSubstitutionTemplateLiteral
265+
).getLiteralValue?.();
266+
267+
if (!templateUrl) {
268+
return await stopSetup(tree, `Could not locate templateUrl in ${componentPath}`);
269+
}
270+
271+
const templateUrlPath = join(dirname(componentPath), templateUrl);
272+
const templateContent = tree.read(templateUrlPath, 'utf8');
265273

266274
tree.write(
267275
templateUrlPath,

0 commit comments

Comments
 (0)