Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/commander/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import createBuild from '../tasks/createBuild.js'
import captureScreenshots from '../tasks/captureScreenshots.js'
import finalizeBuild from '../tasks/finalizeBuild.js'
import { validateWebStaticConfig } from '../lib/schemaValidation.js'
import constants from '../lib/constants.js';
import pkgJSON from '../../package.json'
import chalk from 'chalk'

const command = new Command();

Expand All @@ -29,7 +32,36 @@ command
console.log(`Error: The '--buildName' option cannot be an empty string.`);
process.exit(1);
}
let ctx: Context = ctxInit(command.optsWithGlobals());

try {
if (fs.existsSync(constants.LOG_FILE_PATH)) {
fs.unlinkSync(constants.LOG_FILE_PATH);
}
} catch (err) {}

try {
if (fs.existsSync(constants.LOG_FILE_PATH_STOP)) {
fs.unlinkSync(constants.LOG_FILE_PATH_STOP);
}
} catch (err) {}

let ctx: Context = ctxInit(command.optsWithGlobals());
try {
let { data: { latestVersion, deprecated, additionalDescription } } = await ctx.client.checkUpdate(ctx.log);
console.log(`\nLambdaTest SmartUI CLI v${pkgJSON.version}`);
console.log(chalk.yellow(`${additionalDescription}`));
if (deprecated){
console.warn(`This version is deprecated. A new version ${latestVersion} is available!`);
}
else if (pkgJSON.version !== latestVersion){
console.log(chalk.green(`A new version ${latestVersion} is available!`));
}
else console.log(chalk.gray('https://www.npmjs.com/package/@lambdatest/smartui-cli\n'));
} catch (error) {
// console.error(error);
console.log(chalk.gray('https://www.npmjs.com/package/@lambdatest/smartui-cli\n'));
}

ctx.isSnapshotCaptured = true

if (!fs.existsSync(file)) {
Expand Down
36 changes: 36 additions & 0 deletions src/commander/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import processSnapshots from '../tasks/processSnapshot.js'
import finalizeBuild from '../tasks/finalizeBuild.js'
import snapshotQueue from '../lib/snapshotQueue.js'
import startTunnel from '../tasks/startTunnel.js'
import fs from 'fs';
import constants from '../lib/constants.js';
import pkgJSON from '../../package.json'
import chalk from 'chalk'

const command = new Command();

Expand All @@ -31,8 +35,40 @@ command
console.log(`Error: The '--buildName' option cannot be an empty string.`);
process.exit(1);
}

try {
if (fs.existsSync(constants.LOG_FILE_PATH)) {
fs.unlinkSync(constants.LOG_FILE_PATH);
}
} catch (err) {}

try {
if (fs.existsSync(constants.LOG_FILE_PATH_STOP)) {
fs.unlinkSync(constants.LOG_FILE_PATH_STOP);
}
} catch (err) {}

let ctx: Context = ctxInit(command.optsWithGlobals());

try {
let { data: { latestVersion, deprecated, additionalDescription } } = await ctx.client.checkUpdate(ctx.log);
console.log(`\nLambdaTest SmartUI CLI v${pkgJSON.version}`);
console.log(chalk.yellow(`${additionalDescription}`));
if (deprecated){
console.warn(`This version is deprecated. A new version ${latestVersion} is available!`);
}
else if (pkgJSON.version !== latestVersion){
console.log(chalk.green(`A new version ${latestVersion} is available!`));
}
else console.log(chalk.gray('https://www.npmjs.com/package/@lambdatest/smartui-cli\n'));
} catch (error) {
// console.error(error);
console.log(chalk.gray('https://www.npmjs.com/package/@lambdatest/smartui-cli\n'));
}




