frontity
Version:
Frontity cli and entry point to other packages
49 lines (48 loc) • 1.69 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ora_1 = __importDefault(require("ora"));
const chalk_1 = __importDefault(require("chalk"));
const utils_1 = require("../utils");
const subscribe_1 = __importDefault(require("../commands/subscribe"));
const inquirer_1 = require("inquirer");
/**
* The subscribe CLI command, usually run with `npx frontity subscribe`.
*
* It takes args from the CLI. Then, it runs the subscribe command
* programatically.
*
* @param options - Defined in {@link SubscribeOptions}.
*/
const subscribe = async ({ email }) => {
while (!email) {
const subscribeQuestion = [
{
name: "email",
type: "input",
message: "Please, enter your email:",
},
];
const answer = await inquirer_1.prompt(subscribeQuestion);
email = answer.email;
}
try {
const emitter = subscribe_1.default(email);
emitter.on("message", (message, action) => {
if (action)
ora_1.default.promise(action, message);
else
console.log(message);
});
// Actually subsribe the user
await emitter;
}
catch (error) {
utils_1.errorLogger(error);
}
console.log(`${chalk_1.default.bold("\nThanks for subscribing to our newsletter!")}
\nIf you have any doubts, join our community at ${chalk_1.default.underline.magenta("https://community.frontity.org/")}.\n`);
};
exports.default = subscribe;