-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from LambdaTest/stage
Release v3.0.7
- Loading branch information
Showing
14 changed files
with
281 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import fs from 'fs' | ||
import { Command } from 'commander' | ||
import { Context } from '../types.js' | ||
import { color , Listr, ListrDefaultRendererLogLevels, LoggerFormat } from 'listr2' | ||
import auth from '../tasks/auth.js' | ||
import ctxInit from '../lib/ctx.js' | ||
import getGitInfo from '../tasks/getGitInfo.js' | ||
import createBuild from '../tasks/createBuild.js' | ||
import captureScreenshots from '../tasks/captureScreenshots.js' | ||
import finalizeBuild from '../tasks/finalizeBuild.js' | ||
import { validateFigmaDesignConfig } from '../lib/schemaValidation.js' | ||
import uploadFigmaDesigns from '../tasks/uploadFigmaDesigns.js' | ||
|
||
const command = new Command(); | ||
|
||
command | ||
.name('upload-figma') | ||
.description('Capture screenshots of static sites') | ||
.argument('<file>', 'figma design config file') | ||
.option('--markBaseline', 'Mark the uploaded images as baseline') | ||
.option('--buildName <buildName>' , 'Name of the build') | ||
.action(async function(file, _, command) { | ||
let ctx: Context = ctxInit(command.optsWithGlobals()); | ||
|
||
if (!fs.existsSync(file)) { | ||
console.log(`Error: Figma Config file ${file} not found.`); | ||
return; | ||
} | ||
try { | ||
ctx.figmaDesignConfig = JSON.parse(fs.readFileSync(file, 'utf8')); | ||
if (!validateFigmaDesignConfig(ctx.figmaDesignConfig)) { | ||
const validationError = validateFigmaDesignConfig.errors?.[0]?.message; | ||
throw new Error(validationError || 'Invalid figma design Config'); | ||
} | ||
} catch (error: any) { | ||
console.log(`[smartui] Error: Invalid figma design Config; ${error.message}`); | ||
return; | ||
} | ||
|
||
let tasks = new Listr<Context>( | ||
[ | ||
auth(ctx), | ||
uploadFigmaDesigns(ctx) | ||
], | ||
{ | ||
rendererOptions: { | ||
icon: { | ||
[ListrDefaultRendererLogLevels.OUTPUT]: `→` | ||
}, | ||
color: { | ||
[ListrDefaultRendererLogLevels.OUTPUT]: color.gray as LoggerFormat | ||
} | ||
} | ||
} | ||
) | ||
|
||
try { | ||
await tasks.run(ctx); | ||
} catch (error) { | ||
console.log('\nRefer docs: https://www.lambdatest.com/support/docs/smart-visual-regression-testing/'); | ||
} | ||
|
||
}) | ||
|
||
export default command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Context } from "../types.js"; | ||
|
||
export default async (ctx: Context): Promise<string> => { | ||
const depth = ctx.figmaDesignConfig.depth; | ||
const figmaConfigs = ctx.figmaDesignConfig.figma_config; | ||
let results = ""; | ||
let figmaFileToken = ''; | ||
const markBaseline = ctx.options.markBaseline; | ||
const buildName = ctx.options.buildName; | ||
|
||
for (const config of figmaConfigs) { | ||
|
||
figmaFileToken = config.figma_file_token; | ||
let queryParams = ""; | ||
if (config.figma_ids && config.figma_ids.length > 0) { | ||
const fileIds = config.figma_ids.join(","); | ||
queryParams += `?ids=${fileIds}`; | ||
} | ||
|
||
const authToken = `Basic ${Buffer.from(`${ctx.env.LT_USERNAME}:${ctx.env.LT_ACCESS_KEY}`).toString("base64")}` | ||
|
||
const responseData = await ctx.client.getFigmaFilesAndImages(figmaFileToken, ctx.env.FIGMA_TOKEN, queryParams, authToken, depth, markBaseline, buildName ,ctx.log); | ||
|
||
if (responseData.data.message == "success") { | ||
results = responseData.data.message; | ||
} | ||
} | ||
|
||
return results; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ListrTask, ListrRendererFactory } from 'listr2'; | ||
import { Context } from '../types.js' | ||
import { captureScreenshots } from '../lib/screenshot.js' | ||
import chalk from 'chalk'; | ||
import { updateLogContext } from '../lib/logger.js' | ||
import uploadFigmaDesigns from '../lib/uploadFigmaDesigns.js'; | ||
|
||
export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRendererFactory> => { | ||
return { | ||
title: 'Uploading Figma Designs', | ||
task: async (ctx, task): Promise<void> => { | ||
try { | ||
ctx.task = task; | ||
updateLogContext({task: 'upload-figma'}); | ||
|
||
let results = await uploadFigmaDesigns(ctx); | ||
if (results != 'success') { | ||
throw new Error('Uploading Figma designs failed'); | ||
} | ||
task.title = 'Figma designs images uploaded successfully to SmartUI'; | ||
ctx.log.debug(`Figma designs processed: ${results}`); | ||
} catch (error: any) { | ||
ctx.log.debug(error); | ||
task.output = chalk.gray(`${error.message}`); | ||
throw new Error('Uploading Figma designs failed'); | ||
} | ||
}, | ||
rendererOptions: { persistentOutput: true }, | ||
exitOnError: false | ||
} | ||
} |
Oops, something went wrong.