Skip to content

Commit

Permalink
Merge pull request #114 from ilanbiala/master
Browse files Browse the repository at this point in the history
Release 0.4.1
  • Loading branch information
ilanbiala committed Sep 13, 2015
2 parents 82bd307 + fd5a05b commit 856ee87
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 104 deletions.
13 changes: 11 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
language: node_js
node_js:
- '0.10'
- '0.12'
- 0.10
- 0.12
- 4
matrix:
allow_failures:
- node_js: 4
sudo: false
cache:
apt: true
directories:
- node_modules/
before_install:
- currentfolder=${PWD##*/}
- if [ "$currentfolder" != 'generator-meanjs' ]; then cd .. && eval "mv $currentfolder generator-meanjs" && cd generator-meanjs; fi
Expand Down
93 changes: 55 additions & 38 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

var Promise = require('bluebird');
var child_process = require('child_process');
var clog = require('c.log');
var path = require('path');
var yeoman = require('yeoman-generator');
var Promise = require('bluebird'),
child_process = require('child_process'),
path = require('path'),
s = require('underscore.string'),
generators = require('yeoman-generator'),
log = require('./log');

var exec = function (cmd) {
return new Promise(function (resolve, reject) {
Expand All @@ -27,27 +26,27 @@ var versions = {
'0.4.1': 'v0.4.1'
};

var MeanGenerator = yeoman.generators.Base.extend({
module.exports = generators.Base.extend({

init: function () {
this.pkg = yeoman.file.readJSON(path.join(__dirname, '../package.json'));
this.pkg = this.fs.readJSON(path.join(__dirname, '../package.json'));

this.on('end', function () {
if (!this.options['skip-install']) {
clog.green('Running npm install for you....');
clog.green('This may take a couple minutes.');
log.green('Running npm install for you....');
log.green('This may take a couple minutes.');
exec('cd ' + folder + ' && npm install')
.then(function () {
clog('');
clog.green('------------------------------------------');
clog.green('Your MEAN.js application is ready!');
clog('');
clog.green('To Get Started, run the following command:');
clog('');
clog.yellow('cd ' + folder + ' && grunt');
clog('');
clog.green('Happy Hacking!');
clog.green('------------------------------------------');
log('');
log.green('------------------------------------------');
log.green('Your MEAN.js application is ready!');
log('');
log.green('To Get Started, run the following command:');
log('');
log.yellow('cd ' + folder + ' && grunt');
log('');
log.green('Happy Hacking!');
log.green('------------------------------------------');
});
}
});
Expand All @@ -61,15 +60,15 @@ var MeanGenerator = yeoman.generators.Base.extend({
done();
})
.catch(function (err) {
clog.red(new Error(err));
log.red(new Error(err));
return;
});
},

welcomeMessage: function () {
clog(this.yeoman);
log(this.yeoman);

clog.green('You\'re using the official MEAN.JS generator.');
log.green('You\'re using the official MEAN.JS generator.');
},

promptForVersion: function () {
Expand Down Expand Up @@ -98,7 +97,7 @@ var MeanGenerator = yeoman.generators.Base.extend({
promptForFolder: function () {
var done = this.async();

clog.red(version);
log.red(version);

var prompt = {
name: 'folder',
Expand All @@ -116,14 +115,14 @@ var MeanGenerator = yeoman.generators.Base.extend({
cloneRepo: function () {
var done = this.async();

clog.green('Cloning the MEAN repo.......');
log.green('Cloning the MEAN repo.......');

exec('git clone --branch ' + versions[version] + ' https://github.com/meanjs/mean.git ' + folder)
.then(function () {
done();
})
.catch(function (err) {
clog.red(err);
log.red(err);
return;
});
},
Expand All @@ -148,7 +147,7 @@ var MeanGenerator = yeoman.generators.Base.extend({
done();
})
.catch(function (err) {
clog.red(err);
log.red(err);
return;
});
},
Expand Down Expand Up @@ -191,18 +190,38 @@ var MeanGenerator = yeoman.generators.Base.extend({
this.addArticleExample = props.addArticleExample;
this.addChatExample = props.addChatExample;

this.slugifiedAppName = this._.slugify(this.appName);
this.humanizedAppName = this._.humanize(this.appName);
this.capitalizedAppAuthor = this._.capitalize(this.appAuthor);
this.slugifiedAppName = s(this.appName).slugify().value();
this.humanizedAppName = s(this.appName).humanize().value();
this.capitalizedAppAuthor = s(this.appAuthor).capitalize().value();

done();
}.bind(this));
},

copyTemplates: function () {
this.template(version + '/_package.json', folderPath + 'package.json');
this.template(version + '/_bower.json', folderPath + 'bower.json');
this.template(version + '/config/env/_default.js', folderPath + 'config/env/default.js');
this.fs.copyTpl(
this.templatePath(version + '/_package.json'),
this.destinationPath(folderPath + 'package.json'),
{
slugifiedAppName: this.slugifiedAppName,
appDescription: this.appDescription,
capitalizedAppAuthor: this.capitalizedAppAuthor
});
this.fs.copyTpl(
this.templatePath(version + '/_bower.json'),
this.destinationPath(folderPath + 'bower.json'),
{
slugifiedAppName: this.slugifiedAppName,
appDescription: this.appDescription
});
this.fs.copyTpl(
this.templatePath(version + '/config/env/_default.js'),
this.destinationPath(folderPath + 'config/env/default.js'),
{
appName: this.appName,
appDescription: this.appDescription,
appKeywords: this.appKeywords
});
},

removeChatExample: function () {
Expand All @@ -214,7 +233,7 @@ var MeanGenerator = yeoman.generators.Base.extend({
done();
})
.catch(function (err) {
clog.red(err);
log.red(err);
return;
});
} else {
Expand All @@ -231,7 +250,7 @@ var MeanGenerator = yeoman.generators.Base.extend({
done();
})
.catch(function (err) {
clog.red(err);
log.red(err);
return;
});
} else {
Expand All @@ -240,5 +259,3 @@ var MeanGenerator = yeoman.generators.Base.extend({
}

});

module.exports = MeanGenerator;
39 changes: 39 additions & 0 deletions app/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var chalk = require('chalk');

var log = function log(value) {
console.log(value);
};

log.green = function(value) {
console.log(chalk.green(value));
};

log.blue = function(value) {
console.log(chalk.blue(value));
};

log.red = function(value) {
console.log(chalk.red(value));
};

log.yellow = function(value) {
console.log(chalk.yellow(value));
};

log.magenta = function(value) {
console.log(chalk.magenta(value));
};

log.cyan = function(value) {
console.log(chalk.cyan(value));
};

log.white = function(value) {
console.log(chalk.white(value));
};

log.gray = function(value) {
console.log(chalk.gray(value));
};

module.exports = log;
16 changes: 6 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@
"angular"
],
"dependencies": {
"bluebird": "^2.9.34",
"c.log": "0.0.3",
"chalk": "~0.5.1",
"underscore.inflections": "~0.2.1",
"yeoman-generator": "~0.17.1",
"yo": ">=1.0.0"
"bluebird": "~2.10.0",
"chalk": "~1.1.1",
"underscore.string": "~3.2.2",
"yeoman-generator": "~0.20.3",
"yo": "~1.4.8"
},
"devDependencies": {
"assert": "~1.1.1",
"async": "~0.9.0",
"fs-extra": "~0.10.0",
"mocha": "~1.21.3",
"mocha": "~2.3.2",
"temp": "~0.8.0"
},
"licenses": [
Expand Down
79 changes: 25 additions & 54 deletions test/app.test.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,15 @@
'use strict';

var path = require('path');
var fs = require('fs');
var helpers = require('yeoman-generator').test;
var temp = require('temp').track();
var assert = require('assert');
var exec = require('child_process').exec;
var async = require('async');

//Extending the yeoman helper method
function runGenerator(generatorType, name, context, promptAnswers, done) {
var workspace = context.workspace = temp.mkdirSync();
helpers.testDirectory(path.join(__dirname, 'temp'), function(err) {

if (err) {
return done(err);
}

this.app = helpers.createGenerator('meanjs:' + generatorType, [
path.resolve(__dirname, '../' + generatorType)
], [name]);

helpers.mockPrompt(this.app, promptAnswers);

this.app.options['skip-install'] = true;

this.app.run({}, function() {
done();
});

}.bind(context));
}
var path = require('path'),
helpers = require('yeoman-generator').test,
assert = require('yeoman-generator').assert,
temp = require('temp').track();

describe('Main Generator', function () {
this.timeout(0);
/**
* Setup the temp directory
*/
beforeEach(function (done) {
helpers.testDirectory(path.join(__dirname, 'temp'), function (err) {
if (err) {
console.log('Error', err);
return err;
}
done();
});
helpers.testDirectory(path.join(__dirname, 'temp'), done);
});

/**
Expand All @@ -56,23 +21,29 @@ describe('Main Generator', function () {

describe('Application generator without sample module', function () {
beforeEach(function (done) {
runGenerator('app',
'',
this, {
'version': '0.4.0',
'folder': 'temp',
'appName': 'MEAN',
'appDescription': 'Full-Stack JavaScript with MongoDB, Express, AngularJS, and Node.js',
'appKeywords': 'MongoDB, Express, AngularJS, Node.js',
'appAuthor': 'Test',
'addArticleExample': false,
'addChatExample': false
}, done
);
helpers.run(path.join(__dirname, '../app'))
.withOptions({
'skip-install': true
})
.withArguments([])
.withPrompts({
version: '0.4.0',
folder: 'temp',
appName: 'MEAN',
appDescription: 'Full-Stack JavaScript with MongoDB, Express, AngularJS, and Node.js',
appKeywords: 'MongoDB, Express, AngularJS, Node.js',
appAuthor: 'Test',
addArticleExample: false,
addChatExample: false
})
.on('ready', function (generator) {
// this is called right before `generator.run()` is called
})
.on('end', done);
});

it('should generate a package.json file', function () {
helpers.assertFile('temp/package.json');
assert.file('temp/package.json');
});
});

Expand Down

0 comments on commit 856ee87

Please sign in to comment.