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