conjuror
Version:
A magical CSV data parsing and outputing wizard or witch
115 lines (101 loc) • 2.72 kB
JavaScript
/** Conjuror - Output
* A CLI interface to output a Conjuror report
*/
var inquirer = require('inquirer')
var _ = require('underscore')
var chalk = require('chalk')
var read = require('datapackage-read')
var config = require('../lib/conjuror.config.js')
var Conjuror = require('../lib/conjuror.basic.js')
// Load Conjuror Modules
Conjuror.Recipes = require('../lib/conjuror.recipes.js')
Conjuror.Date = require('../lib/conjuror.date.js')
Conjuror.Trim = require('../lib/conjuror.trim.js')
Conjuror.Search = require('../lib/conjuror.search.js')
// CLI Items
var questions = [{
type: 'list',
name: 'input',
choices: [],
message: 'Select project to run report'
},{
type: 'input',
name: 'output',
message: 'Name this report',
default: ''
},{
type: 'input',
name: 'date',
message: 'Specify date to filter by'
},{
type: "input",
name: "generated",
message: "What date is this generated on",
default: 'today'
},{
type: 'input',
name: 'invoicenumber',
message: 'Does this report have a number',
default: 0
},{
type: "input",
name: "extra",
message: "Specify any extra information",
default: ''
},{
type: "list",
name: "details",
message: "Would you like to show details of data",
choices: ['show', 'hide'],
default: 'show'
},{
type: "input",
name: "message",
message: "Add an optional message to report"
},{
type: 'input',
name: 'price',
message: 'Add a fixed price or leave blank to:',
default: 'tally'
},{
type: 'rawlist',
name: 'currency',
message: 'What country do you live in',
choices: ['USD', 'Euro', 'GPB', 'Bitcoin'],
default: 'USD'
},{
type: 'checkbox',
name: 'formats',
message: 'Select formats to output this report',
choices: ['pdf', 'html', 'csv'],
default: 'pdf'
}
]
// Run CLI
function runOutput() {
// Check for Input
Conjuror.getIngredients(config.get_file_path(), function(config_data) {
console.log(config_data)
// New Invoice Number
var new_count = config.new_invoice_count(config_data.user.invoice_count + 1)
questions[4].default = new_count
// Show Projects
_.each(config_data.projects, function(project, key) {
questions[0].choices.push(project.path)
})
inquirer.prompt(questions).then(answers => {
var app_path = __filename.replace('cli/output.js', '')
var args = {
targets: [],
options: answers,
config: config,
app_path: app_path
}
// Make Output
Conjuror.Grow(args)
// TODO need to update Config (user.invoice_count)
})
})
}
runOutput()