UNPKG

bulk-mail-cli

Version:

Do quick, hassle-free email marketing with this small but very powerful tool! 🔥

54 lines • 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var stripJsonComments = require("strip-json-comments"); var fs = require("fs"); var chalk = require("chalk"); var doesFileExist_1 = require("../../utils/doesFileExist"); var isFileType_1 = require("../../utils/isFileType"); var checkJsonConfiguration_1 = require("./checkJsonConfiguration"); var massMail_1 = require("./massMail"); var fileToJson; var isJsonConfigurationPassed = false; function fileCommand(filePath, shouldRestart) { if (shouldRestart === void 0) { shouldRestart = false; } return tslib_1.__awaiter(this, void 0, void 0, function () { var filePathToConsider; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: filePathToConsider = tslib_1.__spread(filePath)[0] === '/' ? filePath : process.cwd() + "/" + filePath; if (!isFileType_1.default(filePathToConsider, 'json')) { console.log("" + chalk.red.bold("bulk-mail-cli only accepts a JSON configuration file.")); process.exit(); } if (!doesFileExist_1.default(filePathToConsider)) return [3, 2]; try { fileToJson = tslib_1.__assign(tslib_1.__assign({}, JSON.parse(stripJsonComments(fs.readFileSync(filePathToConsider).toString()))), { jsonConfPath: filePathToConsider }); } catch (error) { console.log("" + chalk.red.bold("The given file does not exist:")); process.exit(); } return [4, checkJsonConfiguration_1.default(fileToJson)]; case 1: isJsonConfigurationPassed = _a.sent(); return [3, 3]; case 2: console.log(chalk.red.bold("The given file does not exist:") + " " + chalk.cyan(filePath)); _a.label = 3; case 3: if (!isJsonConfigurationPassed) { process.exit(); } console.log(chalk.green.bold("Starting the Mailing Process >>>") + "\n"); return [4, massMail_1.default(fileToJson, shouldRestart)]; case 4: _a.sent(); return [2]; } }); }); } exports.default = fileCommand; //# sourceMappingURL=index.js.map