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 type { Tree } from '@nx/devkit';
|
||||||
import { checkPathUnderProjectRoot } from '../../utils/path';
|
|
||||||
import {
|
import {
|
||||||
|
validatePathIsUnderProjectRoot,
|
||||||
validateProject,
|
validateProject,
|
||||||
validateStandaloneOption,
|
validateStandaloneOption,
|
||||||
} from '../../utils/validations';
|
} from '../../utils/validations';
|
||||||
@ -8,6 +8,6 @@ import type { Schema } from '../schema';
|
|||||||
|
|
||||||
export function validateOptions(tree: Tree, options: Schema): void {
|
export function validateOptions(tree: Tree, options: Schema): void {
|
||||||
validateProject(tree, options.project);
|
validateProject(tree, options.project);
|
||||||
checkPathUnderProjectRoot(tree, options.project, options.path);
|
validatePathIsUnderProjectRoot(tree, options.project, options.path);
|
||||||
validateStandaloneOption(tree, options.standalone);
|
validateStandaloneOption(tree, options.standalone);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import type { Tree } from '@nx/devkit';
|
import type { Tree } from '@nx/devkit';
|
||||||
import { checkPathUnderProjectRoot } from '../../utils/path';
|
|
||||||
import {
|
import {
|
||||||
|
validatePathIsUnderProjectRoot,
|
||||||
validateProject,
|
validateProject,
|
||||||
validateStandaloneOption,
|
validateStandaloneOption,
|
||||||
} from '../../utils/validations';
|
} from '../../utils/validations';
|
||||||
@ -8,6 +8,6 @@ import type { Schema } from '../schema';
|
|||||||
|
|
||||||
export function validateOptions(tree: Tree, options: Schema): void {
|
export function validateOptions(tree: Tree, options: Schema): void {
|
||||||
validateProject(tree, options.project);
|
validateProject(tree, options.project);
|
||||||
checkPathUnderProjectRoot(tree, options.project, options.path);
|
validatePathIsUnderProjectRoot(tree, options.project, options.path);
|
||||||
validateStandaloneOption(tree, options.standalone);
|
validateStandaloneOption(tree, options.standalone);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import type { Tree } from '@nx/devkit';
|
import type { Tree } from '@nx/devkit';
|
||||||
import { checkPathUnderProjectRoot } from '../../utils/path';
|
|
||||||
import {
|
import {
|
||||||
|
validatePathIsUnderProjectRoot,
|
||||||
validateProject,
|
validateProject,
|
||||||
validateStandaloneOption,
|
validateStandaloneOption,
|
||||||
} from '../../utils/validations';
|
} from '../../utils/validations';
|
||||||
@ -8,6 +8,6 @@ import type { Schema } from '../schema';
|
|||||||
|
|
||||||
export function validateOptions(tree: Tree, options: Schema): void {
|
export function validateOptions(tree: Tree, options: Schema): void {
|
||||||
validateProject(tree, options.project);
|
validateProject(tree, options.project);
|
||||||
checkPathUnderProjectRoot(tree, options.project, options.path);
|
validatePathIsUnderProjectRoot(tree, options.project, options.path);
|
||||||
validateStandaloneOption(tree, options.standalone);
|
validateStandaloneOption(tree, options.standalone);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
import type { Tree } from '@nx/devkit';
|
import type { Tree } from '@nx/devkit';
|
||||||
import { checkPathUnderProjectRoot } from '../../utils/path';
|
import {
|
||||||
import { validateProject } from '../../utils/validations';
|
validatePathIsUnderProjectRoot,
|
||||||
|
validateProject,
|
||||||
|
} from '../../utils/validations';
|
||||||
import type { Schema } from '../schema';
|
import type { Schema } from '../schema';
|
||||||
|
|
||||||
export function validateOptions(tree: Tree, options: Schema): void {
|
export function validateOptions(tree: Tree, options: Schema): void {
|
||||||
validateProject(tree, options.project);
|
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 type { Tree } from '@nx/devkit';
|
||||||
import { checkPathUnderProjectRoot } from '../../utils/path';
|
import {
|
||||||
import { validateProject } from '../../utils/validations';
|
validatePathIsUnderProjectRoot,
|
||||||
|
validateProject,
|
||||||
|
} from '../../utils/validations';
|
||||||
import type { Schema } from '../schema';
|
import type { Schema } from '../schema';
|
||||||
|
|
||||||
export function validateOptions(tree: Tree, options: Schema): void {
|
export function validateOptions(tree: Tree, options: Schema): void {
|
||||||
validateProject(tree, options.project);
|
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 type { Tree } from '@nx/devkit';
|
||||||
import { checkPathUnderProjectRoot } from '../../utils/path';
|
import {
|
||||||
import { validateProject } from '../../utils/validations';
|
validatePathIsUnderProjectRoot,
|
||||||
|
validateProject,
|
||||||
|
} from '../../utils/validations';
|
||||||
import type { Schema } from '../schema';
|
import type { Schema } from '../schema';
|
||||||
|
|
||||||
export function validateOptions(tree: Tree, options: Schema): void {
|
export function validateOptions(tree: Tree, options: Schema): void {
|
||||||
validateProject(tree, options.project);
|
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 = {
|
export type PathGenerationOptions = {
|
||||||
name: string;
|
name: string;
|
||||||
project: string;
|
project: string;
|
||||||
|
|||||||
@ -1,6 +1,12 @@
|
|||||||
import type { Tree } from '@nx/devkit';
|
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 { lt } from 'semver';
|
||||||
|
import { pathStartsWith } from './path';
|
||||||
import { getInstalledAngularVersionInfo } from './version-utils';
|
import { getInstalledAngularVersionInfo } from './version-utils';
|
||||||
|
|
||||||
export function validateProject(tree: Tree, projectName: string): void {
|
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.`);
|
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