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

Add programmatic API #45

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion packages/cli/cli.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#!/usr/bin/env node
import "./dist/index.js";
import { argv } from "node:process";
import run from "./dist/index.js";

run(argv.slice(2).join(" "));
72 changes: 43 additions & 29 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,52 @@ import {
WatchCommand,
} from "./commands/index.js";

const pkg: { name: string; description: string; version: string } = JSON.parse(
readFileSync(new URL("../package.json", import.meta.url), "utf8"),
);
/**
* Programmatic entry point for the Allure 3 CLI
* @param argv the array of arguments which already doesn't includes the node binary and the script path (the first two elements)
* @example
* ```js
* import allure from "allure";
*
* allure("run -- npm test"]); // equivalent to `allure run -- npm test`
* allure("generate ./allure-results"); // equivalent to `allure generate ./allure-results`
* ```
*/
const run = (argv: string) => {
const pkg: { name: string; description: string; version: string } = JSON.parse(
readFileSync(new URL("../package.json", import.meta.url), "utf8"),
);
const cli = cac(pkg.name).usage(pkg.description).help().version(pkg.version);
const commands = [
ClassicCommand,
AwesomeCommand,
CsvCommand,
GenerateCommand,
HistoryCommand,
KnownIssueCommand,
LogCommand,
OpenCommand,
QualityGateCommand,
RunCommand,
SlackCommand,
TestPlanCommand,
WatchCommand,
];

const cli = cac(pkg.name).usage(pkg.description).help().version(pkg.version);
const commands = [
ClassicCommand,
AwesomeCommand,
CsvCommand,
GenerateCommand,
HistoryCommand,
KnownIssueCommand,
LogCommand,
OpenCommand,
QualityGateCommand,
RunCommand,
SlackCommand,
TestPlanCommand,
WatchCommand,
];

commands.forEach((command) => {
command(cli);
});
commands.forEach((command) => {
command(cli);
});

cli.on("command:*", () => {
console.error("Invalid command: %s", cli.args.join(" "));
process.exit(1);
});
cli.on("command:*", () => {
console.error("Invalid command: %s", cli.args.join(" "));
process.exit(1);
});

console.log(cwd());
console.log(cwd());

cli.parse();
cli.parse(["", "", ...argv.split(" ")]);
};

export { defineConfig } from "@allurereport/plugin-api";

export default run;
1 change: 1 addition & 0 deletions packages/cli/src/utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const createCommand = (payload: CreateCommandOptions) => {
if (!payload.name) {
throw new Error("Command name is not provided!");
}

if (!payload.action) {
throw new Error("Command action is not provided!");
}
Expand Down
Loading