Comparing version 2.0.2 to 2.0.3
@@ -52,3 +52,3 @@ var fs = require('fs'); | ||
}); | ||
} | ||
}; | ||
@@ -61,4 +61,4 @@ function copyFilesInDir(dir, options) { | ||
// write it out | ||
fs.writeFileSync(options.projectFolder + '/' + filename, string, {encoding: 'utf8'}) | ||
fs.writeFileSync(options.projectFolder + '/' + filename, string, {encoding: 'utf8'}); | ||
}); | ||
} |
@@ -1,2 +0,2 @@ | ||
var commander = require('commander'); | ||
var inquirer = require('inquirer'); | ||
var chalk = require('chalk'); | ||
@@ -7,113 +7,74 @@ var generateApp = require('./generateApp'); | ||
module.exports = function (config) { | ||
var appName = (function () { | ||
if (!config.name) return 'My Amazing App'; | ||
var appName = 'My Amazing App'; | ||
if (config.name) { | ||
var name = config.name.split(' ')[0]; | ||
name = name.slice(0, 1).toUpperCase() + name.slice(1); | ||
return name + '\'s Amazing App'; | ||
}()); | ||
var progress = 0; | ||
var result = {}; | ||
var schema = [ | ||
appName = name + '\'s Amazing App'; | ||
} | ||
function required(value) { | ||
return !!value.trim() || 'Required'; | ||
} | ||
console.log([ | ||
chalk.bold('ampersand.js') + ' - app generator', | ||
'', | ||
'This will make a new directory for your app in:', | ||
chalk.magenta(process.cwd()), | ||
'', | ||
].join('\n')); | ||
var questions = [ | ||
{ | ||
name: 'projectFolder', | ||
question: [ | ||
chalk.bold('ampersand.js') + ' - app generator', | ||
'', | ||
'This will make a new directory for your app in:', | ||
chalk.green(process.cwd()), | ||
'', | ||
'What do you want to call the folder?' | ||
].join('\n'), | ||
prompt: 'folder name', | ||
test: function (answer) { | ||
if (answer) { | ||
return answer; | ||
} | ||
} | ||
message: 'What do you want to call the folder?', | ||
validate: required | ||
}, | ||
{ | ||
name: 'title', | ||
question: 'What is the human friendly title of your app? (e.g. ' + appName + ')', | ||
prompt: 'app title', | ||
test: function (answer) { | ||
if (answer) { | ||
return answer; | ||
} | ||
message: 'What is the human friendly title of your app?', | ||
default: appName, | ||
filter: function (value) { | ||
return value.replace('"', ''); | ||
}, | ||
message: 'Required' | ||
validate: required | ||
}, | ||
{ | ||
name: 'framework', | ||
question: [ | ||
'Do you want to use hapi or express as a server framework?' | ||
].join('\n'), | ||
prefill: config.framework || 'hapi', | ||
prompt: 'hapi or express', | ||
test: function (answer) { | ||
// default hapi if not set | ||
answer = answer ? answer.toLowerCase().trim() : 'hapi'; | ||
if (['hapi', 'express'].indexOf(answer) !== -1) { | ||
return answer; | ||
} | ||
}, | ||
message: 'Must be \'hapi\' or \'express\'' | ||
type: 'list', | ||
name: 'serverFramework', | ||
message: 'Do you want to use hapi or express as a server framework?', | ||
default: config.framework || 'hapi', | ||
choices: ['hapi', 'express'] | ||
}, | ||
{ | ||
name: 'author', | ||
question: 'What\'s your name? Used to populate "author" field of "package.json"' + chalk.blue('\n\n{\n "name": "app",\n "version": "0.0.1",\n "author": "') + chalk.white('Your answer') + chalk.blue('",\n "dependencies": ...\n}\n'), | ||
prompt: 'Author Name', | ||
prefill: config.name, | ||
test: function (answer) { | ||
// try to see if we've got one | ||
if (!answer) answer = config.name; | ||
if (answer) { | ||
return answer; | ||
} | ||
}, | ||
message: 'Required' | ||
message: [ | ||
'What\'s your name? Used to populate "author" field of "package.json", as:', | ||
'', | ||
chalk.grey('{'), | ||
chalk.grey(' "name": "app",'), | ||
chalk.grey(' "version": "0.0.1",'), | ||
chalk.grey(' "author": "' + chalk.magenta('Your answer') + '",'), | ||
chalk.grey(' "dependencies": ...'), | ||
chalk.grey('}'), | ||
'', | ||
chalk.white('Author Name:') | ||
].join('\n'), | ||
default: config.name, | ||
validate: required | ||
} | ||
]; | ||
function buildQuestion(index) { | ||
var desc = schema[index]; | ||
var prefill; | ||
var str; | ||
// if normal prompt | ||
if (desc) { | ||
prefill = (desc.prefill ? '(' + desc.prefill + ')' : ''); | ||
str = '\n' + desc.question + '\n' + chalk.grey(desc.prompt + ': ') + prefill + ' '; | ||
commander.prompt(str, function (answer) { | ||
var testedAnswer = desc.test(answer); | ||
if (typeof testedAnswer === 'string') { | ||
result[desc.name] = testedAnswer; | ||
progress++; | ||
} else { | ||
console.log(chalk.red('\nerror: ' + desc.message)); | ||
} | ||
buildQuestion(progress); | ||
}); | ||
} else { | ||
// manually remove double quotes from the title since they get templated into code directly | ||
result.title = result.title.replace('"', ''); | ||
generateApp(result, function (err) { | ||
if (!err) { | ||
console.log('\n\n' + chalk.green(chalk.bold(result.title) + ' was created!\n')); | ||
console.log([ | ||
'', | ||
'now cd to it, install dependencies, and run it:', | ||
'', | ||
chalk.grey(' $ cd ' + result.projectFolder + ' && npm install && npm start'), | ||
'' | ||
].join('\n')); | ||
process.stdin.destroy(); | ||
} else { | ||
console.log(chalk.red('error:'), err); | ||
} | ||
}); | ||
} | ||
} | ||
buildQuestion(progress); | ||
inquirer.prompt(questions, function (answers) { | ||
generateApp(answers, function (err) { | ||
if (err) return console.log(chalk.red('error:'), err); | ||
console.log([ | ||
chalk.magenta(chalk.bold(answers.title) + ' was created!'), | ||
'now cd to it, install dependencies, and run it:', | ||
chalk.grey(' $ cd ' + answers.projectFolder + ' && npm install && npm start'), | ||
'' | ||
].join('\n\n')); | ||
process.stdin.destroy(); | ||
}); | ||
}); | ||
}; |
var fs = require('fs'); | ||
var _ = require('underscore'); | ||
var humps = require('humps'); | ||
var esprima = require('esprima'); | ||
@@ -13,10 +12,8 @@ var processTemplate = require('../helpers/process-template'); | ||
var defaultModel = ["var BaseModel = Model.extend({", | ||
" props: {id: 'string'}", | ||
"});"].join('\n'); | ||
var defaultModel = ['var BaseModel = Model.extend({', | ||
' props: {id: \'string\'}', | ||
'});'].join('\n'); | ||
module.exports = function (opts, cb) { | ||
opts || (opts = {}); | ||
var name = opts.name; | ||
//var fileName = humps.decamelize(name, '-'); | ||
module.exports = function(opts, cb) { | ||
opts = opts || {}; | ||
var output = {}; | ||
@@ -35,16 +32,16 @@ | ||
var fieldMap = { | ||
string: function (field) { | ||
requires['InputView'] = 'ampersand-input-view'; | ||
string: function(field) { | ||
requires.InputView = 'ampersand-input-view'; | ||
return ' ' + processTemplate(config.inputtemplate, field).trim(); | ||
}, | ||
array: function (field) { | ||
requires['ArrayInputView'] = 'ampersand-array-input-view'; | ||
array: function(field) { | ||
requires.ArrayInputView = 'ampersand-array-input-view'; | ||
return ' ' + processTemplate(config.arrayinputtemplate, field).trim(); | ||
}, | ||
boolean: function (field) { | ||
requires['CheckboxView'] = 'ampersand-checkbox-view'; | ||
boolean: function(field) { | ||
requires.CheckboxView = 'ampersand-checkbox-view'; | ||
return ' ' + processTemplate(config.checkboxtemplate, field).trim(); | ||
}, | ||
select: function (field) { | ||
requires['SelectView'] = 'ampersand-select-view'; | ||
select: function(field) { | ||
requires.SelectView = 'ampersand-select-view'; | ||
return ' ' + processTemplate(config.selecttemplate, field).trim(); | ||
@@ -61,5 +58,4 @@ } | ||
var mainExport = _.find(ast.body, function (item) { | ||
_.each(ast.body, function(item) { | ||
if (item.type === 'ExpressionStatement') { | ||
var path = 'item.expression.right'; | ||
try { | ||
@@ -69,9 +65,9 @@ // last argument to `extend` | ||
// get props | ||
var props = _.find(objectProperties, function (value) { | ||
var props = _.find(objectProperties, function(value) { | ||
return value.type === 'Property' && value.key.name === 'props'; | ||
}); | ||
var props = props.value.properties; | ||
props = props.value.properties; | ||
// handle different ways of providing types | ||
_.each(props, function (prop) { | ||
_.each(props, function(prop) { | ||
var def = output[prop.key.name] = {}; | ||
@@ -83,3 +79,3 @@ if (prop.value.type === 'Literal') { | ||
} else if (prop.value.type === 'ObjectExpression') { | ||
_.find(prop.value.properties, function (prop) { | ||
_.find(prop.value.properties, function(prop) { | ||
if (prop.type === 'Property' && prop.key.name === 'type') { | ||
@@ -90,3 +86,3 @@ def.type = prop.value.value; | ||
def.type = 'select'; | ||
def.options = _.map(prop.value.elements, function (element) { | ||
def.options = _.map(prop.value.elements, function(element) { | ||
return element.raw; | ||
@@ -99,9 +95,8 @@ }); | ||
} catch (e) {} | ||
} | ||
}) | ||
}); | ||
var buff = []; | ||
_.each(output, function (definition, key) { | ||
_.each(output, function(definition, key) { | ||
var func = fieldMap[definition.type]; | ||
@@ -118,3 +113,3 @@ if (func) { | ||
var requireString = _.reduce(requires, function (buff, value, key) { | ||
var requireString = _.reduce(requires, function(buff, value, key) { | ||
return buff += 'var ' + key + ' = require(\'' + value + '\');\n'; | ||
@@ -128,7 +123,10 @@ }, ''); | ||
cb(null, processTemplate(config.formtemplate, {fields: buff, requires: requireString})); | ||
cb(null, processTemplate(config.formtemplate, { | ||
fields: buff, | ||
requires: requireString | ||
})); | ||
}; | ||
var toLabel = function (string) { | ||
var toLabel = function(string) { | ||
return separateWords(pascalize(string), ' '); | ||
@@ -141,3 +139,3 @@ }; | ||
} | ||
return string.replace(/([a-z])([A-Z0-9])/g, '$1'+ separator +'$2'); | ||
return string.replace(/([a-z])([A-Z0-9])/g, '$1' + separator + '$2'); | ||
}; | ||
@@ -160,2 +158,1 @@ | ||
}; | ||
@@ -5,4 +5,4 @@ new ArrayInputView({ | ||
value: this.model.{{{ name }}} || [], | ||
numberRequired: 0, | ||
minLength: 0, | ||
parent: this | ||
}) |
{ | ||
"name": "ampersand", | ||
"description": "CLI tool for generating single page apps a. la. http://humanjavascript.com", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -13,3 +13,2 @@ "bin": { | ||
"chalk": "^0.5.1", | ||
"commander": "1.1.1", | ||
"escodegen": "^1.3.3", | ||
@@ -20,2 +19,3 @@ "esprima": "~1.2.2", | ||
"humps": "0.0.1", | ||
"inquirer": "^0.8.0", | ||
"jade": "~1.0.2", | ||
@@ -22,0 +22,0 @@ "multiline": "~0.2.0", |
@@ -79,2 +79,3 @@ # The Ampersand CLI | ||
{ | ||
// default framework to be prompted with, options are express or hapi | ||
framework: 'hapi', | ||
@@ -81,0 +82,0 @@ indent: 4, |
@@ -66,3 +66,3 @@ /*global app, me, $*/ | ||
// and it's a local url, navigate internally | ||
if (local && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey) { | ||
if (local && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey && !e.defaultPrevented) { | ||
e.preventDefault(); | ||
@@ -69,0 +69,0 @@ app.navigate(aTag.pathname); |
@@ -1,2 +0,2 @@ | ||
/*global monkey test*/ | ||
/*global monkey, test*/ | ||
@@ -3,0 +3,0 @@ // these tests assume you've loaded the default fixture |
@@ -23,3 +23,3 @@ var rimraf = require('rimraf'); | ||
}); | ||
}) | ||
}) | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
107
436402
12163
+ Addedinquirer@^0.8.0
+ Addedansi-regex@1.1.12.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcli-width@1.1.1(transitive)
+ Addedfigures@1.7.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedinquirer@0.8.5(transitive)
+ Addedlodash@3.10.1(transitive)
+ Addedmute-stream@0.0.4(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedreadline2@0.1.1(transitive)
+ Addedrx@2.5.3(transitive)
+ Addedstrip-ansi@2.0.13.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedthrough@2.3.8(transitive)
- Removedcommander@1.1.1
- Removedcommander@1.1.1(transitive)
- Removedkeypress@0.1.0(transitive)