"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.addConnectCommandToProgram = addConnectCommandToProgram; exports.getAccessToken = getAccessToken; exports.getAccessTokenOrExit = getAccessTokenOrExit; exports.getDir = getDir; exports.setupHandler = setupHandler; exports.getCodeConnectObjects = getCodeConnectObjects; const fs_1 = __importDefault(require("fs")); const preview_utils_1 = require("./preview_utils"); const upload_1 = require("../connect/upload"); const validation_1 = require("../connect/validation"); const create_1 = require("../connect/create"); const project_1 = require("../connect/project"); const logging_1 = require("../common/logging"); const convert_1 = require("../storybook/convert"); const delete_docs_1 = require("../connect/delete_docs"); const run_wizard_1 = require("../connect/wizard/run_wizard"); const parser_executables_1 = require("../connect/parser_executables"); const zod_validation_error_1 = require("zod-validation-error"); const parser_executable_types_1 = require("../connect/parser_executable_types"); const path_1 = __importDefault(require("path")); const updates_1 = require("../common/updates"); const helpers_1 = require("../connect/helpers"); const filter_project_info_1 = require("./filter_project_info"); const parser_1 = require("../html/parser"); const parser_common_1 = require("../connect/parser_common"); const parser_2 = require("../react/parser"); const label_language_mapping_1 = require("../connect/label_language_mapping"); const migration_helpers_1 = require("../connect/migration_helpers"); const raw_templates_1 = require("../connect/raw_templates"); const batch_templates_1 = require("../connect/batch_templates"); const run_wizard_2 = require("../connect/wizard/run_wizard"); const project_2 = require("../connect/project"); function addBaseCommand(command, name, description) { return command .command(name) .description(description) .usage('[options]') .option('-r --dir ', 'directory to parse') .option('-f --file ', 'path to a single Code Connect file to process') .option('-t --token ', 'figma access token') .option('-v --verbose', 'enable verbose logging for debugging') .option('-o --outFile ', 'specify a file to output generated Code Connect') .option('-o --outDir ', 'specify a directory to output generated Code Connect') .option('-c --config ', 'path to a figma config file') .option('-a --api-url ', 'custom Figma API URL to use instead of https://api.figma.com/v1') .option('--skip-update-check', 'skips checking for an updated version of the Figma CLI') .option('--exit-on-unreadable-files', 'exit if any Code Connect files cannot be parsed. We recommend using this option for CI/CD.') .option('--dry-run', 'tests publishing without actually publishing') .addHelpText('before', 'For feedback or bugs, please raise an issue: https://github.com/figma/code-connect/issues'); } function addConnectCommandToProgram(program) { // Main command, invoked with `figma connect` const connectCommand = addBaseCommand(program, 'connect', 'Figma Code Connect').action((0, updates_1.withUpdateCheck)(run_wizard_1.runWizard)); // Sub-commands, invoked with e.g. `figma connect publish` addBaseCommand(connectCommand, 'publish', 'Run Code Connect locally to find any files that have figma connections and publish them to Figma. ' + 'By default this looks for a config file named "figma.config.json", and uses the `include` and `exclude` fields to determine which files to parse. ' + 'If no config file is found, this parses the current directory. An optional `--dir` flag can be used to specify a directory to parse.') .option('--skip-validation', 'skip validation of Code Connect docs') .option('-l --label