Skip to content

Commit 0368400

Browse files
committed
configure cli to upload build scan
1 parent da66b6b commit 0368400

7 files changed

Lines changed: 71 additions & 10 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// lib/axiosClient.ts
2+
const axios = require('axios');
3+
const axiosRetry = require('axios-retry').default;
4+
5+
const axiosClient = axios.create({
6+
baseURL: 'http://localhost:3000/api',
7+
headers: {
8+
'Content-Type': 'application/json',
9+
},
10+
});
11+
12+
axiosRetry(axiosClient, {
13+
retries: 3, // Number of retries
14+
retryDelay: (retryCount) => {
15+
return retryCount * 1000; // Time interval between retries (1000 ms = 1 second)
16+
},
17+
retryCondition: (error) => {
18+
// Retry on network errors or 5xx server errors
19+
return error.response?.status === 500 || error.code === 'ECONNABORTED';
20+
},
21+
});
22+
23+
module.exports = axiosClient;

packages/flowtest-cli/bin/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { Graph } = require('../graph/Graph');
99
const { cloneDeep } = require('lodash');
1010
const dotenv = require('dotenv');
1111
const { GraphLogger, LogLevel } = require('../graph/GraphLogger');
12+
const axiosClient = require('./axiosClient');
1213

1314
const getEnvVariables = (pathname) => {
1415
const content = readFile(pathname);
@@ -42,6 +43,10 @@ const argv = yargs(hideBin(process.argv))
4243
describe: 'timeout for graph run in ms',
4344
demandOption: false,
4445
type: 'number',
46+
})
47+
.option('scan', {
48+
alias: 's',
49+
describe: 'generate and upload build scan',
4550
});
4651
},
4752
async (argv) => {
@@ -85,7 +90,18 @@ const argv = yargs(hideBin(process.argv))
8590
}
8691
logger.add(LogLevel.INFO, `Total time: ${Date.now() - startTime} ms`);
8792
console.log(chalk.bold('Total Time: ') + chalk.dim(`${Date.now() - startTime} ms`));
88-
console.log(logger.get());
93+
//console.log(logger.get());
94+
95+
if (argv.scan) {
96+
try {
97+
const response = await axiosClient.post('/upload', btoa(JSON.stringify(logger.get())));
98+
console.log(response.data.data[0].id);
99+
} catch (error) {
100+
//console.log(error);
101+
console.log(chalk.red(` ✕ `) + chalk.dim('Unable to upload build scan'));
102+
}
103+
}
104+
89105
process.exit(1);
90106
//console.log(chalk.green(JSON.stringify(result)));
91107
} catch (error) {

packages/flowtest-cli/graph/Graph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class Graph {
198198
}
199199

200200
if (this.#checkTimeout()) {
201-
throw `Timeout of ${this.timeout} ms exceeded, stopping graph run`;
201+
throw Error(`Timeout of ${this.timeout} ms exceeded, stopping graph run`);
202202
}
203203
} catch (err) {
204204
console.log(chalk.red(`Flow failed at: ${JSON.stringify(node.data)} due to ${err}`));

packages/flowtest-cli/graph/GraphLogger.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const LogLevel = Object.freeze({
2-
INFO: 0,
3-
WARN: 1,
4-
ERROR: 2,
2+
INFO: 'info',
3+
WARN: 'warn',
4+
ERROR: 'error',
55
});
66

77
class GraphLogger {
@@ -11,7 +11,7 @@ class GraphLogger {
1111

1212
add(logLevel, message, node) {
1313
this.logs.push({
14-
logLevel,
14+
level: logLevel,
1515
timestamp: new Date().toISOString(),
1616
message,
1717
node,

packages/flowtest-cli/graph/compute/assertnode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class assertNode extends Node {
3333

3434
const operator = this.operator;
3535
if (operator == undefined) {
36-
throw 'Operator undefined';
36+
throw Error('Operator undefined');
3737
}
3838
// this.logs.push(
3939
// `Assert var1: ${JSON.stringify(var1)} of type: ${typeof var1}, var2: ${JSON.stringify(var2)} of type: ${typeof var2} with operator: ${operator}`,
@@ -59,7 +59,7 @@ class assertNode extends Node {
5959
result = var1 < var2;
6060
break;
6161
default:
62-
throw 'Unsupported operator';
62+
throw Error('Unsupported operator');
6363
}
6464
this.logger.add(LogLevel.INFO, '', { type: 'assertNode', data: { var1, var2, operator, result } });
6565

packages/flowtest-cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"author": "Sajal Jain <jsajal1993@gmail.com>",
1313
"license": "MIT",
1414
"dependencies": {
15-
"axios": "^1.6.8",
15+
"axios": "^1.7.2",
16+
"axios-retry": "^4.4.0",
1617
"boxen": "^7.1.1",
1718
"chalk": "^3.0.0",
1819
"dotenv": "^16.4.5",

pnpm-lock.yaml

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)