Skip to content

Commit 51ecc7c

Browse files
author
JelteMX
committed
Update versions && tests
1 parent 8c1cc73 commit 51ecc7c

File tree

6 files changed

+123
-68
lines changed

6 files changed

+123
-68
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ First, you need to have NodeJs installed. After that, you need to install Yeoman
1616
npm install -g yo generator-mendix grunt-cli
1717
```
1818

19+
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``)
20+
1921
### Usage
2022

2123
##### 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
7274

7375
Cleans old ``.mpk`` files and creates a new one in your ``/dist`` and ``test/widgets`` folder
7476

77+
* ``csslint``
78+
79+
Lints through all CSS files that are in the ``widget/ui`` folder and checks for errors
80+
7581
### Using Grunt in a widget respository/project you downloaded.
7682

7783
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
9399
* Gulp integration
94100
* Add JSHint (Grunt/Gulp)
95101

102+
## Troubleshooting
103+
104+
105+
96106
## Issues
97107

98108
Issues can be reported on [Github](https://github.com/mendix/generator-mendix/issues).

generators/app/index.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ var parser = new xml2js.Parser();
1010
var yeoman = require('yeoman-generator');
1111
var chalk = require('chalk');
1212

13-
var boilerPlatePath = '/AppStoreWidgetBoilerplate/';
13+
var boilerPlatePath = 'AppStoreWidgetBoilerplate/';
14+
1415
var banner = [
1516
'',
1617
chalk.bold.cyan(' __ ____ __') + ' _ _ _ ',
@@ -26,9 +27,9 @@ var banner = [
2627
''
2728
].join('\n');
2829

29-
module.exports = yeoman.generators.Base.extend({
30+
module.exports = yeoman.Base.extend({
3031
constructor: function () {
31-
yeoman.generators.Base.apply(this, arguments);
32+
yeoman.Base.apply(this, arguments);
3233
var done = this.async();
3334
this.isNew = true;
3435

@@ -175,28 +176,31 @@ module.exports = yeoman.generators.Base.extend({
175176
];
176177

177178
if (this.isNew) {
178-
this.prompt(promptsNew, function (props) {
179-
this.props = props;
180-
// To access props later use this.props.someOption;
181-
done();
182-
}.bind(this));
179+
this
180+
.prompt(promptsNew)
181+
.then(function (props) {
182+
this.props = props;
183+
// To access props later use this.props.someOption;
184+
done();
185+
}.bind(this));
183186
} else {
184187
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'));
185-
this.prompt(promptsUpgrade, function (props) {
186-
this.props = props;
187-
if (!props.upgrade) {
188-
process.exit(0);
189-
} else {
190-
done();
191-
}
192-
}.bind(this));
188+
this
189+
.prompt(promptsUpgrade)
190+
.then(function (props) {
191+
this.props = props;
192+
if (!props.upgrade) {
193+
process.exit(0);
194+
} else {
195+
done();
196+
}
197+
}.bind(this));
193198
}
194199

195200
},
196201

197202
writing: {
198203
app: function () {
199-
200204
// Define widget variables
201205
this.widget = {};
202206
this.widget.widgetName = this.props.widgetName;

generators/app/templates/Gruntfile.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ var path = require("path"),
2323
xmldec: { standalone: null, encoding: "utf-8" }
2424
}),
2525
shelljs = require("shelljs"),
26-
pkg = require("./package.json");
26+
pkg = require("./package.json"),
27+
currentFolder = shelljs.pwd().toString();
2728

28-
var TEST_PATH = path.join(shelljs.pwd(), "/test/Test.mpr");
29-
var WIDGET_XML = path.join(shelljs.pwd(), "/src/", pkg.name, "/", pkg.name + ".xml");
30-
var PACKAGE_XML = path.join(shelljs.pwd(), "/src/package.xml");
31-
var TEST_WIDGETS_FOLDER = path.join(shelljs.pwd(), "./test/widgets");
32-
var TEST_WIDGETS_DEPLOYMENT_FOLDER = path.join(shelljs.pwd(), "./test/deployment/web/widgets");
29+
var TEST_PATH = path.join(currentFolder, "/test/Test.mpr");
30+
var WIDGET_XML = path.join(currentFolder, "/src/", pkg.name, "/", pkg.name + ".xml");
31+
var PACKAGE_XML = path.join(currentFolder, "/src/package.xml");
32+
var TEST_WIDGETS_FOLDER = path.join(currentFolder, "./test/widgets");
33+
var TEST_WIDGETS_DEPLOYMENT_FOLDER = path.join(currentFolder, "./test/deployment/web/widgets");
3334

3435
/**
3536
* 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
4344
if (pkg.paths && pkg.paths.testProjectFolder && pkg.paths.testProjectFileName) {
4445
var folder = pkg.paths.testProjectFolder;
4546
if (folder.indexOf(".") === 0) {
46-
folder = path.join(shelljs.pwd(), folder);
47+
folder = path.join(currentFolder, folder);
4748
}
4849
TEST_PATH = path.join(folder, pkg.paths.testProjectFileName);
4950
TEST_WIDGETS_FOLDER = path.join(folder, "/widgets");
@@ -91,7 +92,7 @@ module.exports = function (grunt) {
9192
},
9293
clean: {
9394
build: [
94-
path.join(shelljs.pwd(), "dist", pkg.name, "/*")
95+
path.join(currentFolder, "dist", pkg.name, "/*")
9596
]
9697
},
9798
csslint: {
@@ -169,7 +170,7 @@ module.exports = function (grunt) {
169170
});
170171

171172
grunt.registerTask("generate-icon", function () {
172-
var iconPath = path.join(shelljs.pwd(), "/icon.png"),
173+
var iconPath = path.join(currentFolder, "/icon.png"),
173174
options = {localFile: true, string: true},
174175
done = this.async();
175176

generators/app/templates/_package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
"dependencies": {
99
},
1010
"devDependencies": {<% if (builder == 'grunt') { %>
11-
"grunt": "0.4.5",
12-
"grunt-contrib-clean": "^0.6.0",
13-
"grunt-contrib-compress": "^0.14.0",
14-
"grunt-contrib-copy": "^0.8.2",
15-
"grunt-contrib-watch": "^0.6.1",
11+
"grunt": "1.0.1",
12+
"grunt-contrib-clean": "^1.0.0",
13+
"grunt-contrib-compress": "^1.2.0",
14+
"grunt-contrib-copy": "^1.0.0",
15+
"grunt-contrib-watch": "^1.0.0",
1616
"grunt-contrib-csslint": "^1.0.0",
1717
"grunt-newer": "^1.1.1",
1818
"node-base64-image": "^0.1.0",
19-
"shelljs": "^0.5.3",
19+
"shelljs": "^0.7.0",
2020
"xml2js": "^0.4.15",
2121
"semver": "^5.1.0",
2222
"node-mendix-modeler-path": "https://github.com/JelteMX/node-mendix-modeler-path/archive/v1.0.0.tar.gz"<% } if (builder == 'gulp') { %><% } %>

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generator-mendix",
3-
"version": "1.3.4",
3+
"version": "1.3.5",
44
"description": "Mendix Widget generator",
55
"license": "MIT",
66
"main": "app/index.js",
@@ -39,6 +39,8 @@
3939
"devDependencies": {
4040
"mocha": "*",
4141
"mock-spawn": "^0.2.6",
42-
"string-template": "1.0.0"
42+
"string-template": "1.0.0",
43+
"yeoman-assert": "^2.2.1",
44+
"yeoman-test": "^1.4.0"
4345
}
4446
}

test/test-app.js

Lines changed: 72 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,96 @@
33
'use strict';
44

55
var path = require('path');
6-
var assert = require('yeoman-generator').assert;
7-
var helpers = require('yeoman-generator').test;
6+
var assert = require('yeoman-assert');
7+
var helpers = require('yeoman-test');
88
var format = require('string-template');
99
var mockSpawn = require('mock-spawn');
1010

11-
describe('Mendix generator:', function () {
11+
describe('Generator:', function () {
1212

1313
var customWidgetName = 'TESTWIDGET';
1414
var mySpawn = mockSpawn();
1515
require('child_process').spawn = mySpawn;
1616

1717
mySpawn.setDefault(mySpawn.simple(0, ''));
1818

19-
before(function (done) {
20-
helpers.run(path.join(__dirname, '../generators/app'))
19+
before(function () {
20+
return helpers.run(path.join(__dirname, '../generators/app'))
2121
.withOptions({ skipInstall: true })
2222
.withPrompts({ widgetName: customWidgetName })
23-
.on('end', done);
23+
.toPromise();
2424
});
2525

26-
it('creates files from generator', function () {
27-
assert.file([
28-
'Gruntfile.js',
29-
'package.json',
30-
'.editorconfig',
31-
'.gitignore'
32-
]);
26+
describe('Copy/create', function () {
27+
it('creates files from generator', function () {
28+
assert.file([
29+
'Gruntfile.js',
30+
'package.json',
31+
'.editorconfig',
32+
'.gitignore'
33+
]);
34+
});
35+
36+
it('copies generic files from AppStoreWidgetBoilerPlate', function () {
37+
assert.file([
38+
'.jshintrc',
39+
'src/package.xml',
40+
'test/Test.mpr',
41+
'xsd/widget.xsd',
42+
'assets/app_store_banner.png',
43+
'assets/app_store_icon.png'
44+
]);
45+
});
46+
47+
it(format('copies files from AppStoreWidgetBoilerPlate based on widgetName ({0})', customWidgetName), function () {
48+
assert.file([
49+
format('src/{0}/{0}.xml', [customWidgetName]),
50+
format('src/{0}/lib/jquery-1.11.2.js', [customWidgetName]),
51+
format('src/{0}/widget/{0}.js', [customWidgetName]),
52+
format('src/{0}/widget/template/{0}.html', [customWidgetName]),
53+
format('src/{0}/widget/ui/{0}.css', [customWidgetName])
54+
]);
55+
});
3356
});
3457

35-
it('copies generic files from AppStoreWidgetBoilerPlate', function () {
36-
assert.file([
37-
'.jshintrc',
38-
'src/package.xml',
39-
'test/Test.mpr',
40-
'xsd/widget.xsd',
41-
'assets/app_store_banner.png',
42-
'assets/app_store_icon.png'
43-
]);
58+
describe('Javascript format', function() {
59+
var jsFile = format('src/{0}/widget/{0}.js', [customWidgetName]);
60+
61+
it('declare', function () {
62+
assert.fileContent(jsFile, format('return declare("{0}.widget.{0}", [ _WidgetBase, _TemplatedMixin ], {', [customWidgetName]));
63+
});
64+
65+
it('require', function () {
66+
assert.fileContent(jsFile, format('require(["{0}/widget/{0}"]);', [customWidgetName]));
67+
});
68+
4469
});
4570

46-
it(format('copies files from AppStoreWidgetBoilerPlate based on widgetName ({0})', customWidgetName), function () {
47-
assert.file([
48-
format('src/{0}/{0}.xml', [customWidgetName]),
49-
format('src/{0}/lib/jquery-1.11.2.js', [customWidgetName]),
50-
format('src/{0}/widget/{0}.js', [customWidgetName]),
51-
format('src/{0}/widget/template/{0}.html', [customWidgetName]),
52-
format('src/{0}/widget/ui/{0}.css', [customWidgetName])
53-
]);
71+
describe('Widget XML format', function() {
72+
var xmlFile = format('src/{0}/{0}.xml', [customWidgetName]);
73+
74+
it('declare', function () {
75+
assert.fileContent(xmlFile, format('<widget id="{0}.widget.{0}" ', [customWidgetName]));
76+
});
77+
it('require', function () {
78+
assert.fileContent(xmlFile, format('<name>{0}</name>', [customWidgetName]));
79+
});
80+
});
81+
82+
describe('Package XML format', function() {
83+
var xmlFile = 'src/package.xml';
84+
85+
it('clientModule', function () {
86+
assert.fileContent(xmlFile, format('<clientModule name="{0}" version="1.0.0" xmlns="http://www.mendix.com/clientModule/1.0/">', [customWidgetName]));
87+
});
88+
89+
it('widgetFiles', function () {
90+
assert.fileContent(xmlFile, format('<widgetFile path="{0}/{0}.xml" />', [customWidgetName]));
91+
});
92+
93+
it('file paths', function () {
94+
assert.fileContent(xmlFile, format('<file path="{0}/widget/" />', [customWidgetName]));
95+
});
5496
});
5597

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

0 commit comments

Comments
 (0)