@argos-ci/cli 4.1.2 → 4.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/argos-cli.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import "../dist/index.js";
3
+ import "../dist/index.mjs";
package/dist/index.mjs ADDED
@@ -0,0 +1,104 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { fileURLToPath } from "node:url";
3
+ import { resolve } from "node:path";
4
+ import { Option, program } from "commander";
5
+ import { finalize, skip, upload } from "@argos-ci/core";
6
+ import ora from "ora";
7
+ //#region src/options.ts
8
+ const parallelNonceOption = new Option("--parallel-nonce <string>", "A unique ID for this parallel build").env("ARGOS_PARALLEL_NONCE");
9
+ const tokenOption = new Option("--token <token>", "Repository token").env("ARGOS_TOKEN");
10
+ const buildNameOption = new Option("--build-name <string>", "Name of the build, in case you want to run multiple Argos builds in a single CI job").env("ARGOS_BUILD_NAME");
11
+ //#endregion
12
+ //#region src/commands/upload.ts
13
+ function uploadCommand(program) {
14
+ program.command("upload").argument("<directory>", "Directory to upload").description("Upload screenshots to Argos").option("-f, --files <patterns...>", "One or more globs matching image file paths to upload", "**/*.{png,jpg,jpeg}").option("-i, --ignore <patterns...>", "One or more globs matching image file paths to ignore (ex: \"**/*.png **/diff.jpg\")").addOption(tokenOption).addOption(buildNameOption).addOption(new Option("--mode <string>", "Mode of comparison applied. CI for visual regression testing, monitoring for visual monitoring.").default("ci").choices(["ci", "monitoring"]).env("ARGOS_MODE")).addOption(new Option("--parallel", "Enable parallel mode. Run multiple Argos builds and combine them at the end").env("ARGOS_PARALLEL")).addOption(new Option("--parallel-total <number>", "The number of parallel nodes being ran").env("ARGOS_PARALLEL_TOTAL")).addOption(parallelNonceOption).addOption(new Option("--parallel-index <number>", "The index of the parallel node being ran (must be at least 1)").env("ARGOS_PARALLEL_INDEX")).addOption(new Option("--reference-branch <string>", "Branch used as baseline for screenshot comparison").env("ARGOS_REFERENCE_BRANCH")).addOption(new Option("--reference-commit <string>", "Commit used as baseline for screenshot comparison").env("ARGOS_REFERENCE_COMMIT")).addOption(new Option("--threshold <number>", "Sensitivity threshold between 0 and 1. The higher the threshold, the less sensitive the diff will be. Default to 0.5").env("ARGOS_THRESHOLD")).addOption(new Option("--subset", "Whether this build contains only a subset of screenshots.\nThis is useful when a build is created from an incomplete test suite where some tests are skipped.").env("ARGOS_SUBSET")).action(async (directory, options) => {
15
+ const spinner = ora("Uploading screenshots").start();
16
+ try {
17
+ const parallel = (() => {
18
+ if (!options.parallel) return;
19
+ if (!options.parallelNonce) {
20
+ spinner.fail("--parallel-nonce is required if --parallel is set");
21
+ process.exit(1);
22
+ }
23
+ if (!options.parallelTotal) {
24
+ spinner.fail("--parallel-total is required if --parallel is set");
25
+ process.exit(1);
26
+ }
27
+ return {
28
+ nonce: options.parallelNonce,
29
+ total: options.parallelTotal,
30
+ index: options.parallelIndex
31
+ };
32
+ })();
33
+ const result = await upload({
34
+ token: options.token,
35
+ root: directory,
36
+ buildName: options.buildName,
37
+ files: options.files,
38
+ ignore: options.ignore,
39
+ parallel,
40
+ referenceBranch: options.referenceBranch,
41
+ referenceCommit: options.referenceCommit,
42
+ mode: options.mode,
43
+ threshold: options.threshold,
44
+ subset: options.subset
45
+ });
46
+ spinner.succeed(`Build created: ${result.build.url}`);
47
+ } catch (error) {
48
+ if (error instanceof Error) {
49
+ spinner.fail(`Build failed: ${error.message}`);
50
+ console.error(error.stack);
51
+ }
52
+ process.exit(1);
53
+ }
54
+ });
55
+ }
56
+ //#endregion
57
+ //#region src/commands/finalize.ts
58
+ function finalizeCommand(program) {
59
+ program.command("finalize").description("Finalize pending parallel builds").addOption(parallelNonceOption).action(async (options) => {
60
+ const spinner = ora("Finalizing builds").start();
61
+ try {
62
+ const result = await finalize({ parallel: options.parallelNonce ? { nonce: options.parallelNonce } : void 0 });
63
+ spinner.succeed(result.builds.length === 0 ? "No builds to finalize" : `Builds finalized: ${result.builds.map((b) => b.url).join(", ")}`);
64
+ } catch (error) {
65
+ if (error instanceof Error) {
66
+ spinner.fail(`Failed to finalize: ${error.message}`);
67
+ console.error(error.stack);
68
+ }
69
+ process.exit(1);
70
+ }
71
+ });
72
+ }
73
+ //#endregion
74
+ //#region src/commands/skip.ts
75
+ function skipCommand(program) {
76
+ program.command("skip").description("Mark a build as skipped").addOption(tokenOption).addOption(buildNameOption).action(async (options) => {
77
+ const spinner = ora("Creating skipped build").start();
78
+ try {
79
+ const result = await skip({
80
+ token: options.token,
81
+ buildName: options.buildName
82
+ });
83
+ spinner.succeed(`Build created: ${result.build.url}`);
84
+ } catch (error) {
85
+ if (error instanceof Error) {
86
+ spinner.fail(`Build failed: ${error.message}`);
87
+ console.error(error.stack);
88
+ }
89
+ process.exit(1);
90
+ }
91
+ });
92
+ }
93
+ //#endregion
94
+ //#region src/index.ts
95
+ const rawPkg = await readFile(resolve(fileURLToPath(new URL(".", import.meta.url)), "..", "package.json"), "utf8");
96
+ const pkg = JSON.parse(rawPkg);
97
+ program.name(pkg.name).description("Interact with and upload screenshots to Argos via command line.").version(pkg.version);
98
+ uploadCommand(program);
99
+ skipCommand(program);
100
+ finalizeCommand(program);
101
+ if (!process.argv.slice(2).length) program.outputHelp();
102
+ else program.parse(process.argv);
103
+ //#endregion
104
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/cli",
3
3
  "description": "Command-line (CLI) for visual testing with Argos.",
