diff --git a/packages/cli/lang/en.json b/packages/cli/lang/en.json index 00931b3595..da8cdfd9ec 100644 --- a/packages/cli/lang/en.json +++ b/packages/cli/lang/en.json @@ -19,6 +19,7 @@ "commands_build_options_w": "Automatically rebuild when changes are made (default: false)", "commands_build_options_s": "Strategy to use for building the wrapper", "commands_build_options_s_strategy": "strategy", + "commands_build_options_l": "Log file to save console output to", "commands_infra_description": "Modular Infrastructure-As-Code Orchestrator", "commands_infra_actions_subtitle": "Infra allows you to execute the following commands:", "commands_infra_options_options": "options", diff --git a/packages/cli/lang/es.json b/packages/cli/lang/es.json index fc27c873b1..da8cdfd9ec 100644 --- a/packages/cli/lang/es.json +++ b/packages/cli/lang/es.json @@ -19,6 +19,7 @@ "commands_build_options_w": "Automatically rebuild when changes are made (default: false)", "commands_build_options_s": "Strategy to use for building the wrapper", "commands_build_options_s_strategy": "strategy", + "commands_build_options_l": "Log file to save console output to", "commands_infra_description": "Modular Infrastructure-As-Code Orchestrator", "commands_infra_actions_subtitle": "Infra allows you to execute the following commands:", "commands_infra_options_options": "options", @@ -233,8 +234,8 @@ "lib_helpers_copyText": "Artifacts written to {path}", "lib_helpers_copyError": "Failed to write build artifacts to {path}", "lib_helpers_copyWarning": "Warnings write build artifacts to {path}", - "lib_helpers_docker_couldNotConnect": "Could not connect to the Docker daemon. Is the docker daemon running?", "lib_helpers_docker_copyText": "Artifacts written to {path} from the image `{image}`", + "lib_helpers_docker_couldNotConnect": "Could not connect to the Docker daemon. Is the docker daemon running?", "lib_helpers_docker_copyError": "Failed to write build artifacts to {path} from the image `{image}`", "lib_helpers_docker_copyWarning": "Warnings write build artifacts to {path} from the image `{image}`", "lib_helpers_docker_buildText": "Building source image `{image}` using dockerfile `{dockerfile}` in context `{context}`", diff --git a/packages/cli/src/__tests__/e2e/build.spec.ts b/packages/cli/src/__tests__/e2e/build.spec.ts index 5765dfc696..24275ff75e 100644 --- a/packages/cli/src/__tests__/e2e/build.spec.ts +++ b/packages/cli/src/__tests__/e2e/build.spec.ts @@ -24,6 +24,7 @@ Options: made (default: false) -v, --verbose Verbose output (default: false) -q, --quiet Suppress output (default: false) + -l, --log-file [path] Log file to save console output to -h, --help display help for command `; @@ -190,6 +191,22 @@ describe("e2e tests for build command", () => { testBuildOutput(testCaseDir, outputDir); }); + it("Should write log to file", async () => { + const testCaseDir = getTestCaseDir(0); + const logFilePath = "./log-file.txt"; + const logFileAbsPath = path.join(testCaseDir, logFilePath); + const { exitCode: code } = await runCLI({ + args: ["build", "-v", "-l", logFilePath], + cwd: testCaseDir, + cli: polywrapCli, + }); + + expect(code).toEqual(0); + expect(fs.existsSync(logFileAbsPath)).toBeTruthy(); + expect(fs.statSync(logFileAbsPath).size).toBeGreaterThan(0); + fs.unlinkSync(logFileAbsPath); + }); + describe("Image strategy", () => { it("Builds for assemblyscript", async () => { const { exitCode: code, stdout: output } = await runCLI({ diff --git a/packages/cli/src/__tests__/e2e/codegen.spec.ts b/packages/cli/src/__tests__/e2e/codegen.spec.ts index cef88b42c9..907ef8adb6 100644 --- a/packages/cli/src/__tests__/e2e/codegen.spec.ts +++ b/packages/cli/src/__tests__/e2e/codegen.spec.ts @@ -24,6 +24,7 @@ Options: PolywrapClient -v, --verbose Verbose output (default: false) -q, --quiet Suppress output (default: false) + -l, --log-file [path] Log file to save console output to -h, --help display help for command `; diff --git a/packages/cli/src/__tests__/e2e/deploy.spec.ts b/packages/cli/src/__tests__/e2e/deploy.spec.ts index 0e8c97b5e9..79db96eee2 100644 --- a/packages/cli/src/__tests__/e2e/deploy.spec.ts +++ b/packages/cli/src/__tests__/e2e/deploy.spec.ts @@ -22,6 +22,7 @@ Options: -o, --output-file Output file path for the deploy result -v, --verbose Verbose output (default: false) -q, --quiet Suppress output (default: false) + -l, --log-file [path] Log file to save console output to -h, --help display help for command `; diff --git a/packages/cli/src/__tests__/e2e/docgen.spec.ts b/packages/cli/src/__tests__/e2e/docgen.spec.ts index 57dae5d829..833ec37b14 100644 --- a/packages/cli/src/__tests__/e2e/docgen.spec.ts +++ b/packages/cli/src/__tests__/e2e/docgen.spec.ts @@ -29,6 +29,7 @@ Options: -i, --imports Also generate docs for dependencies -v, --verbose Verbose output (default: false) -q, --quiet Suppress output (default: false) + -l, --log-file [path] Log file to save console output to -h, --help display help for command `; diff --git a/packages/cli/src/__tests__/e2e/infra.spec.ts b/packages/cli/src/__tests__/e2e/infra.spec.ts index b74b2b6303..86328ed8c1 100644 --- a/packages/cli/src/__tests__/e2e/infra.spec.ts +++ b/packages/cli/src/__tests__/e2e/infra.spec.ts @@ -34,6 +34,7 @@ Options: -o, --modules Use only specified modules -v, --verbose Verbose output (default: false) -q, --quiet Suppress output (default: false) + -l, --log-file [path] Log file to save console output to -h, --help display help for command `; diff --git a/packages/cli/src/__tests__/e2e/manifest.spec.ts b/packages/cli/src/__tests__/e2e/manifest.spec.ts index 6b5f44521f..c3a5136ec7 100644 --- a/packages/cli/src/__tests__/e2e/manifest.spec.ts +++ b/packages/cli/src/__tests__/e2e/manifest.spec.ts @@ -35,6 +35,7 @@ Options: -m, --manifest-file Path to the manifest file (default: polywrap.yaml | polywrap.yml) -f, --format Target format to migrate to (defaults to latest) + -l, --log-file [path] Log file to save console output to -v, --verbose Verbose output (default: false) -q, --quiet Suppress output (default: false) -h, --help display help for command @@ -55,6 +56,7 @@ Options: | polywrap.yml) -v, --verbose Verbose output (default: false) -q, --quiet Suppress output (default: false) + -l, --log-file [path] Log file to save console output to -h, --help display help for command `; diff --git a/packages/cli/src/__tests__/e2e/run.spec.ts b/packages/cli/src/__tests__/e2e/run.spec.ts index 160aff8e37..f9de3da6c0 100644 --- a/packages/cli/src/__tests__/e2e/run.spec.ts +++ b/packages/cli/src/__tests__/e2e/run.spec.ts @@ -25,6 +25,7 @@ Options: run -v, --verbose Verbose output (default: false) -q, --quiet Suppress output (default: false) + -l, --log-file [path] Log file to save console output to -h, --help display help for command `; diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 5b9a1478ee..6e77995d05 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -12,6 +12,7 @@ import { parseDirOption, parseClientConfigOption, parseManifestFileOption, + parseLogFileOption, } from "../lib"; import { CodeGenerator } from "../lib/codegen"; import { @@ -42,6 +43,7 @@ type BuildCommandOptions = { strategy: SupportedStrategies; verbose?: boolean; quiet?: boolean; + logFile?: string; }; export const build: Command = { @@ -75,6 +77,10 @@ export const build: Command = { .option(`-w, --watch`, `${intlMsg.commands_build_options_w()}`) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) + .option( + `-l, --log-file [${pathStr}]`, + `${intlMsg.commands_build_options_l()}` + ) .action(async (options) => { await run({ ...options, @@ -85,6 +91,7 @@ export const build: Command = { clientConfig: await parseClientConfigOption(options.clientConfig), outputDir: parseDirOption(options.outputDir, defaultOutputDir), strategy: options.strategy, + logFile: parseLogFileOption(options.logFile), }); }); }, @@ -135,8 +142,9 @@ async function run(options: BuildCommandOptions) { codegen, verbose, quiet, + logFile, } = options; - const logger = createLogger({ verbose, quiet }); + const logger = createLogger({ verbose, quiet, logFile }); // Get Client const client = new PolywrapClient(clientConfig); diff --git a/packages/cli/src/commands/codegen.ts b/packages/cli/src/commands/codegen.ts index 3ff81f8a1c..ef882081a1 100644 --- a/packages/cli/src/commands/codegen.ts +++ b/packages/cli/src/commands/codegen.ts @@ -14,6 +14,7 @@ import { generateWrapFile, defaultProjectManifestFiles, defaultPolywrapManifest, + parseLogFileOption, } from "../lib"; import { ScriptCodegenerator } from "../lib/codegen/ScriptCodeGenerator"; @@ -35,6 +36,7 @@ type CodegenCommandOptions = { clientConfig: Partial; verbose?: boolean; quiet?: boolean; + logFile?: string; }; export const codegen: Command = { @@ -71,6 +73,10 @@ export const codegen: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) + .option( + `-l, --log-file [${pathStr}]`, + `${intlMsg.commands_build_options_l()}` + ) .action(async (options) => { await run({ ...options, @@ -82,6 +88,7 @@ export const codegen: Command = { defaultProjectManifestFiles ), publishDir: parseDirOption(options.publishDir, defaultPublishDir), + logFile: parseLogFileOption(options.logFile), }); }); }, @@ -96,8 +103,9 @@ async function run(options: CodegenCommandOptions) { publishDir, verbose, quiet, + logFile, } = options; - const logger = createLogger({ verbose, quiet }); + const logger = createLogger({ verbose, quiet, logFile }); // Get Client const client = new PolywrapClient(clientConfig); diff --git a/packages/cli/src/commands/create.ts b/packages/cli/src/commands/create.ts index e071e6f4f8..e3ca293a32 100644 --- a/packages/cli/src/commands/create.ts +++ b/packages/cli/src/commands/create.ts @@ -1,6 +1,6 @@ import { Command, Program } from "./types"; import { createLogger } from "./utils/createLogger"; -import { generateProjectTemplate, intlMsg } from "../lib"; +import { generateProjectTemplate, intlMsg, parseLogFileOption } from "../lib"; import fse from "fs-extra"; import path from "path"; @@ -28,6 +28,7 @@ type CreateCommandOptions = { outputDir?: string; verbose?: boolean; quiet?: boolean; + logFile?: string; }; export const create: Command = { @@ -54,8 +55,15 @@ export const create: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) + .option( + `-l, --log-file [${pathStr}]`, + `${intlMsg.commands_build_options_l()}` + ) .action(async (langStr, nameStr, options) => { - await run("wasm", langStr, nameStr, options); + await run("wasm", langStr, nameStr, { + ...options, + logFile: parseLogFileOption(options.logFile), + }); }); createCommand @@ -75,8 +83,15 @@ export const create: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) + .option( + `-l, --log-file [${pathStr}]`, + `${intlMsg.commands_build_options_l()}` + ) .action(async (langStr, nameStr, options) => { - await run("app", langStr, nameStr, options); + await run("app", langStr, nameStr, { + ...options, + logFile: parseLogFileOption(options.logFile), + }); }); createCommand @@ -96,8 +111,15 @@ export const create: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) + .option( + `-l, --log-file [${pathStr}]`, + `${intlMsg.commands_build_options_l()}` + ) .action(async (langStr, nameStr, options) => { - await run("plugin", langStr, nameStr, options); + await run("plugin", langStr, nameStr, { + ...options, + logFile: parseLogFileOption(options.logFile), + }); }); }, }; @@ -108,8 +130,8 @@ async function run( name: string, options: CreateCommandOptions ) { - const { outputDir, verbose, quiet } = options; - const logger = createLogger({ verbose, quiet }); + const { outputDir, verbose, quiet, logFile } = options; + const logger = createLogger({ verbose, quiet, logFile }); const projectDir = path.resolve(outputDir ? `${outputDir}/${name}` : name); diff --git a/packages/cli/src/commands/deploy.ts b/packages/cli/src/commands/deploy.ts index c35f6ef210..f712f51768 100644 --- a/packages/cli/src/commands/deploy.ts +++ b/packages/cli/src/commands/deploy.ts @@ -9,6 +9,7 @@ import { PolywrapProject, DeployJob, DeployStep, + parseLogFileOption, } from "../lib"; import { DeployManifest } from "@polywrap/polywrap-manifest-types-js"; @@ -25,6 +26,7 @@ type DeployCommandOptions = { outputFile?: string; verbose?: boolean; quiet?: boolean; + logFile?: string; }; type ManifestJob = DeployManifest["jobs"][number]; @@ -48,6 +50,10 @@ export const deploy: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) + .option( + `-l, --log-file [${pathStr}]`, + `${intlMsg.commands_build_options_l()}` + ) .action(async (options) => { await run({ ...options, @@ -55,14 +61,15 @@ export const deploy: Command = { options.manifestFile, defaultPolywrapManifest ), + logFile: parseLogFileOption(options.logFile), }); }); }, }; async function run(options: DeployCommandOptions): Promise { - const { manifestFile, outputFile, verbose, quiet } = options; - const logger = createLogger({ verbose, quiet }); + const { manifestFile, outputFile, verbose, quiet, logFile } = options; + const logger = createLogger({ verbose, quiet, logFile }); const project = new PolywrapProject({ rootDir: nodePath.dirname(manifestFile), diff --git a/packages/cli/src/commands/docgen.ts b/packages/cli/src/commands/docgen.ts index b207ee0da2..03578572c7 100644 --- a/packages/cli/src/commands/docgen.ts +++ b/packages/cli/src/commands/docgen.ts @@ -8,6 +8,7 @@ import { parseManifestFileOption, defaultProjectManifestFiles, getProjectFromManifest, + parseLogFileOption, } from "../lib"; import { Command, Program } from "./types"; import { createLogger } from "./utils/createLogger"; @@ -38,6 +39,7 @@ type DocgenCommandOptions = { imports: boolean; verbose?: boolean; quiet?: boolean; + logFile?: string; }; enum Actions { @@ -93,6 +95,10 @@ export const docgen: Command = { .option(`-i, --imports`, `${intlMsg.commands_docgen_options_i()}`) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) + .option( + `-l, --log-file [${pathStr}]`, + `${intlMsg.commands_build_options_l()}` + ) .action(async (action, options) => { await run(action, { ...options, @@ -102,6 +108,7 @@ export const docgen: Command = { ), docgenDir: parseDirOption(options.docgenDir, defaultDocgenDir), clientConfig: await parseClientConfigOption(options.clientConfig), + logFile: parseLogFileOption(options.logFile), }); }); }, @@ -115,8 +122,9 @@ async function run(command: DocType, options: DocgenCommandOptions) { imports, verbose, quiet, + logFile, } = options; - const logger = createLogger({ verbose, quiet }); + const logger = createLogger({ verbose, quiet, logFile }); let project = await getProjectFromManifest(manifestFile, logger); diff --git a/packages/cli/src/commands/infra.ts b/packages/cli/src/commands/infra.ts index 3cac5c8039..2bd2c4ed35 100644 --- a/packages/cli/src/commands/infra.ts +++ b/packages/cli/src/commands/infra.ts @@ -4,6 +4,7 @@ import { loadInfraManifest, defaultInfraManifest, resolvePathIfExists, + parseLogFileOption, } from "../lib"; import { createLogger } from "./utils/createLogger"; import { Command, Program } from "./types"; @@ -20,6 +21,7 @@ type InfraCommandOptions = { verbose?: boolean; quiet?: boolean; manifest: string; + logFile?: string; }; enum InfraActions { @@ -79,12 +81,17 @@ export const infra: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) + .option( + `-l, --log-file [${pathStr}]`, + `${intlMsg.commands_build_options_l()}` + ) .action(async (action, options) => { await run(action, { ...options, manifest: options.manifestFile ? [options.manifestFile] : defaultInfraManifest, + logFile: parseLogFileOption(options.logFile), }); }); }, @@ -102,9 +109,9 @@ async function run( action: InfraActions, options: InfraCommandOptions & { manifest: string[] } ): Promise { - const { modules, verbose, quiet, manifest } = options; + const { modules, verbose, quiet, manifest, logFile } = options; - const logger = createLogger({ verbose, quiet }); + const logger = createLogger({ verbose, quiet, logFile }); // eslint-disable-next-line prefer-const let modulesArray: string[] = []; diff --git a/packages/cli/src/commands/manifest.ts b/packages/cli/src/commands/manifest.ts index 65696fac62..91a5d044c4 100644 --- a/packages/cli/src/commands/manifest.ts +++ b/packages/cli/src/commands/manifest.ts @@ -16,6 +16,7 @@ import { CacheDirectory, defaultPolywrapManifest, Logger, + parseLogFileOption, } from "../lib"; import { getYamlishSchemaForManifestJsonSchemaObject, @@ -81,6 +82,7 @@ type ManifestSchemaCommandOptions = { manifestFile: ManifestType; verbose?: boolean; quiet?: boolean; + logFile?: string; }; type ManifestMigrateCommandOptions = { @@ -88,6 +90,7 @@ type ManifestMigrateCommandOptions = { format: string; verbose?: boolean; quiet?: boolean; + logFile?: string; }; export const manifest: Command = { @@ -123,8 +126,15 @@ export const manifest: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) + .option( + `-l, --log-file [${pathStr}]`, + `${intlMsg.commands_build_options_l()}` + ) .action(async (type, options) => { - await runSchemaCommand(type, options); + await runSchemaCommand(type, { + ...options, + logFile: parseLogFileOption(options.logFile), + }); }); manifestCommand @@ -150,10 +160,17 @@ export const manifest: Command = { `-f, --format <${formatStr}>`, `${intlMsg.commands_manifest_options_f()}` ) + .option( + `-l, --log-file [${pathStr}]`, + `${intlMsg.commands_build_options_l()}` + ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (type, options) => { - await runMigrateCommand(type, options); + await runMigrateCommand(type, { + ...options, + logFile: parseLogFileOption(options.logFile), + }); }); }, }; @@ -162,8 +179,8 @@ export const runSchemaCommand = async ( type: ManifestType, options: ManifestSchemaCommandOptions ): Promise => { - const { verbose, quiet } = options; - const logger = createLogger({ verbose, quiet }); + const { verbose, quiet, logFile } = options; + const logger = createLogger({ verbose, quiet, logFile }); let manifestfile = ""; switch (type) { @@ -370,8 +387,8 @@ const runMigrateCommand = async ( type: ManifestType, options: ManifestMigrateCommandOptions ) => { - const { verbose, quiet } = options; - const logger = createLogger({ verbose, quiet }); + const { verbose, quiet, logFile } = options; + const logger = createLogger({ verbose, quiet, logFile }); let manifestFile = ""; let manifestString: string; let language: string | undefined; diff --git a/packages/cli/src/commands/run.ts b/packages/cli/src/commands/run.ts index 0d74fd17b7..1278dde736 100644 --- a/packages/cli/src/commands/run.ts +++ b/packages/cli/src/commands/run.ts @@ -15,6 +15,7 @@ import { WorkflowOutput, defaultWorkflowManifest, parseManifestFileOption, + parseLogFileOption, } from "../lib"; import { createLogger } from "./utils/createLogger"; @@ -31,6 +32,7 @@ type WorkflowCommandOptions = { outputFile?: string; verbose?: boolean; quiet?: boolean; + logFile?: string; }; const defaultManifestStr = defaultWorkflowManifest.join(" | "); @@ -62,6 +64,10 @@ export const run: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) + .option( + `-l, --log-file [${pathStr}]`, + `${intlMsg.commands_build_options_l()}` + ) .action(async (options) => { await _run({ ...options, @@ -73,14 +79,23 @@ export const run: Command = { outputFile: options.outputFile ? parseWorkflowOutputFilePathOption(options.outputFile) : undefined, + logFile: parseLogFileOption(options.logFile), }); }); }, }; const _run = async (options: WorkflowCommandOptions) => { - const { manifest, clientConfig, outputFile, verbose, quiet, jobs } = options; - const logger = createLogger({ verbose, quiet }); + const { + manifest, + clientConfig, + outputFile, + verbose, + quiet, + jobs, + logFile, + } = options; + const logger = createLogger({ verbose, quiet, logFile }); const client = new PolywrapClient(clientConfig); const manifestPath = path.resolve(manifest); diff --git a/packages/cli/src/commands/utils/createLogger.ts b/packages/cli/src/commands/utils/createLogger.ts index 497d18e364..bc9ade70cd 100644 --- a/packages/cli/src/commands/utils/createLogger.ts +++ b/packages/cli/src/commands/utils/createLogger.ts @@ -1,16 +1,23 @@ -import { Logger, LogLevel, ConsoleLog } from "../../lib"; +import { Logger, LogLevel, ConsoleLog, Logs, FileLog } from "../../lib"; -export function createLogger(flags: { +export function createLogger(options: { verbose?: boolean; quiet?: boolean; + logFile?: string; }): Logger { - const level = flags.quiet + const level = options.quiet ? LogLevel.ERROR - : flags.verbose + : options.verbose ? LogLevel.DEBUG : LogLevel.INFO; - return new Logger({ + const logs: Logs = { console: new ConsoleLog(level), - }); + }; + + if (options.logFile) { + logs["file"] = new FileLog(options.logFile, level); + } + + return new Logger(logs); } diff --git a/packages/cli/src/lib/logging/Logger.ts b/packages/cli/src/lib/logging/Logger.ts index f21823b1e5..d927a0bd22 100644 --- a/packages/cli/src/lib/logging/Logger.ts +++ b/packages/cli/src/lib/logging/Logger.ts @@ -1,6 +1,6 @@ import { Log, LogLevel } from "./Log"; -interface Logs { +export interface Logs { [name: string]: Log; } diff --git a/packages/cli/src/lib/logging/logs/FileLog.ts b/packages/cli/src/lib/logging/logs/FileLog.ts index ecd9caa295..09eed0a806 100644 --- a/packages/cli/src/lib/logging/logs/FileLog.ts +++ b/packages/cli/src/lib/logging/logs/FileLog.ts @@ -1,6 +1,7 @@ import { Log, LogLevel } from "../Log"; import fs, { WriteStream } from "fs"; +import path from "path"; export class FileLog extends Log { private _logFileStream: WriteStream; @@ -40,6 +41,12 @@ export class FileLog extends Log { } private _createWriteStream() { + const dir = path.dirname(this.logFilePath); + + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }); + } + this._logFileStream = fs.createWriteStream(this.logFilePath, { encoding: "utf8", }); diff --git a/packages/cli/src/lib/option-defaults/getDefaultLogFileName.ts b/packages/cli/src/lib/option-defaults/getDefaultLogFileName.ts new file mode 100644 index 0000000000..9fde4ac51b --- /dev/null +++ b/packages/cli/src/lib/option-defaults/getDefaultLogFileName.ts @@ -0,0 +1,3 @@ +export function getDefaultLogFileName(): string { + return `./.polywrap/logs/polywrap-${Date.now().toString()}.log`; +} diff --git a/packages/cli/src/lib/option-defaults/index.ts b/packages/cli/src/lib/option-defaults/index.ts index 91daa59cd1..08ee5110ab 100644 --- a/packages/cli/src/lib/option-defaults/index.ts +++ b/packages/cli/src/lib/option-defaults/index.ts @@ -1 +1,2 @@ -export * from "./defaultManifestFiles"; +export * from "./defaultManifestFiles"; +export * from "./getDefaultLogFileName"; diff --git a/packages/cli/src/lib/option-parsers/index.ts b/packages/cli/src/lib/option-parsers/index.ts index 482fd2ecde..41098d6c62 100644 --- a/packages/cli/src/lib/option-parsers/index.ts +++ b/packages/cli/src/lib/option-parsers/index.ts @@ -1,5 +1,6 @@ -export * from "./client-config"; -export * from "./codegen"; -export * from "./dir"; -export * from "./run"; -export * from "./manifestFile"; +export * from "./client-config"; +export * from "./codegen"; +export * from "./dir"; +export * from "./log-file"; +export * from "./manifestFile"; +export * from "./run"; diff --git a/packages/cli/src/lib/option-parsers/log-file.ts b/packages/cli/src/lib/option-parsers/log-file.ts new file mode 100644 index 0000000000..dcd5ef1511 --- /dev/null +++ b/packages/cli/src/lib/option-parsers/log-file.ts @@ -0,0 +1,14 @@ +import { getDefaultLogFileName } from "../option-defaults"; + +export function parseLogFileOption( + logFile: string | boolean | undefined +): string | undefined { + if (logFile) { + if (logFile === true) { + return getDefaultLogFileName(); + } + return logFile; + } + + return undefined; +}