Skip to content

Commit 4f66f52

Browse files
author
Jelte Lagendijk
committed
Update development files
1 parent 62990cb commit 4f66f52

File tree

3 files changed

+226
-135
lines changed

3 files changed

+226
-135
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ test/javasource/
22
test/deployment/
33
test/.classpath
44
test/.project
5+
test/theme/
6+
test/userlib/
7+
test/.classpath
8+
test/.project
59
*.launch
610
*.tmp
711
*.lock
@@ -12,4 +16,5 @@ dist/
1216
node_modules/
1317
.editorconfig
1418
*DS_Store*
15-
.vscode/
19+
.vscode/
20+
*.bak

Gruntfile.js

Lines changed: 208 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,223 @@
1-
// Generated on 2015-12-03 using generator-mendix 1.0.0 :: http://github.com/[object Object]
2-
'use strict';
3-
4-
var path = require('path'),
5-
mendixApp = require('node-mendix-modeler-path'),
6-
base64 = require('node-base64-image'),
7-
fs = require('fs'),
8-
xml2js = require('xml2js'),
9-
parser = new xml2js.Parser(),
10-
builder = new xml2js.Builder(),
11-
shelljs = require('shelljs');
1+
// Generated on 2016-02-16 using generator-mendix 1.3.3 :: git+https://github.com/mendix/generator-mendix.git
2+
/*jshint -W069*/
3+
/*global module*/
4+
"use strict";
125

136
// In case you seem to have trouble starting Mendix through `grunt start-mendix`, you might have to set the path to the Mendix application.
147
// If it works, leave MODELER_PATH at null
158
var MODELER_PATH = null;
16-
var MODELER_ARGS = '/file:{path}';
9+
var MODELER_ARGS = "/file:{path}";
1710

18-
// 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
19-
var TEST_PATH = null;
20-
// Use this example if you want to point it to a different subfolder and specific Test project Name:
21-
// var TEST_PATH = path.join(shelljs.pwd(), './<custom folder>/<Custom Test Project Name>.mpr');
11+
/********************************************************************************
12+
* Do not edit anything below, unless you know what you are doing
13+
********************************************************************************/
2214

