-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathutils.ts
More file actions
38 lines (35 loc) · 1.06 KB
/
utils.ts
File metadata and controls
38 lines (35 loc) · 1.06 KB
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
38
import type { CreateNodesContext, CreateNodesContextV2 } from '@nx/devkit';
import { readFile } from 'node:fs/promises';
import * as path from 'node:path';
import { CP_TARGET_NAME } from './constants';
import type {
CreateNodesOptions,
NormalizedCreateNodesContext,
ProjectConfigurationWithName,
} from './types.js';
export async function normalizedCreateNodesContext(
context: CreateNodesContext | CreateNodesContextV2,
projectConfigurationFile: string,
createOptions: CreateNodesOptions = {},
): Promise<NormalizedCreateNodesContext> {
const projectRoot = path.dirname(projectConfigurationFile);
try {
const projectJson = JSON.parse(
(await readFile(projectConfigurationFile)).toString(),
) as ProjectConfigurationWithName;
const { targetName = CP_TARGET_NAME } = createOptions;
return {
...context,
projectJson,
projectRoot,
createOptions: {
...createOptions,
targetName,
},
};
} catch {
throw new Error(
`Error parsing project.json file ${projectConfigurationFile}.`,
);
}
}