UNPKG

draaft

Version:

A CLI to pull content from https://pilot.pm content collaboration platform and feed your static site generator with markdown files

50 lines (49 loc) 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); const yaml = require("js-yaml"); const path = require("path"); const base_1 = require("../base"); const signal_1 = require("../signal"); const write_1 = require("../write"); class States extends base_1.BaseCommand { async run() { const { flags } = this.parse(States); // Get workflow states list let statesList = []; try { this.spinner.start("Get workflow states list"); let firstPage = await this.api.workflowGetAll(); statesList = firstPage.objects; this.spinner.succeed("Workflow states list downloaded"); this.log("This list represents all workflow states created by the user \n =========================="); } catch (error) { this.spinner.fail("Error while downloading workflow states list"); signal_1.signal.fatal(error); this.exit(1); } statesList.forEach((state) => { this.log(`🏳 ${state.label} [id:${state.id}]`); }); if (flags.save) { let writePath = path.join(process.cwd(), ".draaft", "states.yml"); statesList.forEach((element) => { element.is_draft = true; }); if (flags.backup) { write_1.createFileSafe(writePath, yaml.safeDump(statesList)); } else { write_1.createFile(writePath, yaml.safeDump(statesList)); } } } } States.description = "List all workflow states"; States.flags = { help: command_1.flags.help({ char: "h" }), save: command_1.flags.boolean({ char: "s", description: "Save states as file for customisation" }), backup: command_1.flags.boolean({ char: "b", description: "If file exists create backup" }), }; exports.default = States;