forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfluidRunner.ts
134 lines (128 loc) · 3.99 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
127
128
129
130
131
132
133
134
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
import yargs from "yargs";
// eslint-disable-next-line import/no-internal-modules
import { hideBin } from "yargs/helpers";
import { IFluidFileConverter } from "./codeLoaderBundle.js";
import { exportFile } from "./exportFile.js";
// eslint-disable-next-line import/no-internal-modules
import { validateAndParseTelemetryOptions } from "./logger/loggerUtils.js";
import { parseBundleAndExportFile } from "./parseBundleAndExportFile.js";
import { validateCommandLineArgs } from "./utils.js";
/**
* @param fluidFileConverter - needs to be provided if "codeLoaderBundle" is not and vice versa
* @internal
*/
export async function fluidRunner(fluidFileConverter?: IFluidFileConverter): Promise<void> {
await yargs(hideBin(process.argv))
.command(
"exportFile",
"Generate an output for a local ODSP snapshot",
(argv) =>
argv
.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,
})
.option("disableNetworkFetch", {
describe: "Should network fetch calls be explicitly disabled?",
type: "boolean",
demandOption: false,
default: false,
}),
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,
argv.disableNetworkFetch,
)
: exportFile(
fluidFileConverter!,
argv.inputFile,
argv.outputFile,
argv.telemetryFile,
argv.options,
telemetryOptionsResult.telemetryOptions,
argv.timeout,
argv.disableNetworkFetch,
));
if (!result.success) {
console.error(`${result.eventName}: ${result.errorMessage}`);
process.exit(1);
}
process.exit(0);
},
)
.help()
.demandCommand(1)
.parse();
}