Skip to content

Commit 1f7b6aa

Browse files
committed
Added mendix widget generator support
1 parent e3cce67 commit 1f7b6aa

File tree

4 files changed

+103
-44
lines changed

4 files changed

+103
-44
lines changed

.gitignore

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
test/javasource/**/proxies/
2-
test/javasource/com/
3-
test/javasource/system/
4-
test/javasource/*
1+
test/javasource/
52
test/deployment/
63
test/.classpath
74
test/.project
5+
test/theme/
6+
test/userlib/
7+
test/.classpath
8+
test/.project
89
*.launch
910
*.tmp
1011
*.lock
1112
.idea/
12-
*.bak
1313
settings/
14-
node_modules/
1514
dist/
15+
16+
node_modules/
17+
.editorconfig
1618
*DS_Store*
19+
.vscode/
20+
*.bak

.jshintrc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
// Enforcing
3+
"curly" : false,
4+
"forin" : false,
5+
"latedef" : "nofunc",
6+
"newcap" : true,
7+
"quotmark" : "double",
8+
"eqeqeq" : true,
9+
"undef" : true,
10+
"globals" : {
11+
"mendix" : false,
12+
"mx" : false
13+
},
14+
15+
// Relaxing
16+
"laxbreak" : true,
17+
18+
// Environments
19+
"browser" : true,
20+
"devel" : true,
21+
"dojo" : true
22+
}

Gruntfile.js

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
// Generated on 2016-01-04 using generator-mendix 1.1.0 :: http://github.com/git+https://github.com/mendix/generator-mendix.git
1+
// Generated on 2016-03-31 using generator-mendix 1.3.3 :: git+https://github.com/mendix/generator-mendix.git
22
/*jshint -W069*/
33
/*global module*/
44
"use strict";
55

6+
// In case you seem to have trouble starting Mendix through `grunt start-mendix`, you might have to set the path to the Mendix application.
7+
// If it works, leave MODELER_PATH at null
8+
var MODELER_PATH = null;
9+
var MODELER_ARGS = "/file:{path}";
10+
11+
/********************************************************************************
12+
* Do not edit anything below, unless you know what you are doing
13+
********************************************************************************/
14+
615
var path = require("path"),
716
mendixApp = require("node-mendix-modeler-path"),
817
base64 = require("node-base64-image"),
@@ -13,23 +22,35 @@ var path = require("path"),
1322
renderOpts: { pretty: true, indent: " ", newline: "\n" },
1423
xmldec: { standalone: null, encoding: "utf-8" }
1524
}),
16-
shelljs = require("shelljs");
17-
18-
// In case you seem to have trouble starting Mendix through `grunt start-mendix`, you might have to set the path to the Mendix application.
19-
// If it works, leave MODELER_PATH at null
20-
var MODELER_PATH = null;
21-
var MODELER_ARGS = "/file:{path}";
22-
23-
// In case you have a different path to the test project (currently in ./test/Test.mpr) point TEST_PATH to the Test-project (full path). Otherwise, leave at null
24-
var TEST_PATH = null;
25-
// Use this example if you want to point it to a different subfolder and specific Test project Name:
26-
// var TEST_PATH = path.join(shelljs.pwd(), "./<custom folder>/<Custom Test Project Name>.mpr");
25+
shelljs = require("shelljs"),
26+
pkg = require("./package.json");
27+
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");
33+
34+
/**
35+
* If you want to use a custom folder for the test project, make sure these are added to package.json:
36+
* "paths": {
37+
* "testProjectFolder": "./test/",
38+
* "testProjectFileName": "Test.mpr"
39+
* },
40+
* You can test it by running: `grunt folders`
41+
**/
42+
43+
if (pkg.paths && pkg.paths.testProjectFolder && pkg.paths.testProjectFileName) {
44+
var folder = pkg.paths.testProjectFolder;
45+
if (folder.indexOf(".") === 0) {
46+
folder = path.join(shelljs.pwd(), folder);
47+
}
48+
TEST_PATH = path.join(folder, pkg.paths.testProjectFileName);
49+
TEST_WIDGETS_FOLDER = path.join(folder, "/widgets");
50+
TEST_WIDGETS_DEPLOYMENT_FOLDER = path.join(folder, "/deployment/web/widgets");
51+
}
2752

