| 
1 | 1 | import fs from 'fs'  | 
2 | 2 | import { Command } from 'commander'  | 
3 | 3 | import { Context } from '../types.js'  | 
4 |  | -import { color , Listr, ListrDefaultRendererLogLevels, LoggerFormat } from 'listr2'  | 
 | 4 | +import { color, Listr, ListrDefaultRendererLogLevels, LoggerFormat } from 'listr2'  | 
5 | 5 | import auth from '../tasks/auth.js'  | 
6 | 6 | import ctxInit from '../lib/ctx.js'  | 
7 | 7 | import getGitInfo from '../tasks/getGitInfo.js'  | 
8 |  | -import createBuild from '../tasks/createBuild.js'  | 
9 |  | -import captureScreenshots from '../tasks/captureScreenshots.js'  | 
10 | 8 | import finalizeBuild from '../tasks/finalizeBuild.js'  | 
11 |  | -import { validateFigmaDesignConfig } from '../lib/schemaValidation.js'  | 
 | 9 | +import { validateFigmaDesignConfig, validateWebFigmaConfig } from '../lib/schemaValidation.js'  | 
12 | 10 | import uploadFigmaDesigns from '../tasks/uploadFigmaDesigns.js'  | 
 | 11 | +import uploadWebFigma from '../tasks/uploadWebFigma.js'  | 
 | 12 | +import { verifyFigmaWebConfig } from '../lib/config.js'  | 
 | 13 | +import chalk from 'chalk';  | 
13 | 14 | 
 
  | 
14 |  | -const command = new Command();  | 
15 | 15 | 
 
  | 
16 |  | -command  | 
 | 16 | +const uploadFigma = new Command();  | 
 | 17 | +const uploadWebFigmaCommand = new Command();  | 
 | 18 | + | 
 | 19 | +uploadFigma  | 
17 | 20 |     .name('upload-figma')  | 
18 | 21 |     .description('Capture screenshots of static sites')  | 
19 | 22 |     .argument('<file>', 'figma design config file')  | 
20 | 23 |     .option('--markBaseline', 'Mark the uploaded images as baseline')  | 
21 |  | -    .option('--buildName <buildName>' , 'Name of the build')  | 
22 |  | -    .action(async function(file, _, command) {  | 
 | 24 | +    .option('--buildName <buildName>', 'Name of the build')  | 
 | 25 | +    .action(async function (file, _, command) {  | 
23 | 26 |         let ctx: Context = ctxInit(command.optsWithGlobals());  | 
24 | 27 | 
 
  | 
25 | 28 |         if (!fs.existsSync(file)) {  | 
@@ -62,4 +65,67 @@ command  | 
62 | 65 | 
 
  | 
63 | 66 |     })  | 
64 | 67 | 
 
  | 
65 |  | -export default command;  | 
 | 68 | +uploadWebFigmaCommand  | 
 | 69 | +    .name('upload-figma-web')  | 
 | 70 | +    .description('Capture screenshots of static sites')  | 
 | 71 | +    .argument('<file>', 'figma config config file')  | 
 | 72 | +    .option('--markBaseline', 'Mark the uploaded images as baseline')  | 
 | 73 | +    .option('--buildName <buildName>', 'Name of the build')  | 
 | 74 | +    .action(async function (file, _, command) {  | 
 | 75 | +        let ctx: Context = ctxInit(command.optsWithGlobals());  | 
 | 76 | + | 
 | 77 | +        if (!fs.existsSync(file)) {  | 
 | 78 | +            console.log(`Error: figma-web config file ${file} not found.`);  | 
 | 79 | +            return;  | 
 | 80 | +        }  | 
 | 81 | +        try {  | 
 | 82 | +            ctx.config = JSON.parse(fs.readFileSync(file, 'utf8'));  | 
 | 83 | +            ctx.log.info(JSON.stringify(ctx.config));  | 
 | 84 | +            if (!validateWebFigmaConfig(ctx.config)) {  | 
 | 85 | +                ctx.log.debug(JSON.stringify(validateWebFigmaConfig.errors, null, 2));  | 
 | 86 | +                // Iterate and add warning for "additionalProperties"  | 
 | 87 | +                validateWebFigmaConfig.errors?.forEach(error => {  | 
 | 88 | +                    if (error.keyword === "additionalProperties") {  | 
 | 89 | +                        ctx.log.warn(`Additional property "${error.params.additionalProperty}" is not allowed.`)  | 
 | 90 | +                    } else {  | 
 | 91 | +                        const validationError = error.message;  | 
 | 92 | +                        throw new Error(validationError || 'Invalid figma-web config found in file : ' + file);  | 
 | 93 | +                    }  | 
 | 94 | +                });  | 
 | 95 | +            }  | 
 | 96 | + | 
 | 97 | +            //Validate the figma config  | 
 | 98 | +            verifyFigmaWebConfig(ctx);  | 
 | 99 | +        } catch (error: any) {  | 
 | 100 | +            ctx.log.error(chalk.red(`Invalid figma-web config; ${error.message}`));  | 
 | 101 | +            return;  | 
 | 102 | +        }  | 
 | 103 | + | 
 | 104 | +        let tasks = new Listr<Context>(  | 
 | 105 | +            [  | 
 | 106 | +                auth(ctx),  | 
 | 107 | +                getGitInfo(ctx),  | 
 | 108 | +                uploadWebFigma(ctx),  | 
 | 109 | +                finalizeBuild(ctx)  | 
 | 110 | +            ],  | 
 | 111 | +            {  | 
 | 112 | +                rendererOptions: {  | 
 | 113 | +                    icon: {  | 
 | 114 | +                        [ListrDefaultRendererLogLevels.OUTPUT]: `→`  | 
 | 115 | +                    },  | 
 | 116 | +                    color: {  | 
 | 117 | +                        [ListrDefaultRendererLogLevels.OUTPUT]: color.gray as LoggerFormat  | 
 | 118 | +                    }  | 
 | 119 | +                }  | 
 | 120 | +            }  | 
 | 121 | +        )  | 
 | 122 | + | 
 | 123 | +        try {  | 
 | 124 | +            await tasks.run(ctx);  | 
 | 125 | +        } catch (error) {  | 
 | 126 | +            console.log('\nRefer docs: https://www.lambdatest.com/support/docs/smart-visual-regression-testing/');  | 
 | 127 | +        }  | 
 | 128 | + | 
 | 129 | +    })  | 
 | 130 | + | 
 | 131 | +export { uploadFigma, uploadWebFigmaCommand }  | 
0 commit comments