forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject-metadata.ts
37 lines (32 loc) · 1.05 KB
/
project-metadata.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { join } from 'node:path';
/**
* Normalize a directory path string.
* Currently only removes a trailing slash if present.
* @param path A path string.
* @returns A normalized path string.
*/
export function normalizeDirectoryPath(path: string): string {
const last = path[path.length - 1];
if (last === '/' || last === '\\') {
return path.slice(0, -1);
}
return path;
}
export function getProjectRootPaths(
workspaceRoot: string,
projectMetadata: { root?: string; sourceRoot?: string },
) {
const projectRoot = normalizeDirectoryPath(join(workspaceRoot, projectMetadata.root ?? ''));
const rawSourceRoot = projectMetadata.sourceRoot;
const projectSourceRoot = normalizeDirectoryPath(
rawSourceRoot === undefined ? join(projectRoot, 'src') : join(workspaceRoot, rawSourceRoot),
);
return { projectRoot, projectSourceRoot };
}