2853
module.exports = function (grunt) {
29-
var pkg = grunt.file.readJSON("package.json");
30-
var widgetXml = path.join(shelljs.pwd(), "/src/", pkg.name, "/", pkg.name + ".xml");
31-
var packageXml = path.join(shelljs.pwd(), "/src/package.xml");
32-
3354
grunt.initConfig({
3455
watch: {
3556
autoDeployUpdate: {
@@ -59,20 +80,18 @@ module.exports = function (grunt) {
5980
copy: {
6081
deployment: {
6182
files: [
62-
{ dest: "./test/deployment/web/widgets", cwd: "./src/", src: ["**/*"], expand: true }
83+
{ dest: TEST_WIDGETS_DEPLOYMENT_FOLDER, cwd: "./src/", src: ["**/*"], expand: true }
6384
]
6485
},
6586
mpks: {
6687
files: [
67-
{ dest: "./test/widgets", cwd: "./dist/", src: [ pkg.name + ".mpk"], expand: true }
88+
{ dest: TEST_WIDGETS_FOLDER, cwd: "./dist/", src: [ pkg.name + ".mpk"], expand: true }
6889
]
6990
}
7091
},
7192
clean: {
7293
build: [
73-
"./dist/" + pkg.name + "/*",
74-
"./test/deployment/web/widgets/" + pkg.name + "/*",
75-
"./test/widgets/" + pkg.name + ".mpk"
94+
path.join(shelljs.pwd(), "dist", pkg.name, "/*")
7695
]
7796
}
7897
});
@@ -84,14 +103,12 @@ module.exports = function (grunt) {
84103
grunt.loadNpmTasks("grunt-newer");
85104

86105
grunt.registerTask("start-modeler", function () {
87-
var done = this.async(),
88-
testProjectPath = TEST_PATH !== null ? TEST_PATH : path.join(shelljs.pwd(), "/test/Test.mpr");
89-
106+
var done = this.async();
90107
if (MODELER_PATH !== null || (mendixApp.err === null && mendixApp.output !== null && mendixApp.output.cmd && mendixApp.output.arg)) {
91108
grunt.util.spawn({
92109
cmd: MODELER_PATH || mendixApp.output.cmd,
93110
args: [
94-
(MODELER_PATH !== null ? MODELER_ARGS : mendixApp.output.arg).replace("{path}", testProjectPath)
111+
(MODELER_PATH !== null ? MODELER_ARGS : mendixApp.output.arg).replace("{path}", TEST_PATH)
95112
]
96113
}, function () {
97114
done();
@@ -105,12 +122,12 @@ module.exports = function (grunt) {
105122

106123
grunt.registerTask("version", function (version) {
107124
var done = this.async();
108-
if (!grunt.file.exists(packageXml)) {
109-
grunt.log.error("Cannot find " + packageXml);
125+
if (!grunt.file.exists(PACKAGE_XML)) {
126+
grunt.log.error("Cannot find " + PACKAGE_XML);
110127
return done();
111128
}
112129

113-
var xml = grunt.file.read(packageXml);
130+
var xml = grunt.file.read(PACKAGE_XML);
114131
parser.parseString(xml, function (err, res) {
115132
if (err) {
116133
grunt.log.error(err);
@@ -130,7 +147,7 @@ module.exports = function (grunt) {
130147
res.package.clientModule[0]["$"]["version"] = version;
131148
pkg.version = version;
132149
var xmlString = builder.buildObject(res);
133-
grunt.file.write(packageXml, xmlString);
150+
grunt.file.write(PACKAGE_XML, xmlString);
134151
grunt.file.write("package.json", JSON.stringify(pkg, null, 2));
135152
done();
136153
}
@@ -149,21 +166,21 @@ module.exports = function (grunt) {
149166

150167
grunt.log.writeln("Processing icon");
151168

152-
if (!grunt.file.exists(iconPath) || !grunt.file.exists(widgetXml)) {
169+
if (!grunt.file.exists(iconPath) || !grunt.file.exists(WIDGET_XML)) {
153170
grunt.log.error("can\'t generate icon");
154171
return done();
155172
}
156173

157174
base64.base64encoder(iconPath, options, function (err, image) {
158175
if (!err) {
159-
var xmlOld = grunt.file.read(widgetXml);
176+
var xmlOld = grunt.file.read(WIDGET_XML);
160177
parser.parseString(xmlOld, function (err, result) {
161178
if (!err) {
162179
if (result && result.widget && result.widget.icon) {
163180
result.widget.icon[0] = image;
164181
}
165182
var xmlString = builder.buildObject(result);
166-
grunt.file.write(widgetXml, xmlString);
183+
grunt.file.write(WIDGET_XML, xmlString);
167184
done();
168185
}
169186
});
@@ -174,6 +191,17 @@ module.exports = function (grunt) {
174191
});
175192
});
176193

194+
grunt.registerTask("folders", function () {
195+
var done = this.async();
196+
grunt.log.writeln("\nShowing file paths that Grunt will use. You can edit the package.json accordingly\n");
197+
grunt.log.writeln("TEST_PATH: ", TEST_PATH);
198+
grunt.log.writeln("WIDGET_XML: ", WIDGET_XML);
199+
grunt.log.writeln("PACKAGE_XML: ", PACKAGE_XML);
200+
grunt.log.writeln("TEST_WIDGETS_FOLDER: ", TEST_WIDGETS_FOLDER);
201+
grunt.log.writeln("TEST_WIDGETS_DEPLOYMENT_FOLDER: ", TEST_WIDGETS_DEPLOYMENT_FOLDER);
202+
return done();
203+
});
204+
177205
grunt.registerTask("start-mendix", [ "start-modeler" ]);
178206

179207
grunt.registerTask(

package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
"name": "HTMLSnippet",
33
"version": "3.6.0",
44
"description": "",
5+
"license": "",
6+
"author": "",
57
"private": true,
6-
"dependencies": {},
8+
"dependencies": {
9+
},
710
"devDependencies": {
811
"grunt": "0.4.5",
912
"grunt-contrib-clean": "^0.6.0",
@@ -17,14 +20,16 @@
1720
"semver": "^5.1.0",
1821
"node-mendix-modeler-path": "https://github.com/JelteMX/node-mendix-modeler-path/archive/v1.0.0.tar.gz"
1922
},
20-
"repository": {
21-
"type": "git",
22-
"url": "http://github.com/mendix/HTMLSnippet"
23-
},
23+
"repository": {"type":"git","url":"http://github.com/mendix/HTMLSnippet"},
2424
"engines": {
2525
"node": ">=0.12.0"
2626
},
27+
"generatorVersion": "1.3.3",
28+
"paths": {
29+
"testProjectFolder": "./test/",
30+
"testProjectFileName": "Test.mpr"
31+
},
2732
"scripts": {
2833
"test": "grunt test"
2934
}
30-
}
35+
}

0 commit comments

Comments
 (0)