23-
module.exports = function (grunt) {
24-
var pkg = grunt.file.readJSON("package.json");
25-
grunt.verbose;
26-
grunt.initConfig({
27-
watch: {
28-
autoDeployUpdate: {
29-
"files": [ "./src/**/*" ],
30-
"tasks": [ "newer:copy", "compress" ],
31-
options: {
32-
debounceDelay: 250,
33-
livereload: true
34-
}
35-
}
36-
},
37-
compress: {
38-
makezip: {
39-
options: {
40-
archive: "./dist/" + pkg.name + ".mpk",
41-
mode: "zip"
42-
},
43-
files: [{
44-
expand: true,
45-
date: new Date(),
46-
store: false,
47-
cwd: "./src",
48-
src: ["**/*"]
49-
}]
50-
}
51-
},
52-
copy: {
53-
deployment: {
54-
files: [
55-
{ dest: "./test/deployment/web/widgets", cwd: "./src/", src: ["**/*"], expand: true }
56-
]
57-
},
58-
mpks: {
59-
files: [
60-
{ dest: "./test/widgets", cwd: "./dist/", src: [ pkg.name + ".mpk"], expand: true }
61-
]
62-
}
63-
},
64-
clean: {
65-
build: [
66-
"./dist/" + pkg.name + "/*",
67-
"./test/deployment/web/widgets/" + pkg.name + "/*",
68-
"./test/widgets/" + pkg.name + ".mpk"
69-
]
70-
}
71-
});
72-
73-
grunt.loadNpmTasks("grunt-contrib-compress");
74-
grunt.loadNpmTasks("grunt-contrib-clean");
75-
grunt.loadNpmTasks("grunt-contrib-watch");
76-
grunt.loadNpmTasks("grunt-contrib-copy");
77-
grunt.loadNpmTasks("grunt-newer");
78-
79-
grunt.registerTask("start-mendix", function () {
80-
var done = this.async(),
81-
testProjectPath = TEST_PATH !== null ? TEST_PATH : path.join(shelljs.pwd(), '/test/Test.mpr');
82-
83-
if (MODELER_PATH !== null || (mendixApp.err === null && mendixApp.output !== null && mendixApp.output.cmd && mendixApp.output.arg)) {
84-
grunt.util.spawn({
85-
cmd: MODELER_PATH || mendixApp.output.cmd,
86-
args: [
87-
(MODELER_PATH !== null ? MODELER_ARGS : mendixApp.output.arg).replace('{path}', testProjectPath)
88-
]
89-
}, function () {
90-
done();
91-
});
92-
} else {
93-
console.error('Cannot start Modeler, see error:');
94-
console.log(mendixApp.err);
95-
done();
96-
}
97-
});
15+
var path = require("path"),
16+
mendixApp = require("node-mendix-modeler-path"),
17+
base64 = require("node-base64-image"),
18+
semver = require("semver"),
19+
xml2js = require("xml2js"),
20+
parser = new xml2js.Parser(),
21+
builder = new xml2js.Builder({
22+
renderOpts: { pretty: true, indent: " ", newline: "\n" },
23+
xmldec: { standalone: null, encoding: "utf-8" }
24+
}),
25+
shelljs = require("shelljs"),
26+
pkg = require("./package.json");
9827

99-
grunt.registerTask("generate-icon", function () {
100-
var iconPath = path.join(shelljs.pwd(), '/icon.png'),
101-
widgetXml = path.join(shelljs.pwd(), '/src/', pkg.name, '/', pkg.name + '.xml'),
102-
options = {localFile: true, string: true},
103-
done = this.async();
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");
10433

105-
grunt.log.writeln('Processing icon');
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+
**/
10642

107-
if (!grunt.file.exists(iconPath) || !grunt.file.exists(widgetXml)) {
108-
grunt.log.error("can't generate icon");
109-
return done();
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);
11047
}
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+
}
11152

112-
base64.base64encoder(iconPath, options, function (err, image) {
113-
if (!err) {
114-
var xmlOld = grunt.file.read(widgetXml);
115-
parser.parseString(xmlOld, function (err, result) {
116-
if (!err) {
117-
if (result && result.widget && result.widget.icon) {
118-
result.widget.icon[0] = image;
53+
module.exports = function (grunt) {
54+
grunt.initConfig({
55+
watch: {
56+
autoDeployUpdate: {
57+
"files": [ "./src/**/*" ],
58+
"tasks": [ "compress", "newer:copy" ],
59+
options: {
60+
debounceDelay: 250,
61+
livereload: true
62+
}
63+
}
64+
},
65+
compress: {
66+
makezip: {
67+
options: {
68+
archive: "./dist/" + pkg.name + ".mpk",
69+
mode: "zip"
70+
},
71+
files: [{
72+
expand: true,
73+
date: new Date(),
74+
store: false,
75+
cwd: "./src",
76+
src: ["**/*"]
77+
}]
11978
}
120-
var xmlString = builder.buildObject(result);
121-
grunt.file.write(widgetXml, xmlString);
79+
},
80+
copy: {
81+
deployment: {
82+
files: [
83+
{ dest: TEST_WIDGETS_DEPLOYMENT_FOLDER, cwd: "./src/", src: ["**/*"], expand: true }
84+
]
85+
},
86+
mpks: {
87+
files: [
88+
{ dest: TEST_WIDGETS_FOLDER, cwd: "./dist/", src: [ pkg.name + ".mpk"], expand: true }
89+
]
90+
}
91+
},
92+
clean: {
93+
build: [
94+
path.join(shelljs.pwd(), "dist", pkg.name, "/*")
95+
]
96+
}
97+
});
98+
99+
grunt.loadNpmTasks("grunt-contrib-compress");
100+
grunt.loadNpmTasks("grunt-contrib-clean");
101+
grunt.loadNpmTasks("grunt-contrib-watch");
102+
grunt.loadNpmTasks("grunt-contrib-copy");
103+
grunt.loadNpmTasks("grunt-newer");
104+
105+
grunt.registerTask("start-modeler", function () {
106+
var done = this.async();
107+
if (MODELER_PATH !== null || (mendixApp.err === null && mendixApp.output !== null && mendixApp.output.cmd && mendixApp.output.arg)) {
108+
grunt.util.spawn({
109+
cmd: MODELER_PATH || mendixApp.output.cmd,
110+
args: [
111+
(MODELER_PATH !== null ? MODELER_ARGS : mendixApp.output.arg).replace("{path}", TEST_PATH)
112+
]
113+
}, function () {
114+
done();
115+
});
116+
} else {
117+
console.error("Cannot start Modeler, see error:");
118+
console.log(mendixApp.err);
122119
done();
123-
}
120+
}
121+
});
122+
123+
grunt.registerTask("version", function (version) {
124+
var done = this.async();
125+
if (!grunt.file.exists(PACKAGE_XML)) {
126+
grunt.log.error("Cannot find " + PACKAGE_XML);
127+
return done();
128+
}
129+
130+
var xml = grunt.file.read(PACKAGE_XML);
131+
parser.parseString(xml, function (err, res) {
132+
if (err) {
133+
grunt.log.error(err);
134+
return done();
135+
}
136+
if (res.package.clientModule[0]["$"]["version"]) {
137+
var currentVersion = res.package.clientModule[0]["$"]["version"];
138+
if (!version) {
139+
grunt.log.writeln("\nCurrent version is " + currentVersion);
140+
grunt.log.writeln("Set new version by running 'grunt version:x.y.z'");
141+
done();
142+
} else {
143+
if (!semver.valid(version) || !semver.satisfies(version, ">= 1.0.0")) {
144+
grunt.log.error("\nPlease provide a valid version that is higher than 1.0.0. Current version: " + currentVersion);
145+
done();
146+
} else {
147+
res.package.clientModule[0]["$"]["version"] = version;
148+
pkg.version = version;
149+
var xmlString = builder.buildObject(res);
150+
grunt.file.write(PACKAGE_XML, xmlString);
151+
grunt.file.write("package.json", JSON.stringify(pkg, null, 2));
152+
done();
153+
}
154+
}
155+
} else {
156+
grunt.log.error("Cannot find current version number");
157+
}
124158
});
125-
}
159+
126160
});
127-
});
128-
129-
grunt.registerTask(
130-
"default",
131-
"Watches for changes and automatically creates an MPK file, as well as copying the changes to your deployment folder",
132-
[ "watch" ]
133-
);
134-
135-
grunt.registerTask(
136-
"clean build",
137-
"Compiles all the assets and copies the files to the build directory.",
138-
[ "clean", "compress", "copy" ]
139-
);
140-
141-
grunt.registerTask(
142-
"build",
143-
[ "clean build" ]
144-
);
145-
};
161+
162+
grunt.registerTask("generate-icon", function () {
163+
var iconPath = path.join(shelljs.pwd(), "/icon.png"),
164+
options = {localFile: true, string: true},
165+
done = this.async();
166+
167+
grunt.log.writeln("Processing icon");
168+
169+
if (!grunt.file.exists(iconPath) || !grunt.file.exists(WIDGET_XML)) {
170+
grunt.log.error("can\'t generate icon");
171+
return done();
172+
}
173+
174+
base64.base64encoder(iconPath, options, function (err, image) {
175+
if (!err) {
176+
var xmlOld = grunt.file.read(WIDGET_XML);
177+
parser.parseString(xmlOld, function (err, result) {
178+
if (!err) {
179+
if (result && result.widget && result.widget.icon) {
180+
result.widget.icon[0] = image;
181+
}
182+
var xmlString = builder.buildObject(result);
183+
grunt.file.write(WIDGET_XML, xmlString);
184+
done();
185+
}
186+
});
187+
} else {
188+
grunt.log.error("can\'t generate icon");
189+
return done();
190+
}
191+
});
192+
});
193+
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+
205+
grunt.registerTask("start-mendix", [ "start-modeler" ]);
206+
207+
grunt.registerTask(
208+
"default",
209+
"Watches for changes and automatically creates an MPK file, as well as copying the changes to your deployment folder",
210+
[ "watch" ]
211+
);
212+
213+
grunt.registerTask(
214+
"clean build",
215+
"Compiles all the assets and copies the files to the build directory.",
216+
[ "clean", "compress", "copy" ]
217+
);
218+
219+
grunt.registerTask(
220+
"build",
221+
[ "clean build" ]
222+
);
223+
};

0 commit comments

Comments
 (0)