Skip to content

Commit

Permalink
Pull validation methods into own file. Fix version check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean O'Donohue committed Feb 26, 2018
1 parent 48bfe7a commit 0d738b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
27 changes: 17 additions & 10 deletions bin/axolemma
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
#!/usr/bin/env node

const ax = require('axolemma')
const cli = require('commander')
const inquirer = require('inquirer')
const semver = require('semver')
const {Subject} = require('rxjs')
const {bold, green, blue, red} = require('chalk')

const {version} = require('../package.json')

if (semver.lt('8.0.0')) {
console.log(red(`Axolemma supports Node version ${bold('8')} or higher.`))
if (semver.lt(process.version,'8.0.0')) {
console.log(red(`Axolemma supports Node ${bold('v8.0.0')} or higher.`))
console.log(red(`You are currently using ${bold(process.version)}.`))
return process.exit(1)
}

const {version} = require('../package.json')

const ax = require('../')
const {isAlphanumeric} = require('./validation')



cli.version('0.1.0')
cli.on('--help', () => {
console.log(blue(`Type ${bold(green('axolemma'))} to start creating.`))
})

const prompts = new Subject()
inquirer.prompt(prompts)
inquirer.prompt(prompts).ui.process.subscribe(console.log, console.log, function(answers){
console.log(answers)
ax.generate(answers) // Eventually this will be done during the prompts, and user will be prompted to approve of the generated map.
})

prompts.next({
type: 'input',
name: 'areaTitle',
message: blue('What would you like to title this area?'),
validate(input) {
const alphanumeric = /^[0-9a-zA-Z]+$/
return input.match(alphanumeric)
}
validate: isAlphanumeric,
})

prompts.complete()
6 changes: 6 additions & 0 deletions bin/validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
isAlphanumeric(input) {
const alphanumeric = /^[0-9a-zA-Z]+$/
return input.match(alphanumeric)
}
}

0 comments on commit 0d738b7

Please sign in to comment.