diff --git a/generators/app/index.js b/app/index.js similarity index 73% rename from generators/app/index.js rename to app/index.js index 9294c2d..71386ff 100644 --- a/generators/app/index.js +++ b/app/index.js @@ -18,56 +18,85 @@ function copyFromGlob(generator, paths) { }); } -var AngulpifyGenerator = module.exports = yeoman.generators.Base.extend({ +module.exports = yeoman.generators.Base.extend({ + initializing: function () { + this.pkg = require('../package.json'); + }, + constructor: function () { yeoman.generators.Base.apply(this, arguments); + this.option('skip-install', {desc: 'Skip the bower and node installations'}); + + this.option('test-framework', { + desc: 'Test framework to be invoked', + type: String, + defaults: 'mocha' + }); }, - initializing: function () {}, + prompting: function () { var done = this.async(); var welcomeMessage = 'Out of the box I include '+ chalk.red('AngularJS')+', '+chalk.red('Gulp')+' and '+chalk.red('Browserify')+' to build your app.'; this.log(yosay(welcomeMessage)); + var prompts = [ { - type: 'input', name: 'project', message: 'What\'s your project name?', + type: 'input', + name: 'project', + message: 'What\'s your project name?', default: this.appname }, - { - type: 'list', name: 'scripts', message: 'Would you like to use a language other than JavaScript?', - choices: [ - {name: 'Nop, JavaScript please.', value: {name: 'js', extensions: '.js'}} - ], - default: 0 - }, { type: 'list', name: 'styles', message: 'Would you like to use a preprocessor?', choices: [ - {name: 'Less', value: {name: 'less', extensions: '.less'}}, - {name: 'Sass', value: {name: 'sass', extensions: '.scss'}}, - {name: 'Nop, CSS please.', value: {name: 'css', extensions: '.css'}}, + {name: 'Less', value: 'less'}, + {name: 'Sass', value: 'sass'}, + {name: 'Nop, CSS please.', value: 'css'} ], default: 2 }, { - type: 'list', name: 'templates', message: 'Would you like to use a template engine?', + type: 'list', + name: 'templates', + message: 'Would you like to use a template engine?', choices: [ - {name: 'Jade', value: {name: 'jade', extensions: '.jade'}}, - {name: 'Nop. HTML please.', value: {name: 'html', extensions: '.html'}} + {name: 'Jade', value: 'jade'}, + {name: 'Nop. HTML please.', value: 'html'} ], default: 1 } ]; this.prompt(prompts, function (answers) { + this.project = answers.project.trim().replace(/\s+/g, '-').toLowerCase(); - this.scripts = answers.scripts; - this.styles = answers.styles; - this.templates = answers.templates; + + //TODO: Refactor the way extension names are handled + // Umba-wamba to keep things working after prompts changes. + + this.scripts = {name: 'js', extensions: '.js'}; + + if(answers.styles === 'less'){ + this.styles = {name: 'less', extensions: '.less'}; + }else if(answers.styles === 'sass'){ + this.styles = {name: 'sass', extensions: '.scss'}; + }else{ + this.styles = {name: 'css', extensions: '.css'}; + } + + if(answers.templates === 'jade'){ + this.templates = {name: 'jade', extensions: '.jade'}; + }else{ + this.templates = {name: 'html', extensions: '.html'}; + } + done(); }.bind(this)); }, + configuring: function () { + // Scripts this.isJs = function () { return this.scripts.name === 'js'; }; // Styles diff --git a/generators/app/templates/_bower.json b/app/templates/_bower.json similarity index 100% rename from generators/app/templates/_bower.json rename to app/templates/_bower.json diff --git a/generators/app/templates/_gulpfile.js b/app/templates/_gulpfile.js similarity index 100% rename from generators/app/templates/_gulpfile.js rename to app/templates/_gulpfile.js diff --git a/generators/app/templates/_package.json b/app/templates/_package.json similarity index 100% rename from generators/app/templates/_package.json rename to app/templates/_package.json diff --git a/generators/app/templates/editorconfig b/app/templates/editorconfig similarity index 100% rename from generators/app/templates/editorconfig rename to app/templates/editorconfig diff --git a/generators/app/templates/gitignore b/app/templates/gitignore similarity index 100% rename from generators/app/templates/gitignore rename to app/templates/gitignore diff --git a/generators/app/templates/gulp/config.js b/app/templates/gulp/config.js similarity index 52% rename from generators/app/templates/gulp/config.js rename to app/templates/gulp/config.js index e7f7658..54c64ca 100644 --- a/generators/app/templates/gulp/config.js +++ b/app/templates/gulp/config.js @@ -5,28 +5,28 @@ var utilities = require('./utilities'); // Folders & files names var src = './src'; - var assets = 'assets'; - var assets_images = 'images'; - var scripts = 'scripts'; - var scripts_app = 'app'; - var scripts_app_entry = 'app.module<%=scripts.extensions%>'; - var scripts_app_vendors = 'vendors<%=scripts.extensions%>'; - var scripts_config = utilities.config.getFile() || (utilities.env.getEnv() + '.config.json'); - var scripts_index = 'index<%=templates.extensions%>'; - var scripts_app_output = 'app.js'; - var scripts_app_output_partial = 'app*'; - var scripts_vendors_output = 'vendors.js'; - var scripts_vendors_output_partial = 'vendors*'; - var styles = 'styles'; - var styles_main = 'main<%=styles.extensions%>'; - var styles_output = 'app'; +var assets = 'assets'; +var assets_images = 'images'; +var scripts = 'scripts'; +var scripts_app = 'app'; +var scripts_app_entry = 'app.module<%=scripts.extensions%>'; +var scripts_app_vendors = 'vendors<%=scripts.extensions%>'; +var scripts_config = utilities.config.getFile() || (utilities.env.getEnv() + '.config.json'); +var scripts_index = 'index<%=templates.extensions%>'; +var scripts_app_output = 'app.js'; +var scripts_app_output_partial = 'app*'; +var scripts_vendors_output = 'vendors.js'; +var scripts_vendors_output_partial = 'vendors*'; +var styles = 'styles'; +var styles_main = 'main<%=styles.extensions%>'; +var styles_output = 'app'; var build = './build'; var dist = './dist'; var tmp = './.tmp'; - var tmp_config_module = '<%=project%>.config'; - var tmp_config_output = 'config'; - var tmp_templates_module = '<%=project%>.templates'; - var tmp_templates_output = 'templates.js'; +var tmp_config_module = '<%=project%>.config'; +var tmp_config_output = 'config'; +var tmp_templates_module = '<%=project%>.templates'; +var tmp_templates_output = 'templates.js'; var dest = utilities.env.isDev() ? build : dist; @@ -78,61 +78,61 @@ var configuration = { }, index: { src: path.join(src, scripts, scripts_index), - injectSrc: [ + injectSrc: [ path.join(dest, scripts_vendors_output_partial + '.js'), path.join(dest, scripts_app_output_partial + '.{css,js}') ], - inject: { + inject: { ignorePath: path.join(dest), - addRootSlash: false + addRootSlash: false }, - <% if (isHtml()) { %>minifyHtml<% } else if (isJade()) { %>jade<% } %>: {}, - dest: dest - }, - lint: { - src: path.join(src, '**/*<%=scripts.extensions%>') - }, - serve: { - browserSync: { - server: {baseDir: dest}, - open: false - } - }, - styles: { - src: path.join(src, styles, styles_main), + <% if (isHtml()) { %>minifyHtml<% } else if (isJade()) { %>jade<% } %>: {}, +dest: dest +}, +lint: { + src: path.join(src, '**/*<%=scripts.extensions%>') +}, +serve: { + browserSync: { + server: {baseDir: dest}, + open: false + } +}, +styles: { + src: path.join(src, styles, styles_main), basename: styles_output, autoprefixer: {browsers: ['last 2 versions']}, - <% if (isSass()) { %>sass: { - sourcemap: utilities.env.isDev(), +<% if (isSass()) { %>sass: { + sourcemap: utilities.env.isDev(), style: 'compressed' - },<% } else if (isLess()) { %>less: {},<% } %> - dest: dest - }, - templates: { - src: path.join(src, scripts, scripts_app, '**/*<%=templates.extensions%>'), - <% if (isHtml()) { %>minifyHTML<% } else if (isJade()) { %>jade<% } %>: {}, - templateCache: { - filename: tmp_templates_output, - options: { - moduleSystem: 'Browserify', - standalone: true, - module: tmp_templates_module, - base: function (file) { - return path.basename(file.relative); - } + },<% } else if (isLess()) { %>less: {},<% } %> + dest: dest +}, +templates: { + src: path.join(src, scripts, scripts_app, '**/*<%=templates.extensions%>'), +<% if (isHtml()) { %>minifyHTML<% } else if (isJade()) { %>jade<% } %>: {}, + templateCache: { + filename: tmp_templates_output, + options: { + moduleSystem: 'Browserify', + standalone: true, + module: tmp_templates_module, + base: function (file) { + return path.basename(file.relative); } - }, - dest: tmp + } }, - watch: { - lint: path.join(src, scripts, scripts_app, '**/*<%=scripts.extensions%>'), + dest: tmp +}, +watch: { + lint: path.join(src, scripts, scripts_app, '**/*<%=scripts.extensions%>'), index: path.join(src, scripts, scripts_index), config: path.join(src, scripts, scripts_config), templates: path.join(src, scripts, scripts_app, '**/*<%=templates.extensions%>'), styles: path.join(src, styles, '**/*<%=styles.extensions%>'), styles_output: styles_output + '.min.css', reload: path.join(dest, '**/*.{js,html}') - } +} }; module.exports = configuration; diff --git a/generators/app/templates/gulp/tasks/scripts/js/browserify-app.js b/app/templates/gulp/tasks/scripts/js/browserify-app.js similarity index 100% rename from generators/app/templates/gulp/tasks/scripts/js/browserify-app.js rename to app/templates/gulp/tasks/scripts/js/browserify-app.js diff --git a/generators/app/templates/gulp/tasks/scripts/js/lint.js b/app/templates/gulp/tasks/scripts/js/lint.js similarity index 100% rename from generators/app/templates/gulp/tasks/scripts/js/lint.js rename to app/templates/gulp/tasks/scripts/js/lint.js diff --git a/generators/app/templates/gulp/tasks/shared/assets.js b/app/templates/gulp/tasks/shared/assets.js similarity index 100% rename from generators/app/templates/gulp/tasks/shared/assets.js rename to app/templates/gulp/tasks/shared/assets.js diff --git a/generators/app/templates/gulp/tasks/shared/browserify-vendors.js b/app/templates/gulp/tasks/shared/browserify-vendors.js similarity index 100% rename from generators/app/templates/gulp/tasks/shared/browserify-vendors.js rename to app/templates/gulp/tasks/shared/browserify-vendors.js diff --git a/generators/app/templates/gulp/tasks/shared/clean.js b/app/templates/gulp/tasks/shared/clean.js similarity index 100% rename from generators/app/templates/gulp/tasks/shared/clean.js rename to app/templates/gulp/tasks/shared/clean.js diff --git a/generators/app/templates/gulp/tasks/shared/config.js b/app/templates/gulp/tasks/shared/config.js similarity index 100% rename from generators/app/templates/gulp/tasks/shared/config.js rename to app/templates/gulp/tasks/shared/config.js diff --git a/generators/app/templates/gulp/tasks/shared/default.js b/app/templates/gulp/tasks/shared/default.js similarity index 100% rename from generators/app/templates/gulp/tasks/shared/default.js rename to app/templates/gulp/tasks/shared/default.js diff --git a/generators/app/templates/gulp/tasks/shared/serve.js b/app/templates/gulp/tasks/shared/serve.js similarity index 100% rename from generators/app/templates/gulp/tasks/shared/serve.js rename to app/templates/gulp/tasks/shared/serve.js diff --git a/generators/app/templates/gulp/tasks/shared/watch.js b/app/templates/gulp/tasks/shared/watch.js similarity index 100% rename from generators/app/templates/gulp/tasks/shared/watch.js rename to app/templates/gulp/tasks/shared/watch.js diff --git a/generators/app/templates/gulp/tasks/styles/css/styles.js b/app/templates/gulp/tasks/styles/css/styles.js similarity index 100% rename from generators/app/templates/gulp/tasks/styles/css/styles.js rename to app/templates/gulp/tasks/styles/css/styles.js diff --git a/generators/app/templates/gulp/tasks/styles/less/styles.js b/app/templates/gulp/tasks/styles/less/styles.js similarity index 100% rename from generators/app/templates/gulp/tasks/styles/less/styles.js rename to app/templates/gulp/tasks/styles/less/styles.js diff --git a/generators/app/templates/gulp/tasks/styles/sass/styles.js b/app/templates/gulp/tasks/styles/sass/styles.js similarity index 100% rename from generators/app/templates/gulp/tasks/styles/sass/styles.js rename to app/templates/gulp/tasks/styles/sass/styles.js diff --git a/generators/app/templates/gulp/tasks/templates/html/index.js b/app/templates/gulp/tasks/templates/html/index.js similarity index 100% rename from generators/app/templates/gulp/tasks/templates/html/index.js rename to app/templates/gulp/tasks/templates/html/index.js diff --git a/generators/app/templates/gulp/tasks/templates/html/templates.js b/app/templates/gulp/tasks/templates/html/templates.js similarity index 100% rename from generators/app/templates/gulp/tasks/templates/html/templates.js rename to app/templates/gulp/tasks/templates/html/templates.js diff --git a/generators/app/templates/gulp/tasks/templates/jade/index.js b/app/templates/gulp/tasks/templates/jade/index.js similarity index 100% rename from generators/app/templates/gulp/tasks/templates/jade/index.js rename to app/templates/gulp/tasks/templates/jade/index.js diff --git a/generators/app/templates/gulp/tasks/templates/jade/templates.js b/app/templates/gulp/tasks/templates/jade/templates.js similarity index 100% rename from generators/app/templates/gulp/tasks/templates/jade/templates.js rename to app/templates/gulp/tasks/templates/jade/templates.js diff --git a/generators/app/templates/gulp/utilities.js b/app/templates/gulp/utilities.js similarity index 100% rename from generators/app/templates/gulp/utilities.js rename to app/templates/gulp/utilities.js diff --git a/generators/app/templates/jshintrc b/app/templates/jshintrc similarity index 100% rename from generators/app/templates/jshintrc rename to app/templates/jshintrc diff --git a/generators/app/templates/src/assets/images/angulpify.png b/app/templates/src/assets/images/angulpify.png similarity index 100% rename from generators/app/templates/src/assets/images/angulpify.png rename to app/templates/src/assets/images/angulpify.png diff --git a/generators/app/templates/src/scripts/app/app.config.js b/app/templates/src/scripts/app/app.config.js similarity index 100% rename from generators/app/templates/src/scripts/app/app.config.js rename to app/templates/src/scripts/app/app.config.js diff --git a/generators/app/templates/src/scripts/app/app.module.js b/app/templates/src/scripts/app/app.module.js similarity index 100% rename from generators/app/templates/src/scripts/app/app.module.js rename to app/templates/src/scripts/app/app.module.js diff --git a/generators/app/templates/src/scripts/app/core/core.module.js b/app/templates/src/scripts/app/core/core.module.js similarity index 100% rename from generators/app/templates/src/scripts/app/core/core.module.js rename to app/templates/src/scripts/app/core/core.module.js diff --git a/generators/app/templates/src/scripts/app/layout/layout.config.js b/app/templates/src/scripts/app/layout/layout.config.js similarity index 100% rename from generators/app/templates/src/scripts/app/layout/layout.config.js rename to app/templates/src/scripts/app/layout/layout.config.js diff --git a/generators/app/templates/src/scripts/app/layout/layout.html b/app/templates/src/scripts/app/layout/layout.html similarity index 100% rename from generators/app/templates/src/scripts/app/layout/layout.html rename to app/templates/src/scripts/app/layout/layout.html diff --git a/generators/app/templates/src/scripts/app/layout/layout.jade b/app/templates/src/scripts/app/layout/layout.jade similarity index 100% rename from generators/app/templates/src/scripts/app/layout/layout.jade rename to app/templates/src/scripts/app/layout/layout.jade diff --git a/generators/app/templates/src/scripts/app/layout/layout.module.js b/app/templates/src/scripts/app/layout/layout.module.js similarity index 100% rename from generators/app/templates/src/scripts/app/layout/layout.module.js rename to app/templates/src/scripts/app/layout/layout.module.js diff --git a/generators/app/templates/src/scripts/app/vendors.js b/app/templates/src/scripts/app/vendors.js similarity index 100% rename from generators/app/templates/src/scripts/app/vendors.js rename to app/templates/src/scripts/app/vendors.js diff --git a/generators/app/templates/src/scripts/app/welcome/welcome.config.js b/app/templates/src/scripts/app/welcome/welcome.config.js similarity index 100% rename from generators/app/templates/src/scripts/app/welcome/welcome.config.js rename to app/templates/src/scripts/app/welcome/welcome.config.js diff --git a/generators/app/templates/src/scripts/app/welcome/welcome.controller.js b/app/templates/src/scripts/app/welcome/welcome.controller.js similarity index 100% rename from generators/app/templates/src/scripts/app/welcome/welcome.controller.js rename to app/templates/src/scripts/app/welcome/welcome.controller.js diff --git a/generators/app/templates/src/scripts/app/welcome/welcome.html b/app/templates/src/scripts/app/welcome/welcome.html similarity index 100% rename from generators/app/templates/src/scripts/app/welcome/welcome.html rename to app/templates/src/scripts/app/welcome/welcome.html diff --git a/generators/app/templates/src/scripts/app/welcome/welcome.jade b/app/templates/src/scripts/app/welcome/welcome.jade similarity index 100% rename from generators/app/templates/src/scripts/app/welcome/welcome.jade rename to app/templates/src/scripts/app/welcome/welcome.jade diff --git a/generators/app/templates/src/scripts/app/welcome/welcome.module.js b/app/templates/src/scripts/app/welcome/welcome.module.js similarity index 100% rename from generators/app/templates/src/scripts/app/welcome/welcome.module.js rename to app/templates/src/scripts/app/welcome/welcome.module.js diff --git a/generators/app/templates/src/scripts/dev.config.json b/app/templates/src/scripts/dev.config.json similarity index 100% rename from generators/app/templates/src/scripts/dev.config.json rename to app/templates/src/scripts/dev.config.json diff --git a/generators/app/templates/src/scripts/index.html b/app/templates/src/scripts/index.html similarity index 100% rename from generators/app/templates/src/scripts/index.html rename to app/templates/src/scripts/index.html diff --git a/generators/app/templates/src/scripts/index.jade b/app/templates/src/scripts/index.jade similarity index 100% rename from generators/app/templates/src/scripts/index.jade rename to app/templates/src/scripts/index.jade diff --git a/generators/app/templates/src/scripts/prod.config.json b/app/templates/src/scripts/prod.config.json similarity index 100% rename from generators/app/templates/src/scripts/prod.config.json rename to app/templates/src/scripts/prod.config.json diff --git a/generators/app/templates/src/styles/_layout.scss b/app/templates/src/styles/_layout.scss similarity index 100% rename from generators/app/templates/src/styles/_layout.scss rename to app/templates/src/styles/_layout.scss diff --git a/generators/app/templates/src/styles/_variables.scss b/app/templates/src/styles/_variables.scss similarity index 100% rename from generators/app/templates/src/styles/_variables.scss rename to app/templates/src/styles/_variables.scss diff --git a/generators/app/templates/src/styles/layout.css b/app/templates/src/styles/layout.css similarity index 100% rename from generators/app/templates/src/styles/layout.css rename to app/templates/src/styles/layout.css diff --git a/generators/app/templates/src/styles/layout.less b/app/templates/src/styles/layout.less similarity index 100% rename from generators/app/templates/src/styles/layout.less rename to app/templates/src/styles/layout.less diff --git a/generators/app/templates/src/styles/main.css b/app/templates/src/styles/main.css similarity index 100% rename from generators/app/templates/src/styles/main.css rename to app/templates/src/styles/main.css diff --git a/generators/app/templates/src/styles/main.less b/app/templates/src/styles/main.less similarity index 100% rename from generators/app/templates/src/styles/main.less rename to app/templates/src/styles/main.less diff --git a/generators/app/templates/src/styles/main.scss b/app/templates/src/styles/main.scss similarity index 100% rename from generators/app/templates/src/styles/main.scss rename to app/templates/src/styles/main.scss diff --git a/generators/app/templates/src/styles/variables.less b/app/templates/src/styles/variables.less similarity index 100% rename from generators/app/templates/src/styles/variables.less rename to app/templates/src/styles/variables.less diff --git a/package.json b/package.json index 1a4c84c..2055f1f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "generator-angulpify", "version": "1.0.0", - "description": "Yeoman generator involving AngularJS, Gulp and Browserify", + "description": "Yeoman generator for AngularJS apps using Gulp and Browserify", "license": "MIT", "repository": "jgoux/generator-angulpify", "author": { @@ -9,13 +9,16 @@ "email": "julien.goux@live.fr", "url": "https://github.com/jgoux" }, + "main": "app/index.js", "engines": { - "node": ">=0.10.0", - "npm": ">=1.3" + "node": ">=0.10.0" }, "scripts": { - "test": "mocha --reporter spec" + "test": "mocha" }, + "files": [ + "app" + ], "keywords": [ "yeoman-generator", "angularjs", @@ -29,10 +32,12 @@ "globby": "^1.0.0", "gulp": "^3.8.10", "yeoman-generator": "^0.18.3", - "yo": "^1.3.3", "yosay": "^1.0.0" }, "devDependencies": { - "mocha": "^2.0.1" + "mocha": "*" + }, + "peerDependencies": { + "yo": ">=1.0.0" } } diff --git a/test/jade.js b/test/jade.js index 7ffdaa7..6b6376b 100644 --- a/test/jade.js +++ b/test/jade.js @@ -2,42 +2,97 @@ 'use strict'; var path = require('path'); -var helpers = require('yeoman-generator').test; var assert = require('yeoman-generator').assert; +var helpers = require('yeoman-generator').test; +var os = require('os'); + +describe('angulpify: jade', function () { -describe('angulpify: jade feature', function () { + var promptOptions = { + project: 'angulpify', + styles: 'css', + templates: 'jade' + } - var mockPrompts = { - projectName: 'angulpify', - language: 'includeJavaScript', - preprocessor: 'includeCss', - templateEngine: 'includeJade', - goodies: [] + var options = { + 'skip-install-message': true, + 'skip-install': true, + 'skip-welcome-message': true, + 'skip-message': true }; - beforeEach(function (done) { - helpers.testDirectory(path.join(__dirname, 'tmp'), function (err) { - if (err) { - return done(err); - } - this.angulpify = helpers.createGenerator('angulpify:app', ['../../generators/app']); - this.angulpify.options['skip-install'] = true; - this.angulpify.options['skip-welcome-message'] = true; + before(function (done) { + helpers.run(path.join(__dirname, '../app')) + .inDir(path.join(os.tmpdir(), './temp-test')) + .withOptions(options) + .withPrompt(promptOptions) + .on('end', done); + }); + + + it('creates expected config files', function () { - helpers.mockPrompt(this.angulpify, mockPrompts); + var expected = [ + '.editorconfig', + '.gitignore', + '.jshintrc', + '.yo-rc.json' + ]; - done(); - }.bind(this)); + assert.file(expected); }); - it('creates expected files', function (done) { + + it('creates expected gulp files', function () { var expected = [ - 'src/index.jade', - 'src/modules/app/foo/layout.jade' + 'gulpfile.js', + 'gulp/config.js', + 'gulp/utilities.js', + 'gulp/tasks/assets.js', + 'gulp/tasks/browserify-app.js', + 'gulp/tasks/browserify-vendors.js', + 'gulp/tasks/clean.js', + 'gulp/tasks/default.js', + // 'gulp/tasks/images.js', + 'gulp/tasks/index.js', + 'gulp/tasks/lint.js', + //'gulp/tasks/minify.js', + 'gulp/tasks/serve.js', + 'gulp/tasks/styles.js', + 'gulp/tasks/templates.js', + 'gulp/tasks/watch.js', + //'gulp/tasks/watchify.js' ]; - this.angulpify.run({}, function () { - assert.file(expected); - done(); - }); + + assert.file(expected); }); + + it('creates expected script files', function () { + var expected = [ + 'src/scripts/app/app.config.js', + 'src/scripts/app/app.module.js', + 'src/scripts/app/vendors.js', + 'src/scripts/app/core/core.module.js', + 'src/scripts/app/layout/layout.config.js', + 'src/scripts/app/layout/layout.module.js', + 'src/scripts/app/welcome/welcome.config.js', + 'src/scripts/app/welcome/welcome.controller.js', + 'src/scripts/app/welcome/welcome.module.js' + ]; + + assert.file(expected); + + }); + + + it('creates expected template files', function () { + var expected = [ + 'src/scripts/index.jade', + 'src/scripts/app/layout/layout.jade', + 'src/scripts/app/welcome/welcome.jade' + ]; + + assert.file(expected); + }); + }); diff --git a/test/sass.js b/test/sass.js index 3167ab4..d20b01d 100644 --- a/test/sass.js +++ b/test/sass.js @@ -2,66 +2,107 @@ 'use strict'; var path = require('path'); -var helpers = require('yeoman-generator').test; var assert = require('yeoman-generator').assert; +var helpers = require('yeoman-generator').test; +var os = require('os'); -describe('angulpify: sass feature', function () { +describe('angulpify: sass', function () { - var mockPrompts = { - projectName: 'angulpify', - language: 'includeJavaScript', - preprocessor: 'includeSass', - templateEngine: 'includeHtml', - goodies: [] + var promptOptions = { + project: 'angulpify', + styles: 'sass', + templates: 'html' + } + + var options = { + 'skip-install-message': true, + 'skip-install': true, + 'skip-welcome-message': true, + 'skip-message': true }; - beforeEach(function (done) { - helpers.testDirectory(path.join(__dirname, 'tmp'), function (err) { - if (err) { - return done(err); - } - this.angulpify = helpers.createGenerator('angulpify:app', ['../../generators/app']); - this.angulpify.options['skip-install'] = true; - this.angulpify.options['skip-welcome-message'] = true; + before(function (done) { + helpers.run(path.join(__dirname, '../app')) + .inDir(path.join(os.tmpdir(), './temp-test')) + .withOptions(options) + .withPrompt(promptOptions) + .on('end', done); + }); - helpers.mockPrompt(this.angulpify, mockPrompts); - done(); - }.bind(this)); + it('creates expected config files', function () { + + var expected = [ + '.editorconfig', + '.gitignore', + '.jshintrc', + '.yo-rc.json' + ]; + + assert.file(expected); }); - it('creates expected files', function (done) { + + it('creates expected gulp files', function () { var expected = [ - 'src/styles/app.scss', - 'src/styles/_imports.scss', - 'src/styles/_variables.scss', + 'gulpfile.js', + 'gulp/config.js', + 'gulp/utilities.js', + 'gulp/tasks/assets.js', + 'gulp/tasks/browserify-app.js', + 'gulp/tasks/browserify-vendors.js', + 'gulp/tasks/clean.js', + 'gulp/tasks/default.js', + // 'gulp/tasks/images.js', + 'gulp/tasks/index.js', + 'gulp/tasks/lint.js', + //'gulp/tasks/minify.js', + 'gulp/tasks/serve.js', + 'gulp/tasks/styles.js', + 'gulp/tasks/templates.js', + 'gulp/tasks/watch.js', + //'gulp/tasks/watchify.js' + ]; + + assert.file(expected); + }); + + it('creates expected script files', function () { + var expected = [ + 'src/scripts/app/app.config.js', + 'src/scripts/app/app.module.js', + 'src/scripts/app/vendors.js', + 'src/scripts/app/core/core.module.js', + 'src/scripts/app/layout/layout.config.js', + 'src/scripts/app/layout/layout.module.js', + 'src/scripts/app/welcome/welcome.config.js', + 'src/scripts/app/welcome/welcome.controller.js', + 'src/scripts/app/welcome/welcome.module.js' ]; - this.angulpify.run({}, function () { - assert.file(expected); - assert.fileContent('src/styles/_imports.scss', /You can @import all your bower_components \.sass files here/); - assert.fileContent('src/styles/_variables.scss', /You can add\/overwrite all your bower_components \.sass variables here/); - done(); - }); + + assert.file(expected); + }); - /*it('creates expected files with Bootstrap', function (done) { + it('creates expected sass files', function () { var expected = [ - 'src/styles/app.scss', - 'src/styles/_imports.scss', + 'src/styles/_layout.scss', 'src/styles/_variables.scss', + 'src/styles/main.scss' ]; - helpers.mockPrompt(this.angulpify, { - projectName: 'angulpify', - language: 'includeJavascript', - preprocessor: 'includeSass', - templateEngine: 'includeHtml', - goodies: ['includeBootstrap'] - }); - this.angulpify.run({}, function () { - assert.file(expected); - assert.fileContent('src/styles/_imports.scss', /Bootstrap-sass-official \(you can comment unused files\)/); - assert.fileContent('src/styles/_variables.scss', /Bootstrap-sass-official/); - done(); - }); - });*/ + + assert.file(expected); + + }); + + it('creates expected template files', function () { + var expected = [ + 'src/scripts/index.html', + 'src/scripts/app/layout/layout.html', + 'src/scripts/app/welcome/welcome.html' + ]; + + assert.file(expected); + }); + }); diff --git a/test/test.js b/test/test.js index 40fe298..b911618 100644 --- a/test/test.js +++ b/test/test.js @@ -2,116 +2,111 @@ 'use strict'; var path = require('path'); -var helpers = require('yeoman-generator').test; var assert = require('yeoman-generator').assert; +var helpers = require('yeoman-generator').test; +var os = require('os'); describe('angulpify: default features (javascript/css/html)', function () { - var mockPrompts = { - projectName: 'angulpify', - language: 'includeJavaScript', - preprocessor: 'includeCss', - templateEngine: 'includeHtml', - goodies: [] - }; + // not testing the actual run of generators yet + it('the generator can be required without throwing', function () { + this.app = require('../app'); + }); - beforeEach(function (done) { - helpers.testDirectory(path.join(__dirname, 'tmp'), function (err) { - if (err) { - return done(err); - } - this.angulpify = helpers.createGenerator('angulpify:app', ['../../generators/app']); - this.angulpify.options['skip-install'] = true; - this.angulpify.options['skip-welcome-message'] = true; + var promptOptions = { + project: 'angulpify', + styles: 'css', + templates: 'html' + } - helpers.mockPrompt(this.angulpify, mockPrompts); + var options = { + 'skip-install-message': true, + 'skip-install': true, + 'skip-welcome-message': true, + 'skip-message': true + }; - done(); - }.bind(this)); + before(function (done) { + helpers.run(path.join(__dirname, '../app')) + .inDir(path.join(os.tmpdir(), './temp-test')) + .withOptions(options) + .withPrompt(promptOptions) + .on('end', done); }); - it('can be imported without blowing up', function () { - this.app = require('../generators/app'); - assert(this.app !== undefined); - }); - it('creates expected config files', function (done) { - var expected = [ - '.editorconfig', - '.gitignore', - '.jshintrc', - '.yo-rc.json' - ]; - this.angulpify.run({}, function () { + it('creates expected config files', function () { + + var expected = [ + '.editorconfig', + '.gitignore', + '.jshintrc', + '.yo-rc.json' + ]; + assert.file(expected); - done(); - }); }); - it('creates expected gulp files', function (done) { + + it('creates expected gulp files', function () { var expected = [ 'gulpfile.js', 'gulp/config.js', - 'gulp/index.js', + 'gulp/utilities.js', 'gulp/tasks/assets.js', - 'gulp/tasks/browserify.js', + 'gulp/tasks/browserify-app.js', + 'gulp/tasks/browserify-vendors.js', 'gulp/tasks/clean.js', 'gulp/tasks/default.js', - 'gulp/tasks/images.js', + // 'gulp/tasks/images.js', 'gulp/tasks/index.js', 'gulp/tasks/lint.js', - 'gulp/tasks/minify.js', + //'gulp/tasks/minify.js', 'gulp/tasks/serve.js', 'gulp/tasks/styles.js', 'gulp/tasks/templates.js', 'gulp/tasks/watch.js', - 'gulp/tasks/watchify.js' + //'gulp/tasks/watchify.js' ]; - this.angulpify.run({}, function () { - assert.file(expected); - done(); - }); + + assert.file(expected); }); - it('creates expected script files', function (done) { + it('creates expected script files', function () { var expected = [ - 'src/modules/index.js', - 'src/modules/app/foo/fooController.js', - 'src/modules/app/foo/index.js', - 'src/modules/app/index.js', - 'src/modules/common/directives/fooDirective.js', - 'src/modules/common/directives/index.js', - 'src/modules/common/filters/fooFilter.js', - 'src/modules/common/filters/index.js', - 'src/modules/common/services/fooService.js', - 'src/modules/common/services/index.js', - 'src/modules/common/index.js' + 'src/scripts/app/app.config.js', + 'src/scripts/app/app.module.js', + 'src/scripts/app/vendors.js', + 'src/scripts/app/core/core.module.js', + 'src/scripts/app/layout/layout.config.js', + 'src/scripts/app/layout/layout.module.js', + 'src/scripts/app/welcome/welcome.config.js', + 'src/scripts/app/welcome/welcome.controller.js', + 'src/scripts/app/welcome/welcome.module.js' ]; - this.angulpify.run({}, function () { - assert.file(expected); - done(); - }); + + assert.file(expected); + }); - it('creates expected style files', function (done) { + it('creates expected style files', function () { var expected = [ - 'src/styles/app.css' + 'src/styles/layout.css', + 'src/styles/main.css' ]; - this.angulpify.run({}, function () { - assert.file(expected); - done(); - }); + + assert.file(expected); + }); - it('creates expected template files', function (done) { + it('creates expected template files', function () { var expected = [ - 'src/index.html', - 'src/modules/app/foo/layout.html' + 'src/scripts/index.html', + 'src/scripts/app/layout/layout.html', + 'src/scripts/app/welcome/welcome.html' ]; - this.angulpify.run({}, function () { - assert.file(expected); - done(); - }); + + assert.file(expected); }); });