Skip to content

Commit 376bfe2

Browse files
authored
Use config in the commands (#215)
1 parent 0fa44f8 commit 376bfe2

File tree

33 files changed

+929
-355
lines changed

33 files changed

+929
-355
lines changed

.pnp.cjs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
"@allurereport/plugin-api": "workspace:*",
3838
"@allurereport/plugin-awesome": "workspace:*",
3939
"@allurereport/plugin-classic": "workspace:*",
40+
"@allurereport/plugin-csv": "workspace:*",
4041
"@allurereport/plugin-dashboard": "workspace:*",
42+
"@allurereport/plugin-log": "workspace:*",
4143
"@allurereport/plugin-progress": "workspace:*",
4244
"@allurereport/plugin-server-reload": "workspace:*",
4345
"@allurereport/plugin-slack": "workspace:*",

packages/cli/src/commands/allure2.ts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { AllureReport, resolveConfig } from "@allurereport/core";
1+
import { AllureReport, enforcePlugin, readConfig } from "@allurereport/core";
2+
import Allure2Plugin, { type Allure2PluginOptions } from "@allurereport/plugin-allure2";
23
import * as console from "node:console";
4+
import { realpath } from "node:fs/promises";
5+
import process from "node:process";
36
import { createCommand } from "../utils/commands.js";
47

58
type ClassicCommandOptions = {
9+
cwd?: string;
10+
config?: string;
611
output?: string;
712
reportName?: string;
813
reportLanguage?: string;
@@ -12,19 +17,26 @@ type ClassicCommandOptions = {
1217
};
1318

1419
export const ClassicLegacyCommandAction = async (resultsDir: string, options: ClassicCommandOptions) => {
20+
const cwd = await realpath(options.cwd ?? process.cwd());
1521
const before = new Date().getTime();
16-
const { output, reportName: name, historyPath, knownIssues: knownIssuesPath, ...rest } = options;
17-
const config = await resolveConfig({
18-
output,
19-
name,
20-
historyPath,
21-
knownIssuesPath,
22-
plugins: {
23-
"@allurereport/plugin-allure2": {
24-
options: rest,
25-
},
22+
const { config: configPath, output, reportName, historyPath, knownIssues: knownIssuesPath, ...rest } = options;
23+
const defaultAllure2Options = {
24+
...rest,
25+
} as Allure2PluginOptions;
26+
const config = enforcePlugin(
27+
await readConfig(cwd, configPath, {
28+
output,
29+
name: reportName,
30+
knownIssuesPath,
31+
historyPath,
32+
}),
33+
{
34+
id: "allure2",
35+
enabled: true,
36+
options: defaultAllure2Options,
37+
plugin: new Allure2Plugin(defaultAllure2Options),
2638
},
27-
});
39+
);
2840
const allureReport = new AllureReport(config);
2941

3042
await allureReport.start();
@@ -40,6 +52,18 @@ export const ClassicLegacyCommand = createCommand({
4052
name: "allure2 <resultsDir>",
4153
description: "Generates Allure Classic report based on provided Allure Results",
4254
options: [
55+
[
56+
"--config, -c <file>",
57+
{
58+
description: "The path Allure config file",
59+
},
60+
],
61+
[
62+
"--cwd <cwd>",
63+
{
64+
description: "The working directory for the command to run (Default: current working directory)",
65+
},
66+
],
4367
[
4468
"--output, -o <file>",
4569
{

packages/cli/src/commands/awesome.ts

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { AllureReport, resolveConfig } from "@allurereport/core";
1+
import { AllureReport, enforcePlugin, readConfig } from "@allurereport/core";
2+
import { default as AwesomePlugin, type AwesomePluginOptions } from "@allurereport/plugin-awesome";
23
import * as console from "node:console";
4+
import { realpath } from "node:fs/promises";
5+
import process from "node:process";
36
import { createCommand } from "../utils/commands.js";
47

58
type AwesomeCommandOptions = {
9+
cwd?: string;
10+
config?: string;
611
output?: string;
712
reportName?: string;
813
reportLanguage?: string;
@@ -14,22 +19,35 @@ type AwesomeCommandOptions = {
1419
};
1520

1621
export const AwesomeCommandAction = async (resultsDir: string, options: AwesomeCommandOptions) => {
22+
const cwd = await realpath(options.cwd ?? process.cwd());
1723
const before = new Date().getTime();
18-
const { output, reportName: name, historyPath, knownIssues: knownIssuesPath, groupBy, ...rest } = options;
19-
const config = await resolveConfig({
24+
const {
25+
config: configPath,
2026
output,
21-
name,
27+
reportName,
2228
historyPath,
23-
knownIssuesPath,
24-
plugins: {
25-
"@allurereport/plugin-awesome": {
26-
options: {
27-
...rest,
28-
groupBy: groupBy?.split(","),
29-
},
30-
},
29+
knownIssues: knownIssuesPath,
30+
groupBy,
31+
...rest
32+
} = options;
33+
const defaultAwesomeOptions = {
34+
...rest,
35+
groupBy: groupBy?.split(","),
36+
} as AwesomePluginOptions;
37+
const config = enforcePlugin(
38+
await readConfig(cwd, configPath, {
39+
output,
40+
name: reportName,
41+
knownIssuesPath,
42+
historyPath,
43+
}),
44+
{
45+
id: "awesome",
46+
enabled: true,
47+
options: defaultAwesomeOptions,
48+
plugin: new AwesomePlugin(defaultAwesomeOptions),
3149
},
32-
});
50+
);
3351
const allureReport = new AllureReport(config);
3452

3553
await allureReport.start();
@@ -45,6 +63,18 @@ export const AwesomeCommand = createCommand({
4563
name: "awesome <resultsDir>",
4664
description: "Generates Allure Awesome report based on provided Allure Results",
4765
options: [
66+
[
67+
"--config, -c <file>",
68+
{
69+
description: "The path Allure config file",
70+
},
71+
],
72+
[
73+
"--cwd <cwd>",
74+
{
75+
description: "The working directory for the command to run (Default: current working directory)",
76+
},
77+
],
4878
[
4979
"--output, -o <file>",
5080
{

packages/cli/src/commands/classic.ts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { AllureReport, resolveConfig } from "@allurereport/core";
1+
import { AllureReport, enforcePlugin, readConfig } from "@allurereport/core";
2+
import ClassicPlugin, { type ClassicPluginOptions } from "@allurereport/plugin-classic";
23
import * as console from "node:console";
4+
import { realpath } from "node:fs/promises";
5+
import process from "node:process";
36
import { createCommand } from "../utils/commands.js";
47

58
type ClassicCommandOptions = {
9+
cwd?: string;
10+
config?: string;
611
output?: string;
712
reportName?: string;
813
reportLanguage?: string;
@@ -12,19 +17,26 @@ type ClassicCommandOptions = {
1217
};
1318

1419
export const ClassicCommandAction = async (resultsDir: string, options: ClassicCommandOptions) => {
20+
const cwd = await realpath(options.cwd ?? process.cwd());
1521
const before = new Date().getTime();
16-
const { output, reportName: name, historyPath, knownIssues: knownIssuesPath, ...rest } = options;
17-
const config = await resolveConfig({
18-
output,
19-
name,
20-
historyPath,
21-
knownIssuesPath,
22-
plugins: {
23-
"@allurereport/plugin-classic": {
24-
options: rest,
25-
},
22+
const { config: configPath, output, reportName: name, historyPath, knownIssues: knownIssuesPath, ...rest } = options;
23+
const defaultClassicOptions = {
24+
...rest,
25+
} as ClassicPluginOptions;
26+
const config = enforcePlugin(
27+
await readConfig(cwd, configPath, {
28+
output,
29+
name,
30+
historyPath,
31+
knownIssuesPath,
32+
}),
33+
{
34+
id: "classic",
35+
enabled: true,
36+
options: defaultClassicOptions,
37+
plugin: new ClassicPlugin(defaultClassicOptions),
2638
},
27-
});
39+
);
2840
const allureReport = new AllureReport(config);
2941

3042
await allureReport.start();
@@ -40,6 +52,18 @@ export const ClassicCommand = createCommand({
4052
name: "classic <resultsDir>",
4153
description: "Generates Allure Classic report based on provided Allure Results",
4254
options: [
55+
[
56+
"--config, -c <file>",
57+
{
58+
description: "The path Allure config file",
59+
},
60+
],
61+
[
62+
"--cwd <cwd>",
63+
{
64+
description: "The working directory for the command to run (Default: current working directory)",
65+
},
66+
],
4367
[
4468
"--output, -o <file>",
4569
{

packages/cli/src/commands/csv.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
1-
import { AllureReport, resolveConfig } from "@allurereport/core";
1+
import { AllureReport, enforcePlugin, readConfig } from "@allurereport/core";
2+
import CsvPlugin, { type CsvPluginOptions } from "@allurereport/plugin-csv";
23
import * as console from "node:console";
4+
import { realpath } from "node:fs/promises";
5+
import process from "node:process";
36
import { createCommand } from "../utils/commands.js";
47

58
type CsvCommandOptions = {
9+
cwd?: string;
10+
config?: string;
611
separator?: string;
712
disableHeaders?: boolean;
813
output?: string;
914
knownIssues?: string;
1015
};
1116

1217
export const CsvCommandAction = async (resultsDir: string, options: CsvCommandOptions) => {
18+
const cwd = await realpath(options.cwd ?? process.cwd());
1319
const before = new Date().getTime();
14-
const config = await resolveConfig({
15-
plugins: {
16-
"@allurereport/plugin-csv": {
17-
options,
18-
},
20+
const { config: configPath, output, knownIssues: knownIssuesPath, separator, disableHeaders } = options;
21+
const defaultCsvOptions = {
22+
separator,
23+
disableHeaders,
24+
} as CsvPluginOptions;
25+
const config = enforcePlugin(
26+
await readConfig(cwd, configPath, {
27+
output,
28+
knownIssuesPath,
29+
}),
30+
{
31+
id: "csv",
32+
enabled: true,
33+
options: defaultCsvOptions,
34+
plugin: new CsvPlugin(defaultCsvOptions),
1935
},
20-
});
36+
);
2137
const allureReport = new AllureReport(config);
2238

2339
await allureReport.start();
@@ -33,6 +49,18 @@ export const CsvCommand = createCommand({
3349
name: "csv <resultsDir>",
3450
description: "Generates CSV report based on provided Allure Results",
3551
options: [
52+
[
53+
"--config, -c <file>",
54+
{
55+
description: "The path Allure config file",
56+
},
57+
],
58+
[
59+
"--cwd <cwd>",
60+
{
61+
description: "The working directory for the command to run (Default: current working directory)",
62+
},
63+
],
3664
[
3765
"--output, -o <file>",
3866
{

packages/cli/src/commands/dashboard.ts

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { AllureReport, resolveConfig } from "@allurereport/core";
1+
import { AllureReport, enforcePlugin, readConfig } from "@allurereport/core";
2+
import DashboardPlugin, { type DashboardPluginOptions } from "@allurereport/plugin-dashboard";
23
import * as console from "node:console";
4+
import { realpath } from "node:fs/promises";
5+
import process from "node:process";
36
import { createCommand } from "../utils/commands.js";
47

58
type DashboardCommandOptions = {
9+
cwd?: string;
10+
config?: string;
611
output?: string;
712
reportName?: string;
813
reportLanguage?: string;
@@ -12,17 +17,25 @@ type DashboardCommandOptions = {
1217
};
1318

1419
export const DashboardCommandAction = async (resultsDir: string, options: DashboardCommandOptions) => {
20+
const cwd = await realpath(options.cwd ?? process.cwd());
1521
const before = new Date().getTime();
16-
const { output, reportName: name, ...rest } = options;
17-
const config = await resolveConfig({
18-
output,
19-
name,
20-
plugins: {
21-
"@allurereport/plugin-dashboard": {
22-
options: rest,
23-
},
22+
const { config: configPath, output, reportName: name, ...rest } = options;
23+
const defaultDashboardOptions = {
24+
...rest,
25+
reportLanguage: rest.reportLanguage ?? "en",
26+
} as DashboardPluginOptions;
27+
const config = enforcePlugin(
28+
await readConfig(cwd, configPath, {
29+
output,
30+
name,
31+
}),
32+
{
33+
id: "dashboard",
34+
enabled: true,
35+
options: defaultDashboardOptions,
36+
plugin: new DashboardPlugin(defaultDashboardOptions),
2437
},
25-
});
38+
);
2639
const allureReport = new AllureReport(config);
2740

2841
await allureReport.start();
@@ -38,6 +51,18 @@ export const DashboardCommand = createCommand({
3851
name: "dashboard <resultsDir>",
3952
description: "Generates Allure Dashboard report based on provided Allure Results",
4053
options: [
54+
[
55+
"--config, -c <file>",
56+
{
57+
description: "The path Allure config file",
58+
},
59+
],
60+
[
61+
"--cwd <cwd>",
62+
{
63+
description: "The working directory for the command to run (Default: current working directory)",
64+
},
65+
],
4166
[
4267
"--output, -o <file>",
4368
{

0 commit comments

Comments
 (0)