This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const program = require('commander') | |
const { description, version } = require('./package.json') | |
program | |
.description(description) | |
.version(version, '-v, - version') | |
.parse(process.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
quizme | |
Usage: quizme [options] | |
Command-line quiz program | |
Options: | |
-h, - help output usage information |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program | |
.command('start') | |
.description('start a quiz') | |
.action(() => { | |
console.log('start') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
...require('./configure'), | |
...require('./start'), | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program | |
.command('configure <url> [otherUrls...]') | |
.action((url) => { | |
configure({ questions: require(url) }) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
question: `What will be an output of the following JavaScript code? | |
for (var i = 0; i < 10; i++) { | |
setTimeout(function() { | |
console.log(i) | |
}, 1000) | |
}`, | |
options: [ | |
'10 times 10', | |
'9 times 9', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const packageJSON = join(__dirname, '..', 'package.json') | |
const package = require(packageJSON) | |
function configure(state) { | |
package.quizme = { ...state } | |
writeFileSync packageJSON, JSON.stringify(package, null, 2)) | |
} | |
function read() { | |
const { quizme = {} } = package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { configure, start } = require('./commands') | |
program | |
.command('start') | |
.description('start a quiz') | |
.action(start) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { promisify } = require('util') | |
const prompt = require('prompt') | |
const get = promisify(prompt.get) | |
function start() { | |
prompt.start() | |
get( | |
questions | |
.map(({ question }, i) => ({ name: `${i}`, description: question })) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inquirer = require('inquirer') | |
const questions = require(questionsFile) | |
.map(({ | |
question, | |
options | |
}, i) => ({ | |
type: 'list', | |
message: question, | |
choices: options, | |
name: `${i}`, |