| 
 | 1 | +import fs from 'fs'  | 
 | 2 | +import { Command } from 'commander'  | 
 | 3 | +import { Context } from '../types.js'  | 
 | 4 | +import { color , Listr, ListrDefaultRendererLogLevels, LoggerFormat } from 'listr2'  | 
 | 5 | +import auth from '../tasks/auth.js'  | 
 | 6 | +import ctxInit from '../lib/ctx.js'  | 
 | 7 | +import getGitInfo from '../tasks/getGitInfo.js'  | 
 | 8 | +import createBuild from '../tasks/createBuild.js'  | 
 | 9 | +import captureScreenshots from '../tasks/captureScreenshots.js'  | 
 | 10 | +import finalizeBuild from '../tasks/finalizeBuild.js'  | 
 | 11 | +import { validateFigmaDesignConfig } from '../lib/schemaValidation.js'  | 
 | 12 | +import uploadFigmaDesigns from '../tasks/uploadFigmaDesigns.js'  | 
 | 13 | + | 
 | 14 | +const command = new Command();  | 
 | 15 | + | 
 | 16 | +command  | 
 | 17 | +    .name('upload-figma')  | 
 | 18 | +    .description('Capture screenshots of static sites')  | 
 | 19 | +    .argument('<file>', 'figma design config file')  | 
 | 20 | +    .option('--markBaseline', 'Mark the uploaded images as baseline')  | 
 | 21 | +    .option('--buildName <buildName>' , 'Name of the build')  | 
 | 22 | +    .action(async function(file, _, command) {  | 
 | 23 | +        let ctx: Context = ctxInit(command.optsWithGlobals());  | 
 | 24 | + | 
 | 25 | +        if (!fs.existsSync(file)) {  | 
 | 26 | +            console.log(`Error: Figma Config file ${file} not found.`);  | 
 | 27 | +            return;  | 
 | 28 | +        }  | 
 | 29 | +        try {  | 
 | 30 | +            ctx.figmaDesignConfig = JSON.parse(fs.readFileSync(file, 'utf8'));  | 
 | 31 | +            if (!validateFigmaDesignConfig(ctx.figmaDesignConfig)) {  | 
 | 32 | +                const validationError = validateFigmaDesignConfig.errors?.[0]?.message;  | 
 | 33 | +                throw new Error(validationError || 'Invalid figma design Config');  | 
 | 34 | +            }  | 
 | 35 | +        } catch (error: any) {  | 
 | 36 | +            console.log(`[smartui] Error: Invalid figma design Config; ${error.message}`);  | 
 | 37 | +            return;  | 
 | 38 | +        }  | 
 | 39 | + | 
 | 40 | +        let tasks = new Listr<Context>(  | 
 | 41 | +            [  | 
 | 42 | +                auth(ctx),  | 
 | 43 | +                uploadFigmaDesigns(ctx)  | 
 | 44 | +            ],  | 
 | 45 | +            {  | 
 | 46 | +                rendererOptions: {  | 
 | 47 | +                    icon: {  | 
 | 48 | +                        [ListrDefaultRendererLogLevels.OUTPUT]: `→`  | 
 | 49 | +                    },  | 
 | 50 | +                    color: {  | 
 | 51 | +                        [ListrDefaultRendererLogLevels.OUTPUT]: color.gray as LoggerFormat  | 
 | 52 | +                    }  | 
 | 53 | +                }  | 
 | 54 | +            }  | 
 | 55 | +        )  | 
 | 56 | + | 
 | 57 | +        try {  | 
 | 58 | +            await tasks.run(ctx);  | 
 | 59 | +        } catch (error) {  | 
 | 60 | +            console.log('\nRefer docs: https://www.lambdatest.com/support/docs/smart-visual-regression-testing/');  | 
 | 61 | +        }  | 
 | 62 | + | 
 | 63 | +    })  | 
 | 64 | + | 
 | 65 | +export default command;  | 
0 commit comments