Skip to content

Commit ce24d77

Browse files
committed
improve projects commands
1 parent 90fd8f7 commit ce24d77

11 files changed

+159
-18
lines changed

.pnp.cjs

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

packages/cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@
4646
"@allurereport/static-server": "workspace:*",
4747
"cac": "^6.7.14",
4848
"lodash.omit": "^4.5.0",
49+
"prompts": "^2.4.2",
4950
"yoctocolors": "^2.1.1"
5051
},
5152
"devDependencies": {
5253
"@stylistic/eslint-plugin": "^2.6.1",
5354
"@types/eslint": "^8.56.11",
5455
"@types/lodash.omit": "^4.5.9",
5556
"@types/node": "^20.17.9",
57+
"@types/prompts": "^2",
5658
"@typescript-eslint/eslint-plugin": "^8.0.0",
5759
"@typescript-eslint/parser": "^8.0.0",
5860
"@vitest/runner": "^2.1.8",

packages/cli/src/commands/projects/create.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@ export const ProjectsCreateCommandAction = async (projectName: string) => {
99
const project = await historyService.createProject({
1010
name: projectName,
1111
});
12+
const lines: string[] = [
13+
`The "${green(project.name)}" has been created. Insert following code into your Allure Config file, to enable Allure Service features for the project:`,
14+
"",
15+
"{",
16+
" allureService:",
17+
` project: "${project.name}"`,
18+
" }",
19+
"}",
20+
];
1221

1322
// eslint-disable-next-line no-console
14-
console.info(`The ${project.name} ${`<${green(project.id)}>`} has been created`);
23+
console.info(lines.join("\n"));
1524
};
1625

1726
export const ProjectsCreateCommand = createCommand({
Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,58 @@
11
import { readConfig } from "@allurereport/core";
22
import { AllureService } from "@allurereport/service";
3+
import { exit } from "node:process";
4+
import prompts from "prompts";
35
import { createCommand } from "../../utils/commands.js";
46

5-
export const ProjectsDeleteCommandAction = async (projectId: string | undefined) => {
7+
export type ProjectsDeleteCommandOptions = {
8+
force?: boolean;
9+
};
10+
11+
export const ProjectsDeleteCommandAction = async (
12+
projectName: string | undefined,
13+
options?: ProjectsDeleteCommandOptions,
14+
) => {
15+
const { force = false } = options ?? {};
616
const config = await readConfig();
7-
const historyService = new AllureService(config?.allureService?.url);
17+
const allureService = new AllureService(config?.allureService?.url);
18+
19+
if (!projectName) {
20+
// eslint-disable-next-line no-console
21+
console.error("No project name is provided");
22+
exit(1);
23+
}
24+
25+
if (!force) {
26+
const res = await prompts({
27+
type: "confirm",
28+
name: "value",
29+
message: `Are you sure you want to delete project "${projectName}"?`,
30+
});
31+
32+
if (!res.value) {
33+
exit(0);
34+
}
35+
}
836

9-
await historyService.deleteProject({
10-
id: projectId!,
37+
await allureService.deleteProject({
38+
name: projectName,
1139
});
1240

1341
// eslint-disable-next-line no-console
1442
console.info("Project has been deleted");
1543
};
1644

1745
export const ProjectsDeleteCommand = createCommand({
18-
name: "project-delete <id>",
46+
name: "project-delete <name>",
1947
description: "",
20-
options: [],
48+
options: [
49+
[
50+
"--force",
51+
{
52+
description: "Delete project with no confirmation",
53+
default: false,
54+
},
55+
],
56+
],
2157
action: ProjectsDeleteCommandAction,
2258
});

packages/cli/src/commands/projects/list.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { readConfig } from "@allurereport/core";
22
import { AllureService } from "@allurereport/service";
3-
import { green } from "yoctocolors";
3+
import { exit } from "node:process";
4+
import prompts from "prompts";
45
import { createCommand } from "../../utils/commands.js";
56

67
export const ProjectsListCommandAction = async () => {
@@ -10,17 +11,35 @@ export const ProjectsListCommandAction = async () => {
1011

1112
if (projects.length === 0) {
1213
// eslint-disable-next-line no-console
13-
console.info("No projects found. Create a new one with `allure project create` command");
14+
console.info("No projects found. Create a new one with `allure create-project` command");
1415
return;
1516
}
1617

17-
const lines: string[] = ["You have following projects:"];
18+
const res = await prompts({
19+
type: "select",
20+
name: "project",
21+
message: "Select a project",
22+
choices: projects.map((project) => ({
23+
title: project.name,
24+
value: project.name,
25+
})),
26+
});
1827

19-
projects.forEach((project) => {
20-
const name = project.name.length > 20 ? `${project.name.slice(0, 17)}...` : project.name;
28+
if (!res?.project) {
29+
// eslint-disable-next-line no-console
30+
console.error("No project selected");
31+
exit(1);
32+
}
2133

22-
lines.push(`- ${name} ${green(`<${project.id}>`)}`);
23-
});
34+
const lines: string[] = [
35+
"Insert following code into your Allure Config file, to enable Allure Service features for the project:",
36+
"",
37+
"{",
38+
" allureService:",
39+
` project: "${res.project}"`,
40+
" }",
41+
"}",
42+
];
2443

2544
// eslint-disable-next-line no-console
2645
console.info(lines.join("\n"));

packages/service/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,12 @@ export class AllureService {
5555
async profile() {
5656
const { data } = await this.#client.get("/api/user/profile");
5757

58-
// TODO: introduce types
5958
return data as { email: string };
6059
}
6160

6261
async projects() {
6362
const { data } = await this.#client.get("/api/projects/list");
6463

65-
// TODO: introduce types
6664
return data as { id: string; name: string }[];
6765
}
6866

@@ -73,11 +71,10 @@ export class AllureService {
7371
},
7472
});
7573

76-
// TODO: introduce types
7774
return data as { id: string; name: string };
7875
}
7976

80-
async deleteProject(payload: { id: string }) {
77+
async deleteProject(payload: { name: string }) {
8178
const { data } = await this.#client.post("/api/projects/delete", payload, {
8279
headers: {
8380
"Content-Type": "application/json",

yarn.lock

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7562,6 +7562,16 @@ __metadata:
75627562
languageName: node
75637563
linkType: hard
75647564

7565+
"@types/prompts@npm:^2":
7566+
version: 2.4.9
7567+
resolution: "@types/prompts@npm:2.4.9"
7568+
dependencies:
7569+
"@types/node": "npm:*"
7570+
kleur: "npm:^3.0.3"
7571+
checksum: 10/69b8372f4c790b45fea16a46ff8d1bcc71b14579481776b67bd6263637118a7ecb1f12e1311506c29fadc81bf618dc64f1a91f903cfd5be67a0455a227b3e462
7572+
languageName: node
7573+
linkType: hard
7574+
75657575
"@types/prop-types@npm:^15.7.2":
75667576
version: 15.7.14
75677577
resolution: "@types/prop-types@npm:15.7.14"
@@ -8752,6 +8762,7 @@ __metadata:
87528762
"@types/eslint": "npm:^8.56.11"
87538763
"@types/lodash.omit": "npm:^4.5.9"
87548764
"@types/node": "npm:^20.17.9"
8765+
"@types/prompts": "npm:^2"
87558766
"@typescript-eslint/eslint-plugin": "npm:^8.0.0"
87568767
"@typescript-eslint/parser": "npm:^8.0.0"
87578768
"@vitest/runner": "npm:^2.1.8"
@@ -8766,6 +8777,7 @@ __metadata:
87668777
eslint-plugin-no-null: "npm:^1.0.2"
87678778
eslint-plugin-prefer-arrow: "npm:^1.2.3"
87688779
lodash.omit: "npm:^4.5.0"
8780+
prompts: "npm:^2.4.2"
87698781
rimraf: "npm:^6.0.1"
87708782
typescript: "npm:^5.6.3"
87718783
vitest: "npm:^2.1.8"
@@ -15188,6 +15200,13 @@ __metadata:
1518815200
languageName: node
1518915201
linkType: hard
1519015202

15203+
"kleur@npm:^3.0.3":
15204+
version: 3.0.3
15205+
resolution: "kleur@npm:3.0.3"
15206+
checksum: 10/0c0ecaf00a5c6173d25059c7db2113850b5457016dfa1d0e3ef26da4704fbb186b4938d7611246d86f0ddf1bccf26828daa5877b1f232a65e7373d0122a83e7f
15207+
languageName: node
15208+
linkType: hard
15209+
1519115210
"kolorist@npm:^1.6.0, kolorist@npm:^1.8.0":
1519215211
version: 1.8.0
1519315212
resolution: "kolorist@npm:1.8.0"
@@ -17935,6 +17954,16 @@ __metadata:
1793517954
languageName: node
1793617955
linkType: hard
1793717956

17957+
"prompts@npm:^2.4.2":
17958+
version: 2.4.2
17959+
resolution: "prompts@npm:2.4.2"
17960+
dependencies:
17961+
kleur: "npm:^3.0.3"
17962+
sisteransi: "npm:^1.0.5"
17963+
checksum: 10/c52536521a4d21eff4f2f2aa4572446cad227464066365a7167e52ccf8d9839c099f9afec1aba0eed3d5a2514b3e79e0b3e7a1dc326b9acde6b75d27ed74b1a9
17964+
languageName: node
17965+
linkType: hard
17966+
1793817967
"prop-types@npm:^15.7.2, prop-types@npm:^15.8.1":
1793917968
version: 15.8.1
1794017969
resolution: "prop-types@npm:15.8.1"
@@ -19281,6 +19310,13 @@ __metadata:
1928119310
languageName: node
1928219311
linkType: hard
1928319312

19313+
"sisteransi@npm:^1.0.5":
19314+
version: 1.0.5
19315+
resolution: "sisteransi@npm:1.0.5"
19316+
checksum: 10/aba6438f46d2bfcef94cf112c835ab395172c75f67453fe05c340c770d3c402363018ae1ab4172a1026a90c47eaccf3af7b6ff6fa749a680c2929bd7fa2b37a4
19317+
languageName: node
19318+
linkType: hard
19319+
1928419320
"slash@npm:^3.0.0":
1928519321
version: 3.0.0
1928619322
resolution: "slash@npm:3.0.0"

0 commit comments

Comments
 (0)