Skip to content

Commit 730074c

Browse files
authored
Merge pull request #26 from mendix/es6-style
Es6 style
2 parents 6e06b13 + 8a5d011 commit 730074c

26 files changed

Lines changed: 26272 additions & 14786 deletions

.babelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"presets": [
3+
"stage-1",
4+
["env", {
5+
"modules": false
6+
}]
7+
],
8+
"plugins": [
9+
10+
]
11+
}

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
webpack.config.js
2+
Gulpfile.js
3+
build/**/*

.eslintrc

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"extends": ["eslint:recommended"],
3+
"env": {
4+
"amd": true,
5+
"browser": true
6+
},
7+
"plugins": [],
8+
"parserOptions": {
9+
"ecmaVersion": 8,
10+
"sourceType": "module",
11+
"ecmaFeatures": {
12+
"globalReturn": true
13+
}
14+
},
15+
"globals": {
16+
"mendix": true,
17+
"mx": true,
18+
"logger": true,
19+
"mxui": true,
20+
"config": true
21+
},
22+
"rules": {
23+
"comma-dangle": [1,"always-multiline"],
24+
"no-cond-assign": [2,"except-parens"],
25+
"no-console": 0,
26+
"no-constant-condition": 1,
27+
"no-control-regex": 1,
28+
"no-debugger": 2,
29+
"no-dupe-args": 2,
30+
"no-dupe-keys": 2,
31+
"no-duplicate-case": 2,
32+
"no-empty-character-class": 2,
33+
"no-empty": 1,
34+
"no-ex-assign": 2,
35+
"no-extra-boolean-cast": 1,
36+
"no-extra-parens": [1,"all"],
37+
"no-extra-semi": 1,
38+
"no-func-assign": 2,
39+
"no-inner-declarations": [2,"both"],
40+
"no-invalid-regexp": 2,
41+
"no-irregular-whitespace": 2,
42+
"no-obj-calls": 2,
43+
"no-regex-spaces": 1,
44+
"no-sparse-arrays": 2,
45+
"no-unreachable": 2,
46+
"use-isnan": 2,
47+
"valid-typeof": 2,
48+
"no-unexpected-multiline": 2,
49+
"accessor-pairs": [1,{"getWithoutSet":true,"setWithoutGet":true}],
50+
"block-scoped-var": 2,
51+
"consistent-return": 1,
52+
"curly": ["error", "all"],
53+
"default-case": 1,
54+
"dot-notation": 2,
55+
"dot-location": [1,"property"],
56+
"eqeqeq": [2,"smart"],
57+
"guard-for-in": 1,
58+
"no-alert": 2,
59+
"no-caller": 2,
60+
"no-div-regex": 2,
61+
"no-else-return": 1,
62+
"no-eq-null": 2,
63+
"no-eval": 2,
64+
"no-extend-native": 2,
65+
"no-extra-bind": 1,
66+
"no-fallthrough": 1,
67+
"no-floating-decimal": 2,
68+
"no-implied-eval": 2,
69+
"no-invalid-this": 1,
70+
"no-iterator": 1,
71+
"no-labels": 2,
72+
"no-lone-blocks": 2,
73+
"no-loop-func": 2,
74+
"no-multi-spaces": 1,
75+
"no-multi-str": 1,
76+
"no-native-reassign": 2,
77+
"no-new-func": 2,
78+
"no-new-wrappers": 2,
79+
"no-new": 1,
80+
"no-octal-escape": 2,
81+
"no-octal": 2,
82+
"no-param-reassign": [2,{"props":true}],
83+
"no-process-env": 0,
84+
"no-proto": 2,
85+
"no-redeclare": [2,{"builtinGlobals":true}],
86+
"no-return-assign": [2,"always"],
87+
"no-script-url": 2,
88+
"no-self-compare": 1,
89+
"no-sequences": 2,
90+
"no-throw-literal": 2,
91+
"no-useless-call": 2,
92+
"no-with": 2,
93+
"radix": 1,
94+
"wrap-iife": [2,"inside"],
95+
"yoda": [1,"always",{}],
96+
"strict": [1,"global"],
97+
"no-catch-shadow": 2,
98+
"no-delete-var": 2,
99+
"no-label-var": 2,
100+
"no-shadow-restricted-names": 2,
101+
"no-shadow": [2,{"builtinGlobals":true,"hoist":"all"}],
102+
"no-undef-init": 2,
103+
"no-undef": 2,
104+
"no-undefined": 2,
105+
"no-unused-vars": 2,
106+
"no-use-before-define": [2,"nofunc"],
107+
"brace-style": [1,"1tbs",{"allowSingleLine":true}],
108+
"camelcase": [1,{"properties":"always"}],
109+
"comma-spacing": [1,{"after":true}],
110+
"comma-style": 1,
111+
"computed-property-spacing": [2,"always"],
112+
"eol-last": 1,
113+
"indent": [1,4],
114+
"key-spacing": [1,{"mode":"minimum"}],
115+
"new-parens": 2,
116+
"no-lonely-if": 1,
117+
"no-mixed-spaces-and-tabs": [2,"smart-tabs"],
118+
"no-multiple-empty-lines": [1,{"max":4}],
119+
"no-new-object": 2,
120+
"no-spaced-func": 2,
121+
"no-trailing-spaces": 2,
122+
"no-unneeded-ternary": 1,
123+
"semi": [2,"always"],
124+
"space-infix-ops": 1,
125+
"arrow-parens": [2,"as-needed"],
126+
"arrow-spacing": [2,{"before":true,"after":true}],
127+
"constructor-super": 1,
128+
"no-class-assign": 2,
129+
"no-const-assign": 2,
130+
"no-this-before-super": 2,
131+
"no-var": 1,
132+
"prefer-const": 1,
133+
"prefer-spread": 2,
134+
"prefer-reflect": 0,
135+
"require-yield": 1,
136+
"max-len": [1,140,4,{}],
137+
"max-statements": [1,40]
138+
}
139+
}

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
build
2+
package-lock.json
3+
14
test/javasource/
25
test/deployment/
36
test/.classpath
@@ -11,8 +14,6 @@ test/.project
1114
*.lock
1215
.idea/
1316

