diff --git a/.travis.yml b/.travis.yml index 3ac81cbb..7ca70173 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/app/index.js b/app/index.js index c5b2b462..a4a4f4cd 100644 --- a/app/index.js +++ b/app/index.js @@ -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) { @@ -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('------------------------------------------'); }); } }); @@ -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 () { @@ -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', @@ -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; }); }, @@ -148,7 +147,7 @@ var MeanGenerator = yeoman.generators.Base.extend({ done(); }) .catch(function (err) { - clog.red(err); + log.red(err); return; }); }, @@ -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 () { @@ -214,7 +233,7 @@ var MeanGenerator = yeoman.generators.Base.extend({ done(); }) .catch(function (err) { - clog.red(err); + log.red(err); return; }); } else { @@ -231,7 +250,7 @@ var MeanGenerator = yeoman.generators.Base.extend({ done(); }) .catch(function (err) { - clog.red(err); + log.red(err); return; }); } else { @@ -240,5 +259,3 @@ var MeanGenerator = yeoman.generators.Base.extend({ } }); - -module.exports = MeanGenerator; diff --git a/app/log.js b/app/log.js new file mode 100644 index 00000000..451e21f3 --- /dev/null +++ b/app/log.js @@ -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; diff --git a/package.json b/package.json index 0ad2881e..7c0e26ca 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/test/app.test.js b/test/app.test.js index 377ff646..ae7a9dda 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -1,36 +1,7 @@ -'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); @@ -38,13 +9,7 @@ describe('Main Generator', function () { * 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); }); /** @@ -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'); }); });