if (!which.sync(execCommand[0], { nothrow: true })) {
ctx.log.error(`Error: Command not found "${execCommand[0]}"`);
return
Expand Down
34 changes: 33 additions & 1 deletion src/commander/mergeBranch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import ctxInit from '../lib/ctx.js';
import fetchBranchInfo from '../tasks/fetchBranchInfo.js'
import mergeBuilds from '../tasks/mergeBuilds.js'
import getGitInfo from '../tasks/getGitInfo.js'
import constants from '../lib/constants.js';
import fs from 'fs';
import pkgJSON from '../../package.json'
import chalk from 'chalk'

const command = new Command();

Expand All @@ -16,7 +20,35 @@ command
.requiredOption('--target <string>', 'Target branch to merge into')
.action(async function(this: Command, options: { source: string, target: string }) {
const { source, target } = options;
let ctx: Context = ctxInit(command.optsWithGlobals());

try {
if (fs.existsSync(constants.LOG_FILE_PATH)) {
fs.unlinkSync(constants.LOG_FILE_PATH);
}
} catch (err) {}

try {
if (fs.existsSync(constants.LOG_FILE_PATH_STOP)) {
fs.unlinkSync(constants.LOG_FILE_PATH_STOP);
}
} catch (err) {}

let ctx: Context = ctxInit(command.optsWithGlobals());
try {
let { data: { latestVersion, deprecated, additionalDescription } } = await ctx.client.checkUpdate(ctx.log);
console.log(`\nLambdaTest SmartUI CLI v${pkgJSON.version}`);
console.log(chalk.yellow(`${additionalDescription}`));
if (deprecated){
console.warn(`This version is deprecated. A new version ${latestVersion} is available!`);
}
else if (pkgJSON.version !== latestVersion){
console.log(chalk.green(`A new version ${latestVersion} is available!`));
}
else console.log(chalk.gray('https://www.npmjs.com/package/@lambdatest/smartui-cli\n'));
} catch (error) {
// console.error(error);
console.log(chalk.gray('https://www.npmjs.com/package/@lambdatest/smartui-cli\n'));
}

if (!source || source.trim() === '') {
ctx.log.error('Error: The --source option cannot be empty.');
Expand Down
32 changes: 31 additions & 1 deletion src/commander/mergeBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import ctxInit from '../lib/ctx.js';
import fetchBuildInfo from '../tasks/fetchBuildInfo.js'
import mergeBuilds from '../tasks/mergeBuilds.js'
import getGitInfo from '../tasks/getGitInfo.js'
import constants from '../lib/constants.js';
import fs from 'fs';
import pkgJSON from '../../package.json'
import chalk from 'chalk'

const command = new Command();

Expand All @@ -16,7 +20,33 @@ command
.requiredOption('--target <string>', 'Target build to merge into')
.action(async function(this: Command, options: { source: string, target: string }) {
const { source, target } = options;
let ctx: Context = ctxInit(command.optsWithGlobals());

try {
if (fs.existsSync(constants.LOG_FILE_PATH)) {
fs.unlinkSync(constants.LOG_FILE_PATH);
}
} catch (err) {}
try {
if (fs.existsSync(constants.LOG_FILE_PATH_STOP)) {
fs.unlinkSync(constants.LOG_FILE_PATH_STOP);
}
} catch (err) {}
let ctx: Context = ctxInit(command.optsWithGlobals());
try {
let { data: { latestVersion, deprecated, additionalDescription } } = await ctx.client.checkUpdate(ctx.log);
console.log(`\nLambdaTest SmartUI CLI v${pkgJSON.version}`);
console.log(chalk.yellow(`${additionalDescription}`));
if (deprecated){
console.warn(`This version is deprecated. A new version ${latestVersion} is available!`);
}
else if (pkgJSON.version !== latestVersion){
console.log(chalk.green(`A new version ${latestVersion} is available!`));
}
else console.log(chalk.gray('https://www.npmjs.com/package/@lambdatest/smartui-cli\n'));
} catch (error) {
// console.error(error);
console.log(chalk.gray('https://www.npmjs.com/package/@lambdatest/smartui-cli\n'));
}

if (!source || source.trim() === '') {
ctx.log.error('Error: The --source option cannot be empty.');
Expand Down
31 changes: 30 additions & 1 deletion src/commander/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import getGitInfo from '../tasks/getGitInfo.js';
import createBuildExec from '../tasks/createBuildExec.js';
import snapshotQueue from '../lib/snapshotQueue.js';
import { startPolling, startPingPolling } from '../lib/utils.js';
import fs from 'fs';
import constants from '../lib/constants.js';
import pkgJSON from '../../package.json'
import chalk from 'chalk'

const command = new Command();

Expand All @@ -23,7 +27,32 @@ command
console.log(`Error: The '--buildName' option cannot be an empty string.`);
process.exit(1);
}
let ctx: Context = ctxInit(command.optsWithGlobals());
try {
if (fs.existsSync(constants.LOG_FILE_PATH)) {
fs.unlinkSync(constants.LOG_FILE_PATH);
}
} catch (err) {}
try {
if (fs.existsSync(constants.LOG_FILE_PATH_STOP)) {
fs.unlinkSync(constants.LOG_FILE_PATH_STOP);
}
} catch (err) {}
let ctx: Context = ctxInit(command.optsWithGlobals());
try {
let { data: { latestVersion, deprecated, additionalDescription } } = await ctx.client.checkUpdate(ctx.log);
console.log(`\nLambdaTest SmartUI CLI v${pkgJSON.version}`);
console.log(chalk.yellow(`${additionalDescription}`));
if (deprecated){
console.warn(`This version is deprecated. A new version ${latestVersion} is available!`);
}
else if (pkgJSON.version !== latestVersion){
console.log(chalk.green(`A new version ${latestVersion} is available!`));
}
else console.log(chalk.gray('https://www.npmjs.com/package/@lambdatest/smartui-cli\n'));
} catch (error) {
// console.error(error);
console.log(chalk.gray('https://www.npmjs.com/package/@lambdatest/smartui-cli\n'));
}
ctx.snapshotQueue = new snapshotQueue(ctx);
ctx.totalSnapshots = 0
ctx.isStartExec = true
Expand Down
7 changes: 7 additions & 0 deletions src/commander/stopServer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Command } from 'commander';
import axios from 'axios'; // Import axios for HTTP requests
import chalk from 'chalk'
import { Context } from '../types.js'
import ctxInit from '../lib/ctx.js'

const command = new Command();

Expand All @@ -15,7 +17,9 @@ command
.action(async function(this: Command) {
try {
const serverAddress = getSmartUIServerAddress();
let ctx: Context = ctxInit(command.optsWithGlobals());
console.log(chalk.yellow(`Stopping server at ${serverAddress} from terminal...`));
ctx.log_stop.debug(`Stopping server at ${serverAddress} from terminal...`);

// Send POST request to the /stop endpoint with the correct headers
const response = await axios.post(`${serverAddress}/stop`, { timeout: 15000 }, {
Expand All @@ -28,8 +32,11 @@ command
if (response.status === 200) {
console.log(chalk.green('Server stopped successfully'));
console.log(chalk.green(`Response: ${JSON.stringify(response.data)}`)); // Log response data if needed
ctx.log_stop.info('Server stopped successfully');
ctx.log_stop.debug(`Response: ${JSON.stringify(response.data)}`);
} else {
console.log(chalk.red('Failed to stop server'));
ctx.log.error('Failed to stop server');
}
} catch (error: any) {
// Handle any errors during the HTTP request
Expand Down
31 changes: 30 additions & 1 deletion src/commander/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import createBuild from '../tasks/createBuild.js';
import uploadScreenshots from '../tasks/uploadScreenshots.js';
import finalizeBuild from '../tasks/finalizeBuild.js';
import constants from '../lib/constants.js';
import pkgJSON from '../../package.json'
import chalk from 'chalk'

const command = new Command();

Expand All @@ -30,12 +32,39 @@ command
.option('--userName <string>', 'Specify the LT username')
.option('--accessKey <string>', 'Specify the LT accesskey')
.action(async function(directory, _, command) {

try {
if (fs.existsSync(constants.LOG_FILE_PATH)) {
fs.unlinkSync(constants.LOG_FILE_PATH);
}
} catch (err) {}
try {
if (fs.existsSync(constants.LOG_FILE_PATH_STOP)) {
fs.unlinkSync(constants.LOG_FILE_PATH_STOP);
}
} catch (err) {}

const options = command.optsWithGlobals();
if (options.buildName === '') {
console.log(`Error: The '--buildName' option cannot be an empty string.`);
process.exit(1);
}
let ctx: Context = ctxInit(command.optsWithGlobals());
let ctx: Context = ctxInit(command.optsWithGlobals());
try {
let { data: { latestVersion, deprecated, additionalDescription } } = await ctx.client.checkUpdate(ctx.log);
console.log(`\nLambdaTest SmartUI CLI v${pkgJSON.version}`);
console.log(chalk.yellow(`${additionalDescription}`));
if (deprecated){
console.warn(`This version is deprecated. A new version ${latestVersion} is available!`);
}
else if (pkgJSON.version !== latestVersion){
console.log(chalk.green(`A new version ${latestVersion} is available!`));
}
else console.log(chalk.gray('https://www.npmjs.com/package/@lambdatest/smartui-cli\n'));
} catch (error) {
// console.error(error);
console.log(chalk.gray('https://www.npmjs.com/package/@lambdatest/smartui-cli\n'));
}
ctx.isSnapshotCaptured = true

if (!fs.existsSync(directory)) {
Expand Down
Loading