14-
dist/
15-
1617
node_modules/
1718
.editorconfig
1819
*DS_Store*

.jshintrc

Lines changed: 0 additions & 23 deletions
This file was deleted.

Gulpfile.js

Lines changed: 102 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,117 @@
1-
// Generated on 2016-11-08 using generator-mendix 2.0.1 :: git+https://github.com/mendix/generator-mendix.git
2-
/*jshint -W069,-W097*/
3-
"use strict";
4-
5-
// In case you seem to have trouble starting Mendix through `gulp modeler`, you might have to set the path to the Mendix application, otherwise leave both values as they are
6-
var MODELER_PATH = null;
7-
var MODELER_ARGS = "/file:{path}";
8-
9-
/********************************************************************************
10-
* Do not edit anything below, unless you know what you are doing
11-
********************************************************************************/
12-
var gulp = require("gulp"),
13-
zip = require("gulp-zip"),
14-
del = require("del"),
15-
newer = require("gulp-newer"),
16-
gutil = require("gulp-util"),
17-
gulpif = require("gulp-if"),
18-
jsonTransform = require("gulp-json-transform"),
19-
intercept = require("gulp-intercept"),
20-
argv = require("yargs").argv,
21-
widgetBuilderHelper = require("widgetbuilder-gulp-helper");
22-
23-
var pkg = require("./package.json"),
24-
paths = widgetBuilderHelper.generatePaths(pkg),
25-
xmlversion = widgetBuilderHelper.xmlversion;
26-
27-
gulp.task("default", function() {
28-
gulp.watch("./src/**/*", ["compress"]);
29-
gulp.watch("./src/**/*.js", ["copy:js"]);
30-
gulp.watch("./src/**/*.html", ["copy:html"]);
31-
});
1+
const path = require('path');
2+
const fs = require('fs-extra');
3+
const gulp = require('gulp-help')(require('gulp'));
4+
const gutil = require('gulp-util');
5+
const webpack = require('webpack');
6+
const watch = require('gulp-watch');
7+
const gulpCopy = require('gulp-copy');
8+
const sequence = require('gulp-sequence');
9+
const del = require('del');
3210

33-
gulp.task("clean", function () {
34-
return del([
35-
paths.WIDGET_TEST_DEST,
36-
paths.WIDGET_DIST_DEST
37-
], { force: true });
38-
});
11+
const banner = (color, banner) => gutil.colors[color || 'cyan'](banner ? `[${banner}]` : '[GULP]');
3912

40-
gulp.task("compress", ["clean"], function () {
41-
return gulp.src("src/**/*")
42-
.pipe(zip(pkg.name + ".mpk"))
43-
.pipe(gulp.dest(paths.TEST_WIDGETS_FOLDER))
44-
.pipe(gulp.dest("dist"));
45-
});
13+
const pkg = require('./package.json');
4614

47-
gulp.task("copy:js", function () {
48-
return gulp.src(["./src/**/*.js"])
49-
.pipe(newer(paths.TEST_WIDGETS_DEPLOYMENT_FOLDER))
50-
.pipe(gulp.dest(paths.TEST_WIDGETS_DEPLOYMENT_FOLDER));
51-
});
15+
// Set paths for our project folder
5216

