Skip to content

Commit

Permalink
fix(cli): fix could not find any [routes] variable (#1832)
Browse files Browse the repository at this point in the history
  • Loading branch information
devcui committed Sep 29, 2024
1 parent 8cacab3 commit 38daae1
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions schematics/utils/yunzai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import {
url
} from '@angular-devkit/schematics';
import { Schema as ComponentSchema } from '@schematics/angular/component/schema';
import {
findNode,
insertImport,
addProviderToModule as _addProviderToModule
} from '@schematics/angular/utility/ast-utils';
import { insertImport, getSourceNodes } from '@schematics/angular/utility/ast-utils';
import { InsertChange } from '@schematics/angular/utility/change';
import { buildRelativePath, findModuleFromOptions, ModuleOptions } from '@schematics/angular/utility/find-module';
import { parseName } from '@schematics/angular/utility/parse-name';
Expand All @@ -32,11 +28,10 @@ import { addServiceToModuleOrStandalone, findRoutesPath, getSourceFile, ROUTINS_
import { isStandalone } from './standalone';
import { getProject, NgYunzaiProjectDefinition } from './workspace';

const TEMPLATE_FILENAME_RE = /\.template$/;

export interface CommonSchema extends ComponentSchema {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;

_filesPath?: string;
schematicName?: string;
target?: string;
Expand Down Expand Up @@ -178,7 +173,9 @@ export function addValueToVariable(
needWrap: boolean = true
): void {
const source = getSourceFile(tree, filePath);
const node = findNode(source, ts.SyntaxKind.Identifier, variableName);
const node = getSourceNodes(source).find(
node => node.kind == ts.SyntaxKind.Identifier && node.getText() === variableName
);
if (!node) {
throw new SchematicsException(`Could not find any [${variableName}] variable in path '${filePath}'.`);
}
Expand Down

0 comments on commit 38daae1

Please sign in to comment.