UNPKG

qcobjects-cli

Version:

qcobjects cli command line tool

8 lines (7 loc) 9.41 kB
{ "version": 3, "sources": ["../../src/enterprise-commands.ts"], "sourcesContent": ["/**\n * QCObjects CLI 2.4.x\n * ________________\n *\n * Author: Jean Machuca <correojean@gmail.com>\n *\n * Cross Browser Javascript Framework for MVC Patterns\n * QuickCorp/QCObjects is licensed under the\n * GNU Lesser General Public License v3.0\n * [LICENSE] (https://github.com/QuickCorp/QCObjects/blob/master/LICENSE.txt)\n *\n * Permissions of this copyleft license are conditioned on making available\n * complete source code of licensed works and modifications under the same\n * license or the GNU GPLv3. Copyright and license notices must be preserved.\n * Contributors provide an express grant of patent rights. However, a larger\n * work using the licensed work through interfaces provided by the licensed\n * work may be distributed under different terms and without source code for\n * the larger work.\n *\n * Copyright (C) 2015 Jean Machuca,<correojean@gmail.com>\n *\n * Everyone is permitted to copy and distribute verbatim copies of this\n * license document, but changing it is not allowed.\n */\n/*eslint no-unused-vars: \"off\"*/\n/*eslint no-redeclare: \"off\"*/\n/*eslint no-empty: \"off\"*/\n/*eslint strict: \"off\"*/\n/*eslint no-mixed-operators: \"off\"*/\n/*eslint no-undef: \"off\"*/\n\"use strict\";\n\nimport { execSync } from \"node:child_process\";\nimport readline from \"readline\";\nimport { Package, InheritClass, CONFIG, logger } from \"qcobjects\";\n\nconst license: string = CONFIG.get(\"enterprise-license\", \"1234\");\nconst email: string = CONFIG.get(\"enterprise-email\", \"a@b.com\");\n\nconst MESSAGES = {\n NOTE: \"[NOTE: No information will be sent to a server until I got your consent]\",\n EMAIL_PROMPT: \"Please tell me your e-Mail (\uD83D\uDC8C):\",\n PHONE_PROMPT: \"Please tell me your phone number (\uD83E\uDD19): \\n\",\n OPTION_PROMPT: `\nPlease select one of the following options (type a number):\n\n1.- \uD83D\uDE40 This is your first interaction \uD83D\uDE0D with QCObjects Enterprise Edition \uD83C\uDFE2,\nyou want to send your email and phone number to one of our executives to process your\ninquiry, pay the license (when aplies) and receive a new fresh license number\nthat will free up to you the most advanced features for large companies\n\n2.- \u2714 Your assigned executive \uD83E\uDDD1 has given to you a new fresh QCObjects Enterprise Edition License Number\nand you want to enter it to follow up with the next steps.\n\n3.- \uD83C\uDFC3 You want to quit this form, as you got here accidentally\n(You should think about it. It's not a coincidence, It's destiny \uD83D\uDE00).\n\nPlease enter the number of the option and press [enter]: `,\n REGISTRATION_SUCCESS: `\uD83D\uDC4F Congrats! You have been successfully registered to the cloud! \uD83D\uDC4F\nOne of our executives will be in touch with you as soon as possible to give you the next steps\nto get a new License Number and start using QCObjects Entrprise Edition!\n\n(In the meantime, you can continue using all the features of the QCObjects Community Edition)\n`,\n LICENSE_PROMPT: \"Please tell me the number of license that your executive has given to you: \\n\",\n COMMUNITY_EDITION: \"\uD83E\uDD37 You can continue to use QCObjects Community Edition, see you! \uD83D\uDE4B \",\n PHONE_REQUIRED: `You need to enter a Phone Number if you want to be contacted.\nIf you want to quit, press Ctrl-C.\n`,\n EMAIL_REQUIRED: `You need to enter a real e-Mail address if you want to be contacted.\nIf you want to quit, press Ctrl-C.\n`,\n INSTALLING: \"Now, I'm installing QCObjects Enterprise Edition in your computer...\",\n INSTALL_SUCCESS: `\uD83D\uDC4F Congrats! Now you have installed QCObjects Enterprise Edition! \uD83D\uDC4F\nYou can test it using:\n> qcobjects --version\n\nTo find more help, type the command:\n\n> qcobjects --help\n\nEnjoy!\n`,\n INSTALL_FAILURE: \"\uD83E\uDD26 Something went wrong \uD83E\uDD26 when trying to update your license to QCObjects Enterprise Edition. Ask your executive to help.\"\n};\n\nconst OPTIONS = {\n FIRST_INTERACTION: \"1\",\n ENTER_LICENSE: \"2\",\n QUIT: \"3\"\n};\n\nexport class QCObjectsEnterprise extends InheritClass {\n\n install(): void {\n const instance = this;\n instance.installEnterprise(license, email);\n }\n\n static async upgrade(switchCommander: any): Promise<void> {\n const instance = new QCObjectsEnterprise();\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n });\n\n const question = (query: string): Promise<string> => {\n return new Promise(resolve => rl.question(query, resolve));\n };\n\n const emailQuestion = async (): Promise<void> => {\n const email = await question(`${MESSAGES.NOTE}\\n\\n${MESSAGES.EMAIL_PROMPT}`);\n if (email !== \"\") {\n const phoneNumberQuestion = async (): Promise<void> => {\n const phonenumber = await question(MESSAGES.PHONE_PROMPT);\n if (phonenumber !== \"\") {\n const interaction_option = await question(MESSAGES.OPTION_PROMPT);\n logger.infoEnabled = true;\n\n switch (interaction_option) {\n case OPTIONS.FIRST_INTERACTION: {\n try {\n await switchCommander.register(email, phonenumber);\n logger.info(MESSAGES.REGISTRATION_SUCCESS);\n } finally {\n rl.close();\n }\n break;\n }\n case OPTIONS.ENTER_LICENSE: {\n const license = await question(MESSAGES.LICENSE_PROMPT);\n instance.installEnterprise(license, email);\n rl.close();\n break;\n }\n case OPTIONS.QUIT:\n default: {\n logger.info(MESSAGES.COMMUNITY_EDITION);\n rl.close();\n break;\n }\n }\n } else {\n console.log(MESSAGES.PHONE_REQUIRED);\n await phoneNumberQuestion();\n }\n };\n await phoneNumberQuestion();\n } else {\n console.log(MESSAGES.EMAIL_REQUIRED);\n await emailQuestion();\n }\n };\n await emailQuestion();\n }\n\n installEnterprise(license: string, email: string): void {\n const asterisk = \"*\";\n logger.info(`Your entered license number is ${asterisk.repeat(license.length)} and the email that you have entered is ${email}`);\n logger.info(MESSAGES.INSTALLING);\n const cmdDownloadGit = `npm i --force -g git+https://license:${license}@software.qcobjects.io/qcobjects-enterprise/qcobjects-enterprise.git`;\n execSync(cmdDownloadGit);\n const stdout = execSync(\"qcobjects --version\");\n if (stdout.toString().includes(\"Enterprise Edition\")) {\n logger.info(MESSAGES.INSTALL_SUCCESS);\n } else {\n console.log(MESSAGES.INSTALL_FAILURE);\n }\n }\n}\n\nPackage(\"org.qcobjects.enterprise.commands\", [\n QCObjectsEnterprise\n]);\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgCA,gCAAyB;AACz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