regressify 1.0.1 → 1.0.3

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.
@@ -5,8 +5,11 @@ on:
5
5
  branches:
6
6
  - release
7
7
  paths:
8
- - src/**
9
8
  - .engine_scripts/**
9
+ - src/**
10
+ - package.json
11
+ - cli.js
12
+ - generate-tests.js
10
13
 
11
14
  workflow_dispatch:
12
15
 
package/README.md CHANGED
@@ -13,7 +13,7 @@ Please check [Documentation](https://tuyen.blog/optimizely-cms/testing/get-start
13
13
  1. Manual Set up all test and config files in the **visual_tests** folder and place it at the root of the project, or automatically add it using the command:
14
14
 
15
15
  ```bash
16
- npx regressify-cli generate
16
+ npx regressify-cli init
17
17
  ```
18
18
 
19
19
  1. Add to scripts in package.json:
package/cli.js ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs';
3
+ import path, { dirname } from 'path';
4
+ import { exec } from 'child_process';
5
+ import { fileURLToPath, pathToFileURL } from 'url';
6
+ import chalk from 'chalk';
7
+
8
+ function getLibraryPath() {
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = dirname(__filename);
11
+
12
+ let currentDir = __dirname;
13
+ while (!fs.existsSync(path.join(currentDir, 'package.json'))) {
14
+ const parentDir = path.dirname(currentDir);
15
+ if (parentDir === currentDir) {
16
+ return null;
17
+ }
18
+ currentDir = parentDir;
19
+ }
20
+ const packageJsonPath = path.join(currentDir, 'package.json');
21
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
22
+ return `node_modules/${packageJson.name}`;
23
+ }
24
+
25
+ function runCommand(command) {
26
+ const childProcess = exec(command, { env: { ...process.env, FORCE_COLOR: '1' } });
27
+
28
+ childProcess.stdout.on('data', (data) => {
29
+ process.stdout.write(data);
30
+ });
31
+
32
+ childProcess.stderr.on('data', (data) => {
33
+ process.stderr.write(data);
34
+ });
35
+
36
+ childProcess.on('close', (code) => {
37
+ if (code !== 0) {
38
+ console.log(chalk.red(`Command exited with code ${code}`));
39
+ }
40
+ });
41
+
42
+ childProcess.on('error', (err) => {
43
+ console.log(chalk.red(`Failed to start command: ${err.message}`));
44
+ });
45
+ }
46
+
47
+ const args = process.argv.slice(2);
48
+ let commandBase = `tsx ${getLibraryPath()}/src/index.ts`;
49
+
50
+ if (args[0] === 'init') {
51
+ const __filename = fileURLToPath(import.meta.url);
52
+ const __dirname = dirname(__filename);
53
+ const postInstallPath = pathToFileURL(path.join(__dirname, 'generate_tests.js'));
54
+ if (fs.existsSync(postInstallPath)) {
55
+ console.log(chalk.yellow('generate folder visual_tests ...'));
56
+ await import(postInstallPath);
57
+ } else {
58
+ console.log(chalk.red('generate_tests.js not found!'));
59
+ }
60
+ } else if (args[0] === 'ref') {
61
+ const command = `${commandBase} --command test --ref ${args.slice(1).join(' ')}`;
62
+ console.log(chalk.yellow(`Running command: ${command}`));
63
+ runCommand(command);
64
+ } else if (args[0] === 'approve') {
65
+ const command = `${commandBase} --command approve ${args.slice(1).join(' ')}`;
66
+ console.log(chalk.yellow(`Running command: ${command}`));
67
+ runCommand(command);
68
+ } else if (args[0] === 'test') {
69
+ const command = `${commandBase} --command test ${args.slice(1).join(' ')}`;
70
+ console.log(chalk.yellow(`Running command: ${command}`));
71
+ runCommand(command);
72
+ } else {
73
+ console.log(chalk.red("Invalid command. Use one of the following: 'regressify init' 'regressify ref', 'regressify approve', 'regressify test'."));
74
+ }
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "regressify",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Visual regression tests support",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "bin": {
8
- "init": "./init.js",
9
- "ref": "./ref.js",
10
- "test": "./test.js",
11
- "approve": "./approve.js"
8
+ "regressify": "./cli.js"
12
9
  },
13
10
  "scripts": {
14
11
  "ref": "tsx src/index.ts --command test --ref",
package/approve.js DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env node
2
- import chalk from 'chalk';
3
- import { runCommand } from './helpers';
4
-
5
- const args = process.argv.slice(2);
6
- let commandBase = `tsx ${getLibraryPath()}/src/index.ts`;
7
-
8
- const command = `${commandBase} --command approve ${args.slice(1).join(' ')}`;
9
- console.log(chalk.yellow(`Running command: ${command}`));
10
- runCommand(command);
package/init.js DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env node
2
- import fs from 'fs';
3
- import path, { dirname } from 'path';
4
- import { fileURLToPath, pathToFileURL } from 'url';
5
- import chalk from 'chalk';
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = dirname(__filename);
9
- const postInstallPath = pathToFileURL(path.join(__dirname, 'generate_tests.js'));
10
- if (fs.existsSync(postInstallPath)) {
11
- console.log(chalk.yellow('generate folder visual_tests ...'));
12
- await import(postInstallPath);
13
- } else {
14
- console.log(chalk.red('generate_tests.js not found!'));
15
- }
package/ref.js DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
- import chalk from 'chalk';
3
-
4
- const args = process.argv.slice(2);
5
- let commandBase = `tsx ${getLibraryPath()}/src/index.ts`;
6
-
7
- const command = `${commandBase} --command test --ref ${args.slice(1).join(' ')}`;
8
- console.log(chalk.yellow(`Running command: ${command}`));
package/test.js DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env node
2
- import chalk from 'chalk';
3
-
4
- const args = process.argv.slice(2);
5
- let commandBase = `tsx ${getLibraryPath()}/src/index.ts`;
6
-
7
- const command = `${commandBase} --command test ${args.slice(1).join(' ')}`;
8
- console.log(chalk.yellow(`Running command: ${command}`));
9
- runCommand(command);