-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinitial-parameters.ts
46 lines (42 loc) · 1.49 KB
/
initial-parameters.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
38
39
40
41
42
43
44
45
46
import os from 'os';
import path from 'path';
import { getEnvironmentVariables } from './env';
import { readCommandLineArguments } from './command-line-arguments';
import { readProject, Project } from './project';
interface InitialParameters {
project: Project;
tempDirectoryPath: string;
reset: boolean;
today: Date;
}
/**
* Reads the inputs given to this tool via `process.argv` and uses them to
* gather information about the project the tool can use to run.
*
* @param argv - The arguments to this executable.
* @param cwd - The directory in which this executable was run.
* @returns The initial parameters.
*/
export async function determineInitialParameters(
argv: string[],
cwd: string,
): Promise<InitialParameters> {
const inputs = await readCommandLineArguments(argv);
const { TODAY } = getEnvironmentVariables();
const projectDirectoryPath = path.resolve(cwd, inputs.projectDirectory);
const project = await readProject(projectDirectoryPath);
const tempDirectoryPath =
inputs.tempDirectory === undefined
? path.join(
os.tmpdir(),
'create-release-branch',
project.rootPackage.validatedManifest.name.replace('/', '__'),
)
: path.resolve(cwd, inputs.tempDirectory);
const parsedTodayTimestamp =
TODAY === undefined ? NaN : new Date(TODAY).getTime();
const today = isNaN(parsedTodayTimestamp)
? new Date()
: new Date(parsedTodayTimestamp);
return { project, tempDirectoryPath, reset: inputs.reset, today };
}