cleanup(angular): rearrange validation helper function (#16906)
This commit is contained in:
parent
bdfb10db0a
commit
caefe8f509
@ -1,6 +1,6 @@
|
||||
import type { Tree } from '@nx/devkit';
|
||||
import { checkPathUnderProjectRoot } from '../../utils/path';
|
||||
import {
|
||||
validatePathIsUnderProjectRoot,
|
||||
validateProject,
|
||||
validateStandaloneOption,
|
||||
} from '../../utils/validations';
|
||||
@ -8,6 +8,6 @@ import type { Schema } from '../schema';
|
||||
|
||||
export function validateOptions(tree: Tree, options: Schema): void {
|
||||
validateProject(tree, options.project);
|
||||
checkPathUnderProjectRoot(tree, options.project, options.path);
|
||||
validatePathIsUnderProjectRoot(tree, options.project, options.path);
|
||||
validateStandaloneOption(tree, options.standalone);
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import type { Tree } from '@nx/devkit';
|
||||
import { checkPathUnderProjectRoot } from '../../utils/path';
|
||||
import {
|
||||
validatePathIsUnderProjectRoot,
|
||||
validateProject,
|
||||
validateStandaloneOption,
|
||||
} from '../../utils/validations';
|
||||
@ -8,6 +8,6 @@ import type { Schema } from '../schema';
|
||||
|
||||
export function validateOptions(tree: Tree, options: Schema): void {
|
||||
validateProject(tree, options.project);
|
||||
checkPathUnderProjectRoot(tree, options.project, options.path);
|
||||
validatePathIsUnderProjectRoot(tree, options.project, options.path);
|
||||
validateStandaloneOption(tree, options.standalone);
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import type { Tree } from '@nx/devkit';
|
||||
import { checkPathUnderProjectRoot } from '../../utils/path';
|
||||
import {
|
||||
validatePathIsUnderProjectRoot,
|
||||
validateProject,
|
||||
validateStandaloneOption,
|
||||
} from '../../utils/validations';
|
||||
@ -8,6 +8,6 @@ import type { Schema } from '../schema';
|
||||
|
||||
export function validateOptions(tree: Tree, options: Schema): void {
|
||||
validateProject(tree, options.project);
|
||||
checkPathUnderProjectRoot(tree, options.project, options.path);
|
||||
validatePathIsUnderProjectRoot(tree, options.project, options.path);
|
||||
validateStandaloneOption(tree, options.standalone);
|
||||
}
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import type { Tree } from '@nx/devkit';
|
||||
import { checkPathUnderProjectRoot } from '../../utils/path';
|
||||
import { validateProject } from '../../utils/validations';
|
||||
import {
|
||||
validatePathIsUnderProjectRoot,
|
||||
validateProject,
|
||||
} from '../../utils/validations';
|
||||
import type { Schema } from '../schema';
|
||||
|
||||
export function validateOptions(tree: Tree, options: Schema): void {
|
||||
validateProject(tree, options.project);
|
||||
checkPathUnderProjectRoot(tree, options.project, options.path);
|
||||
validatePathIsUnderProjectRoot(tree, options.project, options.path);
|
||||
}
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import type { Tree } from '@nx/devkit';
|
||||
import { checkPathUnderProjectRoot } from '../../utils/path';
|
||||
import { validateProject } from '../../utils/validations';
|
||||
import {
|
||||
validatePathIsUnderProjectRoot,
|
||||
validateProject,
|
||||
} from '../../utils/validations';
|
||||
import type { Schema } from '../schema';
|
||||
|
||||
export function validateOptions(tree: Tree, options: Schema): void {
|
||||
validateProject(tree, options.project);
|
||||
checkPathUnderProjectRoot(tree, options.project, options.path);
|
||||
validatePathIsUnderProjectRoot(tree, options.project, options.path);
|
||||
}
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import type { Tree } from '@nx/devkit';
|
||||
import { checkPathUnderProjectRoot } from '../../utils/path';
|
||||
import { validateProject } from '../../utils/validations';
|
||||
import {
|
||||
validatePathIsUnderProjectRoot,
|
||||
validateProject,
|
||||
} from '../../utils/validations';
|
||||
import type { Schema } from '../schema';
|
||||
|
||||
export function validateOptions(tree: Tree, options: Schema): void {
|
||||
validateProject(tree, options.project);
|
||||
checkPathUnderProjectRoot(tree, options.project, options.path);
|
||||
validatePathIsUnderProjectRoot(tree, options.project, options.path);
|
||||
}
|
||||
|
||||
@ -31,30 +31,6 @@ export function getRelativeImportToFile(
|
||||
)}`;
|
||||
}
|
||||
|
||||
export function checkPathUnderProjectRoot(
|
||||
tree: Tree,
|
||||
projectName: string,
|
||||
path: string
|
||||
): void {
|
||||
if (!path) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { root } = readProjectConfiguration(tree, projectName);
|
||||
|
||||
let pathToComponent = normalizePath(path);
|
||||
pathToComponent = pathToComponent.startsWith('/')
|
||||
? pathToComponent.slice(1)
|
||||
: pathToComponent;
|
||||
|
||||
if (!pathStartsWith(pathToComponent, root)) {
|
||||
throw new Error(
|
||||
`The path provided (${path}) does not exist under the project root (${root}). ` +
|
||||
`Please make sure to provide a path that exists under the project root.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export type PathGenerationOptions = {
|
||||
name: string;
|
||||
project: string;
|
||||
|
||||
@ -1,6 +1,12 @@
|
||||
import type { Tree } from '@nx/devkit';
|
||||
import { getProjects, stripIndents } from '@nx/devkit';
|
||||
import {
|
||||
getProjects,
|
||||
normalizePath,
|
||||
readProjectConfiguration,
|
||||
stripIndents,
|
||||
} from '@nx/devkit';
|
||||
import { lt } from 'semver';
|
||||
import { pathStartsWith } from './path';
|
||||
import { getInstalledAngularVersionInfo } from './version-utils';
|
||||
|
||||
export function validateProject(tree: Tree, projectName: string): void {
|
||||
@ -30,3 +36,27 @@ export function validateStandaloneOption(
|
||||
You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`);
|
||||
}
|
||||
}
|
||||
|
||||
export function validatePathIsUnderProjectRoot(
|
||||
tree: Tree,
|
||||
projectName: string,
|
||||
path: string
|
||||
): void {
|
||||
if (!path) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { root } = readProjectConfiguration(tree, projectName);
|
||||
|
||||
let pathToComponent = normalizePath(path);
|
||||
pathToComponent = pathToComponent.startsWith('/')
|
||||
? pathToComponent.slice(1)
|
||||
: pathToComponent;
|
||||
|
||||
if (!pathStartsWith(pathToComponent, root)) {
|
||||
throw new Error(
|
||||
`The path provided (${path}) does not exist under the project root (${root}). ` +
|
||||
`Please make sure to provide a path that exists under the project root.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user