Merge pull request #239 from toadkicker/fix_228_b
Implement a prompt when there is no app name given
This commit is contained in:
commit
7ed493d1a2
48
lib/cmd.js
48
lib/cmd.js
|
@ -1,12 +1,15 @@
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var colors = require('colors');
|
var colors = require('colors');
|
||||||
var shelljs = require('shelljs');
|
var shelljs = require('shelljs');
|
||||||
|
var promptly = require('promptly');
|
||||||
|
var path = require('path');
|
||||||
var Embark = require('../lib/index');
|
var Embark = require('../lib/index');
|
||||||
|
|
||||||
var Cmd = function() {
|
var Cmd = function() {
|
||||||
program.version(Embark.version);
|
program.version(Embark.version);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Cmd.prototype.process = function(args) {
|
Cmd.prototype.process = function(args) {
|
||||||
this.newApp();
|
this.newApp();
|
||||||
this.demo();
|
this.demo();
|
||||||
|
@ -26,20 +29,41 @@ Cmd.prototype.process = function(args) {
|
||||||
program.parse(args);
|
program.parse(args);
|
||||||
};
|
};
|
||||||
|
|
||||||
Cmd.prototype.newApp = function() {
|
Cmd.prototype.newApp = function(name) {
|
||||||
program
|
|
||||||
.command('new [name]')
|
|
||||||
.description('new application')
|
|
||||||
.action(function(name, options) {
|
|
||||||
if (name === undefined) {
|
|
||||||
|
|
||||||
console.log("please specify your app Name".red);
|
var validateName = function (value) {
|
||||||
console.log("e.g embark new MyApp".green);
|
try {
|
||||||
console.log("e.g embark new --help for more information".green);
|
if(value.match(/^[a-zA-Z\s\-]+$/)) return value;
|
||||||
process.exit(9);
|
} catch (e) {
|
||||||
|
throw new Error('Name must be only letters, spaces, or dashes');
|
||||||
}
|
}
|
||||||
Embark.generateTemplate('boilerplate', './', name);
|
};
|
||||||
});
|
|
||||||
|
program
|
||||||
|
.command('new [name]')
|
||||||
|
.description('new application')
|
||||||
|
.action(function (name) {
|
||||||
|
if (name === undefined) {
|
||||||
|
var parentDirectory = path.dirname(__dirname).split("/").pop();
|
||||||
|
return promptly.prompt("Name your app (default is " + parentDirectory + "):", {
|
||||||
|
default: parentDirectory,
|
||||||
|
validator: validateName
|
||||||
|
}, function (err, inputvalue) {
|
||||||
|
if (err) {
|
||||||
|
console.error('Invalid name:', err.message);
|
||||||
|
// Manually call retry
|
||||||
|
// The passed error has a retry method to easily prompt again.
|
||||||
|
err.retry();
|
||||||
|
} else {
|
||||||
|
//slightly different assignment of name since it comes from child prompt
|
||||||
|
Embark.generateTemplate('boilerplate', './', inputvalue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Embark.generateTemplate('boilerplate', './', name);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Cmd.prototype.demo = function() {
|
Cmd.prototype.demo = function() {
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
"fs-extra": "^2.0.0",
|
"fs-extra": "^2.0.0",
|
||||||
"globule": "^1.1.0",
|
"globule": "^1.1.0",
|
||||||
"merge": "^1.2.0",
|
"merge": "^1.2.0",
|
||||||
|
"promptly": "^2.1.0",
|
||||||
"serve-static": "^1.11.1",
|
"serve-static": "^1.11.1",
|
||||||
"shelljs": "^0.5.0",
|
"shelljs": "^0.5.0",
|
||||||
"solc": "0.4.8",
|
"solc": "0.4.8",
|
||||||
|
@ -49,6 +50,8 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"grunt": "^1.0.1",
|
"grunt": "^1.0.1",
|
||||||
"grunt-cli": "^1.2.0",
|
"grunt-cli": "^1.2.0",
|
||||||
|
"grunt-contrib-clean": "^1.0.0",
|
||||||
|
"grunt-contrib-coffee": "^1.0.0",
|
||||||
"grunt-contrib-jshint": "^1.0.0",
|
"grunt-contrib-jshint": "^1.0.0",
|
||||||
"grunt-mocha-test": "^0.13.2",
|
"grunt-mocha-test": "^0.13.2",
|
||||||
"matchdep": "^1.0.1",
|
"matchdep": "^1.0.1",
|
||||||
|
|
64
test/cmd.js
64
test/cmd.js
|
@ -1,41 +1,51 @@
|
||||||
var Embark = require('../lib/index');
|
var Embark = require('../lib/index');
|
||||||
var Cmd = require('../lib/cmd');
|
var Cmd = require('../lib/cmd');
|
||||||
|
|
||||||
|
// Function to send a line to stdin
|
||||||
|
function sendLine(line) {
|
||||||
|
setImmediate(function () {
|
||||||
|
process.stdin.emit('data', line + '\n');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var passingLines = function () {
|
||||||
|
var lines = [];
|
||||||
|
lines.push('Initializing Embark Template....');
|
||||||
|
lines.push('Installing packages.. this can take a few seconds');
|
||||||
|
lines.push('Init complete');
|
||||||
|
return lines;
|
||||||
|
};
|
||||||
|
|
||||||
describe('embark.Cmd', function () {
|
describe('embark.Cmd', function () {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
var cmd = new Cmd(Embark);
|
|
||||||
describe('#new', function () {
|
|
||||||
it('it should not create an app without a name', function (done) {
|
|
||||||
cmd.newApp(undefined, function (output) {
|
|
||||||
var lines = output.split('\n');
|
|
||||||
assert.equal(lines[0], 'please specify your app Name');
|
|
||||||
assert.equal(lines[1], 'e.g embark new MyApp');
|
|
||||||
assert.equal(lines[2], 'e.g embark new --help for more information');
|
|
||||||
});
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
describe('#new', function () {
|
||||||
it('it should create an app with a name', function (done) {
|
it('it should create an app with a name', function (done) {
|
||||||
|
var cmd = new Cmd(Embark);
|
||||||
|
var pl = passingLines();
|
||||||
var appname = 'deleteapp';
|
var appname = 'deleteapp';
|
||||||
cmd.newApp(appname, function (output) {
|
cmd.newApp(appname, function (output) {
|
||||||
var lines = output.split('\n');
|
var lines = output.split('\n');
|
||||||
assert.equal(lines[0], 'Initializing Embark Template....');
|
console.log(lines);
|
||||||
assert.equal(lines[1], 'Installing packages.. this can take a few seconds');
|
assert.equal(lines[0], pl[0]);
|
||||||
assert.equal(lines[2], 'Init complete');
|
assert.equal(lines[1], pl[1]);
|
||||||
|
assert.equal(lines[2], pl[2]);
|
||||||
assert.equal(lines[3], 'App ready at ./' + appname);
|
assert.equal(lines[3], 'App ready at ./' + appname);
|
||||||
});
|
});
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// describe("#help", function () {
|
it('it should prompt when given an empty app name', function (done) {
|
||||||
// it('it should spit out helpful text if no arguments are supplied', function (done) {
|
var cmd = new Cmd(Embark);
|
||||||
// cmd.process([], function (output) {
|
var pl = passingLines();
|
||||||
// var lines = output.split('\n');
|
var appname = 'deleteapp';
|
||||||
// assert.equal(lines[0], '\n');
|
|
||||||
// assert.equal(lines[1], 'Usage:');
|
cmd.newApp(undefined, function (output) {
|
||||||
// done();
|
var lines = output.split('\n');
|
||||||
// });
|
console.log(lines);
|
||||||
// })
|
sendLine(appname + '\n');
|
||||||
// })
|
assert.equal(lines[0], pl[0]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
});
|
});
|
Loading…
Reference in New Issue