@regressionproof/cli 0.3.9 → 0.4.1
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/commands/invite/AcceptInvite.js +43 -0
- package/build/components/Init.js +16 -1
- package/build/components/Init.tsx +17 -1
- package/build/esm/commands/invite/AcceptInvite.js +44 -0
- package/build/esm/components/Init.js +16 -1
- package/build/esm/utilities/version.d.ts +1 -0
- package/build/esm/utilities/version.js +9 -0
- package/build/utilities/version.d.ts +1 -0
- package/build/utilities/version.js +9 -0
- package/package.json +3 -3
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import ConfigManager from '../../config/ConfigManager.js';
|
|
5
|
+
import { toSlug } from '../../utilities/slug.js';
|
|
6
|
+
import { getCliVersion } from '../../utilities/version.js';
|
|
1
7
|
const API_URL = process.env.REGRESSIONPROOF_API_URL ?? 'https://api.regressionproof.ai';
|
|
2
8
|
export default async function acceptInvite(token) {
|
|
3
9
|
const response = await fetch(`${API_URL}/invites/accept`, {
|
|
@@ -12,6 +18,43 @@ export default async function acceptInvite(token) {
|
|
|
12
18
|
throw new Error(`Invite accept failed: ${response.status} ${text}`);
|
|
13
19
|
}
|
|
14
20
|
const data = (await response.json());
|
|
21
|
+
const projectName = deriveProjectNameFromUrl(data.url);
|
|
22
|
+
const configManager = new ConfigManager();
|
|
23
|
+
configManager.saveCredentials(projectName, {
|
|
24
|
+
url: data.url,
|
|
25
|
+
token: data.token,
|
|
26
|
+
});
|
|
27
|
+
writeLocalConfig(process.cwd(), projectName, data.url);
|
|
28
|
+
ensureMirrorCloned(configManager.getConfigDir(projectName), data.url, data.token);
|
|
15
29
|
console.log('Project URL:', data.url);
|
|
16
30
|
console.log('Project token:', data.token);
|
|
17
31
|
}
|
|
32
|
+
function deriveProjectNameFromUrl(url) {
|
|
33
|
+
const match = url.match(/[/:]([^/:]+?)(\.git)?$/);
|
|
34
|
+
const name = toSlug(match?.[1] ?? '');
|
|
35
|
+
if (!name) {
|
|
36
|
+
throw new Error(`Unable to determine project name from url: ${url}`);
|
|
37
|
+
}
|
|
38
|
+
return name;
|
|
39
|
+
}
|
|
40
|
+
function writeLocalConfig(cwd, projectName, url) {
|
|
41
|
+
const configPath = path.join(cwd, '.regressionproof.json');
|
|
42
|
+
const version = getCliVersion();
|
|
43
|
+
const payload = {
|
|
44
|
+
version,
|
|
45
|
+
projectName,
|
|
46
|
+
remote: {
|
|
47
|
+
url,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
fs.writeFileSync(configPath, JSON.stringify(payload, null, 2));
|
|
51
|
+
}
|
|
52
|
+
function ensureMirrorCloned(configDir, url, token) {
|
|
53
|
+
const mirrorPath = path.join(configDir, 'mirror');
|
|
54
|
+
if (fs.existsSync(mirrorPath)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
58
|
+
const authedUrl = url.replace('://', `://${token}@`);
|
|
59
|
+
execSync(`git clone "${authedUrl}" "${mirrorPath}"`, { stdio: 'inherit' });
|
|
60
|
+
}
|
package/build/components/Init.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
3
4
|
import { buildRegressionProofClient } from '@regressionproof/client';
|
|
4
5
|
import { Box, Text, useApp } from 'ink';
|
|
5
6
|
import BigText from 'ink-big-text';
|
|
@@ -8,6 +9,7 @@ import React from 'react';
|
|
|
8
9
|
import ConfigManager from '../config/ConfigManager.js';
|
|
9
10
|
import JestConfigurator from '../jest/JestConfigurator.js';
|
|
10
11
|
import { getRepoNameFromGit, toSlug } from '../utilities/slug.js';
|
|
12
|
+
import { getCliVersion } from '../utilities/version.js';
|
|
11
13
|
const API_URL = process.env.REGRESSIONPROOF_API_URL ?? 'https://api.regressionproof.ai';
|
|
12
14
|
class InitComponent extends React.Component {
|
|
13
15
|
checkTimeout = null;
|
|
@@ -114,6 +116,7 @@ class InitComponent extends React.Component {
|
|
|
114
116
|
const credentials = await this.apiClient.registerProject({ name });
|
|
115
117
|
this.setState({ credentials });
|
|
116
118
|
this.configManager.saveCredentials(name, credentials);
|
|
119
|
+
this.writeLocalConfig(name, credentials.url);
|
|
117
120
|
await this.installAndConfigure();
|
|
118
121
|
}
|
|
119
122
|
catch (err) {
|
|
@@ -178,6 +181,18 @@ class InitComponent extends React.Component {
|
|
|
178
181
|
}
|
|
179
182
|
return { success: true };
|
|
180
183
|
}
|
|
184
|
+
writeLocalConfig(projectName, url) {
|
|
185
|
+
const configPath = path.join(process.cwd(), '.regressionproof.json');
|
|
186
|
+
const version = getCliVersion();
|
|
187
|
+
const payload = {
|
|
188
|
+
version,
|
|
189
|
+
projectName,
|
|
190
|
+
remote: {
|
|
191
|
+
url,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
writeFileSync(configPath, JSON.stringify(payload, null, 2));
|
|
195
|
+
}
|
|
181
196
|
getPackageManager() {
|
|
182
197
|
if (existsSync('pnpm-lock.yaml')) {
|
|
183
198
|
return { command: 'pnpm', args: ['add', '-D'] };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process'
|
|
2
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
3
4
|
import type { RegressionProofClient } from '@regressionproof/client'
|
|
4
5
|
import { buildRegressionProofClient } from '@regressionproof/client'
|
|
5
6
|
import { Box, Text, useApp } from 'ink'
|
|
@@ -9,6 +10,7 @@ import React from 'react'
|
|
|
9
10
|
import ConfigManager, { Credentials } from '../config/ConfigManager.js'
|
|
10
11
|
import JestConfigurator, { JestConfigResult } from '../jest/JestConfigurator.js'
|
|
11
12
|
import { getRepoNameFromGit, toSlug } from '../utilities/slug.js'
|
|
13
|
+
import { getCliVersion } from '../utilities/version.js'
|
|
12
14
|
|
|
13
15
|
const API_URL =
|
|
14
16
|
process.env.REGRESSIONPROOF_API_URL ?? 'https://api.regressionproof.ai'
|
|
@@ -135,6 +137,7 @@ class InitComponent extends React.Component<Props, State> {
|
|
|
135
137
|
this.setState({ credentials })
|
|
136
138
|
|
|
137
139
|
this.configManager.saveCredentials(name, credentials)
|
|
140
|
+
this.writeLocalConfig(name, credentials.url)
|
|
138
141
|
await this.installAndConfigure()
|
|
139
142
|
} catch (err) {
|
|
140
143
|
this.setState({
|
|
@@ -225,6 +228,19 @@ class InitComponent extends React.Component<Props, State> {
|
|
|
225
228
|
return { success: true }
|
|
226
229
|
}
|
|
227
230
|
|
|
231
|
+
private writeLocalConfig(projectName: string, url: string): void {
|
|
232
|
+
const configPath = path.join(process.cwd(), '.regressionproof.json')
|
|
233
|
+
const version = getCliVersion()
|
|
234
|
+
const payload = {
|
|
235
|
+
version,
|
|
236
|
+
projectName,
|
|
237
|
+
remote: {
|
|
238
|
+
url,
|
|
239
|
+
},
|
|
240
|
+
}
|
|
241
|
+
writeFileSync(configPath, JSON.stringify(payload, null, 2))
|
|
242
|
+
}
|
|
243
|
+
|
|
228
244
|
private getPackageManager(): PackageManager {
|
|
229
245
|
if (existsSync('pnpm-lock.yaml')) {
|
|
230
246
|
return { command: 'pnpm', args: ['add', '-D'] }
|
|
@@ -8,6 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
var _a;
|
|
11
|
+
import { execSync } from 'child_process';
|
|
12
|
+
import fs from 'fs';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import ConfigManager from '../../config/ConfigManager.js.js';
|
|
15
|
+
import { toSlug } from '../../utilities/slug.js.js';
|
|
16
|
+
import { getCliVersion } from '../../utilities/version.js.js';
|
|
11
17
|
const API_URL = (_a = process.env.REGRESSIONPROOF_API_URL) !== null && _a !== void 0 ? _a : 'https://api.regressionproof.ai';
|
|
12
18
|
export default function acceptInvite(token) {
|
|
13
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -23,7 +29,45 @@ export default function acceptInvite(token) {
|
|
|
23
29
|
throw new Error(`Invite accept failed: ${response.status} ${text}`);
|
|
24
30
|
}
|
|
25
31
|
const data = (yield response.json());
|
|
32
|
+
const projectName = deriveProjectNameFromUrl(data.url);
|
|
33
|
+
const configManager = new ConfigManager();
|
|
34
|
+
configManager.saveCredentials(projectName, {
|
|
35
|
+
url: data.url,
|
|
36
|
+
token: data.token,
|
|
37
|
+
});
|
|
38
|
+
writeLocalConfig(process.cwd(), projectName, data.url);
|
|
39
|
+
ensureMirrorCloned(configManager.getConfigDir(projectName), data.url, data.token);
|
|
26
40
|
console.log('Project URL:', data.url);
|
|
27
41
|
console.log('Project token:', data.token);
|
|
28
42
|
});
|
|
29
43
|
}
|
|
44
|
+
function deriveProjectNameFromUrl(url) {
|
|
45
|
+
var _a;
|
|
46
|
+
const match = url.match(/[/:]([^/:]+?)(\.git)?$/);
|
|
47
|
+
const name = toSlug((_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : '');
|
|
48
|
+
if (!name) {
|
|
49
|
+
throw new Error(`Unable to determine project name from url: ${url}`);
|
|
50
|
+
}
|
|
51
|
+
return name;
|
|
52
|
+
}
|
|
53
|
+
function writeLocalConfig(cwd, projectName, url) {
|
|
54
|
+
const configPath = path.join(cwd, '.regressionproof.json');
|
|
55
|
+
const version = getCliVersion();
|
|
56
|
+
const payload = {
|
|
57
|
+
version,
|
|
58
|
+
projectName,
|
|
59
|
+
remote: {
|
|
60
|
+
url,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
fs.writeFileSync(configPath, JSON.stringify(payload, null, 2));
|
|
64
|
+
}
|
|
65
|
+
function ensureMirrorCloned(configDir, url, token) {
|
|
66
|
+
const mirrorPath = path.join(configDir, 'mirror');
|
|
67
|
+
if (fs.existsSync(mirrorPath)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
71
|
+
const authedUrl = url.replace('://', `://${token}@`);
|
|
72
|
+
execSync(`git clone "${authedUrl}" "${mirrorPath}"`, { stdio: 'inherit' });
|
|
73
|
+
}
|
|
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
var _a;
|
|
11
11
|
import { spawnSync } from 'node:child_process';
|
|
12
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
12
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
13
14
|
import { buildRegressionProofClient } from '@regressionproof/client';
|
|
14
15
|
import { Box, Text, useApp } from 'ink';
|
|
15
16
|
import BigText from 'ink-big-text';
|
|
@@ -18,6 +19,7 @@ import React from 'react';
|
|
|
18
19
|
import ConfigManager from '../config/ConfigManager.js.js';
|
|
19
20
|
import JestConfigurator from '../jest/JestConfigurator.js.js';
|
|
20
21
|
import { getRepoNameFromGit, toSlug } from '../utilities/slug.js.js';
|
|
22
|
+
import { getCliVersion } from '../utilities/version.js.js';
|
|
21
23
|
const API_URL = (_a = process.env.REGRESSIONPROOF_API_URL) !== null && _a !== void 0 ? _a : 'https://api.regressionproof.ai';
|
|
22
24
|
class InitComponent extends React.Component {
|
|
23
25
|
constructor(props) {
|
|
@@ -125,6 +127,7 @@ class InitComponent extends React.Component {
|
|
|
125
127
|
const credentials = yield this.apiClient.registerProject({ name });
|
|
126
128
|
this.setState({ credentials });
|
|
127
129
|
this.configManager.saveCredentials(name, credentials);
|
|
130
|
+
this.writeLocalConfig(name, credentials.url);
|
|
128
131
|
yield this.installAndConfigure();
|
|
129
132
|
}
|
|
130
133
|
catch (err) {
|
|
@@ -193,6 +196,18 @@ class InitComponent extends React.Component {
|
|
|
193
196
|
}
|
|
194
197
|
return { success: true };
|
|
195
198
|
}
|
|
199
|
+
writeLocalConfig(projectName, url) {
|
|
200
|
+
const configPath = path.join(process.cwd(), '.regressionproof.json');
|
|
201
|
+
const version = getCliVersion();
|
|
202
|
+
const payload = {
|
|
203
|
+
version,
|
|
204
|
+
projectName,
|
|
205
|
+
remote: {
|
|
206
|
+
url,
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
writeFileSync(configPath, JSON.stringify(payload, null, 2));
|
|
210
|
+
}
|
|
196
211
|
getPackageManager() {
|
|
197
212
|
if (existsSync('pnpm-lock.yaml')) {
|
|
198
213
|
return { command: 'pnpm', args: ['add', '-D'] };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getCliVersion(): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
export function getCliVersion() {
|
|
3
|
+
const packageUrl = new URL('../../package.json', import.meta.url);
|
|
4
|
+
const packageJson = JSON.parse(readFileSync(packageUrl, 'utf-8'));
|
|
5
|
+
if (!packageJson.version) {
|
|
6
|
+
throw new Error('Unable to determine CLI version from package.json');
|
|
7
|
+
}
|
|
8
|
+
return packageJson.version;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getCliVersion(): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
export function getCliVersion() {
|
|
3
|
+
const packageUrl = new URL('../../package.json', import.meta.url);
|
|
4
|
+
const packageJson = JSON.parse(readFileSync(packageUrl, 'utf-8'));
|
|
5
|
+
if (!packageJson.version) {
|
|
6
|
+
throw new Error('Unable to determine CLI version from package.json');
|
|
7
|
+
}
|
|
8
|
+
return packageJson.version;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regressionproof/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"watch.tsc": "tsc -w"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@regressionproof/client": "^0.
|
|
41
|
+
"@regressionproof/client": "^0.4.1",
|
|
42
42
|
"dotenv": "^17.2.3",
|
|
43
43
|
"ink": "^5.1.0",
|
|
44
44
|
"ink-big-text": "^2.0.0",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"^#spruce/(.*)$": "<rootDir>/build/.spruce/$1"
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "5f4b7535038870bdbd859a12d2c97fceb021b347"
|
|
88
88
|
}
|