|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// In case you seem to have trouble starting Mendix through `grunt start-mendix`, you might have to set the path to the Mendix application. |
| 4 | +// If it works, leave MODELER_PATH at null |
| 5 | +var MODELER_PATH = null; |
| 6 | +var MODELER_ARGS = '/file:{path}'; |
| 7 | + |
| 8 | +var path = require('path'), |
| 9 | + mendixApp = require('node-mendix-modeler-path'), |
| 10 | + shelljs = require('shelljs'); |
| 11 | + |
| 12 | +// 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 |
| 13 | +var TEST_PATH = path.join(shelljs.pwd(), './test/Test.mpr'); |
| 14 | + |
| 15 | +module.exports = function (grunt) { |
| 16 | + var pkg = grunt.file.readJSON("package.json"); |
| 17 | + grunt.verbose; |
| 18 | + grunt.initConfig({ |
| 19 | + watch: { |
| 20 | + autoDeployUpdate: { |
| 21 | + "files": [ "./src/**/*" ], |
| 22 | + "tasks": [ "newer:copy", "compress" ], |
| 23 | + options: { |
| 24 | + debounceDelay: 250, |
| 25 | + livereload: true |
| 26 | + } |
| 27 | + } |
| 28 | + }, |
| 29 | + compress: { |
| 30 | + makezip: { |
| 31 | + options: { |
| 32 | + archive: "./dist/" + pkg.name + ".mpk", |
| 33 | + mode: "zip" |
| 34 | + }, |
| 35 | + files: [{ |
| 36 | + expand: true, |
| 37 | + date: new Date(), |
| 38 | + store: false, |
| 39 | + cwd: "./src", |
| 40 | + src: ["**/*"] |
| 41 | + }] |
| 42 | + } |
| 43 | + }, |
| 44 | + copy: { |
| 45 | + deployment: { |
| 46 | + files: [ |
| 47 | + { dest: "./test/deployment/web/widgets", cwd: "./src/", src: ["**/*"], expand: true } |
| 48 | + ] |
| 49 | + }, |
| 50 | + mpks: { |
| 51 | + files: [ |
| 52 | + { dest: "./test/widgets", cwd: "./dist/", src: [ pkg.name + ".mpk"], expand: true } |
| 53 | + ] |
| 54 | + } |
| 55 | + }, |
| 56 | + clean: { |
| 57 | + build: [ |
| 58 | + "./dist/" + pkg.name + "/*", |
| 59 | + "./test/deployment/web/widgets/" + pkg.name + "/*", |
| 60 | + "./test/widgets/" + pkg.name + ".mpk" |
| 61 | + ] |
| 62 | + } |
| 63 | + }); |
| 64 | + |
| 65 | + grunt.loadNpmTasks("grunt-contrib-compress"); |
| 66 | + grunt.loadNpmTasks("grunt-contrib-clean"); |
| 67 | + grunt.loadNpmTasks("grunt-contrib-watch"); |
| 68 | + grunt.loadNpmTasks("grunt-contrib-copy"); |
| 69 | + grunt.loadNpmTasks("grunt-newer"); |
| 70 | + |
| 71 | + grunt.registerTask("start-modeler", function () { |
| 72 | + var done = this.async(), |
| 73 | + testProjectPath = TEST_PATH !== null ? TEST_PATH : path.join(shelljs.pwd(), '/test/Test.mpr'); |
| 74 | + |
| 75 | + if (MODELER_PATH !== null || (mendixApp.err === null && mendixApp.output !== null && mendixApp.output.cmd && mendixApp.output.arg)) { |
| 76 | + grunt.util.spawn({ |
| 77 | + cmd: MODELER_PATH || mendixApp.output.cmd, |
| 78 | + args: [ |
| 79 | + (MODELER_PATH !== null ? MODELER_ARGS : mendixApp.output.arg).replace('{path}', testProjectPath) |
| 80 | + ] |
| 81 | + }, function () { |
| 82 | + done(); |
| 83 | + }); |
| 84 | + } else { |
| 85 | + console.error('Cannot start Modeler, see error:'); |
| 86 | + console.log(mendixApp.err); |
| 87 | + done(); |
| 88 | + } |
| 89 | + }); |
| 90 | + |
| 91 | + grunt.registerTask( |
| 92 | + "default", |
| 93 | + "Watches for changes and automatically creates an MPK file, as well as copying the changes to your deployment folder", |
| 94 | + [ "watch" ] |
| 95 | + ); |
| 96 | + |
| 97 | + grunt.registerTask( |
| 98 | + "clean build", |
| 99 | + "Compiles all the assets and copies the files to the build directory.", |
| 100 | + [ "clean", "compress", "copy" ] |
| 101 | + ); |
| 102 | + |
| 103 | + grunt.registerTask( |
| 104 | + "build", |
| 105 | + [ "clean build" ] |
| 106 | + ); |
| 107 | +}; |
0 commit comments