Skip to content

Commit

Permalink
Update versions && tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteMX committed May 23, 2016
1 parent 8c1cc73 commit 51ecc7c
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 68 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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).
38 changes: 21 additions & 17 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(' __ ____ __') + ' _ _ _ ',
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
19 changes: 10 additions & 9 deletions generators/app/templates/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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");
Expand Down Expand Up @@ -91,7 +92,7 @@ module.exports = function (grunt) {
},
clean: {
build: [
path.join(shelljs.pwd(), "dist", pkg.name, "/*")
path.join(currentFolder, "dist", pkg.name, "/*")
]
},
csslint: {
Expand Down Expand Up @@ -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();

Expand Down
12 changes: 6 additions & 6 deletions generators/app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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') { %><% } %>
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
}
106 changes: 72 additions & 34 deletions test/test-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,96 @@
'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();
require('child_process').spawn = mySpawn;

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('<widget id="{0}.widget.{0}" ', [customWidgetName]));
});
it('require', function () {
assert.fileContent(xmlFile, format('<name>{0}</name>', [customWidgetName]));
});
});

describe('Package XML format', function() {
var xmlFile = 'src/package.xml';

it('clientModule', function () {
assert.fileContent(xmlFile, format('<clientModule name="{0}" version="1.0.0" xmlns="http://www.mendix.com/clientModule/1.0/">', [customWidgetName]));
});

it('widgetFiles', function () {
assert.fileContent(xmlFile, format('<widgetFile path="{0}/{0}.xml" />', [customWidgetName]));
});

it('file paths', function () {
assert.fileContent(xmlFile, format('<file path="{0}/widget/" />', [customWidgetName]));
});
});

// TODO: Check if the custom files use the correct prompts
// it('creates a custom package.json', function () {
// assert.noFileContent('Gruntfile.js');
// });
});

0 comments on commit 51ecc7c

Please sign in to comment.