UNPKG

@kriscodeman/clarity-cli

Version:

Because we got better 💩 to do! 🏃🏻💨

208 lines (207 loc) 13.6 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var chalk_1 = __importDefault(require("chalk")); var clear_1 = __importDefault(require("clear")); var figlet_1 = __importDefault(require("figlet")); var commander_1 = require("commander"); var clarity_util_1 = require("./clarity-util"); var process_1 = require("process"); var promptly_1 = __importDefault(require("promptly")); var os_1 = __importDefault(require("os")); var packageJson = __importStar(require("../package.json")); var cli = function () { return __awaiter(void 0, void 0, void 0, function () { var browserType, splash, options, osUser, userName, pass, website, confirmed; return __generator(this, function (_a) { switch (_a.label) { case 0: (0, clear_1.default)(); splash = function () { console.log(chalk_1.default.blue("⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰")); console.log(chalk_1.default.blue(figlet_1.default.textSync("clarity-cli ⏰", { horizontalLayout: "full" }))); console.log(chalk_1.default.blue("🏃🏻 💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨⏰")); }; splash(); commander_1.program .version(packageJson.version) .description("A cli for Clarity Timesheets, because we have better 💩 to do! 🏃🏻💨") .option("-c, --chrome", "Use Chrome Browser") .option("-f, --firefox", "Use Firefox Browser") .option("-s, --safari", "Use Safari Browser") .option("-d, --dryRun", "Don't actually submit the timesheet for approval, just stop at the end.") .option("-h, --headless", "Use headless mode. Oh boy, sure hope you trust me!") .option("-i, --installHelp", "Get installation help") .option("-u, --userName <username>", "Your org username") .option("-w, --website <url>", "Your clarity api url, WITHOUT PROTOCOL, simply like 'clarity.mycompany.com'.") .option("-H, --hours '<number>'", "Hours, if you want to customize the default hours per day") .option("-M, --monday '<number>'", "Hours for Monday, if you want to customize") .option("-T, --tuesday '<number>'", "Hours for Tuesday, if you want to customize") .option("-W, --wednesday '<number>'", "Hours for Wednesday, if you want to customize") .option("-T, --thursday '<number>'", "Hours for Thursday, if you want to customize") .option("-F, --friday '<number>'", "Hours for Friday, if you want to customize") .parse(process.argv); options = commander_1.program.opts(); // handle help param if (!process.argv.slice(2).length) { commander_1.program.outputHelp(); } console.log("\r\n"); console.log("\r\n"); if (options.installHelp) { console.log(chalk_1.default.blue("Need help setting up?")); console.log(chalk_1.default.blue("Happy to help!")); console.log(chalk_1.default.blue("First, go here: https://github.com/SeleniumHQ/selenium/tree/trunk/javascript/node/selenium-webdriver#readme")); console.log(chalk_1.default.blue("Then make sure you have the Driver for your browser installed. If you are using Chrome, get ChromeDriver, etc. ")); (0, process_1.exit)(0); } if (!!options.userName) return [3 /*break*/, 2]; osUser = os_1.default.userInfo().username; return [4 /*yield*/, promptly_1.default.prompt("Your organization username: (default: ".concat(osUser, ")"), { default: osUser, })]; case 1: userName = _a.sent(); options.userName = userName; _a.label = 2; case 2: return [4 /*yield*/, promptly_1.default.password("Password: ", { silent: true })]; case 3: pass = _a.sent(); options.pass = pass; if (!!options.website) return [3 /*break*/, 5]; return [4 /*yield*/, promptly_1.default.prompt("Your organization's clarity url (e.g. clarity.mybiz.com): ")]; case 4: website = _a.sent(); options.website = website; _a.label = 5; case 5: if (!(!options.safari && !options.chrome && !options.firefox)) return [3 /*break*/, 7]; return [4 /*yield*/, promptly_1.default.choose("Which browser have you set up for selenium-webdriver? (default: chrome)", ["chrome", "safari", "firefox"], { default: "chrome" })]; case 6: browserType = (_a.sent()); options[browserType] = true; return [3 /*break*/, 8]; case 7: browserType = options.safari ? "safari" : options.chrome ? "chrome" : options.firefox ? "firefox" : "chrome"; _a.label = 8; case 8: if (!options.hours) { options.hours = 8; } console.log(chalk_1.default.yellow(figlet_1.default.textSync("order up!"))); console.log("\r\n"); console.log(chalk_1.default.yellow("browser: ".concat(browserType))); console.log(chalk_1.default.yellow("userName: ".concat(options.userName))); console.log(chalk_1.default.yellow("password: hahaa-jkjk-:p")); console.log(chalk_1.default.yellow("website: ".concat(options.website))); console.log(chalk_1.default.yellow("dryRun: ".concat(options.dryRun ? "true" : "false"))); console.log(chalk_1.default.yellow("headless: ".concat(options.headless ? "true" : "false"))); console.log(chalk_1.default.yellow("hours: ".concat(options.hours))); console.log(chalk_1.default.yellow("monday: ".concat(options.monday ? options.monday : options.hours))); console.log(chalk_1.default.yellow("tuesday: ".concat(options.tuesday ? options.tuesday : options.hours))); console.log(chalk_1.default.yellow("wednesday: ".concat(options.wednesday ? options.wednesday : options.hours))); console.log(chalk_1.default.yellow("thursday: ".concat(options.thursday ? options.thursday : options.hours))); console.log(chalk_1.default.yellow("friday: ".concat(options.friday ? options.friday : options.hours))); console.log("\r\n"); return [4 /*yield*/, promptly_1.default.confirm("look good to you? (y) or (n)")]; case 9: confirmed = _a.sent(); if (!confirmed) { return [2 /*return*/]; } (0, clear_1.default)(); console.log(chalk_1.default.blue("booting up ".concat(browserType, "..."))); (0, clarity_util_1.clarity)(browserType, options.userName, options.pass, options.website, options.dryRun, options.headless, options.hours, options.monday, options.tuesday, options.wednesday, options.thursday, options.friday) .then(function () { (0, clear_1.default)(); splash(); console.log(chalk_1.default.green(figlet_1.default.textSync("All done!", { horizontalLayout: "full" }))); console.log(chalk_1.default.green("✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅")); console.log("\r\n"); console.log(chalk_1.default.blue("... btw ...")); console.log("\r\n"); console.log(chalk_1.default.blue("... here's a shortcut command for next time ...")); console.log("\r\n"); console.log(chalk_1.default.blue("⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰⏰")); var commandString = "clarity -u ".concat(options.userName, " -w ").concat(options.website, " ").concat((options.chrome && "-c ") || "").concat((options.safari && "-s ") || "").concat((options.firefox && "-f ") || "").concat((options.headless && "-h ") || "").concat((options.dryRun && "-d ") || "").concat((options.hours && options.hours != 8 && "-H '".concat(options.hours, "' ")) || "").concat((options.monday && "-M '".concat(options.monday, "' ")) || "").concat((options.tuesday && "-T '".concat(options.tuesday, "' ")) || "").concat((options.wednesday && "-W '".concat(options.wednesday, "' ")) || "").concat((options.thursday && "--thursday '".concat(options.thrusday, "' ")) || "").concat((options.friday && "-F '".concat(options.friday, "' ")) || ""); console.log("\r\n"); console.log("\r\n"); console.log(chalk_1.default.magenta(commandString)); console.log("\r\n"); console.log("\r\n"); console.log(chalk_1.default.blue("🏃🏻 💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨💨⏰")); }) .catch(console.error); return [2 /*return*/]; } }); }); }; exports.default = cli; void cli();