diff --git a/README.md b/README.md index 7cf357f..28e2f93 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ First, you need to have NodeJs installed. After that, you need to install Yeoman npm install -g yo generator-mendix grunt-cli ``` +Make sure you have the latest version of ``yo``. The version we work with currently is 1.8.3 (which you can check by running ``yo --version``) + ### Usage ##### 1.) Start the generator in the folder you want to create a widget: @@ -72,6 +74,10 @@ and then check if the path is correct by running the ``grunt folders`` task Cleans old ``.mpk`` files and creates a new one in your ``/dist`` and ``test/widgets`` folder +* ``csslint`` + +Lints through all CSS files that are in the ``widget/ui`` folder and checks for errors + ### Using Grunt in a widget respository/project you downloaded. If you download or clone one of our repositories that has a ``Gruntfile.js`` and ``package.json`` included, you need to install the dependencies first to be able to run Grunt: @@ -93,6 +99,10 @@ If you download or clone one of our repositories that has a ``Gruntfile.js`` and * Gulp integration * Add JSHint (Grunt/Gulp) +## Troubleshooting + + + ## Issues Issues can be reported on [Github](https://github.com/mendix/generator-mendix/issues). diff --git a/generators/app/index.js b/generators/app/index.js index 4dbe4a3..9818e5c 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -10,7 +10,8 @@ var parser = new xml2js.Parser(); var yeoman = require('yeoman-generator'); var chalk = require('chalk'); -var boilerPlatePath = '/AppStoreWidgetBoilerplate/'; +var boilerPlatePath = 'AppStoreWidgetBoilerplate/'; + var banner = [ '', chalk.bold.cyan(' __ ____ __') + ' _ _ _ ', @@ -26,9 +27,9 @@ var banner = [ '' ].join('\n'); -module.exports = yeoman.generators.Base.extend({ +module.exports = yeoman.Base.extend({ constructor: function () { - yeoman.generators.Base.apply(this, arguments); + yeoman.Base.apply(this, arguments); var done = this.async(); this.isNew = true; @@ -175,28 +176,31 @@ module.exports = yeoman.generators.Base.extend({ ]; if (this.isNew) { - this.prompt(promptsNew, function (props) { - this.props = props; - // To access props later use this.props.someOption; - done(); - }.bind(this)); + this + .prompt(promptsNew) + .then(function (props) { + this.props = props; + // To access props later use this.props.someOption; + done(); + }.bind(this)); } else { this.log(chalk.bold.red(' The directory is not empty. If you are creating a new widget, please open the generator in an empty folder (Press Ctrl+C to abort)\n\n')); - this.prompt(promptsUpgrade, function (props) { - this.props = props; - if (!props.upgrade) { - process.exit(0); - } else { - done(); - } - }.bind(this)); + this + .prompt(promptsUpgrade) + .then(function (props) { + this.props = props; + if (!props.upgrade) { + process.exit(0); + } else { + done(); + } + }.bind(this)); } }, writing: { app: function () { - // Define widget variables this.widget = {}; this.widget.widgetName = this.props.widgetName; diff --git a/generators/app/templates/Gruntfile.js b/generators/app/templates/Gruntfile.js index 9ac68a8..382fc9f 100644 --- a/generators/app/templates/Gruntfile.js +++ b/generators/app/templates/Gruntfile.js @@ -23,13 +23,14 @@ var path = require("path"), xmldec: { standalone: null, encoding: "utf-8" } }), shelljs = require("shelljs"), - pkg = require("./package.json"); + pkg = require("./package.json"), + currentFolder = shelljs.pwd().toString(); -var TEST_PATH = path.join(shelljs.pwd(), "/test/Test.mpr"); -var WIDGET_XML = path.join(shelljs.pwd(), "/src/", pkg.name, "/", pkg.name + ".xml"); -var PACKAGE_XML = path.join(shelljs.pwd(), "/src/package.xml"); -var TEST_WIDGETS_FOLDER = path.join(shelljs.pwd(), "./test/widgets"); -var TEST_WIDGETS_DEPLOYMENT_FOLDER = path.join(shelljs.pwd(), "./test/deployment/web/widgets"); +var TEST_PATH = path.join(currentFolder, "/test/Test.mpr"); +var WIDGET_XML = path.join(currentFolder, "/src/", pkg.name, "/", pkg.name + ".xml"); +var PACKAGE_XML = path.join(currentFolder, "/src/package.xml"); +var TEST_WIDGETS_FOLDER = path.join(currentFolder, "./test/widgets"); +var TEST_WIDGETS_DEPLOYMENT_FOLDER = path.join(currentFolder, "./test/deployment/web/widgets"); /** * If you want to use a custom folder for the test project, make sure these are added to package.json: @@ -43,7 +44,7 @@ var TEST_WIDGETS_DEPLOYMENT_FOLDER = path.join(shelljs.pwd(), "./test/deployment if (pkg.paths && pkg.paths.testProjectFolder && pkg.paths.testProjectFileName) { var folder = pkg.paths.testProjectFolder; if (folder.indexOf(".") === 0) { - folder = path.join(shelljs.pwd(), folder); + folder = path.join(currentFolder, folder); } TEST_PATH = path.join(folder, pkg.paths.testProjectFileName); TEST_WIDGETS_FOLDER = path.join(folder, "/widgets"); @@ -91,7 +92,7 @@ module.exports = function (grunt) { }, clean: { build: [ - path.join(shelljs.pwd(), "dist", pkg.name, "/*") + path.join(currentFolder, "dist", pkg.name, "/*") ] }, csslint: { @@ -169,7 +170,7 @@ module.exports = function (grunt) { }); grunt.registerTask("generate-icon", function () { - var iconPath = path.join(shelljs.pwd(), "/icon.png"), + var iconPath = path.join(currentFolder, "/icon.png"), options = {localFile: true, string: true}, done = this.async(); diff --git a/generators/app/templates/_package.json b/generators/app/templates/_package.json index 025851c..e12fa09 100644 --- a/generators/app/templates/_package.json +++ b/generators/app/templates/_package.json @@ -8,15 +8,15 @@ "dependencies": { }, "devDependencies": {<% if (builder == 'grunt') { %> - "grunt": "0.4.5", - "grunt-contrib-clean": "^0.6.0", - "grunt-contrib-compress": "^0.14.0", - "grunt-contrib-copy": "^0.8.2", - "grunt-contrib-watch": "^0.6.1", + "grunt": "1.0.1", + "grunt-contrib-clean": "^1.0.0", + "grunt-contrib-compress": "^1.2.0", + "grunt-contrib-copy": "^1.0.0", + "grunt-contrib-watch": "^1.0.0", "grunt-contrib-csslint": "^1.0.0", "grunt-newer": "^1.1.1", "node-base64-image": "^0.1.0", - "shelljs": "^0.5.3", + "shelljs": "^0.7.0", "xml2js": "^0.4.15", "semver": "^5.1.0", "node-mendix-modeler-path": "https://github.com/JelteMX/node-mendix-modeler-path/archive/v1.0.0.tar.gz"<% } if (builder == 'gulp') { %><% } %> diff --git a/package.json b/package.json index a278922..b586fd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "generator-mendix", - "version": "1.3.4", + "version": "1.3.5", "description": "Mendix Widget generator", "license": "MIT", "main": "app/index.js", @@ -39,6 +39,8 @@ "devDependencies": { "mocha": "*", "mock-spawn": "^0.2.6", - "string-template": "1.0.0" + "string-template": "1.0.0", + "yeoman-assert": "^2.2.1", + "yeoman-test": "^1.4.0" } } diff --git a/test/test-app.js b/test/test-app.js index cd9e139..66e5cad 100644 --- a/test/test-app.js +++ b/test/test-app.js @@ -3,12 +3,12 @@ 'use strict'; var path = require('path'); -var assert = require('yeoman-generator').assert; -var helpers = require('yeoman-generator').test; +var assert = require('yeoman-assert'); +var helpers = require('yeoman-test'); var format = require('string-template'); var mockSpawn = require('mock-spawn'); -describe('Mendix generator:', function () { +describe('Generator:', function () { var customWidgetName = 'TESTWIDGET'; var mySpawn = mockSpawn(); @@ -16,45 +16,83 @@ describe('Mendix generator:', function () { mySpawn.setDefault(mySpawn.simple(0, '')); - before(function (done) { - helpers.run(path.join(__dirname, '../generators/app')) + before(function () { + return helpers.run(path.join(__dirname, '../generators/app')) .withOptions({ skipInstall: true }) .withPrompts({ widgetName: customWidgetName }) - .on('end', done); + .toPromise(); }); - it('creates files from generator', function () { - assert.file([ - 'Gruntfile.js', - 'package.json', - '.editorconfig', - '.gitignore' - ]); + describe('Copy/create', function () { + it('creates files from generator', function () { + assert.file([ + 'Gruntfile.js', + 'package.json', + '.editorconfig', + '.gitignore' + ]); + }); + + it('copies generic files from AppStoreWidgetBoilerPlate', function () { + assert.file([ + '.jshintrc', + 'src/package.xml', + 'test/Test.mpr', + 'xsd/widget.xsd', + 'assets/app_store_banner.png', + 'assets/app_store_icon.png' + ]); + }); + + it(format('copies files from AppStoreWidgetBoilerPlate based on widgetName ({0})', customWidgetName), function () { + assert.file([ + format('src/{0}/{0}.xml', [customWidgetName]), + format('src/{0}/lib/jquery-1.11.2.js', [customWidgetName]), + format('src/{0}/widget/{0}.js', [customWidgetName]), + format('src/{0}/widget/template/{0}.html', [customWidgetName]), + format('src/{0}/widget/ui/{0}.css', [customWidgetName]) + ]); + }); }); - it('copies generic files from AppStoreWidgetBoilerPlate', function () { - assert.file([ - '.jshintrc', - 'src/package.xml', - 'test/Test.mpr', - 'xsd/widget.xsd', - 'assets/app_store_banner.png', - 'assets/app_store_icon.png' - ]); + describe('Javascript format', function() { + var jsFile = format('src/{0}/widget/{0}.js', [customWidgetName]); + + it('declare', function () { + assert.fileContent(jsFile, format('return declare("{0}.widget.{0}", [ _WidgetBase, _TemplatedMixin ], {', [customWidgetName])); + }); + + it('require', function () { + assert.fileContent(jsFile, format('require(["{0}/widget/{0}"]);', [customWidgetName])); + }); + }); - it(format('copies files from AppStoreWidgetBoilerPlate based on widgetName ({0})', customWidgetName), function () { - assert.file([ - format('src/{0}/{0}.xml', [customWidgetName]), - format('src/{0}/lib/jquery-1.11.2.js', [customWidgetName]), - format('src/{0}/widget/{0}.js', [customWidgetName]), - format('src/{0}/widget/template/{0}.html', [customWidgetName]), - format('src/{0}/widget/ui/{0}.css', [customWidgetName]) - ]); + describe('Widget XML format', function() { + var xmlFile = format('src/{0}/{0}.xml', [customWidgetName]); + + it('declare', function () { + assert.fileContent(xmlFile, format('{0}', [customWidgetName])); + }); + }); + + describe('Package XML format', function() { + var xmlFile = 'src/package.xml'; + + it('clientModule', function () { + assert.fileContent(xmlFile, format('', [customWidgetName])); + }); + + it('widgetFiles', function () { + assert.fileContent(xmlFile, format('', [customWidgetName])); + }); + + it('file paths', function () { + assert.fileContent(xmlFile, format('', [customWidgetName])); + }); }); - // TODO: Check if the custom files use the correct prompts - // it('creates a custom package.json', function () { - // assert.noFileContent('Gruntfile.js'); - // }); });