Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI log file output option #1329

Merged
merged 7 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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}`",
Expand Down
17 changes: 17 additions & 0 deletions packages/cli/src/__tests__/e2e/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`;

Expand Down Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/__tests__/e2e/codegen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`;

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/__tests__/e2e/deploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Options:
-o, --output-file <path> 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
`;

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/__tests__/e2e/docgen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`;

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/__tests__/e2e/infra.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Options:
-o, --modules <module,module> 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
`;

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/__tests__/e2e/manifest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Options:
-m, --manifest-file <path> Path to the manifest file (default: polywrap.yaml
| polywrap.yml)
-f, --format <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
Expand All @@ -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
`;

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/__tests__/e2e/run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`;

Expand Down
10 changes: 9 additions & 1 deletion packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
parseDirOption,
parseClientConfigOption,
parseManifestFileOption,
parseLogFileOption,
} from "../lib";
import { CodeGenerator } from "../lib/codegen";
import {
Expand Down Expand Up @@ -42,6 +43,7 @@ type BuildCommandOptions = {
strategy: SupportedStrategies;
verbose?: boolean;
quiet?: boolean;
logFile?: string;
};

export const build: Command = {
Expand Down Expand Up @@ -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,
Expand All @@ -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),
});
});
},
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion packages/cli/src/commands/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
generateWrapFile,
defaultProjectManifestFiles,
defaultPolywrapManifest,
parseLogFileOption,
} from "../lib";
import { ScriptCodegenerator } from "../lib/codegen/ScriptCodeGenerator";

Expand All @@ -35,6 +36,7 @@ type CodegenCommandOptions = {
clientConfig: Partial<PolywrapClientConfig>;
verbose?: boolean;
quiet?: boolean;
logFile?: string;
};

export const codegen: Command = {
Expand Down Expand Up @@ -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,
Expand All @@ -82,6 +88,7 @@ export const codegen: Command = {
defaultProjectManifestFiles
),
publishDir: parseDirOption(options.publishDir, defaultPublishDir),
logFile: parseLogFileOption(options.logFile),
});
});
},
Expand All @@ -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);
Expand Down
34 changes: 28 additions & 6 deletions packages/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -28,6 +28,7 @@ type CreateCommandOptions = {
outputDir?: string;
verbose?: boolean;
quiet?: boolean;
logFile?: string;
};

export const create: Command = {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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),
});
});
},
};
Expand All @@ -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);

Expand Down
11 changes: 9 additions & 2 deletions packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PolywrapProject,
DeployJob,
DeployStep,
parseLogFileOption,
} from "../lib";

import { DeployManifest } from "@polywrap/polywrap-manifest-types-js";
Expand All @@ -25,6 +26,7 @@ type DeployCommandOptions = {
outputFile?: string;
verbose?: boolean;
quiet?: boolean;
logFile?: string;
};

type ManifestJob = DeployManifest["jobs"][number];
Expand All @@ -48,21 +50,26 @@ 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,
manifestFile: parseManifestFileOption(
options.manifestFile,
defaultPolywrapManifest
),
logFile: parseLogFileOption(options.logFile),
});
});
},
};

async function run(options: DeployCommandOptions): Promise<void> {
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),
Expand Down
10 changes: 9 additions & 1 deletion packages/cli/src/commands/docgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
parseManifestFileOption,
defaultProjectManifestFiles,
getProjectFromManifest,
parseLogFileOption,
} from "../lib";
import { Command, Program } from "./types";
import { createLogger } from "./utils/createLogger";
Expand Down Expand Up @@ -38,6 +39,7 @@ type DocgenCommandOptions = {
imports: boolean;
verbose?: boolean;
quiet?: boolean;
logFile?: string;
};

enum Actions {
Expand Down Expand Up @@ -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,
Expand All @@ -102,6 +108,7 @@ export const docgen: Command = {
),
docgenDir: parseDirOption(options.docgenDir, defaultDocgenDir),
clientConfig: await parseClientConfigOption(options.clientConfig),
logFile: parseLogFileOption(options.logFile),
});
});
},
Expand All @@ -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);

Expand Down
Loading