UNPKG

proca

Version:
102 lines (91 loc) 2.63 kB
import { Args, Flags } from "@oclif/core"; import { error, stdout, ux } from "@oclif/core/ux"; import { get as getConfig, getFilename, write } from "#src/config.mjs"; import Command from "#src/procaCommand.mjs"; export default class CampaignList extends Command { static enableJsonFlag = true; static aliases = ["config:setup"]; static deprecateAliases = true; static args = { environment: Args.string({ description: "environment", default: "default", }), }; static description = "create setting to access the server authentication"; static examples = [ "<%= config.bin %> <%= command.id %> --user=xavier@example.org --token=API-12345789", ]; static flags = { // flag with no value (-f, --force) ...super.globalFlags, force: Flags.boolean({ description: "write over an existing configuration", default: false, helpValue: "(default false)", }), url: Flags.string({ description: "url of the proca server api", default: "https://api.proca.app/api", helpValue: "<url>", }), token: Flags.string({ description: "user token on proca server", helpValue: "<API-token>", required: true, }), n8n: Flags.string({ description: "api access on the n8n server", helpValue: "<n8n api>", }), supabase: Flags.string({ description: "url of the supabase", helpValue: "<url>", }), "supabase-anon-key": Flags.string({ description: "anonymous key", }), "supabase-secrey-key": Flags.string({ description: "secret service key", }), }; format = (obj) => { const content = ["# generated by proca-api"]; for (const [key, value] of Object.entries(obj)) { if (value) { content.push(`${key}='${value.replace(/'/g, "''")}'`); } else { content.push(`#${key}= `); } } return content.join("\n"); }; generate = function () { const mapping = { REACT_APP_NAME: "proca", REACT_APP_API_URL: this.flags.url, PROCA_TOKEN: this.flags.token, N8N_TOKEN: this.flags.n8n, REACT_APP_SUPABASE_URL: this.flags.supabase, REACT_APP_SUPABASE_ANON_KEY: this.flags.supabase_anon_key, SUPABASE_SECRET_KEY: this.flags.supabase_secret_key, }; return this.format(mapping); }; async run() { const { args, flags } = await this.parse(); const file = getFilename(this.config.configDir); const userConfig = getConfig(file); if (userConfig && !this.flags.force) { this.error("config file exists already", { code: "CONFIG_ERR", _ref: "README.md#", suggestions: [ `edit ${file}`, "add --force flag\nWARNING, it will delete the existing file", ], }); } write(file, this.generate()); } }