Skip to content

Commit 164936c

Browse files
author
JelteMX
committed
Add folders task, add package.json paths && update parsing old package.json
1 parent 205253c commit 164936c

File tree

4 files changed

+100
-42
lines changed

4 files changed

+100
-42
lines changed

generators/app/index.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ module.exports = yeoman.generators.Base.extend({
4242
if (srcFolderContent.length === 1) {
4343
this.current.name = srcFolderContent[0];
4444
}
45+
if (!extfs.isEmptySync(this.destinationPath('package.json'))) {
46+
try {
47+
var destPkg = JSON.parse(fs.readFileSync(this.destinationPath('package.json')).toString());
48+
this.current.description = destPkg.description;
49+
this.current.author = destPkg.author;
50+
this.current.copyright = destPkg.copyright;
51+
this.current.license = destPkg.license;
52+
this.current.repository = destPkg.repository ? JSON.stringify(destPkg.repository) : false;
53+
} catch (e) {}
54+
}
4555
if (!extfs.isEmptySync(this.destinationPath('src/package.xml'))) {
4656
this.isNew = false;
4757
var pkgXml = fs.readFileSync(this.destinationPath('src/package.xml')).toString();
@@ -51,7 +61,11 @@ module.exports = yeoman.generators.Base.extend({
5161
process.exit(0);
5262
}
5363
if (result.package.clientModule[0]["$"]["version"]) {
54-
this.current.version = result.package.clientModule[0]["$"]["version"];
64+
var version = result.package.clientModule[0]["$"]["version"];
65+
if (version.split(".").length === 2) {
66+
version += ".0";
67+
}
68+
this.current.version = version;
5569
}
5670
done();
5771
}.bind(this));
@@ -91,7 +105,7 @@ module.exports = yeoman.generators.Base.extend({
91105
type: 'input',
92106
name: 'copyright',
93107
message: 'Add a copyright',
94-
default: '<Your Company> 2015',
108+
default: '<Your Company> 2016',
95109
store: true
96110
},{
97111
type: 'input',
@@ -187,21 +201,21 @@ module.exports = yeoman.generators.Base.extend({
187201
this.widget = {};
188202
this.widget.widgetName = this.props.widgetName;
189203
this.widget.packageName = this.props.widgetName;
190-
this.widget.description = this.props.description;
204+
this.widget.description = this.props.description || this.current.description;
191205
this.widget.version = this.props.version;
192-
this.widget.author = this.props.author;
206+
this.widget.author = this.props.author || this.current.author;
193207
this.widget.date = (new Date()).toLocaleDateString();
194-
this.widget.copyright = this.props.copyright;
195-
this.widget.license = this.props.license;
208+
this.widget.copyright = this.props.copyright || this.current.copyright;
209+
this.widget.license = this.props.license || this.current.license;
210+
this.widget.generatorVersion = pkg.version;
196211
this.widget.github = (this.props.github !== '<none>' && typeof this.props.github !== 'undefined') ? '"http://github.com/' + this.props.github + '/' + this.widget.widgetName + '"' : false;
212+
this.widget.repository = this.current.repository || false;
197213

198214
// Using grunt (future version will include Gulp)
199215
this.widget.builder = 'grunt';
200216

201217
if (this.isNew) {
202218
// Copy generic files
203-
this.fs.copy(this.templatePath(boilerPlatePath + '.jshintrc'), this.destinationPath('.jshintrc'));
204-
this.fs.copy(this.templatePath('_gitignore'), this.destinationPath('.gitignore'));
205219
this.fs.copy(this.templatePath('icon.png'), this.destinationPath('icon.png'));
206220
this.fs.copy(this.templatePath(boilerPlatePath + 'assets/app_store_banner.png'), this.destinationPath('assets/app_store_banner.png'));
207221
this.fs.copy(this.templatePath(boilerPlatePath + 'assets/app_store_icon.png'), this.destinationPath('assets/app_store_icon.png'));
@@ -278,6 +292,12 @@ module.exports = yeoman.generators.Base.extend({
278292
);
279293
}
280294

295+
// Gitignore
296+
this.fs.copy(this.templatePath('_gitignore'), this.destinationPath('.gitignore'));
297+
298+
// jshint
299+
this.fs.copy(this.templatePath(boilerPlatePath + '.jshintrc'), this.destinationPath('.jshintrc'));
300+
281301
// Package.JSON
282302
this.template('_package.json', 'package.json', this.widget, {});
283303

generators/app/templates/Gruntfile.js

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
// Generated on <%= (new Date).toISOString().split('T')[0] %> using <%= pkg.name %> <%= pkg.version %> :: http://github.com/<%= pkg.repository.url %>
1+
// Generated on <%= (new Date).toISOString().split('T')[0] %> using <%= pkg.name %> <%= pkg.version %> :: <%= pkg.repository.url %>
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,20 @@ 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, "/*"),
95+
path.join(TEST_WIDGETS_DEPLOYMENT_FOLDER, pkg.name, "/*"),
96+
path.join(TEST_WIDGETS_FOLDER, pkg.name + ".mpk")
7697
]
7798
}
7899
});
@@ -84,14 +105,12 @@ module.exports = function (grunt) {
84105
grunt.loadNpmTasks("grunt-newer");
85106

86107
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-
108+
var done = this.async();
90109
if (MODELER_PATH !== null || (mendixApp.err === null && mendixApp.output !== null && mendixApp.output.cmd && mendixApp.output.arg)) {
91110
grunt.util.spawn({
92111
cmd: MODELER_PATH || mendixApp.output.cmd,
93112
args: [
94-
(MODELER_PATH !== null ? MODELER_ARGS : mendixApp.output.arg).replace("{path}", testProjectPath)
113+
(MODELER_PATH !== null ? MODELER_ARGS : mendixApp.output.arg).replace("{path}", TEST_PATH)
95114
]
96115
}, function () {
97116
done();
@@ -105,12 +124,12 @@ module.exports = function (grunt) {
105124

106125
grunt.registerTask("version", function (version) {
107126
var done = this.async();
108-
if (!grunt.file.exists(packageXml)) {
109-
grunt.log.error("Cannot find " + packageXml);
127+
if (!grunt.file.exists(PACKAGE_XML)) {
128+
grunt.log.error("Cannot find " + PACKAGE_XML);
110129
return done();
111130
}
112131

113-
var xml = grunt.file.read(packageXml);
132+
var xml = grunt.file.read(PACKAGE_XML);
114133
parser.parseString(xml, function (err, res) {
115134
if (err) {
116135
grunt.log.error(err);
@@ -130,7 +149,7 @@ module.exports = function (grunt) {
130149
res.package.clientModule[0]["$"]["version"] = version;
131150
pkg.version = version;
132151
var xmlString = builder.buildObject(res);
133-
grunt.file.write(packageXml, xmlString);
152+
grunt.file.write(PACKAGE_XML, xmlString);
134153
grunt.file.write("package.json", JSON.stringify(pkg, null, 2));
135154
done();
136155
}
@@ -149,21 +168,21 @@ module.exports = function (grunt) {
149168

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

152-
if (!grunt.file.exists(iconPath) || !grunt.file.exists(widgetXml)) {
171+
if (!grunt.file.exists(iconPath) || !grunt.file.exists(WIDGET_XML)) {
153172
grunt.log.error("can\'t generate icon");
154173
return done();
155174
}
156175

157176
base64.base64encoder(iconPath, options, function (err, image) {
158177
if (!err) {
159-
var xmlOld = grunt.file.read(widgetXml);
178+
var xmlOld = grunt.file.read(WIDGET_XML);
160179
parser.parseString(xmlOld, function (err, result) {
161180
if (!err) {
162181
if (result && result.widget && result.widget.icon) {
163182
result.widget.icon[0] = image;
164183
}
165184
var xmlString = builder.buildObject(result);
166-
grunt.file.write(widgetXml, xmlString);
185+
grunt.file.write(WIDGET_XML, xmlString);
167186
done();
168187
}
169188
});
@@ -174,6 +193,17 @@ module.exports = function (grunt) {
174193
});
175194
});
176195

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

179209
grunt.registerTask(

generators/app/templates/_package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"name": "<%= widgetName %>",
33
"version": "<%= version %>",
44
"description": "<%= description %>",
5+
"license": "<%= license %>",
6+
"author": "<%= author %>",
57
"private": true,
68
"dependencies": {
79
},
@@ -21,10 +23,16 @@
2123
"repository": {
2224
"type": "git",
2325
"url": <%= github %>
24-
},<% } %>
26+
},<% } %><% if (repository) { %>
27+
"repository": <%= repository %>,<% } %>
2528
"engines": {
2629
"node": ">=0.12.0"
2730
},
31+
"generatorVersion": "<%= generatorVersion %>",
32+
"paths": {
33+
"testProjectFolder": "./test/",
34+
"testProjectFileName": "Test.mpr"
35+
},
2836
"scripts": {<% if (builder == 'grunt') { %>
2937
"test": "grunt test"<% } if (builder == 'gulp') { %>
3038
<% } %>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generator-mendix",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Mendix Widget generator",
55
"license": "MIT",
66
"main": "app/index.js",

0 commit comments

Comments
 (0)