@regressionproof/cli 0.7.4 → 0.9.0
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/build/cli.js +21 -45
- package/build/commands/CommandRunner.d.ts +7 -0
- package/build/commands/CommandRunner.js +15 -0
- package/build/commands/commands.d.ts +7 -0
- package/build/commands/commands.js +118 -0
- package/build/components/Banner.d.ts +2 -0
- package/build/components/Banner.js +13 -0
- package/build/components/Banner.tsx +20 -0
- package/build/components/CommandHeading.d.ts +6 -0
- package/build/components/CommandHeading.js +5 -0
- package/build/components/CommandHeading.tsx +10 -0
- package/build/components/CommandLayout.d.ts +7 -0
- package/build/components/CommandLayout.js +8 -0
- package/build/components/CommandLayout.tsx +17 -0
- package/build/components/Doctor.d.ts +7 -0
- package/build/components/Doctor.js +43 -0
- package/build/components/Doctor.tsx +63 -0
- package/build/components/Init.js +2 -5
- package/build/components/Init.tsx +2 -10
- package/build/doctor/Doctor.d.ts +8 -0
- package/build/doctor/Doctor.js +55 -0
- package/build/doctor/DoctorContext.d.ts +14 -0
- package/build/doctor/DoctorContext.js +48 -0
- package/build/doctor/DoctorOutput.d.ts +6 -0
- package/build/doctor/DoctorOutput.js +32 -0
- package/build/doctor/DoctorResult.d.ts +8 -0
- package/build/doctor/DoctorResult.js +1 -0
- package/build/doctor/DoctorRunner.d.ts +9 -0
- package/build/doctor/DoctorRunner.js +13 -0
- package/build/doctor/checks/ApiReachabilityCheck.d.ts +5 -0
- package/build/doctor/checks/ApiReachabilityCheck.js +41 -0
- package/build/doctor/checks/CredentialsCheck.d.ts +6 -0
- package/build/doctor/checks/CredentialsCheck.js +55 -0
- package/build/doctor/checks/JestReporterCheck.d.ts +5 -0
- package/build/doctor/checks/JestReporterCheck.js +35 -0
- package/build/doctor/checks/LocalConfigCheck.d.ts +5 -0
- package/build/doctor/checks/LocalConfigCheck.js +17 -0
- package/build/doctor/checks/MirrorAccessCheck.d.ts +12 -0
- package/build/doctor/checks/MirrorAccessCheck.js +210 -0
- package/build/esm/cli.js +21 -45
- package/build/esm/commands/CommandRunner.d.ts +7 -0
- package/build/esm/commands/CommandRunner.js +26 -0
- package/build/esm/commands/commands.d.ts +7 -0
- package/build/esm/commands/commands.js +128 -0
- package/build/esm/components/Banner.d.ts +2 -0
- package/build/esm/components/Banner.js +13 -0
- package/build/esm/components/CommandHeading.d.ts +6 -0
- package/build/esm/components/CommandHeading.js +5 -0
- package/build/esm/components/CommandLayout.d.ts +7 -0
- package/build/esm/components/CommandLayout.js +8 -0
- package/build/esm/components/Doctor.d.ts +7 -0
- package/build/esm/components/Doctor.js +43 -0
- package/build/esm/components/Init.js +2 -5
- package/build/esm/doctor/Doctor.d.ts +8 -0
- package/build/esm/doctor/Doctor.js +67 -0
- package/build/esm/doctor/DoctorContext.d.ts +14 -0
- package/build/esm/doctor/DoctorContext.js +43 -0
- package/build/esm/doctor/DoctorOutput.d.ts +6 -0
- package/build/esm/doctor/DoctorOutput.js +32 -0
- package/build/esm/doctor/DoctorResult.d.ts +8 -0
- package/build/esm/doctor/DoctorResult.js +1 -0
- package/build/esm/doctor/DoctorRunner.d.ts +9 -0
- package/build/esm/doctor/DoctorRunner.js +23 -0
- package/build/esm/doctor/checks/ApiReachabilityCheck.d.ts +5 -0
- package/build/esm/doctor/checks/ApiReachabilityCheck.js +52 -0
- package/build/esm/doctor/checks/CredentialsCheck.d.ts +6 -0
- package/build/esm/doctor/checks/CredentialsCheck.js +66 -0
- package/build/esm/doctor/checks/JestReporterCheck.d.ts +5 -0
- package/build/esm/doctor/checks/JestReporterCheck.js +46 -0
- package/build/esm/doctor/checks/LocalConfigCheck.d.ts +5 -0
- package/build/esm/doctor/checks/LocalConfigCheck.js +28 -0
- package/build/esm/doctor/checks/MirrorAccessCheck.d.ts +12 -0
- package/build/esm/doctor/checks/MirrorAccessCheck.js +224 -0
- package/build/esm/jest/JestConfigurator.js +9 -0
- package/build/esm/jest/JestReporterConfigInspector.d.ts +13 -0
- package/build/esm/jest/JestReporterConfigInspector.js +60 -0
- package/build/esm/utilities/renderBanner.d.ts +1 -0
- package/build/esm/utilities/renderBanner.js +7 -0
- package/build/jest/JestConfigurator.js +9 -0
- package/build/jest/JestReporterConfigInspector.d.ts +13 -0
- package/build/jest/JestReporterConfigInspector.js +56 -0
- package/build/utilities/renderBanner.d.ts +1 -0
- package/build/utilities/renderBanner.js +7 -0
- package/package.json +4 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Doctor from './Doctor.js';
|
|
2
|
+
import DoctorContext from './DoctorContext.js';
|
|
3
|
+
export default class DoctorRunner {
|
|
4
|
+
static async run(options) {
|
|
5
|
+
const cwd = options?.cwd ?? process.cwd();
|
|
6
|
+
const apiUrl = options?.apiUrl ??
|
|
7
|
+
process.env.REGRESSIONPROOF_API_URL ??
|
|
8
|
+
'https://api.regressionproof.ai';
|
|
9
|
+
const fix = options?.fix ?? false;
|
|
10
|
+
const context = DoctorContext.fromCwd(cwd, apiUrl, fix);
|
|
11
|
+
return new Doctor(context).run();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export default class ApiReachabilityCheck {
|
|
2
|
+
async run(context) {
|
|
3
|
+
const checkName = `rp-doctor-${Date.now()}`;
|
|
4
|
+
const url = `${context.apiUrl}/check-name/${checkName}`;
|
|
5
|
+
try {
|
|
6
|
+
const response = await fetch(url, { method: 'GET' });
|
|
7
|
+
if (response.ok) {
|
|
8
|
+
return {
|
|
9
|
+
status: 'ok',
|
|
10
|
+
name: 'API reachability',
|
|
11
|
+
details: [`API responded at ${context.apiUrl}.`],
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (response.status === 502) {
|
|
15
|
+
return {
|
|
16
|
+
status: 'warn',
|
|
17
|
+
name: 'API reachability',
|
|
18
|
+
details: [
|
|
19
|
+
'API is reachable, but Git server communication failed (502).',
|
|
20
|
+
],
|
|
21
|
+
fix: 'Check the Git server connectivity or API configuration.',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
status: 'warn',
|
|
26
|
+
name: 'API reachability',
|
|
27
|
+
details: [`API responded with status ${response.status}.`],
|
|
28
|
+
fix: 'Verify REGRESSIONPROOF_API_URL or check API logs.',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
33
|
+
return {
|
|
34
|
+
status: 'fail',
|
|
35
|
+
name: 'API reachability',
|
|
36
|
+
details: [`API request failed: ${message}`],
|
|
37
|
+
fix: 'Check your network or verify REGRESSIONPROOF_API_URL.',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import ConfigManager from '../../config/ConfigManager.js';
|
|
3
|
+
export default class CredentialsCheck {
|
|
4
|
+
async run(context) {
|
|
5
|
+
if (!context.projectName) {
|
|
6
|
+
return {
|
|
7
|
+
name: 'Credentials for project',
|
|
8
|
+
status: 'warn',
|
|
9
|
+
details: [
|
|
10
|
+
'Unable to resolve project name from .regressionproof.json.',
|
|
11
|
+
],
|
|
12
|
+
fix: 'Run `npx regressionproof init` from the project root.',
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const configManager = new ConfigManager();
|
|
16
|
+
const configPath = context.credentialsPath;
|
|
17
|
+
if (!configPath || !fs.existsSync(configPath)) {
|
|
18
|
+
return {
|
|
19
|
+
name: `Credentials for project "${context.projectName}"`,
|
|
20
|
+
status: 'fail',
|
|
21
|
+
details: [
|
|
22
|
+
`Missing credentials at ${configPath ??
|
|
23
|
+
configManager.getConfigDir(context.projectName)}.`,
|
|
24
|
+
],
|
|
25
|
+
fix: 'Run `npx regressionproof invite accept <token>` (teammate) or `npx regressionproof init` (owner).',
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const parsed = this.safeReadJson(configPath);
|
|
29
|
+
const url = parsed?.remote?.url;
|
|
30
|
+
const token = parsed?.remote?.token;
|
|
31
|
+
if (!url || !token) {
|
|
32
|
+
return {
|
|
33
|
+
name: `Credentials for project "${context.projectName}"`,
|
|
34
|
+
status: 'fail',
|
|
35
|
+
details: [
|
|
36
|
+
'Credentials file is missing remote.url or remote.token.',
|
|
37
|
+
],
|
|
38
|
+
fix: 'Run `npx regressionproof invite accept <token>` to refresh credentials.',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
name: `Credentials for project "${context.projectName}"`,
|
|
43
|
+
status: 'ok',
|
|
44
|
+
details: [`Credentials found at ${configPath}.`],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
safeReadJson(filePath) {
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import JestReporterConfigInspector from '../../jest/JestReporterConfigInspector.js';
|
|
2
|
+
export default class JestReporterCheck {
|
|
3
|
+
async run(context) {
|
|
4
|
+
const inspector = new JestReporterConfigInspector();
|
|
5
|
+
const inspection = inspector.inspect(context.cwd);
|
|
6
|
+
if (!inspection.hasPackageJson) {
|
|
7
|
+
return {
|
|
8
|
+
name: 'Jest reporter configured',
|
|
9
|
+
status: 'warn',
|
|
10
|
+
details: ['No package.json found in the current directory.'],
|
|
11
|
+
fix: 'Run `npx regressionproof init` from the project root.',
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (inspection.isInstalled && inspection.isConfigured) {
|
|
15
|
+
return {
|
|
16
|
+
name: 'Jest reporter configured',
|
|
17
|
+
status: 'ok',
|
|
18
|
+
details: ['Reporter is installed and configured.'],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const details = [];
|
|
22
|
+
if (!inspection.isInstalled) {
|
|
23
|
+
details.push('Reporter package is not installed.');
|
|
24
|
+
}
|
|
25
|
+
if (!inspection.isConfigured) {
|
|
26
|
+
details.push('Jest config does not include the reporter.');
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
name: 'Jest reporter configured',
|
|
30
|
+
status: 'warn',
|
|
31
|
+
details,
|
|
32
|
+
fix: 'Run `npx regressionproof init` or add the reporter to your Jest config.',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default class LocalConfigCheck {
|
|
2
|
+
async run(context) {
|
|
3
|
+
if (!context.localConfigPath) {
|
|
4
|
+
return {
|
|
5
|
+
name: 'Local project config (.regressionproof.json)',
|
|
6
|
+
status: 'warn',
|
|
7
|
+
details: [`Missing .regressionproof.json in ${context.cwd}.`],
|
|
8
|
+
fix: 'Run `npx regressionproof init` from the project root.',
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
name: 'Local project config (.regressionproof.json)',
|
|
13
|
+
status: 'ok',
|
|
14
|
+
details: [`Found at ${context.localConfigPath}.`],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import DoctorContext from '../DoctorContext.js';
|
|
2
|
+
import type { DoctorResult } from '../DoctorResult.js';
|
|
3
|
+
export default class MirrorAccessCheck {
|
|
4
|
+
run(context: DoctorContext): Promise<DoctorResult>;
|
|
5
|
+
private checkPullAccess;
|
|
6
|
+
private checkPushAccess;
|
|
7
|
+
private isNoCommitsError;
|
|
8
|
+
private isNonFastForwardError;
|
|
9
|
+
private isDivergedBranchError;
|
|
10
|
+
private trySyncMirror;
|
|
11
|
+
private getErrorMessage;
|
|
12
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { MirrorSyncer } from '@regressionproof/snapshotter';
|
|
4
|
+
import ConfigManager from '../../config/ConfigManager.js';
|
|
5
|
+
export default class MirrorAccessCheck {
|
|
6
|
+
async run(context) {
|
|
7
|
+
if (!context.projectName) {
|
|
8
|
+
return {
|
|
9
|
+
name: 'Mirror directory',
|
|
10
|
+
status: 'warn',
|
|
11
|
+
details: [
|
|
12
|
+
'Unable to resolve project name from .regressionproof.json.',
|
|
13
|
+
],
|
|
14
|
+
fix: 'Run `npx regressionproof init` from the project root.',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const configManager = new ConfigManager();
|
|
18
|
+
const mirrorPath = context.mirrorPath;
|
|
19
|
+
const credentials = configManager.loadCredentials(context.projectName);
|
|
20
|
+
if (!mirrorPath || !fs.existsSync(mirrorPath)) {
|
|
21
|
+
return {
|
|
22
|
+
name: 'Mirror directory',
|
|
23
|
+
status: 'warn',
|
|
24
|
+
details: [
|
|
25
|
+
`Mirror directory not found at ${mirrorPath ??
|
|
26
|
+
configManager.getConfigDir(context.projectName)}.`,
|
|
27
|
+
'This is normal before the first snapshot is created.',
|
|
28
|
+
],
|
|
29
|
+
fix: 'Run your tests to create the first snapshot.',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (!credentials) {
|
|
33
|
+
return {
|
|
34
|
+
name: 'Mirror directory',
|
|
35
|
+
status: 'warn',
|
|
36
|
+
details: ['Credentials not found; remote access not checked.'],
|
|
37
|
+
fix: 'Run `npx regressionproof invite accept <token>` (teammate) or `npx regressionproof init` (owner).',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const authedUrl = credentials.url.replace('://', `://${credentials.token}@`);
|
|
41
|
+
const pullResult = this.checkPullAccess(authedUrl);
|
|
42
|
+
if (!pullResult.ok) {
|
|
43
|
+
return {
|
|
44
|
+
name: 'Mirror directory',
|
|
45
|
+
status: 'fail',
|
|
46
|
+
details: [
|
|
47
|
+
'Unable to access remote (pull).',
|
|
48
|
+
pullResult.message ?? 'Unknown error.',
|
|
49
|
+
],
|
|
50
|
+
fix: 'Run `npx regressionproof invite accept <token>` to refresh credentials.',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const pushResult = this.checkPushAccess(mirrorPath, authedUrl);
|
|
54
|
+
if (context.fix && pushResult.status === 'warn') {
|
|
55
|
+
if (pushResult.reason === 'non_fast_forward') {
|
|
56
|
+
const fixResult = await this.trySyncMirror(mirrorPath);
|
|
57
|
+
if (!fixResult.ok) {
|
|
58
|
+
const message = fixResult.message ?? 'Unknown error.';
|
|
59
|
+
if (this.isDivergedBranchError(message)) {
|
|
60
|
+
return {
|
|
61
|
+
name: 'Mirror directory',
|
|
62
|
+
status: 'warn',
|
|
63
|
+
details: [
|
|
64
|
+
'Mirror has diverged; manual merge/rebase required.',
|
|
65
|
+
],
|
|
66
|
+
fix: 'Run `git -C <mirror> pull --rebase` (or merge) to resolve divergence.',
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
name: 'Mirror directory',
|
|
71
|
+
status: 'fail',
|
|
72
|
+
details: ['Unable to sync mirror.', message],
|
|
73
|
+
fix: 'Run `npx regressionproof doctor --fix` again or pull the mirror manually.',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const retryResult = this.checkPushAccess(mirrorPath, authedUrl);
|
|
77
|
+
if (retryResult.status === 'ok') {
|
|
78
|
+
return {
|
|
79
|
+
name: 'Mirror directory',
|
|
80
|
+
status: 'ok',
|
|
81
|
+
details: [
|
|
82
|
+
`Mirror directory exists at ${mirrorPath}.`,
|
|
83
|
+
'Mirror synced successfully.',
|
|
84
|
+
'Remote access confirmed (pull/push).',
|
|
85
|
+
],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
name: 'Mirror directory',
|
|
90
|
+
status: 'warn',
|
|
91
|
+
details: [
|
|
92
|
+
`Mirror directory exists at ${mirrorPath}.`,
|
|
93
|
+
'Mirror sync completed; recheck push access.',
|
|
94
|
+
],
|
|
95
|
+
fix: 'Re-run `npx regressionproof doctor` to confirm sync results.',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
throw new Error('Doctor --fix not implemented for this mirror issue.');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (pushResult.status === 'fail') {
|
|
103
|
+
return {
|
|
104
|
+
name: 'Mirror directory',
|
|
105
|
+
status: 'fail',
|
|
106
|
+
details: [
|
|
107
|
+
'Unable to access remote (push).',
|
|
108
|
+
pushResult.message ?? 'Unknown error.',
|
|
109
|
+
],
|
|
110
|
+
fix: 'Run `npx regressionproof invite accept <token>` to refresh credentials.',
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (pushResult.status === 'warn') {
|
|
114
|
+
return {
|
|
115
|
+
name: 'Mirror directory',
|
|
116
|
+
status: 'warn',
|
|
117
|
+
details: [
|
|
118
|
+
'Remote access confirmed (pull).',
|
|
119
|
+
pushResult.message ?? 'Unknown error.',
|
|
120
|
+
],
|
|
121
|
+
fix: 'Run `npx regressionproof doctor --fix` or pull latest changes in the mirror.',
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
name: 'Mirror directory',
|
|
126
|
+
status: 'ok',
|
|
127
|
+
details: [
|
|
128
|
+
`Mirror directory exists at ${mirrorPath}.`,
|
|
129
|
+
'Remote access confirmed (pull/push).',
|
|
130
|
+
],
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
checkPullAccess(url) {
|
|
134
|
+
try {
|
|
135
|
+
execSync(`git ls-remote "${url}"`, { stdio: 'pipe' });
|
|
136
|
+
return { ok: true };
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
return {
|
|
140
|
+
ok: false,
|
|
141
|
+
message: this.getErrorMessage(err),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
checkPushAccess(mirrorPath, url) {
|
|
146
|
+
try {
|
|
147
|
+
execSync(`git -C "${mirrorPath}" push --dry-run "${url}" HEAD`, {
|
|
148
|
+
stdio: 'pipe',
|
|
149
|
+
});
|
|
150
|
+
return { status: 'ok' };
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
const message = this.getErrorMessage(err);
|
|
154
|
+
if (this.isNoCommitsError(message)) {
|
|
155
|
+
return {
|
|
156
|
+
status: 'warn',
|
|
157
|
+
message: 'No commits in mirror; push check skipped.',
|
|
158
|
+
reason: 'no_commits',
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (this.isNonFastForwardError(message)) {
|
|
162
|
+
return {
|
|
163
|
+
status: 'warn',
|
|
164
|
+
message: 'Remote has newer commits; mirror is behind (non-fast-forward).',
|
|
165
|
+
reason: 'non_fast_forward',
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return { status: 'fail', message, reason: 'other' };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
isNoCommitsError(message) {
|
|
172
|
+
const normalized = message.toLowerCase();
|
|
173
|
+
return (normalized.includes('src refspec') ||
|
|
174
|
+
normalized.includes('does not match any') ||
|
|
175
|
+
normalized.includes('no commits'));
|
|
176
|
+
}
|
|
177
|
+
isNonFastForwardError(message) {
|
|
178
|
+
const normalized = message.toLowerCase();
|
|
179
|
+
return (normalized.includes('fetch first') ||
|
|
180
|
+
normalized.includes('non-fast-forward') ||
|
|
181
|
+
normalized.includes('failed to push some refs'));
|
|
182
|
+
}
|
|
183
|
+
isDivergedBranchError(message) {
|
|
184
|
+
const normalized = message.toLowerCase();
|
|
185
|
+
return (normalized.includes('diverging branches') ||
|
|
186
|
+
normalized.includes('not possible to fast-forward'));
|
|
187
|
+
}
|
|
188
|
+
async trySyncMirror(mirrorPath) {
|
|
189
|
+
try {
|
|
190
|
+
const syncer = new MirrorSyncer();
|
|
191
|
+
await syncer.syncBlocking(mirrorPath);
|
|
192
|
+
return { ok: true };
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
return {
|
|
196
|
+
ok: false,
|
|
197
|
+
message: this.getErrorMessage(err),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
getErrorMessage(err) {
|
|
202
|
+
if (err && typeof err === 'object') {
|
|
203
|
+
const error = err;
|
|
204
|
+
return (error.stderr?.toString().trim() ||
|
|
205
|
+
error.stdout?.toString().trim() ||
|
|
206
|
+
error.message);
|
|
207
|
+
}
|
|
208
|
+
return String(err);
|
|
209
|
+
}
|
|
210
|
+
}
|
package/build/esm/cli.js
CHANGED
|
@@ -1,52 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import 'dotenv/config';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import acceptInvite from './commands/invite/AcceptInvite.js.js';
|
|
6
|
-
import createInvite from './commands/invite/CreateInvite.js.js';
|
|
7
|
-
import listInvites from './commands/invite/ListInvites.js.js';
|
|
8
|
-
import revokeInvite from './commands/invite/RevokeInvite.js.js';
|
|
9
|
-
import Init from './components/Init.js.js';
|
|
3
|
+
import { runCommand } from './commands/CommandRunner.js.js';
|
|
4
|
+
import { getCommandHandler } from './commands/commands.js.js';
|
|
10
5
|
const command = process.argv[2];
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
else if (subcommand === 'accept') {
|
|
24
|
-
if (!arg) {
|
|
25
|
-
console.error('Usage: regressionproof invite accept <token>');
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
void acceptInvite(arg);
|
|
29
|
-
}
|
|
30
|
-
else if (subcommand === 'list') {
|
|
31
|
-
void listInvites(arg);
|
|
32
|
-
}
|
|
33
|
-
else if (subcommand === 'revoke') {
|
|
34
|
-
if (!arg) {
|
|
35
|
-
console.error('Usage: regressionproof invite revoke <token>');
|
|
6
|
+
const commandArgs = process.argv.slice(3);
|
|
7
|
+
const handler = getCommandHandler(command);
|
|
8
|
+
if (!handler) {
|
|
9
|
+
void runCommand({
|
|
10
|
+
heading: 'RegressionProof CLI',
|
|
11
|
+
handler: () => {
|
|
12
|
+
console.log('Usage: regressionproof <command>');
|
|
13
|
+
console.log('');
|
|
14
|
+
console.log('Commands:');
|
|
15
|
+
console.log(' init [projectName] Initialize a new project');
|
|
16
|
+
console.log(' invite ... Manage project invites');
|
|
17
|
+
console.log(' doctor Check project configuration');
|
|
36
18
|
process.exit(1);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
console.error('Usage: regressionproof invite <create|accept|list|revoke>');
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
19
|
+
},
|
|
20
|
+
});
|
|
44
21
|
}
|
|
45
22
|
else {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
process.exit(1);
|
|
23
|
+
void runCommand({
|
|
24
|
+
heading: handler.heading,
|
|
25
|
+
isInk: handler.isInk,
|
|
26
|
+
handler: () => handler.run(commandArgs),
|
|
27
|
+
});
|
|
52
28
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { renderBanner } from '../utilities/renderBanner.js.js';
|
|
11
|
+
export function runCommand(options) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
renderBanner();
|
|
14
|
+
if (!options.isInk && options.heading) {
|
|
15
|
+
console.log(options.heading);
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
yield options.handler();
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
22
|
+
console.error(message);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|