53-
gulp.task("copy:html", function () {
54-
return gulp.src(["./src/**/*.html"])
55-
.pipe(newer(paths.TEST_WIDGETS_DEPLOYMENT_FOLDER))
56-
.pipe(gulp.dest(paths.TEST_WIDGETS_DEPLOYMENT_FOLDER));
57-
});
17+
const projectPath = pkg.widget.path ? path.resolve(pkg.widget.path) + '/' : false;
18+
const widgetsFolder = projectPath ? path.join(projectPath, `/widgets/`) : false;
19+
const deploymentFolder = projectPath ? path.join(projectPath, `/deployment/web/widgets/`) : false;
20+
21+
// Check if project folder exists and is accessible
22+
23+
let stat = null;
24+
if (!projectPath) {
25+
gutil.log(`${banner()} No testproject defined, only copying files to dist/build folder. Set project path in ${gutil.colors.cyan('widget.path')} in ${gutil.colors.magenta('package.json')}`);
26+
} else {
27+
gutil.log(`${banner()} Testproject defined: ${gutil.colors.magenta(projectPath)}`);
28+
try {
29+
stat = projectPath ? fs.statSync(projectPath) : null;
30+
} catch (e) {
31+
gutil.log(`${banner('red')} Error getting project directory:`, e.toString());
32+
gutil.log(`${banner('red')} Copying to the project directory has been disabled`);
33+
stat = null;
34+
}
35+
}
36+
37+
// Helper functions
5838

59-
gulp.task("version:xml", function () {
60-
return gulp.src(paths.PACKAGE_XML)
61-
.pipe(xmlversion(argv.n))
62-
.pipe(gulp.dest("./src/"));
39+
const runWebpack = callback => {
40+
webpack(require('./webpack.config.js'), function (err, stats) {
41+
if (err) throw new gutil.PluginError("webpack", err);
42+
gutil.log(banner('cyan', 'WEBPACK'), stats.toString({
43+
colors: true,
44+
modules: false
45+
}));
46+
callback && callback();
47+
});
48+
};
49+
50+
const copyFile = paths => {
51+
try {
52+
fs.copySync(paths.src, paths.dest);
53+
} catch (err) {
54+
gutil.log(`${banner('red')} Copy fail`, err);
55+
}
56+
};
57+
58+
const getPaths = (file, srcFolder, destFolder) => {
59+
return {
60+
src: path.join(__dirname, srcFolder, file.relative),
61+
dest: path.join(destFolder, file.relative),
62+
}
63+
}
64+
65+
// Base tasks
66+
67+
gulp.task('watch:src', () => {
68+
return watch('src/**/*', {
69+
verbose: true
70+
}, () => {
71+
runWebpack();
72+
})
6373
});
6474

65-
gulp.task("version:json", function () {
66-
return gulp.src("./package.json")
67-
.pipe(gulpif(typeof argv.n !== "undefined", jsonTransform(function(data) {
68-
data.version = argv.n;
69-
return data;
70-
}, 2)))
71-
.pipe(gulp.dest("./"));
75+
gulp.task('watch:build', () => {
76+
return watch('build/**/*', {
77+
verbose: stat !== null,
78+
read: false
79+
}, file => {
80+
if (stat !== null) {
81+
const paths = getPaths(file, 'build', deploymentFolder);
82+
if (paths.src.indexOf('package.xml') !== -1) {
83+
return;
84+
}
85+
copyFile(paths);
86+
}
87+
})
7288
});
7389

74-
gulp.task("icon", function (cb) {
75-
var icon = (typeof argv.file !== "undefined") ? argv.file : "./icon.png";
76-
console.log("\nUsing this file to create a base64 string: " + gutil.colors.cyan(icon));
77-
gulp.src(icon)
78-
.pipe(intercept(function (file) {
79-
console.log("\nCopy the following to your " + pkg.name + ".xml (after description):\n\n" + gutil.colors.cyan("<icon>") + file.contents.toString("base64") + gutil.colors.cyan("<\\icon>") + "\n");
80-
cb();
81-
}));
90+
gulp.task('watch:dist', () => {
91+
return watch(`dist/${pkg.widget.package}.mpk`, {
92+
verbose: stat !== null,
93+
read: false
94+
}, file => {
95+
if (stat !== null) {
96+
const paths = getPaths(file, 'dist', widgetsFolder);
97+
copyFile(paths);
98+
}
99+
})
82100
});
83101

84-
gulp.task("folders", function () {
85-
paths.showPaths(); return;
102+
gulp.task('clean', `Cleanup the dist/build`, () => {
103+
return del([
104+
'dist',
105+
'build'
106+
], { force: true });
86107
});
87108

88-
gulp.task("modeler", function (cb) {
89-
widgetBuilderHelper.runmodeler(MODELER_PATH, MODELER_ARGS, paths.TEST_PATH, cb);
109+
// Final tasks
110+
111+
gulp.task('build', 'Build the widget', done => {
112+
sequence('clean', 'build-dist', done);
90113
});
91114

92-
gulp.task("build", ["compress"]);
93-
gulp.task("version", ["version:xml", "version:json"]);
115+
gulp.task('build-dist', callback => { runWebpack(callback); });
116+
117+
gulp.task('default', ['watch:src', 'watch:build', 'watch:dist']);

0 commit comments

Comments
 (0)