Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ShowByCondition/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
test/javasource/
test/deployment/
test/.classpath
test/.project
test/theme/
test/userlib/
test/.classpath
test/.project
*.launch
*.tmp
*.lock
.idea/

dist/

node_modules/
.editorconfig
*DS_Store*
.vscode/
*.bak
23 changes: 23 additions & 0 deletions ShowByCondition/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// Enforcing
"curly" : false,
"forin" : false,
"latedef" : "nofunc",
"newcap" : true,
"quotmark" : "double",
"eqeqeq" : true,
"undef" : true,
"globals" : {
"mendix" : false,
"mx" : false,
"logger" : false
},

// Relaxing
"laxbreak" : true,

// Environments
"browser" : true,
"devel" : true,
"dojo" : true
}
233 changes: 233 additions & 0 deletions ShowByCondition/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
// Generated on 2016-10-22 using generator-mendix 1.3.7 :: git+https://github.com/mendix/generator-mendix.git
/*jshint -W069*/
/*global module*/
"use strict";

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

/********************************************************************************
* Do not edit anything below, unless you know what you are doing
********************************************************************************/

var path = require("path"),
mendixApp = require("node-mendix-modeler-path"),
base64 = require("node-base64-image"),
semver = require("semver"),
xml2js = require("xml2js"),
parser = new xml2js.Parser(),
builder = new xml2js.Builder({
renderOpts: { pretty: true, indent: " ", newline: "\n" },
xmldec: { standalone: null, encoding: "utf-8" }
}),
shelljs = require("shelljs"),
pkg = require("./package.json"),
currentFolder = shelljs.pwd().toString();

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:
* "paths": {
* "testProjectFolder": "./test/",
* "testProjectFileName": "Test.mpr"
* },
* You can test it by running: `grunt folders`
**/

if (pkg.paths && pkg.paths.testProjectFolder && pkg.paths.testProjectFileName) {
var folder = pkg.paths.testProjectFolder;
if (folder.indexOf(".") === 0) {
folder = path.join(currentFolder, folder);
}
TEST_PATH = path.join(folder, pkg.paths.testProjectFileName);
TEST_WIDGETS_FOLDER = path.join(folder, "/widgets");
TEST_WIDGETS_DEPLOYMENT_FOLDER = path.join(folder, "/deployment/web/widgets");
}

