├── .gitignore ├── index.mjs ├── package.json ├── README.md └── clojurequiz.cljs /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | DS-STORE 3 | /.nrepl-port 4 | -------------------------------------------------------------------------------- /index.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { loadFile } from 'nbb'; 4 | import { fileURLToPath } from 'url'; 5 | import { dirname, resolve } from 'path'; 6 | 7 | const __dirname = fileURLToPath(dirname(import.meta.url)); 8 | 9 | await loadFile(resolve(__dirname, 'clojurequiz.cljs')); 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "clojure-quiz", 3 | "version": "0.0.8", 4 | "description": "Who wants to be a Clojure/Script millionaire?", 5 | "homepage": "https://github.com/prestancedesign/clojure-quiz", 6 | "type": "module", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/prestancedesign/clojure-quiz" 10 | }, 11 | "bin": { 12 | "clojure-quiz": "index.mjs" 13 | }, 14 | "dependencies": { 15 | "chalk": "^4.1.2", 16 | "chalk-animation": "^1.6.0", 17 | "figlet": "^1.5.2", 18 | "gradient-string": "^2.0.0", 19 | "inquirer": "^8.2.0", 20 | "nanospinner": "^1.0.0", 21 | "nbb": "^0.1.5" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Clojure/Script Millionaire CLI Tool 2 | 3 | A super fancy CLI tool write in ClojureScript using [nbb](https://github.com/babashka/nbb) (Ad-hoc CLJS scripting on Node.js). 4 | 5 | ## Take the Quiz 6 | 7 | ``` 8 | npx clojure-quiz 9 | ``` 10 | or directly in your browser: https://replit.com/@prestancedesign/clojure-quiz 11 | 12 | ## Packages Used 13 | 14 | [chalk](https://github.com/chalk/chalk) | 15 | [inquirer](https://github.com/SBoudrias/Inquirer.js) | 16 | [gradient-string](https://github.com/bokub/gradient-string) | 17 | [chalk-animation](https://github.com/bokub/chalk-animation) | 18 | [figlet](https://github.com/patorjk/figlet.js) | 19 | [nanospinner](https://github.com/usmanyunusov/nanospinner) 20 | 21 | 22 | ```sh 23 | npm i chalk chalk-animation figlet gradient-string inquirer nanospinner 24 | ``` 25 | 26 | Thanks Fireship for the original Node.js [project](https://github.com/fireship-io/javascript-millionaire). 27 | -------------------------------------------------------------------------------- /clojurequiz.cljs: -------------------------------------------------------------------------------- 1 | (ns clojurequiz 2 | (:require 3 | [promesa.core :as p] 4 | ["chalk$default" :as chalk] 5 | ["chalk-animation$default" :refer [rainbow]] 6 | ["inquirer$default" :as inquirer] 7 | ["gradient-string$default" :as gradient] 8 | ["figlet$default" :as figlet] 9 | ["console$log" :as log] 10 | ["nanospinner$default" :refer [createSpinner]])) 11 | 12 | (def player-name (atom "")) 13 | 14 | (defn sleep 15 | ([] (sleep 2000)) 16 | ([ms] (js/Promise. (fn [resolve] (js/setTimeout resolve ms))))) 17 | 18 | (defn welcome [] 19 | (p/let [rainbow-title (rainbow "Who Wants To Be A Clojure Millionaire? \n")] 20 | rainbow-title 21 | (sleep) 22 | (.stop rainbow-title) 23 | (log (str (chalk/bgBlue "HOW TO PLAY\n") 24 | "I am a process on your computer.\n" 25 | "If you get any question wrong I will be " (chalk/bgRed "killed\n") 26 | "So get all the questions right...")))) 27 | 28 | (defn handle-answer [is-correct] 29 | (p/let [spinner (.start (createSpinner "Checking answer..."))] 30 | (sleep 1000) 31 | (if is-correct 32 | (.success spinner #js {:text (str "Nice work " @player-name ". That's a legit answer")}) 33 | (do 34 | (.error spinner #js {:text (str "💀💀💀 Game over, you lose " @player-name "!")}) 35 | (.exit js/process 1))))) 36 | 37 | (defn ask-name [] 38 | (p/let [answers (inquirer/prompt #js {:name "player_name" 39 | :type "input" 40 | :message "What is your name?" 41 | :default (fn [] "Player")})] 42 | (reset! player-name (.-player_name answers)))) 43 | 44 | (defn winner [] 45 | (js/console.clear) 46 | (figlet (str "Congrats , " @player-name " !\n $ 1 , 0 0 0 , 0 0 0") 47 | (fn [err data] 48 | (log (.multiline (.-pastel gradient) data) "\n") 49 | (log (.green chalk "Programming isn't about what you know; it's about making the command line look cool"))))) 50 | 51 | (defn question-1 [] 52 | (p/let [answers (inquirer/prompt (clj->js {:name "question_1" 53 | :type "list" 54 | :message "When was Clojure released?\n" 55 | :choices ["May 23rd, 2011" 56 | "Oct 16th, 2007" 57 | "Dec 4th, 2005" 58 | "Dec 17, 1996"]}))] 59 | (handle-answer (= (.-question_1 answers) "Oct 16th, 2007")))) 60 | 61 | (defn question-2 [] 62 | (p/let [answers (inquirer/prompt (clj->js {:name "question_2" 63 | :type "list" 64 | :message "Who designed Clojure\n" 65 | :choices ["Yukihiro Matsumoto" 66 | "John Clojure" 67 | "Rich Hickey" 68 | "James Gosling"]}))] 69 | (handle-answer (= (.-question_2 answers) "Rich Hickey")))) 70 | 71 | (defn question-3 [] 72 | (p/let [answers (inquirer/prompt (clj->js {:name "question_3" 73 | :type "list" 74 | :message "Which of these is not a file extension for Clojure?\n" 75 | :choices ["clj" 76 | "cljc" 77 | "ens" 78 | "edn"]}))] 79 | (handle-answer (= (.-question_3 answers) "ens")))) 80 | 81 | (defn question-4 [] 82 | (p/let [answers (inquirer/prompt (clj->js {:name "question_4" 83 | :type "list" 84 | :message "Which of these platforms is not used to run Clojure?\n" 85 | :choices ["Java Virtual Machine" 86 | "Common Language Runtime" 87 | "Commodore 64" 88 | "JavaScript"]}))] 89 | (handle-answer (= (.-question_4 answers) "Commodore 64")))) 90 | 91 | (js/console.clear) 92 | 93 | (p/do! (welcome) 94 | (ask-name) 95 | (question-1) 96 | (question-2) 97 | (question-3) 98 | (question-4) 99 | (winner)) 100 | --------------------------------------------------------------------------------