UNPKG

proca

Version:
110 lines (97 loc) 2.89 kB
import { Args, Flags } from "@oclif/core"; import { error, stdout, ux } from "@oclif/core/ux"; import { get as getConfig, getFilename, load, 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 = "update the setting used to authenticate to the servers and services"; static examples = [ "<%= config.bin %> <%= command.id %> --user=xavier@example.org --token=API-12345789", ]; static flags = { // flag with no value (-f, --force) ...super.globalFlags, url: Flags.string({ description: "url of the proca server api", default: "https://api.proca.app/api", helpValue: "<url>", }), "cloudflare-zone": Flags.string({ description: "zone for your cloudflare cdn", }), "cloudflare-token": Flags.string({ description: "token for your cloudflare cdn", }), token: Flags.string({ description: "user token on proca server", helpValue: "<API-token>", }), 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 config = this.config; const { args, flags, raw } = await this.parse(); const rawf = raw.filter((d) => d.type === "flag").map((d) => d.flag); const file = getFilename(this.config.configDir); const userConfig = getConfig(file, true); console.log("config file", file); console.error(file, userConfig, rawf); process.exit(1); 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()); } }