Skip to content

Commit c32bb41

Browse files
Andries SmitAndries Smit
authored andcommitted
Bump version
1 parent 1943930 commit c32bb41

File tree

5 files changed

+600
-365
lines changed

5 files changed

+600
-365
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ test/.project
77
*.lock
88
*.bak
99
.idea/
10-
*.mws
10+
*.mws
11+
node_modules/
12+
dist/

Gruntfile.js

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
// Generated on 2018-03-28 using generator-mendix 2.2.3 :: git+https://github.com/mendix/generator-mendix.git
2+
/*jshint -W069*/
3+
/*global module*/
4+
"use strict";
5+
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+
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"),
27+
currentFolder = shelljs.pwd().toString();
28+
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");
34+
35+
/**
36+
* If you want to use a custom folder for the test project, make sure these are added to package.json:
37+
* "paths": {
38+
* "testProjectFolder": "./test/",
39+
* "testProjectFileName": "Test.mpr"
40+
* },
41+
* You can test it by running: `grunt folders`
42+
**/
43+
44+
if (pkg.paths && pkg.paths.testProjectFolder && pkg.paths.testProjectFileName) {
45+
var folder = pkg.paths.testProjectFolder;
46+
if (folder.indexOf(".") === 0) {
47+
folder = path.join(currentFolder, folder);
48+
}
49+
TEST_PATH = path.join(folder, pkg.paths.testProjectFileName);
50+
TEST_WIDGETS_FOLDER = path.join(folder, "/widgets");
51+
TEST_WIDGETS_DEPLOYMENT_FOLDER = path.join(folder, "/deployment/web/widgets");
52+
}
53+
54+
module.exports = function (grunt) {
55+
grunt.initConfig({
56+
watch: {
57+
autoDeployUpdate: {
58+
"files": [ "./src/**/*" ],
59+
"tasks": [ "compress", "newer:copy" ],
60+
options: {
61+
debounceDelay: 250,
62+
livereload: true
63+
}
64+
}
65+
},
66+
compress: {
67+
makezip: {
68+
options: {
69+
archive: "./dist/MxTestProject/widgets/" + pkg.name + ".mpk",
70+
mode: "zip"
71+
},
72+
files: [{
73+
expand: true,
74+
date: new Date(),
75+
store: false,
76+
cwd: "./src",
77+
src: ["**/*"]
78+
}]
79+
}
80+
},
81+
copy: {
82+
deployment: {
83+
files: [
84+
{ dest: TEST_WIDGETS_DEPLOYMENT_FOLDER, cwd: "./src/", src: ["**/*"], expand: true }
85+
]
86+
},
87+
mpks: {
88+
files: [
89+
{ dest: TEST_WIDGETS_FOLDER, cwd: "./dist/", src: [ pkg.name + ".mpk"], expand: true }
90+
]
91+
}
92+
},
93+
clean: {
94+
build: [
95+
path.join(currentFolder, "dist", pkg.name, "/*")
96+
]
97+
},
98+
csslint: {
99+
strict: {
100+
options: {
101+
import: 2
102+
},
103+
src: ["src/" + pkg.name + "/widget/ui/*.css"]
104+
}
105+
}
106+
});
107+
108+
grunt.loadNpmTasks("grunt-contrib-compress");
109+
grunt.loadNpmTasks("grunt-contrib-clean");
110+
grunt.loadNpmTasks("grunt-contrib-watch");
111+
grunt.loadNpmTasks("grunt-contrib-copy");
112+
grunt.loadNpmTasks("grunt-newer");
113+
grunt.loadNpmTasks("grunt-contrib-csslint");
114+
115+
grunt.registerTask("start-modeler", function () {
116+
var done = this.async();
117+
if (MODELER_PATH !== null || (mendixApp.err === null && mendixApp.output !== null && mendixApp.output.cmd && mendixApp.output.arg)) {
118+
grunt.util.spawn({
119+
cmd: MODELER_PATH || mendixApp.output.cmd,
120+
args: [
121+
(MODELER_PATH !== null ? MODELER_ARGS : mendixApp.output.arg).replace("{path}", TEST_PATH)
122+
]
123+
}, function () {
124+
done();
125+
});
126+
} else {
127+
console.error("Cannot start Modeler, see error:");
128+
console.log(mendixApp.err);
129+
done();
130+
}
131+
});
132+
133+
grunt.registerTask("version", function (version) {
134+
var done = this.async();
135+
if (!grunt.file.exists(PACKAGE_XML)) {
136+
grunt.log.error("Cannot find " + PACKAGE_XML);
137+
return done();
138+
}
139+
140+
var xml = grunt.file.read(PACKAGE_XML);
141+
parser.parseString(xml, function (err, res) {
142+
if (err) {
143+
grunt.log.error(err);
144+
return done();
145+
}
146+
if (res.package.clientModule[0]["$"]["version"]) {
147+
var currentVersion = res.package.clientModule[0]["$"]["version"];
148+
if (!version) {
149+
grunt.log.writeln("\nCurrent version is " + currentVersion);
150+
grunt.log.writeln("Set new version by running 'grunt version:x.y.z'");
151+
done();
152+
} else {
153+
if (!semver.valid(version) || !semver.satisfies(version, ">= 1.0.0")) {
154+
grunt.log.error("\nPlease provide a valid version that is higher than 1.0.0. Current version: " + currentVersion);
155+
done();
156+
} else {
157+
res.package.clientModule[0]["$"]["version"] = version;
158+
pkg.version = version;
159+
var xmlString = builder.buildObject(res);
160+
grunt.file.write(PACKAGE_XML, xmlString);
161+
grunt.file.write("package.json", JSON.stringify(pkg, null, 2));
162+
done();
163+
}
164+
}
165+
} else {
166+
grunt.log.error("Cannot find current version number");
167+
}
168+
});
169+
170+
});
171+
172+
grunt.registerTask("generate-icon", function () {
173+
var iconPath = path.join(currentFolder, "/icon.png"),
174+
options = {localFile: true, string: true},
175+
done = this.async();
176+
177+
grunt.log.writeln("Processing icon");
178+
179+
if (!grunt.file.exists(iconPath) || !grunt.file.exists(WIDGET_XML)) {
180+
grunt.log.error("can\'t generate icon");
181+
return done();
182+
}
183+
184+
base64.base64encoder(iconPath, options, function (err, image) {
185+
if (!err) {
186+
var xmlOld = grunt.file.read(WIDGET_XML);
187+
parser.parseString(xmlOld, function (err, result) {
188+
if (!err) {
189+
if (result && result.widget && result.widget.icon) {
190+
result.widget.icon[0] = image;
191+
}
192+
var xmlString = builder.buildObject(result);
193+
grunt.file.write(WIDGET_XML, xmlString);
194+
done();
195+
}
196+
});
197+
} else {
198+
grunt.log.error("can\'t generate icon");
199+
return done();
200+
}
201+
});
202+
});
203+
204+
grunt.registerTask("folders", function () {
205+
var done = this.async();
206+
grunt.log.writeln("\nShowing file paths that Grunt will use. You can edit the package.json accordingly\n");
207+
grunt.log.writeln("TEST_PATH: ", TEST_PATH);
208+
grunt.log.writeln("WIDGET_XML: ", WIDGET_XML);
209+
grunt.log.writeln("PACKAGE_XML: ", PACKAGE_XML);
210+
grunt.log.writeln("TEST_WIDGETS_FOLDER: ", TEST_WIDGETS_FOLDER);
211+
grunt.log.writeln("TEST_WIDGETS_DEPLOYMENT_FOLDER: ", TEST_WIDGETS_DEPLOYMENT_FOLDER);
212+
return done();
213+
});
214+
215+
grunt.registerTask("start-mendix", [ "start-modeler" ]);
216+
217+
grunt.registerTask(
218+
"default",
219+
"Watches for changes and automatically creates an MPK file, as well as copying the changes to your deployment folder",
220+
[ "clean build", "watch" ]
221+
);
222+
223+
grunt.registerTask(
224+
"clean build",
225+
"Compiles all the assets and copies the files to the build directory.",
226+
[ "clean", "compress", "copy" ]
227+
);
228+
229+
grunt.registerTask(
230+
"build",
231+
[ "clean build" ]
232+
);
233+
};

0 commit comments

Comments
 (0)