UNPKG

uxp-linter-test-app

Version:

UXP LINTER is useful for linting your code with ESLint rules and guidelines.

54 lines (45 loc) 1.69 kB
#!/usr/bin/env node "use strict"; require("v8-compile-cache"); //Allowed report formats are mentioned below: //compact, json, string, tap, unix, verbose const { exec } = require('child_process'); const constants = require('./constants'), utils = require('./utils'); const { allowedCSSFormats } = constants; const outputDirectory = './reports'; let reportFilePath = ''; async function generateReport() { var nodeArgs = require('minimist')(process.argv.slice(2)); let reportFormat = !!nodeArgs._[0] ? nodeArgs._[0].toLowerCase() : 'string'; const execCommand = await createReportCommand(reportFormat); if (execCommand) { executeReportCommand(execCommand); } else { console.error('\x1b[31m%s\x1b[0m', 'Error: Please select a valid report type or format!'); } } function executeReportCommand(execCommand) { exec(execCommand, (error, data, getter) => { if (error && getter) { console.error('\x1b[31m%s\x1b[0m', `Error: ${getter} ${reportFilePath}`); throw error; } console.log('\x1b[32m%s\x1b[0m', 'Report generated successfully -> ', reportFilePath); }); } async function createReportCommand(reportFormat) { console.log(`Selected report format -> ${reportFormat}`); let fileNamePrefix = 'uxp-css-lint-report'; const cssLintCmd = await utils.getLintCommand('css', 'Report'); let execCommand; allowedCSSFormats.forEach(format => { if (format.type === reportFormat) { reportFilePath = `${outputDirectory}/${fileNamePrefix}-${reportFormat}.${format.ext}`; execCommand = `${cssLintCmd} -f ${reportFormat} -o ${reportFilePath}`; return; } }); return execCommand; } module.exports = generateReport();