forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfluidRunner.ts
126 lines (122 loc) · 3.8 KB
/
fluidRunner.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
import * as yargs from "yargs";
import { exportFile } from "./exportFile";
import { IFluidFileConverter } from "./codeLoaderBundle";
import { parseBundleAndExportFile } from "./parseBundleAndExportFile";
// eslint-disable-next-line import/no-internal-modules
import { validateAndParseTelemetryOptions } from "./logger/loggerUtils";
import { validateCommandLineArgs } from "./utils";
/**
* @param fluidFileConverter - needs to be provided if "codeLoaderBundle" is not and vice versa
*/
export function fluidRunner(fluidFileConverter?: IFluidFileConverter) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
yargs
.strict()
.version(false)
.command(
"exportFile",
"Generate an output for a local ODSP snapshot",
// eslint-disable-next-line @typescript-eslint/no-shadow
(yargs) =>
yargs
.option("codeLoader", {
describe:
'Path to code loader bundle. Required if this application is being called without modification.\nSee "README.md" for more details.',
type: "string",
demandOption: false,
})
.option("inputFile", {
describe: "Path to local ODSP snapshot",
type: "string",
demandOption: true,
})
.option("outputFile", {
describe:
"Path of output file (cannot already exist).\nExecution result will be written here",
type: "string",
demandOption: true,
})
.option("telemetryFile", {
describe:
"Path of telemetry file for config and session data (cannot already exist)",
type: "string",
demandOption: true,
})
.option("options", {
describe: "Additional options passed to container on execution",
type: "string",
demandOption: false,
})
.option("telemetryFormat", {
describe:
'Output format for telemetry. Current options are: ["JSON", "CSV"]',
type: "string",
demandOption: false,
default: "JSON",
})
.option("telemetryProp", {
describe:
'Property to add to every telemetry entry. Formatted like "--telemetryProp prop1 value1 --telemetryProp prop2 \\"value 2\\"".',
type: "array",
demandOption: false,
})
.option("eventsPerFlush", {
describe:
"Number of telemetry events per flush to telemetryFile (only applicable for JSON format)",
type: "number",
demandOption: false,
})
.option("timeout", {
describe: "Allowed timeout in ms before process is automatically cancelled",
type: "number",
demandOption: false,
}),
// eslint-disable-next-line @typescript-eslint/no-misused-promises
async (argv) => {
const argsError = validateCommandLineArgs(argv.codeLoader, fluidFileConverter);
if (argsError) {
console.error(argsError);
process.exit(1);
}
const telemetryOptionsResult = validateAndParseTelemetryOptions(
argv.telemetryFormat,
argv.telemetryProp,
argv.eventsPerFlush,
);
if (!telemetryOptionsResult.success) {
console.error(telemetryOptionsResult.error);
process.exit(1);
}
const result = await (argv.codeLoader
? parseBundleAndExportFile(
argv.codeLoader,
argv.inputFile,
argv.outputFile,
argv.telemetryFile,
argv.options,
telemetryOptionsResult.telemetryOptions,
argv.timeout,
)
: exportFile(
fluidFileConverter!,
argv.inputFile,
argv.outputFile,
argv.telemetryFile,
argv.options,
telemetryOptionsResult.telemetryOptions,
argv.timeout,
));
if (!result.success) {
console.error(`${result.eventName}: ${result.errorMessage}`);
process.exit(1);
}
process.exit(0);
},
)
.help()
.demandCommand().argv;
}