module.exports = function (grunt) {
grunt.initConfig({
watch: {
autoDeployUpdate: {
"files": [ "./src/**/*" ],
"tasks": [ "compress", "newer:copy" ],
options: {
debounceDelay: 250,
livereload: true
}
}
},
compress: {
makezip: {
options: {
archive: "./dist/" + pkg.name + ".mpk",
mode: "zip"
},
files: [{
expand: true,
date: new Date(),
store: false,
cwd: "./src",
src: ["**/*"]
}]
}
},
copy: {
deployment: {
files: [
{ dest: TEST_WIDGETS_DEPLOYMENT_FOLDER, cwd: "./src/", src: ["**/*"], expand: true }
]
},
mpks: {
files: [
{ dest: TEST_WIDGETS_FOLDER, cwd: "./dist/", src: [ pkg.name + ".mpk"], expand: true }
]
}
},
clean: {
build: [
path.join(currentFolder, "dist", pkg.name, "/*")
]
},
csslint: {
strict: {
options: {
import: 2
},
src: ["src/" + pkg.name + "/widget/ui/*.css"]
}
}
});

grunt.loadNpmTasks("grunt-contrib-compress");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-newer");
grunt.loadNpmTasks("grunt-contrib-csslint");

grunt.registerTask("start-modeler", function () {
var done = this.async();
if (MODELER_PATH !== null || (mendixApp.err === null && mendixApp.output !== null && mendixApp.output.cmd && mendixApp.output.arg)) {
grunt.util.spawn({
cmd: MODELER_PATH || mendixApp.output.cmd,
args: [
(MODELER_PATH !== null ? MODELER_ARGS : mendixApp.output.arg).replace("{path}", TEST_PATH)
]
}, function () {
done();
});
} else {
console.error("Cannot start Modeler, see error:");
console.log(mendixApp.err);
done();
}
});

grunt.registerTask("version", function (version) {
var done = this.async();
if (!grunt.file.exists(PACKAGE_XML)) {
grunt.log.error("Cannot find " + PACKAGE_XML);
return done();
}

var xml = grunt.file.read(PACKAGE_XML);
parser.parseString(xml, function (err, res) {
if (err) {
grunt.log.error(err);
return done();
}
if (res.package.clientModule[0]["$"]["version"]) {
var currentVersion = res.package.clientModule[0]["$"]["version"];
if (!version) {
grunt.log.writeln("\nCurrent version is " + currentVersion);
grunt.log.writeln("Set new version by running 'grunt version:x.y.z'");
done();
} else {
if (!semver.valid(version) || !semver.satisfies(version, ">= 1.0.0")) {
grunt.log.error("\nPlease provide a valid version that is higher than 1.0.0. Current version: " + currentVersion);
done();
} else {
res.package.clientModule[0]["$"]["version"] = version;
pkg.version = version;
var xmlString = builder.buildObject(res);
grunt.file.write(PACKAGE_XML, xmlString);
grunt.file.write("package.json", JSON.stringify(pkg, null, 2));
done();
}
}
} else {
grunt.log.error("Cannot find current version number");
}
});

});

grunt.registerTask("generate-icon", function () {
var iconPath = path.join(currentFolder, "/icon.png"),
options = {localFile: true, string: true},
done = this.async();

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

if (!grunt.file.exists(iconPath) || !grunt.file.exists(WIDGET_XML)) {
grunt.log.error("can\'t generate icon");
return done();
}

base64.base64encoder(iconPath, options, function (err, image) {
if (!err) {
var xmlOld = grunt.file.read(WIDGET_XML);
parser.parseString(xmlOld, function (err, result) {
if (!err) {
if (result && result.widget && result.widget.icon) {
result.widget.icon[0] = image;
}
var xmlString = builder.buildObject(result);
grunt.file.write(WIDGET_XML, xmlString);
done();
}
});
} else {
grunt.log.error("can\'t generate icon");
return done();
}
});
});

grunt.registerTask("folders", function () {
var done = this.async();
grunt.log.writeln("\nShowing file paths that Grunt will use. You can edit the package.json accordingly\n");
grunt.log.writeln("TEST_PATH: ", TEST_PATH);
grunt.log.writeln("WIDGET_XML: ", WIDGET_XML);
grunt.log.writeln("PACKAGE_XML: ", PACKAGE_XML);
grunt.log.writeln("TEST_WIDGETS_FOLDER: ", TEST_WIDGETS_FOLDER);
grunt.log.writeln("TEST_WIDGETS_DEPLOYMENT_FOLDER: ", TEST_WIDGETS_DEPLOYMENT_FOLDER);
return done();
});

grunt.registerTask("start-mendix", [ "start-modeler" ]);

grunt.registerTask(
"default",
"Watches for changes and automatically creates an MPK file, as well as copying the changes to your deployment folder",
[ "watch" ]
);

grunt.registerTask(
"clean build",
"Compiles all the assets and copies the files to the build directory.",
[ "clean", "compress", "copy" ]
);

grunt.registerTask(
"build",
[ "clean build" ]
);
};
35 changes: 35 additions & 0 deletions ShowByCondition/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "ShowByCondition",
"version": "1.1.0",
"description": "",
"license": "",
"author": "",
"private": true,
"dependencies": {
},
"devDependencies": {
"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.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"
},
"engines": {
"node": ">=0.12.0"
},
"generatorVersion": "1.3.7",
"paths": {
"testProjectFolder": "./test/",
"testProjectFileName": "Test.mpr"
},
"scripts": {
"test": "grunt test"
}
}
Loading