4
- "version": "4.1.2",
4
+ "version": "4.1.4",
5
5
  "bin": {
6
6
  "argos": "./bin/argos-cli.js"
7
7
  },
@@ -34,17 +34,17 @@
34
34
  "access": "public"
35
35
  },
36
36
  "dependencies": {
37
- "@argos-ci/core": "5.1.2",
37
+ "@argos-ci/core": "5.2.0",
38
38
  "commander": "^14.0.3",
39
- "ora": "^9.1.0",
39
+ "ora": "^9.3.0",
40
40
  "update-notifier": "^7.3.1"
41
41
  },
42
42
  "scripts": {
43
- "build": "tsup",
43
+ "build": "tsdown",
44
44
  "e2e": "node e2e/upload.js && node e2e/skip.js",
45
45
  "check-types": "tsc",
46
46
  "check-format": "prettier --check --ignore-unknown --ignore-path=../../.gitignore --ignore-path=../../.prettierignore .",
47
47
  "lint": "eslint ."
48
48
  },
49
- "gitHead": "3e325792c50e801034c3248d94d7b1dc91bede71"
49
+ "gitHead": "82add1422f689642095d43a9e3bb0d2a008728af"
50
50
  }
package/dist/index.js DELETED
@@ -1,180 +0,0 @@
1
- // src/index.ts
2
- import { readFile } from "fs/promises";
3
- import { fileURLToPath } from "url";
4
- import { resolve } from "path";
5
- import { program } from "commander";
6
-
7
- // src/commands/upload.ts
8
- import { Option as Option2 } from "commander";
9
- import { upload } from "@argos-ci/core";
10
- import ora from "ora";
11
-
12
- // src/options.ts
13
- import { Option } from "commander";
14
- var parallelNonceOption = new Option(
15
- "--parallel-nonce <string>",
16
- "A unique ID for this parallel build"
17
- ).env("ARGOS_PARALLEL_NONCE");
18
- var tokenOption = new Option(
19
- "--token <token>",
20
- "Repository token"
21
- ).env("ARGOS_TOKEN");
22
- var buildNameOption = new Option(
23
- "--build-name <string>",
24
- "Name of the build, in case you want to run multiple Argos builds in a single CI job"
25
- ).env("ARGOS_BUILD_NAME");
26
-
27
- // src/commands/upload.ts
28
- function uploadCommand(program2) {
29
- program2.command("upload").argument("<directory>", "Directory to upload").description("Upload screenshots to Argos").option(
30
- "-f, --files <patterns...>",
31
- "One or more globs matching image file paths to upload",
32
- "**/*.{png,jpg,jpeg}"
33
- ).option(
34
- "-i, --ignore <patterns...>",
35
- 'One or more globs matching image file paths to ignore (ex: "**/*.png **/diff.jpg")'
36
- ).addOption(tokenOption).addOption(buildNameOption).addOption(
37
- new Option2(
38
- "--mode <string>",
39
- "Mode of comparison applied. CI for visual regression testing, monitoring for visual monitoring."
40
- ).default("ci").choices(["ci", "monitoring"]).env("ARGOS_MODE")
41
- ).addOption(
42
- new Option2(
43
- "--parallel",
44
- "Enable parallel mode. Run multiple Argos builds and combine them at the end"
45
- ).env("ARGOS_PARALLEL")
46
- ).addOption(
47
- new Option2(
48
- "--parallel-total <number>",
49
- "The number of parallel nodes being ran"
50
- ).env("ARGOS_PARALLEL_TOTAL")
51
- ).addOption(parallelNonceOption).addOption(
52
- new Option2(
53
- "--parallel-index <number>",
54
- "The index of the parallel node being ran (must be at least 1)"
55
- ).env("ARGOS_PARALLEL_INDEX")
56
- ).addOption(
57
- new Option2(
58
- "--reference-branch <string>",
59
- "Branch used as baseline for screenshot comparison"
60
- ).env("ARGOS_REFERENCE_BRANCH")
61
- ).addOption(
62
- new Option2(
63
- "--reference-commit <string>",
64
- "Commit used as baseline for screenshot comparison"
65
- ).env("ARGOS_REFERENCE_COMMIT")
66
- ).addOption(
67
- new Option2(
68
- "--threshold <number>",
69
- "Sensitivity threshold between 0 and 1. The higher the threshold, the less sensitive the diff will be. Default to 0.5"
70
- ).env("ARGOS_THRESHOLD")
71
- ).addOption(
72
- new Option2(
73
- "--subset",
74
- "Whether this build contains only a subset of screenshots.\nThis is useful when a build is created from an incomplete test suite where some tests are skipped."
75
- ).env("ARGOS_SUBSET")
76
- ).action(async (directory, options) => {
77
- const spinner = ora("Uploading screenshots").start();
78
- try {
79
- const parallel = (() => {
80
- if (!options.parallel) {
81
- return void 0;
82
- }
83
- if (!options.parallelNonce) {
84
- spinner.fail("--parallel-nonce is required if --parallel is set");
85
- process.exit(1);
86
- }
87
- if (!options.parallelTotal) {
88
- spinner.fail("--parallel-total is required if --parallel is set");
89
- process.exit(1);
90
- }
91
- return {
92
- nonce: options.parallelNonce,
93
- total: options.parallelTotal,
94
- index: options.parallelIndex
95
- };
96
- })();
97
- const result = await upload({
98
- token: options.token,
99
- root: directory,
100
- buildName: options.buildName,
101
- files: options.files,
102
- ignore: options.ignore,
103
- parallel,
104
- referenceBranch: options.referenceBranch,
105
- referenceCommit: options.referenceCommit,
106
- mode: options.mode,
107
- threshold: options.threshold,
108
- subset: options.subset
109
- });
110
- spinner.succeed(`Build created: ${result.build.url}`);
111
- } catch (error) {
112
- if (error instanceof Error) {
113
- spinner.fail(`Build failed: ${error.message}`);
114
- console.error(error.stack);
115
- }
116
- process.exit(1);
117
- }
118
- });
119
- }
120
-
121
- // src/commands/finalize.ts
122
- import ora2 from "ora";
123
- import { finalize } from "@argos-ci/core";
124
- function finalizeCommand(program2) {
125
- program2.command("finalize").description("Finalize pending parallel builds").addOption(parallelNonceOption).action(async (options) => {
126
- const spinner = ora2("Finalizing builds").start();
127
- try {
128
- const result = await finalize({
129
- parallel: options.parallelNonce ? { nonce: options.parallelNonce } : void 0
130
- });
131
- spinner.succeed(
132
- result.builds.length === 0 ? "No builds to finalize" : `Builds finalized: ${result.builds.map((b) => b.url).join(", ")}`
133
- );
134
- } catch (error) {
135
- if (error instanceof Error) {
136
- spinner.fail(`Failed to finalize: ${error.message}`);
137
- console.error(error.stack);
138
- }
139
- process.exit(1);
140
- }
141
- });
142
- }
143
-
144
- // src/commands/skip.ts
145
- import { skip } from "@argos-ci/core";
146
- import ora3 from "ora";
147
- function skipCommand(program2) {
148
- program2.command("skip").description("Mark a build as skipped").addOption(tokenOption).addOption(buildNameOption).action(async (options) => {
149
- const spinner = ora3("Creating skipped build").start();
150
- try {
151
- const result = await skip({
152
- token: options.token,
153
- buildName: options.buildName
154
- });
155
- spinner.succeed(`Build created: ${result.build.url}`);
156
- } catch (error) {
157
- if (error instanceof Error) {
158
- spinner.fail(`Build failed: ${error.message}`);
159
- console.error(error.stack);
160
- }
161
- process.exit(1);
162
- }
163
- });
164
- }
165
-
166
- // src/index.ts
167
- var __dirname = fileURLToPath(new URL(".", import.meta.url));
168
- var rawPkg = await readFile(resolve(__dirname, "..", "package.json"), "utf8");
169
- var pkg = JSON.parse(rawPkg);
170
- program.name(pkg.name).description(
171
- "Interact with and upload screenshots to Argos via command line."
172
- ).version(pkg.version);
173
- uploadCommand(program);
174
- skipCommand(program);
175
- finalizeCommand(program);
176
- if (!process.argv.slice(2).length) {
177
- program.outputHelp();
178
- } else {
179
- program.parse(process.argv);
180
- }