forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildContext.ts
More file actions
40 lines (33 loc) · 1.28 KB
/
BuildContext.ts
File metadata and controls
40 lines (33 loc) · 1.28 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
39
40
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { PackageJsonLookup } from '@microsoft/node-core-library';
export interface IBuildContextParameters {
/**
* If unspecified, then process.cwd() is used.
*/
currentWorkingDirectory?: string;
}
export class BuildContext {
public readonly packageJsonLookup: PackageJsonLookup = new PackageJsonLookup();
/**
* The absolute path to the folder containing package.json for the project
* that we're building.
* Example: "C:\MyRepo\project-1"
*/
public readonly projectFolder: string;
public constructor(parameters?: IBuildContextParameters) {
let currentWorkingDirectory: string = process.cwd();
if (parameters) {
if (parameters.currentWorkingDirectory) {
currentWorkingDirectory = parameters.currentWorkingDirectory;
}
}
const projectFolder: string | undefined = this.packageJsonLookup
.tryGetPackageFolderFor(currentWorkingDirectory);
if (!projectFolder) {
throw new Error('Unable to find a package.json for the current folder: ' + currentWorkingDirectory);
}
console.log(`Project folder is: "${projectFolder}"`);
this.projectFolder = projectFolder;
}
}